2015-05-18 21:04:10 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
# -*- coding: cp1252 -*-
|
|
|
|
|
|
|
|
|
|
import logging # Global logger
|
|
|
|
|
|
|
|
|
|
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-22 16:44:23 +02:00
|
|
|
from includes import globals # Global variables
|
|
|
|
|
|
|
|
|
|
|
2015-05-22 20:07:09 +02:00
|
|
|
def bosMonRequest(httprequest, params, headers):
|
2015-05-22 23:46:54 +02:00
|
|
|
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))
|
2015-05-22 20:07:09 +02:00
|
|
|
|
|
|
|
|
|
2015-05-18 21:49:03 +02:00
|
|
|
def run(typ,freq,data):
|
2015-05-18 21:04:10 +02:00
|
|
|
try:
|
2015-05-20 09:41:29 +02:00
|
|
|
#ConfigParser
|
|
|
|
|
logging.debug("reading config file")
|
|
|
|
|
try:
|
2015-05-20 17:25:22 +02:00
|
|
|
for key,val in globals.config.items("BosMon"):
|
2015-05-20 09:41:29 +02:00
|
|
|
logging.debug(" - %s = %s", key, val)
|
|
|
|
|
except:
|
|
|
|
|
logging.exception("cannot read config file")
|
2015-05-18 21:04:10 +02:00
|
|
|
|
2015-05-22 20:07:09 +02:00
|
|
|
try:
|
|
|
|
|
#Initialize header an connect to BosMon-Server
|
|
|
|
|
headers = {}
|
|
|
|
|
headers['Content-type'] = "application/x-www-form-urlencoded"
|
|
|
|
|
headers['Accept'] = "text/plain"
|
|
|
|
|
if globals.config.get("BosMon", "bosmon_user"):
|
|
|
|
|
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"))
|
2015-05-22 23:46:54 +02:00
|
|
|
#debug-level to shell (0=no debug|1)
|
2015-05-24 23:09:38 +02:00
|
|
|
httprequest.set_debuglevel(1)
|
2015-05-22 20:07:09 +02:00
|
|
|
except:
|
|
|
|
|
logging.exception("cannot connect to BosMon")
|
|
|
|
|
|
2015-05-18 21:04:10 +02:00
|
|
|
else:
|
2015-05-22 20:07:09 +02:00
|
|
|
if typ == "FMS":
|
2015-05-24 23:09:38 +02:00
|
|
|
logging.debug("Start FMS to BosMon")
|
|
|
|
|
try:
|
2015-05-22 23:46:54 +02:00
|
|
|
#BosMon-Telegramin expected assembly group, direction and tsi in one field
|
2015-05-24 23:09:38 +02:00
|
|
|
#structure: Byte 1: assembly group; Byte 2: Direction; Byte 3+4: tactic short info
|
|
|
|
|
info = 0
|
|
|
|
|
#assembly group:
|
|
|
|
|
info = info + 1 # + b0001 (Assumption: is in every time 1 (no output from multimon-ng))
|
|
|
|
|
#direction:
|
|
|
|
|
if data["direction"] == "1":
|
|
|
|
|
info = info + 2 # + b0010
|
|
|
|
|
#tsi:
|
|
|
|
|
if "IV" in data["tsi"]:
|
|
|
|
|
info = info + 12 # + b1100
|
|
|
|
|
elif "III" in data["tsi"]:
|
|
|
|
|
info = info + 8 # + b1000
|
|
|
|
|
elif "II" in data["tsi"]:
|
|
|
|
|
info = info + 4 # + b0100
|
|
|
|
|
params = urllib.urlencode({'type':'fms', 'address':data["fms"], 'status':data["status"], 'info':info, 'flags':'0'})
|
|
|
|
|
logging.debug(" - Params: %s", params)
|
|
|
|
|
bosMonRequest(httprequest, params, headers)
|
|
|
|
|
except:
|
|
|
|
|
logging.exception("FMS to BosMon failed")
|
2015-05-22 20:07:09 +02:00
|
|
|
|
|
|
|
|
elif typ == "ZVEI":
|
2015-05-22 23:46:54 +02:00
|
|
|
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:
|
2015-05-24 23:09:38 +02:00
|
|
|
logging.exception("ZVEI to BosMon failed")
|
2015-05-22 20:07:09 +02:00
|
|
|
|
|
|
|
|
elif typ == "POC":
|
|
|
|
|
logging.debug("Start POC to BosMon")
|
|
|
|
|
try:
|
|
|
|
|
#BosMon-Telegramin expected "a-d" as RIC-sub/function
|
|
|
|
|
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"]})
|
|
|
|
|
logging.debug(" - Params: %s", params)
|
|
|
|
|
bosMonRequest(httprequest, params, headers)
|
|
|
|
|
except:
|
2015-05-24 23:09:38 +02:00
|
|
|
logging.exception("POC to BosMon failed")
|
2015-05-22 20:07:09 +02:00
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
logging.warning("Invalid Typ: %s", typ)
|
|
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
logging.debug("close BosMon-Connection")
|
|
|
|
|
httprequest.close()
|
2015-05-22 10:00:09 +02:00
|
|
|
|
2015-05-18 21:04:10 +02:00
|
|
|
except:
|
2015-05-22 16:44:23 +02:00
|
|
|
logging.exception("")
|