]>
git.ipfire.org Git - oddments/fireinfo.git/blob - sendprofile
5 import logging
.handlers
13 ENABLED_FILE
= "/var/ipfire/main/send_profile"
15 log_level
= logging
.INFO
17 log_level
= logging
.DEBUG
20 log
= logging
.getLogger()
21 log
.setLevel(log_level
)
22 log
.addHandler(logging
.handlers
.SysLogHandler("/dev/log"))
23 log
.addHandler(logging
.StreamHandler(sys
.stderr
))
24 for handler
in log
.handlers
:
25 handler
.setLevel(log_level
)
27 PROFILE_URL
= "http://stasy.ipfire.org/send/%(public_id)s"
29 def send_profile(profile
):
30 logging
.debug("Sending profile:")
31 for line
in json
.dumps(profile
, sort_keys
=True, indent
=4).splitlines():
35 request
= urllib2
.Request(PROFILE_URL
% profile
,
36 data
= urllib
.urlencode({"profile" : json
.dumps(profile
)}),
38 urllib2
.urlopen(request
, timeout
=60)
39 except (urllib2
.HTTPError
, urllib2
.URLError
), e
:
40 reason
= "Unknown reason"
42 if isinstance(e
, urllib2
.HTTPError
):
44 elif isinstance(e
, urllib2
.URLError
):
47 logging
.error("Profile was not sent propertly: %s" % reason
)
50 logging
.debug("Profile was sent successfully.")
53 logging
.info("%s was started." % sys
.argv
[0])
55 # Collect system information
56 system
= fireinfo
.System()
57 profile
= system
.profile()
59 # If --dump is passed -> only dump the output.
60 if "--dump" in sys
.argv
:
61 print json
.dumps(profile
, sort_keys
=True, indent
=4)
64 if not os
.path
.exists(ENABLED_FILE
):
65 del profile
["profile"]
69 except urllib2
.URLError
: