Merge pull request #22 from Schrolli91/develop

merge to master
This commit is contained in:
Schrolli91 2015-05-23 06:49:58 +02:00
commit e2356c22a6
20 changed files with 389 additions and 280 deletions

232
boswatch.py Normal file → Executable file
View file

@ -8,30 +8,19 @@
# For more Information see the README.md
##### Info #####
import globals # Global variables
import pluginloader
import logging
import argparse #for parse the args
import ConfigParser #for parse the config file
import re #Regex for validation
import os #for script path
import time #timestamp for doublealarm
import os #for log mkdir
import time #timestamp
import subprocess
from includes import globals # Global variables
def throwAlarm(typ,data):
logging.debug("[ ALARM ]")
for name, plugin in pluginList.items():
logging.debug("call Plugin: %s", name)
plugin.run(typ,"0",data)
logging.debug("[END ALARM]")
# Programm
try:
try:
try:
#create logger
globals.script_path = os.path.dirname(os.path.abspath(__file__))
@ -52,13 +41,12 @@ try:
ch = logging.StreamHandler()
ch.setLevel(logging.INFO) #log level >= info
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.addHandler(ch)
except:
logging.exception("cannot create logger")
else:
try:
try:
#clear log
bos_log = open(globals.script_path+"/log/boswatch.log", "w")
rtl_log = open(globals.script_path+"/log/rtl_fm.log", "w")
@ -70,12 +58,11 @@ try:
rtl_log.close()
mon_log.close()
logging.debug("BOSWatch has started")
logging.debug("Logfiles cleared")
logging.debug("Logfiles cleared")
except:
logging.exception("cannot clear Logfiles")
try:
try:
#parse args
logging.debug("parse args")
#With -h or --help you get the Args help
@ -89,13 +76,12 @@ try:
parser.add_argument("-s", "--squelch", help="Level of Squelch", type=int, default=0)
parser.add_argument("-v", "--verbose", help="Shows more Information", action="store_true")
parser.add_argument("-q", "--quiet", help="Shows no Information. Only Logfiles", action="store_true")
args = parser.parse_args()
args = parser.parse_args()
except:
logging.error("cannot parse args")
else:
try:
logging.error("cannot parse args")
else:
try:
#display/log args
logging.debug(" - Frequency: %s", args.freq)
logging.debug(" - Device: %s", args.device)
@ -128,105 +114,52 @@ try:
ch.setLevel(logging.CRITICAL)
if not args.quiet: #only if not quiet mode
print " ____ ____ ______ __ __ __ "
print " / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ b"
print " / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ e"
print " / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / t"
print " /_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ a"
print " German BOS Information Script "
print " by Bastian Schroll "
print ""
print "Frequency: "+args.freq
print "Device-ID: "+str(args.device)
print "Error in PPM: "+str(args.error)
print "Active Demods: "+str(len(args.demod))
if "FMS" in args.demod:
print "- FMS"
if "ZVEI" in args.demod:
print "- ZVEI"
if "POC512" in args.demod:
print "- POC512"
if "POC1200" in args.demod:
print "- POC1200"
if "POC2400" in args.demod:
print "- POC2400"
print "Squelch: "+str(args.squelch)
if args.verbose:
print "Verbose Mode!"
print ""
from includes import shellHeader
shellHeader.printHeader(args)
except:
logging.exception("cannot display/log args")
try:
#preload vars
logging.debug("pre-load variables")
fms_id = 0
fms_id_old = 0
fms_time_old = 0
zvei_id = 0
zvei_id_old = 0
zvei_time_old = 0
poc_id = 0
poc_id_old = 0
poc_time_old = 0
except:
logging.debug("cannot pre-load variables")
try:
try:
#read config
logging.debug("reading config file")
globals.config = ConfigParser.ConfigParser()
globals.config.read(globals.script_path+"/config/config.ini")
for key,val in globals.config.items("BOSWatch"):
logging.debug(" - %s = %s", key, val)
logging.debug(" - %s = %s", key, val)
except:
logging.debug("cannot read config file")
logging.exception("cannot read config file")
else:
try:
#load plugins
logging.debug("loading plugins")
pluginList = {}
for i in pluginloader.getPlugins():
plugin = pluginloader.loadPlugin(i)
pluginList[i["name"]] = plugin
except:
logging.exception("cannot load Plugins")
try:
#load plugins
from includes import pluginLoader
pluginLoader.loadPlugins()
try:
#start rtl_fm
logging.debug("starting rtl_fm")
rtl_fm = subprocess.Popen("rtl_fm -d "+str(args.device)+" -f "+str(args.freq)+" -M fm -s 22050 -p "+str(args.error)+" -E DC -F 0 -l "+str(args.squelch)+" -g 100",
#stdin=rtl_fm.stdout,
stdout=subprocess.PIPE,
stderr=open(globals.script_path+"/log/rtl_fm.log","a"),
shell=True)
shell=True)
except:
logging.exception("cannot start rtl_fm")
else:
try:
else:
try:
#start multimon
logging.debug("starting multimon-ng")
multimon_ng = subprocess.Popen("multimon-ng "+str(demodulation)+" -f alpha -t raw /dev/stdin - ",
stdin=rtl_fm.stdout,
stdout=subprocess.PIPE,
stderr=open(globals.script_path+"/log/multimon.log","a"),
shell=True)
shell=True)
except:
logging.exception("cannot start multimon-ng")
else:
logging.debug("start decoding")
while True:
#RAW Data from Multimon-NG
#ZVEI2: 25832
@ -236,114 +169,11 @@ try:
#only for develop
#decoded = "ZVEI2: 25832"
#decoded = "FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=III(mit NA,ohneSIGNAL)) CRC correct\n'"
#decoded = "POCSAG1200: Address: 1234567 Function: 1 Alpha: XXMSG MEfeweffsjh"
#decoded = "POCSAG1200: Address: 1234567 Function: 1 Alpha: Hello World"
#time.sleep(1)
timestamp = int(time.time())#Get Timestamp
#FMS Decoder Section
#check FMS: -> check CRC -> validate -> check double alarm -> log
if "FMS:" in decoded:
logging.debug("recieved FMS")
fms_service = decoded[19] #Organisation
fms_country = decoded[36] #Bundesland
fms_location = decoded[65:67] #Ort
fms_vehicle = decoded[72:76] #Fahrzeug
fms_status = decoded[84] #Status
fms_direction = decoded[101] #Richtung
fms_tsi = decoded[114:117] #Taktische Kruzinformation
if "CRC correct" in decoded: #check CRC is correct
fms_id = fms_service+fms_country+fms_location+fms_vehicle+fms_status+fms_direction #build FMS id
if re.search("[0-9a-f]{8}[0-9a-f]{1}[01]{1}", fms_id): #if FMS is valid
if fms_id == fms_id_old and timestamp < fms_time_old + globals.config.getint("BOSWatch", "fms_double_ignore_time"): #check for double alarm
logging.warning("FMS double alarm: %s within %s second(s)", fms_id_old, timestamp-fms_time_old)
fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new
else:
logging.info("FMS:%s Status:%s Richtung:%s TKI:%s", fms_id[0:8], fms_status, fms_direction, fms_tsi)
data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "tsi":fms_tsi}
throwAlarm("FMS",data)
fms_id_old = fms_id #save last id
fms_time_old = timestamp #save last time
else:
logging.warning("No valid FMS: %s", fms_id)
else:
logging.warning("FMS CRC incorrect")
#ZVEI Decoder Section
#check ZVEI: -> validate -> check double alarm -> log
if "ZVEI2:" in decoded:
logging.debug("recieved ZVEI")
zvei_id = decoded[7:12] #ZVEI Code
if re.search("[0-9F]{5}", zvei_id): #if ZVEI is valid
if zvei_id == zvei_id_old and timestamp < zvei_time_old + globals.config.getint("BOSWatch", "zvei_double_ignore_time"): #check for double alarm
logging.warning("ZVEI double alarm: %s within %s second(s)", zvei_id_old, timestamp-zvei_time_old)
zvei_time_old = timestamp #in case of double alarm, zvei_double_ignore_time set new
else:
logging.info("5-Ton: %s", zvei_id)
data = {"zvei":zvei_id}
throwAlarm("ZVEI",data)
zvei_id_old = zvei_id #save last id
zvei_time_old = timestamp #save last time
else:
logging.warning("No valid ZVEI: %s", zvei_id)
#POCSAG Decoder Section
#check POCSAG -> validate -> check double alarm -> log
if "POCSAG" in decoded:
logging.debug("recieved POCSAG")
bitrate = 0
if "POCSAG512:" in decoded:
bitrate = 512
poc_id = decoded[20:27]
poc_sub = decoded[39].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1")
elif "POCSAG1200:" in decoded:
bitrate = 1200
poc_id = decoded[21:28]
poc_sub = decoded[40].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1")
elif "POCSAG2400:" in decoded:
bitrate = 2400
poc_id = decoded[21:28]
poc_sub = decoded[40].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1")
if bitrate is 0:
logging.warning("POCSAG Bitrate not found")
else:
logging.debug("POCSAG Bitrate: %s", bitrate)
if "Alpha:" in decoded: #check if there is a text message
poc_text = decoded.split('Alpha: ')[1].strip().rstrip('<EOT>').strip()
else:
poc_text = ""
if re.search("[0-9]{7}", poc_id): #if POC is valid
if int(poc_id) >= globals.config.getint("BOSWatch", "poc_filter_range_start"):
if int(poc_id) <= globals.config.getint("BOSWatch", "poc_filter_range_end"):
if poc_id == poc_id_old and timestamp < poc_time_old + globals.config.getint("BOSWatch", "poc_double_ignore_time"): #check for double alarm
logging.warning("POCSAG%s double alarm: %s within %s second(s)", bitrate, poc_id_old, timestamp-poc_time_old)
poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new
else:
logging.info("POCSAG%s: %s %s %s ", bitrate, poc_id, poc_sub, poc_text)
data = {"ric":poc_id, "function":poc_sub, "msg":poc_text, "bitrate":bitrate}
throwAlarm("POC",data)
poc_id_old = poc_id #save last id
poc_time_old = timestamp #save last time
else:
logging.warning("POCSAG%s: %s out of filter range (high)", bitrate, poc_id)
else:
logging.warning("POCSAG%s: %s out of filter range (low)", bitrate, poc_id)
else:
logging.warning("No valid POCSAG%s RIC: %s", bitrate, poc_id)
from includes import decoder
decoder.decode(args.freq, decoded)
except KeyboardInterrupt:
logging.warning("Keyboard Interrupt")

View file

@ -16,8 +16,8 @@ poc_filter_range_start = 0000000
poc_filter_range_end = 9999999
#can take on or off the plugins (0|1)
[Plugins]
#can take on or off the plugins (0|1)
MySQL = 0
BosMon = 0
httpRequest = 0
@ -43,7 +43,7 @@ tablePOC = bos_pocsag
bosmon_server = 192.168.0.1
bosmon_port = 80
#channel-name of typ "Web-Telegramm"
bosmon_channel = pocsag
bosmon_channel = channel
#Use this, when BosMon has restricted access
bosmon_user =
bosmon_password =

View file

@ -1,7 +0,0 @@
#!/usr/bin/python
# -*- coding: cp1252 -*-
#Global variables
config = 0
script_path = ""

14
includes/alarmHandler.py Normal file
View file

@ -0,0 +1,14 @@
#!/usr/bin/python
# -*- coding: cp1252 -*-
import logging
from includes import globals # Global variables
def processAlarm(typ,freq,data):
logging.debug("[ ALARM ]")
for name, plugin in globals.pluginList.items():
logging.debug("call Plugin: %s", name)
plugin.run(typ,freq,data)
logging.debug("return from: %s", name)
logging.debug("[END ALARM]")

27
includes/decoder.py Normal file
View file

@ -0,0 +1,27 @@
#!/usr/bin/python
# -*- coding: cp1252 -*-
import logging
def decode(freq, decoded):
#FMS Decoder Section
#check FMS: -> check CRC -> validate -> check double alarm -> log
if "FMS:" in decoded:
logging.debug("recieved FMS")
from includes.decoders import fms
fms.decode(freq, decoded)
#ZVEI Decoder Section
#check ZVEI: -> validate -> check double alarm -> log
if "ZVEI2:" in decoded:
logging.debug("recieved ZVEI")
from includes.decoders import zvei
zvei.decode(freq, decoded)
#POCSAG Decoder Section
#check POCSAG -> validate -> check double alarm -> log
if "POCSAG" in decoded:
logging.debug("recieved POCSAG")
from includes.decoders import poc
poc.decode(freq, decoded)

40
includes/decoders/fms.py Normal file
View file

@ -0,0 +1,40 @@
#!/usr/bin/python
# -*- coding: cp1252 -*-
import logging
import time #timestamp for doublealarm
import re #Regex for validation
from includes import globals # Global variables
#FMS Decoder Function
#validate -> check double alarm -> log
def decode(freq, decoded):
timestamp = int(time.time())#Get Timestamp
fms_service = decoded[19] #Organisation
fms_country = decoded[36] #Bundesland
fms_location = decoded[65:67] #Ort
fms_vehicle = decoded[72:76] #Fahrzeug
fms_status = decoded[84] #Status
fms_direction = decoded[101] #Richtung
fms_tsi = decoded[114:117] #Taktische Kruzinformation
if "CRC correct" in decoded: #check CRC is correct
fms_id = fms_service+fms_country+fms_location+fms_vehicle+fms_status+fms_direction #build FMS id
if re.search("[0-9a-f]{8}[0-9a-f]{1}[01]{1}", fms_id): #if FMS is valid
if fms_id == globals.fms_id_old and timestamp < globals.fms_time_old + globals.config.getint("BOSWatch", "fms_double_ignore_time"): #check for double alarm
logging.info("FMS double alarm: %s within %s second(s)", globals.fms_id_old, timestamp-globals.fms_time_old)
globals.fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new
else:
logging.info("FMS:%s Status:%s Richtung:%s TKI:%s", fms_id[0:8], fms_status, fms_direction, fms_tsi)
data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "tsi":fms_tsi}
from includes import alarmHandler
alarmHandler.processAlarm("FMS",freq,data)
globals.fms_id_old = fms_id #save last id
globals.fms_time_old = timestamp #save last time
else:
logging.warning("No valid FMS: %s", fms_id)
else:
logging.warning("FMS CRC incorrect")

60
includes/decoders/poc.py Normal file
View file

@ -0,0 +1,60 @@
#!/usr/bin/python
# -*- coding: cp1252 -*-
import logging
import time #timestamp for doublealarm
import re #Regex for validation
from includes import globals # Global variables
#POCSAG Decoder Function
#validate -> check double alarm -> log
def decode(freq, decoded):
bitrate = 0
timestamp = int(time.time())#Get Timestamp
if "POCSAG512:" in decoded:
bitrate = 512
poc_id = decoded[20:27]
poc_sub = decoded[39].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1")
elif "POCSAG1200:" in decoded:
bitrate = 1200
poc_id = decoded[21:28]
poc_sub = decoded[40].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1")
elif "POCSAG2400:" in decoded:
bitrate = 2400
poc_id = decoded[21:28]
poc_sub = decoded[40].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1")
if bitrate is 0:
logging.warning("POCSAG Bitrate not found")
else:
logging.debug("POCSAG Bitrate: %s", bitrate)
if "Alpha:" in decoded: #check if there is a text message
poc_text = decoded.split('Alpha: ')[1].strip().rstrip('<EOT>').strip()
else:
poc_text = ""
if re.search("[0-9]{7}", poc_id): #if POC is valid
if int(poc_id) >= globals.config.getint("BOSWatch", "poc_filter_range_start"):
if int(poc_id) <= globals.config.getint("BOSWatch", "poc_filter_range_end"):
if poc_id == globals.poc_id_old and timestamp < globals.poc_time_old + globals.config.getint("BOSWatch", "poc_double_ignore_time"): #check for double alarm
logging.info("POCSAG%s double alarm: %s within %s second(s)", bitrate, globals.poc_id_old, timestamp-globals.poc_time_old)
globals.poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new
else:
logging.info("POCSAG%s: %s %s %s ", bitrate, poc_id, poc_sub, poc_text)
data = {"ric":poc_id, "function":poc_sub, "msg":poc_text, "bitrate":bitrate}
from includes import alarmHandler
alarmHandler.processAlarm("POC",freq,data)
globals.poc_id_old = poc_id #save last id
globals.poc_time_old = timestamp #save last time
else:
logging.info("POCSAG%s: %s out of filter range (high)", bitrate, poc_id)
else:
logging.info("POCSAG%s: %s out of filter range (low)", bitrate, poc_id)
else:
logging.warning("No valid POCSAG%s RIC: %s", bitrate, poc_id)

29
includes/decoders/zvei.py Normal file
View file

@ -0,0 +1,29 @@
#!/usr/bin/python
# -*- coding: cp1252 -*-
import logging
import time #timestamp for doublealarm
import re #Regex for validation
from includes import globals # Global variables
#ZVEI Decoder Function
#validate -> check double alarm -> log
def decode(freq, decoded):
timestamp = int(time.time())#Get Timestamp
zvei_id = decoded[7:12] #ZVEI Code
if re.search("[0-9F]{5}", zvei_id): #if ZVEI is valid
if zvei_id == globals.zvei_id_old and timestamp < globals.zvei_time_old + globals.config.getint("BOSWatch", "zvei_double_ignore_time"): #check for double alarm
logging.info("ZVEI double alarm: %s within %s second(s)", globals.zvei_id_old, timestamp-globals.zvei_time_old)
globals.zvei_time_old = timestamp #in case of double alarm, zvei_double_ignore_time set new
else:
logging.info("5-Ton: %s", zvei_id)
data = {"zvei":zvei_id}
from includes import alarmHandler
alarmHandler.processAlarm("ZVEI",freq,data)
globals.zvei_id_old = zvei_id #save last id
globals.zvei_time_old = timestamp #save last time
else:
logging.warning("No valid ZVEI: %s", zvei_id)

19
includes/globals.py Normal file
View file

@ -0,0 +1,19 @@
#!/usr/bin/python
# -*- coding: cp1252 -*-
#Global variables
config = 0
script_path = ""
#double alarm
fms_id_old = 0
fms_time_old = 0
zvei_id_old = 0
zvei_time_old = 0
poc_id_old = 0
poc_time_old = 0
#pluginHandler
pluginList = {}

View file

@ -2,10 +2,20 @@
# -*- coding: cp1252 -*-
import logging # Global logger
import globals # Global variables
import imp
import os
from includes import globals # Global variables
def loadPlugins():
try:
logging.debug("loading plugins")
for i in getPlugins():
plugin = loadPlugin(i)
globals.pluginList[i["name"]] = plugin
except:
logging.exception("cannot load Plugins")
def getPlugins():
try:
@ -33,6 +43,7 @@ def getPlugins():
return plugins
def loadPlugin(plugin):
try:
logging.debug("load Plugin: %s", plugin["name"])

32
includes/shellHeader.py Normal file
View file

@ -0,0 +1,32 @@
#!/usr/bin/python
# -*- coding: cp1252 -*-
def printHeader(args):
print " ____ ____ ______ __ __ __ "
print " / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ b"
print " / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ e"
print " / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / t"
print " /_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ a"
print " German BOS Information Script "
print " by Bastian Schroll "
print ""
print "Frequency: "+args.freq
print "Device-ID: "+str(args.device)
print "Error in PPM: "+str(args.error)
print "Active Demods: "+str(len(args.demod))
if "FMS" in args.demod:
print "- FMS"
if "ZVEI" in args.demod:
print "- ZVEI"
if "POC512" in args.demod:
print "- POC512"
if "POC1200" in args.demod:
print "- POC1200"
if "POC2400" in args.demod:
print "- POC2400"
print "Squelch: "+str(args.squelch)
if args.verbose:
print "Verbose Mode!"
print ""

View file

@ -1,15 +1,19 @@
#!/usr/bin/python
# -*- coding: cp1252 -*-
import time
import pluginloader
import os #for absolute path: os.path.dirname(os.path.abspath(__file__))
###########################################################################
# Use this as a simple Plugin Loading Tool to test your own Coded Plugins #
###########################################################################
import logging
import globals
import ConfigParser #for parse the config file
import os #for log mkdir
import time #timestamp for doublealarm
from includes import globals # Global variables
from includes import pluginLoader
from includes import alarmHandler
#create new logger
logger = logging.getLogger()
@ -34,37 +38,41 @@ logger.addHandler(ch)
#exception - error with exception message in log
#critical - critical error, program exit
globals.script_path = os.path.dirname(os.path.abspath(__file__))
#ConfigParser
logging.debug("reading config file")
try:
logging.debug("reading config file")
globals.config = ConfigParser.ConfigParser()
globals.config.read(globals.script_path+"./config/config.ini")
globals.config.read(globals.script_path+"/config/config.ini")
for key,val in globals.config.items("Plugins"):
logging.debug(" - %s = %s", key, val)
except:
logging.exception("cannot read config file")
pluginLoader.loadPlugins()
# ----- Test Data ----- #
#typ = "FMS"
#data = {"fms":"12345678", "status":"2", "direction":"1", "tsi":"III"}
typ = "ZVEI"
data = {"zvei":"12345"}
#data = {"ric":"1234567", "function":"1", "msg":"Hello World!"}
logging.debug("Load Plugins...")
pluginList = {}
for i in pluginloader.getPlugins():
plugin = pluginloader.loadPlugin(i)
pluginList[i["name"]] = plugin
logging.debug("All loaded...")
#typ = "POC"
#data = {"ric":"1234567", "function":"1", "msg":"Hello World!, "bitrate":"1200"}
while True:
try:
time.sleep(1)
logging.info(" = = = = = = = = = ")
logging.info("Alarm!")
for name, plugin in pluginList.items():
logging.debug("call Plugin: %s", name)
plugin.run("ZVEI","0",data)
print ""
alarmHandler.processAlarm(typ,"0",data)
except KeyboardInterrupt:
logging.warning("Keyboard Interrupt")
exit()
except:
logging.exception("Cannot Throw Modules")
exit()
logging.exception("unknown error")
exit()

View file

@ -2,12 +2,27 @@
# -*- 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
from includes import globals # Global variables
def bosMonRequest(httprequest, params, headers):
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):
try:
#ConfigParser
@ -18,39 +33,59 @@ def run(typ,freq,data):
except:
logging.exception("cannot read config file")
########## User Plugin CODE ##########
if typ == "FMS":
logging.warning("%s not supported", typ)
elif typ == "ZVEI":
logging.warning("%s not supported", typ)
elif typ == "POC":
logging.debug("Start POC to BosMon")
try:
#Defined data structure:
# data["ric"]
# data["function"]
# data["msg"]
#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)
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"))))
httprequest = httplib.HTTPConnection(globals.config.get("BosMon", "bosmon_server"), globals.config.get("BosMon", "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
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))
except:
logging.error("POC to BosMon failed")
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"))
#debug-level to shell (0=no debug|1)
httprequest.set_debuglevel(0)
except:
logging.exception("cannot connect to BosMon")
else:
logging.warning("Invalid Typ: %s", typ)
########## User Plugin CODE ##########
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.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")
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:
logging.error("POC to BosMon failed")
else:
logging.warning("Invalid Typ: %s", typ)
finally:
logging.debug("close BosMon-Connection")
httprequest.close()
except:
logging.exception("")
logging.exception("")

View file

@ -2,10 +2,13 @@
# -*- coding: cp1252 -*-
import logging # Global logger
import globals # Global variables
import mysql
import mysql.connector
from includes import globals # Global variables
def run(typ,freq,data):
try:
#ConfigParser
@ -33,7 +36,8 @@ def run(typ,freq,data):
elif typ == "ZVEI":
#data = {"zvei":zvei_id}
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tableZVEI")+" (time,zvei) VALUES (NOW(),%s)",(data["zvei"]))
#Don't use %s here (bug in mysql-lib with one parameter)
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tableZVEI")+" (time,zvei) VALUES (NOW(),"+(data["zvei"])+")")
elif typ == "POC":
#data = {"ric":poc_id, "function":poc_sub, "msg":poc_text}

View file

@ -1,9 +1,6 @@
#!/usr/bin/python
# -*- coding: cp1252 -*-
import logging # Global logger
import globals # Global variables
#########
# USAGE
#
@ -23,8 +20,12 @@ import globals # Global variables
# usable Loglevels debug|info|warning|error|exception|critical
# if you use .exception in Try:Exception: Construct, it logs the Python EX.message too
import logging # Global logger
import httplib #for the HTTP request
from includes import globals # Global variables
def run(typ,freq,data):
try:
#ConfigParser
@ -65,7 +66,11 @@ def run(typ,freq,data):
logging.exception("no HTTP request been sended")
except: #otherwise
logging.exception("cannot get HTTP response")
finally:
logging.debug("close HTTP-Connection")
httprequest.close()
########## User Plugin CODE ##########
except:
logging.exception("unknown error")
logging.exception("unknown error")

View file

@ -1,9 +1,6 @@
#!/usr/bin/python
# -*- coding: cp1252 -*-
import logging # Global logger
import globals # Global variables
#########
# USAGE
#
@ -23,6 +20,11 @@ import globals # Global variables
# usable Loglevels debug|info|warning|error|exception|critical
# if you use .exception in Try:Exception: Construct, it logs the Python EX.message too
import logging # Global logger
from includes import globals # Global variables
def run(typ,freq,data):
try:
#ConfigParser
@ -45,4 +47,4 @@ def run(typ,freq,data):
########## User Plugin CODE ##########
except:
logging.exception("unknown error")
logging.exception("unknown error")