From 7731031a15b3b7cb97faff078be1ca730e912a7e Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Mon, 18 May 2015 21:49:03 +0200 Subject: [PATCH 01/24] little changes --- plugin_test/config/config.ini | 2 -- plugin_test/plugin_test.py | 11 ++++++----- plugin_test/pluginloader.py | 1 + plugin_test/plugins/BosMon/__init__.py | 12 ++++++------ plugin_test/plugins/template/__init__.py | 4 +--- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/plugin_test/config/config.ini b/plugin_test/config/config.ini index ba86077..193ca98 100644 --- a/plugin_test/config/config.ini +++ b/plugin_test/config/config.ini @@ -4,8 +4,6 @@ #can take on or off the modules (0|1) [Module] -MySQL = 0 -HTTPrequest = 0 BosMon = 0 # for developing template-module is enabled template = 1 diff --git a/plugin_test/plugin_test.py b/plugin_test/plugin_test.py index 86920df..06207ad 100755 --- a/plugin_test/plugin_test.py +++ b/plugin_test/plugin_test.py @@ -8,8 +8,9 @@ import pluginloader import os #for absolute path: os.path.dirname(os.path.abspath(__file__)) import ConfigParser #for parse the config file -#create new logger import logging + +#create new logger logger = logging.getLogger() logger.setLevel(logging.DEBUG) @@ -32,20 +33,20 @@ logger.addHandler(ch) #log levels #---------- #debug - debug messages only for log -#info - only an information +#info - inormation for normal display #warning #error - normal error - program goes further -#exception - error handler in try:exc: into the message +#exception - error with exception message in log #critical - critical error, program exit #ConfigParser -logging.info("reading config file") try: + logging.debug("reading config file") script_path = os.path.dirname(os.path.abspath(__file__)) globals.config = ConfigParser.ConfigParser() globals.config.read(script_path+"/config/config.ini") except: - logging.error("cannot read config file","error") + logging.exception("cannot read config file") #data = {"zvei":"12345"} data = {"ric":"1234567", "function":"1", "msg":"Hello World!"} diff --git a/plugin_test/pluginloader.py b/plugin_test/pluginloader.py index 60e6e56..cb353e4 100644 --- a/plugin_test/pluginloader.py +++ b/plugin_test/pluginloader.py @@ -18,6 +18,7 @@ def getPlugins(): if not os.path.isdir(location) or not MainModule + ".py" in os.listdir(location): continue logging.debug("found plugin: "+i) + # is the plugin enabled in the config-file? try: usePlugin = int(globals.config.get("Module", i)) diff --git a/plugin_test/plugins/BosMon/__init__.py b/plugin_test/plugins/BosMon/__init__.py index 00845c3..b66a4ce 100644 --- a/plugin_test/plugins/BosMon/__init__.py +++ b/plugin_test/plugins/BosMon/__init__.py @@ -8,7 +8,7 @@ import httplib #for the HTTP request import urllib #for the HTTP request with parameters import base64 #for the HTTP request with User/Password -def run(typ,frequenz,daten): +def run(typ,freq,data): logging.debug("BosMon Plugin called") logging.debug(" - typ: " +typ) try: @@ -33,12 +33,12 @@ def run(typ,frequenz,daten): logging.debug("Start POC to BosMon") try: #Defined data structure: - # daten["ric"] - # daten["function"] - # daten["msg"] + # data["ric"] + # data["function"] + # data["msg"] #BosMon-Telegramin expected "a-d" as RIC-sub/function - daten["function"] = daten["function"].replace("1", "a").replace("2", "b").replace("3", "c").replace("4", "d") - params = urllib.urlencode({'type':'pocsag', 'address':daten["ric"], 'flags':'0', 'function':daten["function"], 'message':daten["msg"]}) + 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:" +params) headers = {} headers['Content-type'] = "application/x-www-form-urlencoded" diff --git a/plugin_test/plugins/template/__init__.py b/plugin_test/plugins/template/__init__.py index 0e10a17..f9008a2 100644 --- a/plugin_test/plugins/template/__init__.py +++ b/plugin_test/plugins/template/__init__.py @@ -5,10 +5,8 @@ import logging # Global logger import globals # Global variables def run(typ,freq,data): - logging.debug("Strat Plugin: template") + logging.debug("template Plugin called") try: logging.info("ZVEI: %s wurde auf %s empfangen!", data["zvei"],freq) - logging.debug("try 5/0") - test = 5/0 except: logging.exception("Error in Template Plugin") \ No newline at end of file From 2b2f8c54e6cc4a79f7cac96b12581c2aa4914421 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Mon, 18 May 2015 21:59:11 +0200 Subject: [PATCH 02/24] little Modul changes --- plugin_test/plugin_test.py | 12 ++++++------ plugin_test/plugins/BosMon/__init__.py | 3 +-- plugin_test/plugins/template/__init__.py | 1 - 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/plugin_test/plugin_test.py b/plugin_test/plugin_test.py index 06207ad..32e8991 100755 --- a/plugin_test/plugin_test.py +++ b/plugin_test/plugin_test.py @@ -52,9 +52,9 @@ except: data = {"ric":"1234567", "function":"1", "msg":"Hello World!"} while True: - time.sleep(1) - logging.info("Alarm!") - for i in pluginloader.getPlugins(): - logging.debug("Load Plugin: " + i["name"]) - plugin = pluginloader.loadPlugin(i) - plugin.run("POC","80000000",data) \ No newline at end of file + time.sleep(1) + logging.info("Alarm!") + for i in pluginloader.getPlugins(): + plugin = pluginloader.loadPlugin(i) + logging.debug(i["name"] + " Plugin called") + plugin.run("POC","80000000",data) \ No newline at end of file diff --git a/plugin_test/plugins/BosMon/__init__.py b/plugin_test/plugins/BosMon/__init__.py index b66a4ce..4b0d124 100644 --- a/plugin_test/plugins/BosMon/__init__.py +++ b/plugin_test/plugins/BosMon/__init__.py @@ -9,8 +9,6 @@ import urllib #for the HTTP request with parameters import base64 #for the HTTP request with User/Password def run(typ,freq,data): - logging.debug("BosMon Plugin called") - logging.debug(" - typ: " +typ) try: #get BosMon-Config bosmon_server = globals.config.get("BosMon", "bosmon_server") @@ -18,6 +16,7 @@ def run(typ,freq,data): bosmon_user = globals.config.get("BosMon", "bosmon_user") bosmon_password = globals.config.get("BosMon", "bosmon_password") bosmon_channel = globals.config.get("BosMon", "bosmon_channel") + logging.debug(" - typ: " +typ) logging.debug(" - Server: " +bosmon_server) logging.debug(" - Port: " +bosmon_port) logging.debug(" - User: " +bosmon_user) diff --git a/plugin_test/plugins/template/__init__.py b/plugin_test/plugins/template/__init__.py index f9008a2..7d44380 100644 --- a/plugin_test/plugins/template/__init__.py +++ b/plugin_test/plugins/template/__init__.py @@ -5,7 +5,6 @@ import logging # Global logger import globals # Global variables def run(typ,freq,data): - logging.debug("template Plugin called") try: logging.info("ZVEI: %s wurde auf %s empfangen!", data["zvei"],freq) except: From 367e68e5fe4f78e06df733ad119b09d7991332d7 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Mon, 18 May 2015 22:10:23 +0200 Subject: [PATCH 03/24] little changes in template modul --- plugin_test/plugin_test.py | 4 ++-- plugin_test/plugins/template/__init__.py | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/plugin_test/plugin_test.py b/plugin_test/plugin_test.py index 32e8991..fe8ac5d 100755 --- a/plugin_test/plugin_test.py +++ b/plugin_test/plugin_test.py @@ -25,7 +25,7 @@ logger.addHandler(fh) #create a display loger ch = logging.StreamHandler() -ch.setLevel(logging.ERROR) #log level >= Error +ch.setLevel(logging.INFO) #log level >= info ch.setFormatter(formatter) logger.addHandler(ch) @@ -33,7 +33,7 @@ logger.addHandler(ch) #log levels #---------- #debug - debug messages only for log -#info - inormation for normal display +#info - information for normal display #warning #error - normal error - program goes further #exception - error with exception message in log diff --git a/plugin_test/plugins/template/__init__.py b/plugin_test/plugins/template/__init__.py index 7d44380..a82d6b1 100644 --- a/plugin_test/plugins/template/__init__.py +++ b/plugin_test/plugins/template/__init__.py @@ -5,7 +5,8 @@ import logging # Global logger import globals # Global variables def run(typ,freq,data): - try: - logging.info("ZVEI: %s wurde auf %s empfangen!", data["zvei"],freq) - except: - logging.exception("Error in Template Plugin") \ No newline at end of file + try: + if typ == "ZVEI": + logging.info("ZVEI: %s wurde auf %s empfangen!", data["zvei"],freq) + except: + logging.exception("Error in Template Plugin") \ No newline at end of file From 0bef06c2ad6936709ee9f410bdc873047c943b4a Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 07:29:39 +0200 Subject: [PATCH 04/24] insert debug msg, edit pluginloader.py --- plugin_test/plugin_test.py | 22 +++++++------ plugin_test/pluginloader.py | 41 ++++++++++++------------ plugin_test/plugins/none/__init__.py | 9 ++++++ plugin_test/plugins/template/__init__.py | 2 ++ 4 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 plugin_test/plugins/none/__init__.py diff --git a/plugin_test/plugin_test.py b/plugin_test/plugin_test.py index fe8ac5d..a002b6d 100755 --- a/plugin_test/plugin_test.py +++ b/plugin_test/plugin_test.py @@ -6,7 +6,7 @@ import time import pluginloader import os #for absolute path: os.path.dirname(os.path.abspath(__file__)) -import ConfigParser #for parse the config file +import configparser #for parse the config file import logging @@ -15,7 +15,7 @@ logger = logging.getLogger() logger.setLevel(logging.DEBUG) #set log string format -formatter = logging.Formatter('%(asctime)s - %(levelname)s: %(message)s', '%d.%m.%Y %I:%M:%S') +formatter = logging.Formatter('%(asctime)s - %(module)s - %(levelname)s: %(message)s', '%d.%m.%Y %I:%M:%S') #create a file loger fh = logging.FileHandler('boswatch.log', 'w') @@ -39,11 +39,11 @@ logger.addHandler(ch) #exception - error with exception message in log #critical - critical error, program exit -#ConfigParser +#configparser try: logging.debug("reading config file") script_path = os.path.dirname(os.path.abspath(__file__)) - globals.config = ConfigParser.ConfigParser() + globals.config = configparser.ConfigParser() globals.config.read(script_path+"/config/config.ini") except: logging.exception("cannot read config file") @@ -52,9 +52,13 @@ except: data = {"ric":"1234567", "function":"1", "msg":"Hello World!"} while True: - time.sleep(1) - logging.info("Alarm!") + try: + time.sleep(1) + logging.info("Alarm!") for i in pluginloader.getPlugins(): - plugin = pluginloader.loadPlugin(i) - logging.debug(i["name"] + " Plugin called") - plugin.run("POC","80000000",data) \ No newline at end of file + plugin = pluginloader.loadPlugin(i) + logging.debug(i["name"] + " Plugin called") + plugin.run("POC","80000000",data) + except: + logging.exception("Cannot Throw Modules") + exit() \ No newline at end of file diff --git a/plugin_test/pluginloader.py b/plugin_test/pluginloader.py index cb353e4..e5f45ae 100644 --- a/plugin_test/pluginloader.py +++ b/plugin_test/pluginloader.py @@ -10,26 +10,27 @@ PluginFolder = "./plugins" MainModule = "__init__" def getPlugins(): - plugins = [] - possibleplugins = os.listdir(PluginFolder) - for i in possibleplugins: - location = os.path.join(PluginFolder, i) - # plugins have to be a subdir with MainModule, if not skip - if not os.path.isdir(location) or not MainModule + ".py" in os.listdir(location): - continue - logging.debug("found plugin: "+i) + plugins = [] + possibleplugins = os.listdir(PluginFolder) + for i in possibleplugins: + location = os.path.join(PluginFolder, i) + # plugins have to be a subdir with MainModule, if not skip + if not os.path.isdir(location) or not MainModule + ".py" in os.listdir(location): + continue + logging.debug("found plugin: "+i) - # is the plugin enabled in the config-file? - try: - usePlugin = int(globals.config.get("Module", i)) - except: #no entry for plugin found in config-file, skip - continue - logging.debug("use Plugin: "+str(usePlugin)) - if usePlugin: - info = imp.find_module(MainModule, [location]) - plugins.append({"name": i, "info": info}) - logging.debug("append Plugin: "+i) - return plugins + # is the plugin enabled in the config-file? + try: + usePlugin = int(globals.config.get("Module", i)) + except: #no entry for plugin found in config-file, skip + logging.warning("Plugin not in config: "+i) + + logging.debug("use Plugin: "+str(usePlugin)) + if usePlugin: + info = imp.find_module(MainModule, [location]) + plugins.append({"name": i, "info": info}) + logging.debug("append Plugin: "+i) + return plugins def loadPlugin(plugin): - return imp.load_module(MainModule, *plugin["info"]) \ No newline at end of file + return imp.load_module(MainModule, *plugin["info"]) \ No newline at end of file diff --git a/plugin_test/plugins/none/__init__.py b/plugin_test/plugins/none/__init__.py new file mode 100644 index 0000000..dffa895 --- /dev/null +++ b/plugin_test/plugins/none/__init__.py @@ -0,0 +1,9 @@ +#!/usr/bin/python +# -*- coding: cp1252 -*- + +import logging # Global logger +import globals # Global variables + +def run(typ,freq,data): + logging.info("Nothing to do") + \ No newline at end of file diff --git a/plugin_test/plugins/template/__init__.py b/plugin_test/plugins/template/__init__.py index a82d6b1..d0f6005 100644 --- a/plugin_test/plugins/template/__init__.py +++ b/plugin_test/plugins/template/__init__.py @@ -8,5 +8,7 @@ def run(typ,freq,data): try: if typ == "ZVEI": logging.info("ZVEI: %s wurde auf %s empfangen!", data["zvei"],freq) + else: + logging.warning(typ + " not supportet") except: logging.exception("Error in Template Plugin") \ No newline at end of file From ec7e695761b1fd7b02650bece51285f741de247c Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 07:35:58 +0200 Subject: [PATCH 05/24] edit Log format --- plugin_test/plugin_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin_test/plugin_test.py b/plugin_test/plugin_test.py index a002b6d..17697ee 100755 --- a/plugin_test/plugin_test.py +++ b/plugin_test/plugin_test.py @@ -15,7 +15,6 @@ logger = logging.getLogger() logger.setLevel(logging.DEBUG) #set log string format -formatter = logging.Formatter('%(asctime)s - %(module)s - %(levelname)s: %(message)s', '%d.%m.%Y %I:%M:%S') #create a file loger fh = logging.FileHandler('boswatch.log', 'w') From 96ba4a459c6ff5b96a279f748b56d22d9cdbc1b8 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 07:42:23 +0200 Subject: [PATCH 06/24] edit log format --- plugin_test/plugin_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin_test/plugin_test.py b/plugin_test/plugin_test.py index 17697ee..4fb0229 100755 --- a/plugin_test/plugin_test.py +++ b/plugin_test/plugin_test.py @@ -15,6 +15,7 @@ logger = logging.getLogger() logger.setLevel(logging.DEBUG) #set log string format +formatter = logging.Formatter('%(asctime)s - %(module)s [%(levelname)s] %(message)s', '%d.%m.%Y %I:%M:%S') #create a file loger fh = logging.FileHandler('boswatch.log', 'w') From 82fc315ee5cdeba60b33b9b19df7932eb6b53c3d Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 08:07:06 +0200 Subject: [PATCH 07/24] load plugins only at start --- plugin_test/plugin_test.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugin_test/plugin_test.py b/plugin_test/plugin_test.py index 4fb0229..2a4ee35 100755 --- a/plugin_test/plugin_test.py +++ b/plugin_test/plugin_test.py @@ -51,13 +51,17 @@ except: #data = {"zvei":"12345"} data = {"ric":"1234567", "function":"1", "msg":"Hello World!"} +#read Plugins +pluginList = [] +for i in pluginloader.getPlugins(): + plugin = pluginloader.loadPlugin(i) + pluginList.append(plugin) + while True: try: time.sleep(1) logging.info("Alarm!") - for i in pluginloader.getPlugins(): - plugin = pluginloader.loadPlugin(i) - logging.debug(i["name"] + " Plugin called") + for plugin in pluginList: plugin.run("POC","80000000",data) except: logging.exception("Cannot Throw Modules") From 5974487f37515eb78f14489064797a2813f71d37 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 09:02:56 +0200 Subject: [PATCH 08/24] modul loading problems --- plugin_test/plugin_test.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugin_test/plugin_test.py b/plugin_test/plugin_test.py index 2a4ee35..c542a3d 100755 --- a/plugin_test/plugin_test.py +++ b/plugin_test/plugin_test.py @@ -52,16 +52,24 @@ except: data = {"ric":"1234567", "function":"1", "msg":"Hello World!"} #read Plugins -pluginList = [] +pluginlist = [] for i in pluginloader.getPlugins(): plugin = pluginloader.loadPlugin(i) - pluginList.append(plugin) + print(plugin) + pluginlist.append(plugin) +print() + +for i in pluginlist: + print(i) + +exit() while True: try: time.sleep(1) logging.info("Alarm!") for plugin in pluginList: + logging.info(plugin) plugin.run("POC","80000000",data) except: logging.exception("Cannot Throw Modules") From b8eb2a034a77ae8059472fb9036d1460b5237565 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 09:36:17 +0200 Subject: [PATCH 09/24] solve problems with pluginloader --- plugin_test/plugin_test.py | 18 +++--------------- plugin_test/pluginloader.py | 1 + 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/plugin_test/plugin_test.py b/plugin_test/plugin_test.py index c542a3d..4fb0229 100755 --- a/plugin_test/plugin_test.py +++ b/plugin_test/plugin_test.py @@ -51,25 +51,13 @@ except: #data = {"zvei":"12345"} data = {"ric":"1234567", "function":"1", "msg":"Hello World!"} -#read Plugins -pluginlist = [] -for i in pluginloader.getPlugins(): - plugin = pluginloader.loadPlugin(i) - print(plugin) - pluginlist.append(plugin) - -print() - -for i in pluginlist: - print(i) - -exit() while True: try: time.sleep(1) logging.info("Alarm!") - for plugin in pluginList: - logging.info(plugin) + for i in pluginloader.getPlugins(): + plugin = pluginloader.loadPlugin(i) + logging.debug(i["name"] + " Plugin called") plugin.run("POC","80000000",data) except: logging.exception("Cannot Throw Modules") diff --git a/plugin_test/pluginloader.py b/plugin_test/pluginloader.py index e5f45ae..768e521 100644 --- a/plugin_test/pluginloader.py +++ b/plugin_test/pluginloader.py @@ -9,6 +9,7 @@ import os PluginFolder = "./plugins" MainModule = "__init__" + def getPlugins(): plugins = [] possibleplugins = os.listdir(PluginFolder) From ee89d0776c50216d22e506ded8bc82bc3f1d140b Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 09:36:35 +0200 Subject: [PATCH 10/24] edit template plugin --- plugin_test/config/config.ini | 8 ++++++++ plugin_test/plugins/template/__init__.py | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/plugin_test/config/config.ini b/plugin_test/config/config.ini index 193ca98..c14d041 100644 --- a/plugin_test/config/config.ini +++ b/plugin_test/config/config.ini @@ -7,6 +7,7 @@ BosMon = 0 # for developing template-module is enabled template = 1 +none = 1 [BosMon] #Server as IP of DNS-Name (without http://) @@ -18,3 +19,10 @@ bosmon_channel = pocsag #Use this, when BosMon has restricted access bosmon_user = bosmon_password = + + +[template] +data1 = test123 +data2 = test345 +data3 = test567 +data4 = test789 \ No newline at end of file diff --git a/plugin_test/plugins/template/__init__.py b/plugin_test/plugins/template/__init__.py index d0f6005..9fff55c 100644 --- a/plugin_test/plugins/template/__init__.py +++ b/plugin_test/plugins/template/__init__.py @@ -9,6 +9,6 @@ def run(typ,freq,data): if typ == "ZVEI": logging.info("ZVEI: %s wurde auf %s empfangen!", data["zvei"],freq) else: - logging.warning(typ + " not supportet") + logging.warning(typ + " not implemented") except: - logging.exception("Error in Template Plugin") \ No newline at end of file + logging.exception("") \ No newline at end of file From 83debc08901973935b0a15d46f3368dc417a6098 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 09:36:46 +0200 Subject: [PATCH 11/24] edit logging in bosmon plugin --- plugin_test/plugins/BosMon/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin_test/plugins/BosMon/__init__.py b/plugin_test/plugins/BosMon/__init__.py index 4b0d124..78ecac0 100644 --- a/plugin_test/plugins/BosMon/__init__.py +++ b/plugin_test/plugins/BosMon/__init__.py @@ -23,10 +23,10 @@ def run(typ,freq,data): logging.debug(" - Channel: " +bosmon_channel) if typ == "FMS": - logging.warning("FMS not implemented in BosMon plugin") + logging.warning("FMS not implemented") elif typ == "ZVEI": - logging.warning("ZVEI not implemented in BosMon plugin") + logging.warning("ZVEI not implemented") elif typ == "POC": logging.debug("Start POC to BosMon") @@ -52,8 +52,8 @@ def run(typ,freq,data): else: logging.warning("BosMon response: "+str(httpresponse.status)+" - "+str(httpresponse.reason)) except: - logging.warning("POC to BosMon failed") + logging.error("POC to BosMon failed") else: - logging.warning("typ '"+typ+"' undefined in BosMon plugin") + logging.warning("undefined typ '"+typ+"'") except: - logging.exception("Error in BosMon Plugin") \ No newline at end of file + logging.exception("") \ No newline at end of file From d225b745da25380154baee4105ac62cb1522c402 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 11:25:38 +0200 Subject: [PATCH 12/24] boswatch.py without pluginloader --- plugin_test/boswatch.py | 342 ++++++++++++++++++++++++++++++++++ plugin_test/config/config.ini | 19 ++ 2 files changed, 361 insertions(+) create mode 100644 plugin_test/boswatch.py diff --git a/plugin_test/boswatch.py b/plugin_test/boswatch.py new file mode 100644 index 0000000..9b1691f --- /dev/null +++ b/plugin_test/boswatch.py @@ -0,0 +1,342 @@ +#!/usr/bin/python +# -*- coding: cp1252 -*- + +##### Info ##### +# BOSWatch +# Autor: Bastian Schroll +# Python Script to receive and decode German BOS Information with rtl_fm and multimon-NG +# 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 + +#create new logger +logger = logging.getLogger() +logger.setLevel(logging.DEBUG) +#set log string format +formatter = logging.Formatter('%(asctime)s - %(module)s [%(levelname)s] %(message)s', '%d.%m.%Y %I:%M:%S') +#create a file logger +fh = logging.FileHandler('log/boswatch.log', 'w') +fh.setLevel(logging.DEBUG) #log level >= Debug +fh.setFormatter(formatter) +logger.addHandler(fh) +#create a display logger +ch = logging.StreamHandler() +ch.setLevel(logging.INFO) #log level >= info +ch.setFormatter(formatter) +logger.addHandler(ch) + + +# Programm +try: + + #first Clear the Logfiles for logging + try: + script_path = os.path.dirname(os.path.abspath(__file__)) + + if not os.path.exists(script_path+"/log/"): + os.mkdir(script_path+"/log/") + + bos_log = open(script_path+"/log/boswatch.log", "w") + rtl_log = open(script_path+"/log/rtl_fm.log", "w") + mon_log = open(script_path+"/log/multimon.log", "w") +# bos_log.write("##### "+curtime()+" #####\n\n") +# rtl_log.write("##### "+curtime()+" #####\n\n") +# mon_log.write("##### "+curtime()+" #####\n\n") + bos_log.close() + rtl_log.close() + mon_log.close() + logging.debug("BOSWatch has started") + except: + logging.exception("cannot clear Logfiles") + + try: + logging.debug("parse args") + #With -h or --help you get the Args help + #ArgsParser + parser = argparse.ArgumentParser(prog="boswatch.py", description="BOSWatch is a Python Script to Recive and Decode German BOS Information with rtl_fm and multimon-NG", epilog="More Options you can find in the extern config.ini File in this Folder") + #parser.add_argument("-c", "--channel", help="BOS Channel you want to listen") + parser.add_argument("-f", "--freq", help="Frequency you want to listen", required=True) + parser.add_argument("-d", "--device", help="Device you want to use (Check with rtl_test)", type=int, default=0) + parser.add_argument("-e", "--error", help="Frequency-Error of your Device in PPM", type=int, default=0) + parser.add_argument("-a", "--demod", help="Demodulation Functions", choices=['FMS', 'ZVEI', 'POC512', 'POC1200', 'POC2400'], required=True, nargs="+") + 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 = [] + args = parser.parse_args() + except: + logging.exception("cannot parse args") + + #Read Data from Args, Put it into working Variables + freq = args.freq + device = args.device + error = args.error + squelch = args.squelch + + logging.debug(" - Frequency: %s", freq) + logging.debug(" - Device: %s", device) + logging.debug(" - PPM Error: %s", error) + logging.debug(" - Squelch: %s", squelch) + + demodulation = "" + if "FMS" in args.demod: + demodulation += "-a FMSFSK " + logging.debug(" - Demod: FMS") + if "ZVEI" in args.demod: + demodulation += "-a ZVEI2 " + logging.debug(" - Demod: ZVEI") + if "POC512" in args.demod: + demodulation += "-a POCSAG512 " + logging.debug(" - Demod: POC512") + if "POC1200" in args.demod: + demodulation += "-a POCSAG1200 " + logging.debug(" - Demod: P") + if "POC2400" in args.demod: + demodulation += "-a POCSAG2400 " + logging.debug(" - Demod: POC2400") + + logging.debug(" - Verbose Mode: %s", args.verbose) + logging.debug(" - Quiet Mode: %s", args.quiet) + + if args.verbose: + ch.setLevel(logging.DEBUG) + if args.quiet: + 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: "+freq + print "Device-ID: "+str(device) + print "Error in PPM: "+str(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(squelch) + if args.verbose: + print "Verbose Mode!" + print "" + + #variables pre-load + 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 + + + #ConfigParser + logging.debug("reading config file") + try: + globals.config = ConfigParser.ConfigParser() + globals.config.read(script_path+"/config/config.ini") + fms_double_ignore_time = int(globals.config.get("FMS", "double_ignore_time")) + zvei_double_ignore_time = int(globals.config.get("ZVEI", "double_ignore_time")) + poc_double_ignore_time = int(globals.config.get("POC", "double_ignore_time")) + poc_filter_range_start = int(globals.config.get("POC", "filter_range_start")) + poc_filter_range_end = int(globals.config.get("POC", "filter_range_end")) + except: + logging.exception("cannot read config file") + + #in case of reading error, set standard values + logging.debug("set to standard configuration") + fms_double_ignore_time = 5 + zvei_double_ignore_time = 5 + poc_double_ignore_time = 10 + poc_filter_range_start = 0000000 + poc_filter_range_end = 9999999 + finally: + logging.debug(" - fms_double_ignore_time = %s", fms_double_ignore_time) + logging.debug(" - zvei_double_ignore_time = %s", zvei_double_ignore_time) + logging.debug(" - poc_double_ignore_time = %s", poc_double_ignore_time) + logging.debug(" - poc_filter_range_start = %s", poc_filter_range_start) + logging.debug(" - poc_filter_range_end = %s", poc_filter_range_end) + + + logging.debug("starting rtl_fm") +# try: +# rtl_fm = subprocess.Popen("rtl_fm -d "+str(device)+" -f "+str(freq)+" -M fm -s 22050 -p "+str(error)+" -E DC -F 0 -l "+str(squelch)+" -g 100", +# #stdin=rtl_fm.stdout, +# stdout=subprocess.PIPE, +# stderr=open(script_path+"/log/rtl_fm.log","a"), +# shell=True) +# except: +# logging.exception("cannot start rtl_fm") +# + logging.debug("starting multimon-ng") +# try: +# multimon_ng = subprocess.Popen("multimon-ng "+str(demodulation)+" -f alpha -t raw /dev/stdin - ", +# stdin=rtl_fm.stdout, +# stdout=subprocess.PIPE, +# stderr=open(script_path+"/log/multimon.log","a"), +# shell=True) +# except: +# logging.exception("cannot start multimon-ng") + + + logging.debug("start decoding") + while True: + #RAW Data from Multimon-NG + #ZVEI2: 25832 + #FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST2=III(mit NA,ohneSIGNAL)) CRC correct\n' + decoded = ""#str(multimon_ng.stdout.readline()) #Get line data from multimon stdout + + if True: #if input data avalable + + 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 + fms_double_ignore_time: #check for double alarm + logging.warning("FMS double alarm: "+fms_id_old) + fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new + else: + logging.info("FMS:"+fms_id[0:8]+" Status:"+fms_status+" Richtung:"+fms_direction+" TKI:"+fms_tsi,"info") + fms_id_old = fms_id #save last id + fms_time_old = timestamp #save last time + else: + logging.warning("No valid FMS: "+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 + zvei_double_ignore_time: #check for double alarm + logging.warning("ZVEI double alarm: "+zvei_id_old) + zvei_time_old = timestamp #in case of double alarm, zvei_double_ignore_time set new + else: + logging.info("5-Ton: "+zvei_id,"info") + zvei_id_old = zvei_id #save last id + zvei_time_old = timestamp #save last time + else: + logging.warning("No valid ZVEI: "+zvei_id) + + + #POCSAG512 Decoder Section + #check POCSAG512: -> validate -> check double alarm -> log + #POCSAG512: Address: 1234567 Function: 1 Alpha: XXMSG MEfeweffsjh + if "POCSAG512:" in decoded: + logging.debug("recieved POCSAG512") + + poc_id = decoded[20:27] #POC Code + poc_sub = decoded[39].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1") + if "Alpha:" in decoded: #check if there is a text message + poc_text = decoded.split('Alpha: ')[1].strip().rstrip('').strip() + else: + poc_text = "" + + if re.search("[0-9]{7}", poc_id): #if POC is valid + if poc_id >= poc_filter_range_start: + if poc_id >= poc_filter_range_start: + if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm + logging.warning("POC512 double alarm: "+poc_id_old) + poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new + else: + logging.info("POCSAG512: "+poc_id+" "+poc_sub+" "+poc_text,"info") + poc_id_old = poc_id #save last id + poc_time_old = timestamp #save last time + else: + logging.warning("POCSAG512: "+poc_id+" out of filter range") + else: + logging.warning("POCSAG512: "+poc_id+" out of filter range") + else: + logging.warning("No valid POCSAG512: "+poc_id) + + + #POCSAG1200 Decoder Section + #check POCSAG1200: -> validate -> check double alarm -> log + #POCSAG1200: Address: 1234567 Function: 1 Alpha: XXMSG MEfeweffsjh + if "POCSAG1200:" in decoded: + logging.debug("recieved POCSAG1200") + + poc_id = decoded[21:28] #POC Code + poc_sub = decoded[40].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1") + if "Alpha:" in decoded: #check if there is a text message + poc_text = decoded.split('Alpha: ')[1].strip().rstrip('').strip() + else: + poc_text = "" + + if re.search("[0-9]{7}", poc_id): #if POC is valid + if poc_id >= poc_filter_range_start: + if poc_id >= poc_filter_range_start: + if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm + logging.warning("POC1200 double alarm: "+poc_id_old) + poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new + else: + logging.info("POCSAG1200: "+poc_id+" "+poc_sub+" "+poc_text,"info") + poc_id_old = poc_id #save last id + poc_time_old = timestamp #save last time + else: + logging.warning("POCSAG1200: "+poc_id+" out of filter range") + else: + logging.warning("POCSAG1200: "+poc_id+" out of filter range") + else: + logging.warning("No valid POCSAG1200: "+poc_id) + +except KeyboardInterrupt: + logging.warning("Keyboard Interrupt") +except: + logging.exception("") +finally: + try: +# rtl_fm.terminate() + logging.debug("rtl_fm terminated") +# multimon_ng.terminate() + logging.debug("multimon-ng terminated") + logging.debug("exiting BOSWatch") + except: + logging.exception("failed in clean-up routine") + finally: + exit(0) diff --git a/plugin_test/config/config.ini b/plugin_test/config/config.ini index c14d041..a5c8c36 100644 --- a/plugin_test/config/config.ini +++ b/plugin_test/config/config.ini @@ -2,6 +2,25 @@ # BOSWatch Config File # ######################## +######################## +# BOSWatch Config File # +######################## + +[FMS] +#time to ignore same alarm in a row (sek) +double_ignore_time = 5 + +[ZVEI] +#time to ignore same alarm in a row (sek) +double_ignore_time = 5 + +[POC] +#time to ignore same alarm in a row (sek) +double_ignore_time = 10 +filter_range_start = 0000000 +filter_range_end = 9999999 + + #can take on or off the modules (0|1) [Module] BosMon = 0 From baa204c3861561718bdaf9a83c9bff1c15c6820a Mon Sep 17 00:00:00 2001 From: Schrolli91 Date: Tue, 19 May 2015 11:27:37 +0200 Subject: [PATCH 13/24] Delete boswatch.log --- plugin_test/boswatch.log | 50 ---------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 plugin_test/boswatch.log diff --git a/plugin_test/boswatch.log b/plugin_test/boswatch.log deleted file mode 100644 index 0564611..0000000 --- a/plugin_test/boswatch.log +++ /dev/null @@ -1,50 +0,0 @@ -18.05.2015 03:30:59 - INFO: Alarm! -18.05.2015 03:30:59 - DEBUG: Loading plugin template -18.05.2015 03:30:59 - DEBUG: Throw Template Plugin -18.05.2015 03:30:59 - INFO: ZVEI: 12345 wurde auf 80000000 empfangen! -18.05.2015 03:30:59 - DEBUG: try 5/0 -18.05.2015 03:30:59 - ERROR: Error in Template Plugin -Traceback (most recent call last): - File "./plugins\template\__init__.py", line 8, in run - test = 5/0 -ZeroDivisionError: division by zero -18.05.2015 03:31:00 - INFO: Alarm! -18.05.2015 03:31:00 - DEBUG: Loading plugin template -18.05.2015 03:31:00 - DEBUG: Throw Template Plugin -18.05.2015 03:31:00 - INFO: ZVEI: 12345 wurde auf 80000000 empfangen! -18.05.2015 03:31:00 - DEBUG: try 5/0 -18.05.2015 03:31:00 - ERROR: Error in Template Plugin -Traceback (most recent call last): - File "./plugins\template\__init__.py", line 8, in run - test = 5/0 -ZeroDivisionError: division by zero -18.05.2015 03:31:01 - INFO: Alarm! -18.05.2015 03:31:01 - DEBUG: Loading plugin template -18.05.2015 03:31:01 - DEBUG: Throw Template Plugin -18.05.2015 03:31:01 - INFO: ZVEI: 12345 wurde auf 80000000 empfangen! -18.05.2015 03:31:01 - DEBUG: try 5/0 -18.05.2015 03:31:01 - ERROR: Error in Template Plugin -Traceback (most recent call last): - File "./plugins\template\__init__.py", line 8, in run - test = 5/0 -ZeroDivisionError: division by zero -18.05.2015 03:31:02 - INFO: Alarm! -18.05.2015 03:31:02 - DEBUG: Loading plugin template -18.05.2015 03:31:02 - DEBUG: Throw Template Plugin -18.05.2015 03:31:02 - INFO: ZVEI: 12345 wurde auf 80000000 empfangen! -18.05.2015 03:31:02 - DEBUG: try 5/0 -18.05.2015 03:31:02 - ERROR: Error in Template Plugin -Traceback (most recent call last): - File "./plugins\template\__init__.py", line 8, in run - test = 5/0 -ZeroDivisionError: division by zero -18.05.2015 03:31:03 - INFO: Alarm! -18.05.2015 03:31:03 - DEBUG: Loading plugin template -18.05.2015 03:31:03 - DEBUG: Throw Template Plugin -18.05.2015 03:31:03 - INFO: ZVEI: 12345 wurde auf 80000000 empfangen! -18.05.2015 03:31:03 - DEBUG: try 5/0 -18.05.2015 03:31:03 - ERROR: Error in Template Plugin -Traceback (most recent call last): - File "./plugins\template\__init__.py", line 8, in run - test = 5/0 -ZeroDivisionError: division by zero From 97957fe3fde0b904a102515f90f58168ad0da0cf Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 11:42:52 +0200 Subject: [PATCH 14/24] insert pluginloader in boswatch.py --- plugin_test/boswatch.py | 51 ++++++++++++++++++++++++----------- plugin_test/config/config.ini | 4 --- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/plugin_test/boswatch.py b/plugin_test/boswatch.py index 9b1691f..86e1c50 100644 --- a/plugin_test/boswatch.py +++ b/plugin_test/boswatch.py @@ -36,6 +36,13 @@ ch.setFormatter(formatter) logger.addHandler(ch) +def throwAlarm(typ,data): + for i in pluginloader.getPlugins(): + plugin = pluginloader.loadPlugin(i) + logging.debug(i["name"] + " Plugin called") + + + # Programm try: @@ -234,14 +241,17 @@ try: 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 + fms_double_ignore_time: #check for double alarm - logging.warning("FMS double alarm: "+fms_id_old) + logging.warning("FMS double alarm: %s", fms_id_old) fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new else: - logging.info("FMS:"+fms_id[0:8]+" Status:"+fms_status+" Richtung:"+fms_direction+" TKI:"+fms_tsi,"info") + data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "tki":fms_tsi} + throwAlarm("FMS",data) + logging.info("FMS:%s Status:%s Richtung:%s TKI:%s", fms_id[0:8], fms_status, fms_direction, fms_tsi) + fms_id_old = fms_id #save last id fms_time_old = timestamp #save last time else: - logging.warning("No valid FMS: "+fms_id) + logging.warning("No valid FMS: %s", fms_id) else: logging.warning("FMS CRC incorrect") @@ -254,14 +264,17 @@ try: 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 + zvei_double_ignore_time: #check for double alarm - logging.warning("ZVEI double alarm: "+zvei_id_old) + logging.warning("ZVEI double alarm: %s", zvei_id_old) zvei_time_old = timestamp #in case of double alarm, zvei_double_ignore_time set new else: - logging.info("5-Ton: "+zvei_id,"info") + data = {"zvei":"1234567"} + throwAlarm("ZVEI",data) + logging.info("5-Ton: %s", zvei_id) + zvei_id_old = zvei_id #save last id zvei_time_old = timestamp #save last time else: - logging.warning("No valid ZVEI: "+zvei_id) + logging.warning("No valid ZVEI: %s", zvei_id) #POCSAG512 Decoder Section @@ -281,18 +294,21 @@ try: if poc_id >= poc_filter_range_start: if poc_id >= poc_filter_range_start: if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm - logging.warning("POC512 double alarm: "+poc_id_old) + logging.warning("POC512 double alarm: %s", poc_id_old) poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new else: - logging.info("POCSAG512: "+poc_id+" "+poc_sub+" "+poc_text,"info") + data = {"ric":"1234567", "function":"1", "msg":"Hello World!"} + throwAlarm("POC",data) + logging.info("POCSAG512: %s %s %s ", poc_id, poc_sub, poc_text) + poc_id_old = poc_id #save last id poc_time_old = timestamp #save last time else: - logging.warning("POCSAG512: "+poc_id+" out of filter range") + logging.warning("POCSAG512: %s out of filter range", poc_id) else: - logging.warning("POCSAG512: "+poc_id+" out of filter range") + logging.warning("POCSAG512: %s out of filter range", poc_id) else: - logging.warning("No valid POCSAG512: "+poc_id) + logging.warning("No valid POCSAG512: %s", poc_id) #POCSAG1200 Decoder Section @@ -312,18 +328,21 @@ try: if poc_id >= poc_filter_range_start: if poc_id >= poc_filter_range_start: if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm - logging.warning("POC1200 double alarm: "+poc_id_old) + logging.warning("POC1200 double alarm: %s", poc_id_old) poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new else: - logging.info("POCSAG1200: "+poc_id+" "+poc_sub+" "+poc_text,"info") + data = {"ric":"1234567", "function":"1", "msg":"Hello World!"} + throwAlarm("POC",data) + logging.info("POCSAG1200: %s %s %s", poc_id, poc_sub, poc_text) + poc_id_old = poc_id #save last id poc_time_old = timestamp #save last time else: - logging.warning("POCSAG1200: "+poc_id+" out of filter range") + logging.warning("POCSAG1200: %s out of filter range", poc_id) else: - logging.warning("POCSAG1200: "+poc_id+" out of filter range") + logging.warning("POCSAG1200: %s out of filter range", poc_id) else: - logging.warning("No valid POCSAG1200: "+poc_id) + logging.warning("No valid POCSAG1200: %s", poc_id) except KeyboardInterrupt: logging.warning("Keyboard Interrupt") diff --git a/plugin_test/config/config.ini b/plugin_test/config/config.ini index a5c8c36..3a966c8 100644 --- a/plugin_test/config/config.ini +++ b/plugin_test/config/config.ini @@ -2,10 +2,6 @@ # BOSWatch Config File # ######################## -######################## -# BOSWatch Config File # -######################## - [FMS] #time to ignore same alarm in a row (sek) double_ignore_time = 5 From b1039b5fb3b3b83a122526f3cb55bc65791c9305 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 11:45:51 +0200 Subject: [PATCH 15/24] tabulator error --- plugin_test/boswatch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin_test/boswatch.py b/plugin_test/boswatch.py index 86e1c50..7fc6f80 100644 --- a/plugin_test/boswatch.py +++ b/plugin_test/boswatch.py @@ -38,8 +38,9 @@ logger.addHandler(ch) def throwAlarm(typ,data): for i in pluginloader.getPlugins(): - plugin = pluginloader.loadPlugin(i) - logging.debug(i["name"] + " Plugin called") + plugin = pluginloader.loadPlugin(i) + logging.debug(i["name"] + " Plugin called") + plugin.run(typ,"0",data) From abefd3c21a014ffa5081cda3487376169b054eb4 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 11:49:43 +0200 Subject: [PATCH 16/24] use real data at alarm --- plugin_test/boswatch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin_test/boswatch.py b/plugin_test/boswatch.py index 7fc6f80..b7ed95f 100644 --- a/plugin_test/boswatch.py +++ b/plugin_test/boswatch.py @@ -268,7 +268,7 @@ try: logging.warning("ZVEI double alarm: %s", zvei_id_old) zvei_time_old = timestamp #in case of double alarm, zvei_double_ignore_time set new else: - data = {"zvei":"1234567"} + data = {"zvei":zvei_id} throwAlarm("ZVEI",data) logging.info("5-Ton: %s", zvei_id) @@ -298,7 +298,7 @@ try: logging.warning("POC512 double alarm: %s", poc_id_old) poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new else: - data = {"ric":"1234567", "function":"1", "msg":"Hello World!"} + data = {"ric":poc_id, "function":poc_sub, "msg":poc_text} throwAlarm("POC",data) logging.info("POCSAG512: %s %s %s ", poc_id, poc_sub, poc_text) @@ -332,7 +332,7 @@ try: logging.warning("POC1200 double alarm: %s", poc_id_old) poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new else: - data = {"ric":"1234567", "function":"1", "msg":"Hello World!"} + data = {"ric":poc_id, "function":poc_sub, "msg":poc_text} throwAlarm("POC",data) logging.info("POCSAG1200: %s %s %s", poc_id, poc_sub, poc_text) From de80f49aa32c28dda7ad425e1c7c929569870961 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 12:01:01 +0200 Subject: [PATCH 17/24] change logging in bosmon plugin --- plugin_test/plugins/BosMon/__init__.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugin_test/plugins/BosMon/__init__.py b/plugin_test/plugins/BosMon/__init__.py index 78ecac0..315c110 100644 --- a/plugin_test/plugins/BosMon/__init__.py +++ b/plugin_test/plugins/BosMon/__init__.py @@ -11,16 +11,17 @@ import base64 #for the HTTP request with User/Password def run(typ,freq,data): try: #get BosMon-Config + logging.debug("read config file") 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") - logging.debug(" - typ: " +typ) - logging.debug(" - Server: " +bosmon_server) - logging.debug(" - Port: " +bosmon_port) - logging.debug(" - User: " +bosmon_user) - logging.debug(" - Channel: " +bosmon_channel) + 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) if typ == "FMS": logging.warning("FMS not implemented") @@ -38,7 +39,7 @@ def run(typ,freq,data): #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:" +params) + logging.debug(" - Params: %s", params) headers = {} headers['Content-type'] = "application/x-www-form-urlencoded" headers['Accept'] = "text/plain" @@ -48,12 +49,12 @@ def run(typ,freq,data): 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: "+str(httpresponse.status)+" - "+str(httpresponse.reason)) + logging.debug("BosMon response: %s - %s", str(httpresponse.status), str(httpresponse.reason)) else: - logging.warning("BosMon response: "+str(httpresponse.status)+" - "+str(httpresponse.reason)) + logging.warning("BosMon response: %s - %s", str(httpresponse.status), str(httpresponse.reason)) except: logging.error("POC to BosMon failed") else: - logging.warning("undefined typ '"+typ+"'") + logging.warning("undefined typ '%s'", typ) except: logging.exception("") \ No newline at end of file From d028df662e1a128b271563b6dfc43b18495a00d2 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 12:58:13 +0200 Subject: [PATCH 18/24] edit template plugin --- plugin_test/boswatch.py | 5 +---- plugin_test/plugins/template/__init__.py | 25 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/plugin_test/boswatch.py b/plugin_test/boswatch.py index b7ed95f..e7aa883 100644 --- a/plugin_test/boswatch.py +++ b/plugin_test/boswatch.py @@ -42,8 +42,6 @@ def throwAlarm(typ,data): logging.debug(i["name"] + " Plugin called") plugin.run(typ,"0",data) - - # Programm try: @@ -80,7 +78,6 @@ 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 = [] args = parser.parse_args() except: logging.exception("cannot parse args") @@ -348,7 +345,7 @@ try: except KeyboardInterrupt: logging.warning("Keyboard Interrupt") except: - logging.exception("") + logging.exception("unknown error") finally: try: # rtl_fm.terminate() diff --git a/plugin_test/plugins/template/__init__.py b/plugin_test/plugins/template/__init__.py index 9fff55c..1e2eccc 100644 --- a/plugin_test/plugins/template/__init__.py +++ b/plugin_test/plugins/template/__init__.py @@ -6,9 +6,24 @@ import globals # Global variables def run(typ,freq,data): try: - if typ == "ZVEI": - logging.info("ZVEI: %s wurde auf %s empfangen!", data["zvei"],freq) - else: - logging.warning(typ + " not implemented") + logging.debug("read config file") + data1 = globals.config.get("template", "data1") + data2 = globals.config.get("template", "data2") + data3 = globals.config.get("template", "data3") + data4 = globals.config.get("template", "data4") + logging.debug(" - Data1: %s", data1) + logging.debug(" - Data2: %s", data2) + logging.debug(" - Data3: %s", data3) + logging.debug(" - Data4: %s", data4) + + if typ == "FMS": + logging.debug("FMS: %s Status: %s Dir: $s", data["fms"], data["status", data["direction") + elif typ == "ZVEI": + logging.debug("ZVEI: %s", data["zvei"]) + elif typ == "POC": + logging.debug("POC: %s/%s - %s", data["ric"], data["function"], data["msg"]) + else + logging.warning(typ + " not supportet") + except: - logging.exception("") \ No newline at end of file + logging.exception("unknown error") \ No newline at end of file From b3d80b976f2ca434b9253ccc6e8616ae3cfbbcd9 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 14:04:50 +0200 Subject: [PATCH 19/24] test plugins with boswatch.py test pluginloader with boswatch.py + little error in template plugin --- plugin_test/boswatch.py | 24 +++++++++++++++--------- plugin_test/plugins/template/__init__.py | 4 ++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/plugin_test/boswatch.py b/plugin_test/boswatch.py index e7aa883..944c13e 100644 --- a/plugin_test/boswatch.py +++ b/plugin_test/boswatch.py @@ -216,8 +216,14 @@ try: #RAW Data from Multimon-NG #ZVEI2: 25832 #FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST2=III(mit NA,ohneSIGNAL)) CRC correct\n' - decoded = ""#str(multimon_ng.stdout.readline()) #Get line data from multimon stdout - + #decoded = str(multimon_ng.stdout.readline()) #Get line data from multimon stdout + + #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'" + time.sleep(1) + + if True: #if input data avalable timestamp = int(time.time())#Get Timestamp @@ -242,9 +248,9 @@ try: logging.warning("FMS double alarm: %s", fms_id_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, "tki":fms_tsi} throwAlarm("FMS",data) - logging.info("FMS:%s Status:%s Richtung:%s TKI:%s", fms_id[0:8], fms_status, fms_direction, fms_tsi) fms_id_old = fms_id #save last id fms_time_old = timestamp #save last time @@ -265,10 +271,10 @@ try: logging.warning("ZVEI double alarm: %s", zvei_id_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) - logging.info("5-Ton: %s", zvei_id) - + zvei_id_old = zvei_id #save last id zvei_time_old = timestamp #save last time else: @@ -295,10 +301,10 @@ try: logging.warning("POC512 double alarm: %s", poc_id_old) poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new else: + logging.info("POCSAG512: %s %s %s ", poc_id, poc_sub, poc_text) data = {"ric":poc_id, "function":poc_sub, "msg":poc_text} throwAlarm("POC",data) - logging.info("POCSAG512: %s %s %s ", poc_id, poc_sub, poc_text) - + poc_id_old = poc_id #save last id poc_time_old = timestamp #save last time else: @@ -329,10 +335,10 @@ try: logging.warning("POC1200 double alarm: %s", poc_id_old) poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new else: + logging.info("POCSAG1200: %s %s %s", poc_id, poc_sub, poc_text) data = {"ric":poc_id, "function":poc_sub, "msg":poc_text} throwAlarm("POC",data) - logging.info("POCSAG1200: %s %s %s", poc_id, poc_sub, poc_text) - + poc_id_old = poc_id #save last id poc_time_old = timestamp #save last time else: diff --git a/plugin_test/plugins/template/__init__.py b/plugin_test/plugins/template/__init__.py index 1e2eccc..0cebb17 100644 --- a/plugin_test/plugins/template/__init__.py +++ b/plugin_test/plugins/template/__init__.py @@ -17,12 +17,12 @@ def run(typ,freq,data): logging.debug(" - Data4: %s", data4) if typ == "FMS": - logging.debug("FMS: %s Status: %s Dir: $s", data["fms"], data["status", data["direction") + logging.debug("FMS: %s Status: %s Dir: %s", data["fms"], data["status"], data["direction"]) elif typ == "ZVEI": logging.debug("ZVEI: %s", data["zvei"]) elif typ == "POC": logging.debug("POC: %s/%s - %s", data["ric"], data["function"], data["msg"]) - else + else: logging.warning(typ + " not supportet") except: From 86f4197d0fb65e4467b5bfb5a024b9e2af5ef129 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 14:30:03 +0200 Subject: [PATCH 20/24] edit Log Time Format to 24 hours --- plugin_test/boswatch.py | 2 +- plugin_test/plugin_test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin_test/boswatch.py b/plugin_test/boswatch.py index 944c13e..7ea591d 100644 --- a/plugin_test/boswatch.py +++ b/plugin_test/boswatch.py @@ -23,7 +23,7 @@ import time #timestamp for doublealarm logger = logging.getLogger() logger.setLevel(logging.DEBUG) #set log string format -formatter = logging.Formatter('%(asctime)s - %(module)s [%(levelname)s] %(message)s', '%d.%m.%Y %I:%M:%S') +formatter = logging.Formatter('%(asctime)s - %(module)s [%(levelname)s] %(message)s', '%d.%m.%Y %H:%M:%S') #create a file logger fh = logging.FileHandler('log/boswatch.log', 'w') fh.setLevel(logging.DEBUG) #log level >= Debug diff --git a/plugin_test/plugin_test.py b/plugin_test/plugin_test.py index 4fb0229..0d34f14 100755 --- a/plugin_test/plugin_test.py +++ b/plugin_test/plugin_test.py @@ -15,7 +15,7 @@ logger = logging.getLogger() logger.setLevel(logging.DEBUG) #set log string format -formatter = logging.Formatter('%(asctime)s - %(module)s [%(levelname)s] %(message)s', '%d.%m.%Y %I:%M:%S') +formatter = logging.Formatter('%(asctime)s - %(module)s [%(levelname)s] %(message)s', '%d.%m.%Y %H:%M:%S') #create a file loger fh = logging.FileHandler('boswatch.log', 'w') From 30f0a3c88df9e1c9f3c70ced249805065463b0ab Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 14:38:51 +0200 Subject: [PATCH 21/24] shows time between double alarms --- plugin_test/boswatch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin_test/boswatch.py b/plugin_test/boswatch.py index 7ea591d..bbc0725 100644 --- a/plugin_test/boswatch.py +++ b/plugin_test/boswatch.py @@ -245,7 +245,7 @@ try: 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 + fms_double_ignore_time: #check for double alarm - logging.warning("FMS double alarm: %s", fms_id_old) + 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) @@ -268,7 +268,7 @@ try: 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 + zvei_double_ignore_time: #check for double alarm - logging.warning("ZVEI double alarm: %s", zvei_id_old) + 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) @@ -298,7 +298,7 @@ try: if poc_id >= poc_filter_range_start: if poc_id >= poc_filter_range_start: if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm - logging.warning("POC512 double alarm: %s", poc_id_old) + logging.warning("POC512 double alarm: %s within %s second(s)", 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("POCSAG512: %s %s %s ", poc_id, poc_sub, poc_text) @@ -332,7 +332,7 @@ try: if poc_id >= poc_filter_range_start: if poc_id >= poc_filter_range_start: if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm - logging.warning("POC1200 double alarm: %s", poc_id_old) + logging.warning("POC1200 double alarm: %s within %s second(s)", 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("POCSAG1200: %s %s %s", poc_id, poc_sub, poc_text) From 928b143e2ed5d979b5875435605f6fa43bcfc9c6 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 15:11:22 +0200 Subject: [PATCH 22/24] little format change in log --- plugin_test/boswatch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin_test/boswatch.py b/plugin_test/boswatch.py index bbc0725..62472a7 100644 --- a/plugin_test/boswatch.py +++ b/plugin_test/boswatch.py @@ -23,7 +23,7 @@ import time #timestamp for doublealarm logger = logging.getLogger() logger.setLevel(logging.DEBUG) #set log string format -formatter = logging.Formatter('%(asctime)s - %(module)s [%(levelname)s] %(message)s', '%d.%m.%Y %H:%M:%S') +formatter = logging.Formatter('%(asctime)s - %(module)-15s [%(levelname)-8s] %(message)s', '%d.%m.%Y %H:%M:%S') #create a file logger fh = logging.FileHandler('log/boswatch.log', 'w') fh.setLevel(logging.DEBUG) #log level >= Debug From 39300f8c7cec3d7a1e20e1d698f36dff8b8db126 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 15:42:25 +0200 Subject: [PATCH 23/24] little edit plugin_test.py --- plugin_test/plugin_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin_test/plugin_test.py b/plugin_test/plugin_test.py index 0d34f14..c59b04b 100755 --- a/plugin_test/plugin_test.py +++ b/plugin_test/plugin_test.py @@ -6,7 +6,7 @@ import time import pluginloader import os #for absolute path: os.path.dirname(os.path.abspath(__file__)) -import configparser #for parse the config file +import ConfigParser #for parse the config file import logging @@ -43,7 +43,7 @@ logger.addHandler(ch) try: logging.debug("reading config file") script_path = os.path.dirname(os.path.abspath(__file__)) - globals.config = configparser.ConfigParser() + globals.config = ConfigParser.ConfigParser() globals.config.read(script_path+"/config/config.ini") except: logging.exception("cannot read config file") From 2d64d468a8063bbf9f7804e0c71ad42bcabc6115 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 19 May 2015 15:43:15 +0200 Subject: [PATCH 24/24] change Module Names --- plugin_test/pluginloader.py | 8 +++----- plugin_test/plugins/BosMon/{__init__.py => BosMon.py} | 0 plugin_test/plugins/none/{__init__.py => none.py} | 0 plugin_test/plugins/template/{__init__.py => template.py} | 0 4 files changed, 3 insertions(+), 5 deletions(-) rename plugin_test/plugins/BosMon/{__init__.py => BosMon.py} (100%) rename plugin_test/plugins/none/{__init__.py => none.py} (100%) rename plugin_test/plugins/template/{__init__.py => template.py} (100%) diff --git a/plugin_test/pluginloader.py b/plugin_test/pluginloader.py index 768e521..80bc996 100644 --- a/plugin_test/pluginloader.py +++ b/plugin_test/pluginloader.py @@ -7,8 +7,6 @@ import imp import os PluginFolder = "./plugins" -MainModule = "__init__" - def getPlugins(): plugins = [] @@ -16,7 +14,7 @@ def getPlugins(): for i in possibleplugins: location = os.path.join(PluginFolder, i) # plugins have to be a subdir with MainModule, if not skip - if not os.path.isdir(location) or not MainModule + ".py" in os.listdir(location): + if not os.path.isdir(location) or not i + ".py" in os.listdir(location): continue logging.debug("found plugin: "+i) @@ -28,10 +26,10 @@ def getPlugins(): logging.debug("use Plugin: "+str(usePlugin)) if usePlugin: - info = imp.find_module(MainModule, [location]) + info = imp.find_module(i, [location]) plugins.append({"name": i, "info": info}) logging.debug("append Plugin: "+i) return plugins def loadPlugin(plugin): - return imp.load_module(MainModule, *plugin["info"]) \ No newline at end of file + return imp.load_module(plugin["name"], *plugin["info"]) \ No newline at end of file diff --git a/plugin_test/plugins/BosMon/__init__.py b/plugin_test/plugins/BosMon/BosMon.py similarity index 100% rename from plugin_test/plugins/BosMon/__init__.py rename to plugin_test/plugins/BosMon/BosMon.py diff --git a/plugin_test/plugins/none/__init__.py b/plugin_test/plugins/none/none.py similarity index 100% rename from plugin_test/plugins/none/__init__.py rename to plugin_test/plugins/none/none.py diff --git a/plugin_test/plugins/template/__init__.py b/plugin_test/plugins/template/template.py similarity index 100% rename from plugin_test/plugins/template/__init__.py rename to plugin_test/plugins/template/template.py