]>
git.ipfire.org Git - oddments/fireinfo.git/blob - sendprofile
5 import logging
.handlers
12 log_level
= logging
.DEBUG
15 log
= logging
.getLogger()
16 log
.setLevel(log_level
)
17 log
.addHandler(logging
.handlers
.SysLogHandler("/dev/log"))
18 log
.addHandler(logging
.StreamHandler(sys
.stdout
))
19 for handler
in log
.handlers
:
20 handler
.setLevel(log_level
)
22 PROFILE_URL
= "http://stasy.ipfire.org/send/%(public_id)s"
24 def send_profile(profile
):
25 logging
.debug("Sending profile:")
26 for line
in json
.dumps(profile
, sort_keys
=True, indent
=4).splitlines():
30 request
= urllib2
.Request(PROFILE_URL
% profile
,
31 data
= urllib
.urlencode({"profile" : json
.dumps(profile
)}),
33 urllib2
.urlopen(request
, timeout
=60)
34 except (urllib2
.HTTPError
, urllib2
.URLError
), e
:
35 reason
= "Unknown reason"
37 if isinstance(e
, urllib2
.HTTPError
):
39 elif isinstance(e
, urllib2
.URLError
):
42 logging
.error("Profile was not sent propertly: %s" % reason
)
45 logging
.debug("Profile was sent successfully.")
48 logging
.info("%s was started." % sys
.argv
[0])
50 # Collect system information
51 system
= fireinfo
.System()
53 send_profile(system
.profile())
54 except urllib2
.URLError
: