implement ZVEI in BosMon-plugin

This commit is contained in:
JHCD 2015-05-22 23:46:54 +02:00
parent 096ba7e6b6
commit 01bec5df35

View file

@ -11,12 +11,16 @@ from includes import globals # Global variables
def bosMonRequest(httprequest, params, headers):
httprequest.request("POST", "/telegramin/"+globals.config.get("BosMon", "bosmon_channel")+"/input.xml", params, headers)
httpresponse = httprequest.getresponse()
if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error
logging.debug("BosMon response: %s - %s", str(httpresponse.status), str(httpresponse.reason))
else:
logging.warning("BosMon response: %s - %s", str(httpresponse.status), str(httpresponse.reason))
try:
httprequest.request("POST", "/telegramin/"+globals.config.get("BosMon", "bosmon_channel")+"/input.xml", params, headers)
except:
logging.exception("request to BosMon failed")
else:
httpresponse = httprequest.getresponse()
if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error
logging.debug("BosMon response: %s - %s", str(httpresponse.status), str(httpresponse.reason))
else:
logging.warning("BosMon response: %s - %s", str(httpresponse.status), str(httpresponse.reason))
def run(typ,freq,data):
@ -38,15 +42,32 @@ def run(typ,freq,data):
headers['Authorization'] = "Basic {0}".format(base64.b64encode("{0}:{1}".format(globals.config.get("BosMon", "bosmon_user"), globals.config.get("BosMon", "bosmon_password"))))
logging.debug("connect to BosMon")
httprequest = httplib.HTTPConnection(globals.config.get("BosMon", "bosmon_server"), globals.config.get("BosMon", "bosmon_port"))
#debug-level to shell (0=no debug|1)
httprequest.set_debuglevel(1)
except:
logging.exception("cannot connect to BosMon")
else:
if typ == "FMS":
logging.warning("%s not supported", typ)
#logging.debug("Start FMS to BosMon")
#try:
#BosMon-Telegramin expected assembly group, direction and tsi in one field
#structure:
#params = urllib.urlencode({'type':'fms', 'address':data["fms"], 'status':data["status"], 'info':'0', 'flags':'0'})
#logging.debug(" - Params: %s", params)
#bosMonRequest(httprequest, params, headers)
#except:
#logging.error("FMS to BosMon failed")
elif typ == "ZVEI":
logging.warning("%s not supported", typ)
logging.debug("Start ZVEI to BosMon")
try:
params = urllib.urlencode({'type':'zvei', 'address':data["zvei"], 'flags':'0'})
logging.debug(" - Params: %s", params)
bosMonRequest(httprequest, params, headers)
except:
logging.error("ZVEI to BosMon failed")
elif typ == "POC":
logging.debug("Start POC to BosMon")