-
Notifications
You must be signed in to change notification settings - Fork 0
/
reporting.py
45 lines (41 loc) · 2.2 KB
/
reporting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from argumentHandler import *
from urllib2 import *
import urllib, hmac, hashlib, ssl
errorReportFailed,signature=0,config.signature
def httpGet(url, sign = True):
try:
if sign:
global signature
signature=hmac.new(config.privatekey, signature, hashlib.sha512).hexdigest()
url+='&signature='+signature
print '<', url
req=Request(url)
req.add_header("Authorization", "Basic %s" % (base64.b64encode(config.username+":"+config.password)))
# resp=urlopen(req, cafile="../certificate/rootCA.pem")
resp=urlopen(req, context=ssl._create_unverified_context()) # FIXME: Re-enable certificate validation
str=resp.read()
print '> ', str
resp.close()
return True
except URLError as error:
print 'URLError', error, 'requesting', url
return False
def sendAlive(company, ship, controller, instance, day, ms):
if not errorReportFailed:
url=config.remotescheme+'://'+config.remotehost+':'+config.remoteport+'/Alive?company='+str(company)+'&ship='+str(ship)+'&controller='+str(controller)+'&instance='+str(instance)+'&day='+str(day)+'&ms='+str(ms)
if not httpGet(url):
sendError(company, ship, controller, instance, "One or more alive-reports failed")
else:
sendError(company, ship, controller, instance, "One or more error-reports failed")
def sendReset(company, ship, controller, instance):
if not errorReportFailed:
url=config.remotescheme+'://'+config.remotehost+':'+config.remoteport+'/Reset?company='+str(company)+'&ship='+str(ship)+'&controller='+str(controller)+'&instance='+str(instance)
if not httpGet(url):
sendError(company, ship, controller, instance, "Unable to reset")
else:
sendError(company, ship, controller, instance, "One or more error-reports failed")
def sendError(company, ship, controller, instance, error):
global errorReportFailed
errorReportFailed=True
url=config.remotescheme+'://'+config.remotehost+':'+config.remoteport+'/Alert?company='+str(company)+'&ship='+str(ship)+'&controller='+str(controller)+'&instance='+str(instance)+'&error='+urllib.quote_plus(error)
errorReportFailed=not httpGet(url)