2015-05-18 21:04:10 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
# -*- coding: cp1252 -*-
|
|
|
|
|
|
|
|
|
|
import logging # Global logger
|
|
|
|
|
import globals # Global variables
|
|
|
|
|
|
|
|
|
|
import httplib #for the HTTP request
|
|
|
|
|
import urllib #for the HTTP request with parameters
|
|
|
|
|
import base64 #for the HTTP request with User/Password
|
2015-05-18 16:05:34 +02:00
|
|
|
|
2015-05-18 21:49:03 +02:00
|
|
|
def run(typ,freq,data):
|
2015-05-18 21:04:10 +02:00
|
|
|
try:
|
|
|
|
|
#get BosMon-Config
|
2015-05-19 12:01:01 +02:00
|
|
|
logging.debug("read config file")
|
2015-05-18 21:04:10 +02:00
|
|
|
bosmon_server = globals.config.get("BosMon", "bosmon_server")
|
|
|
|
|
bosmon_port = globals.config.get("BosMon", "bosmon_port")
|
|
|
|
|
bosmon_user = globals.config.get("BosMon", "bosmon_user")
|
|
|
|
|
bosmon_password = globals.config.get("BosMon", "bosmon_password")
|
|
|
|
|
bosmon_channel = globals.config.get("BosMon", "bosmon_channel")
|
2015-05-19 12:01:01 +02:00
|
|
|
logging.debug(" - typ: %s", typ)
|
|
|
|
|
logging.debug(" - Server: %s", bosmon_server)
|
|
|
|
|
logging.debug(" - Port: %s", bosmon_port)
|
|
|
|
|
logging.debug(" - User: %s", bosmon_user)
|
|
|
|
|
logging.debug(" - Channel: %s", bosmon_channel)
|
2015-05-18 21:04:10 +02:00
|
|
|
|
|
|
|
|
if typ == "FMS":
|
2015-05-19 09:36:46 +02:00
|
|
|
logging.warning("FMS not implemented")
|
2015-05-18 21:04:10 +02:00
|
|
|
|
|
|
|
|
elif typ == "ZVEI":
|
2015-05-19 09:36:46 +02:00
|
|
|
logging.warning("ZVEI not implemented")
|
2015-05-18 21:04:10 +02:00
|
|
|
|
|
|
|
|
elif typ == "POC":
|
|
|
|
|
logging.debug("Start POC to BosMon")
|
|
|
|
|
try:
|
|
|
|
|
#Defined data structure:
|
2015-05-18 21:49:03 +02:00
|
|
|
# data["ric"]
|
|
|
|
|
# data["function"]
|
|
|
|
|
# data["msg"]
|
2015-05-18 21:04:10 +02:00
|
|
|
#BosMon-Telegramin expected "a-d" as RIC-sub/function
|
2015-05-18 21:49:03 +02:00
|
|
|
data["function"] = data["function"].replace("1", "a").replace("2", "b").replace("3", "c").replace("4", "d")
|
|
|
|
|
params = urllib.urlencode({'type':'pocsag', 'address':data["ric"], 'flags':'0', 'function':data["function"], 'message':data["msg"]})
|
2015-05-19 12:01:01 +02:00
|
|
|
logging.debug(" - Params: %s", params)
|
2015-05-18 21:04:10 +02:00
|
|
|
headers = {}
|
|
|
|
|
headers['Content-type'] = "application/x-www-form-urlencoded"
|
|
|
|
|
headers['Accept'] = "text/plain"
|
|
|
|
|
if bosmon_user:
|
|
|
|
|
headers['Authorization'] = "Basic {0}".format(base64.b64encode("{0}:{1}".format(bosmon_user, bosmon_password)))
|
|
|
|
|
httprequest = httplib.HTTPConnection(bosmon_server, bosmon_port)
|
|
|
|
|
httprequest.request("POST", "/telegramin/"+bosmon_channel+"/input.xml", params, headers)
|
|
|
|
|
httpresponse = httprequest.getresponse()
|
|
|
|
|
if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error
|
2015-05-19 12:01:01 +02:00
|
|
|
logging.debug("BosMon response: %s - %s", str(httpresponse.status), str(httpresponse.reason))
|
2015-05-18 21:04:10 +02:00
|
|
|
else:
|
2015-05-19 12:01:01 +02:00
|
|
|
logging.warning("BosMon response: %s - %s", str(httpresponse.status), str(httpresponse.reason))
|
2015-05-18 21:04:10 +02:00
|
|
|
except:
|
2015-05-19 09:36:46 +02:00
|
|
|
logging.error("POC to BosMon failed")
|
2015-05-18 21:04:10 +02:00
|
|
|
else:
|
2015-05-19 12:01:01 +02:00
|
|
|
logging.warning("undefined typ '%s'", typ)
|
2015-05-18 21:04:10 +02:00
|
|
|
except:
|
2015-05-19 09:36:46 +02:00
|
|
|
logging.exception("")
|