From ac7965137d9426f44ce4169baa32d4d74caef82d Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sat, 23 May 2015 07:48:02 +0200 Subject: [PATCH 01/11] set Loglevel of fileHandler in config.ini --- boswatch.py | 13 ++++++++++--- config/config.template.ini | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/boswatch.py b/boswatch.py index 90dabc8..2a8e2de 100755 --- a/boswatch.py +++ b/boswatch.py @@ -125,11 +125,18 @@ try: 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.exception("cannot read config file") - else: + else: + try: + #set the loglevel of the file handler + logging.debug("set loglevel of fileHandler") + fh.setLevel(globals.config.getint("BOSWatch","loglevel")) + except: + logging.exception("cannot set loglevel of fileHandler") + #load plugins from includes import pluginLoader pluginLoader.loadPlugins() @@ -191,4 +198,4 @@ finally: logging.warning("failed in clean-up routine") finally: logging.info("BOSWatch exit()") - exit(0) \ No newline at end of file + exit(0) diff --git a/config/config.template.ini b/config/config.template.ini index fa0a032..e697a7e 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -3,6 +3,9 @@ ######################## [BOSWatch] +#set loglevel for logfile +loglevel = 20 + #time to ignore same alarm in a row (sek) fms_double_ignore_time = 5 From 8ce7af579b266a134c495ba63712e3f61e33c0d6 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sat, 23 May 2015 07:50:20 +0200 Subject: [PATCH 02/11] edit config.template.ini --- config/config.template.ini | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/config/config.template.ini b/config/config.template.ini index e697a7e..cafa98f 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -4,7 +4,12 @@ [BOSWatch] #set loglevel for logfile -loglevel = 20 +#10 = debug +#20 = info +#30 = warning +#40 = error +#50 = critical +loglevel = 10 #time to ignore same alarm in a row (sek) fms_double_ignore_time = 5 @@ -45,18 +50,15 @@ tablePOC = bos_pocsag #actually no ssl supported bosmon_server = 192.168.0.1 bosmon_port = 80 + #channel-name of typ "Web-Telegramm" bosmon_channel = channel + #Use this, when BosMon has restricted access bosmon_user = bosmon_password = -##################### -##### Not ready yet # -##################### - - [httpRequest] #URL without http:// fms_url = www.google.de @@ -64,6 +66,11 @@ zvei_url = www.google.de poc_url = www.google.de +##################### +##### Not ready yet # +##################### + + [template] data1 = test123 data2 = test345 From 298ed0a06c199857b34147f84e8fd9f1b0b7293e Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sat, 23 May 2015 08:40:35 +0200 Subject: [PATCH 03/11] fixed error httpreq plugin --- plugins/httpRequest/httpRequest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/httpRequest/httpRequest.py b/plugins/httpRequest/httpRequest.py index 689c4bc..85ee16f 100644 --- a/plugins/httpRequest/httpRequest.py +++ b/plugins/httpRequest/httpRequest.py @@ -53,7 +53,7 @@ def run(typ,freq,data): logging.warning("Invalid Typ: %s", typ) except: - loggin.exception("cannot send HTTP request") + logging.exception("cannot send HTTP request") else: try: From 43e56967cc8b9a781191144fba1f03167635ad7b Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sat, 23 May 2015 08:47:05 +0200 Subject: [PATCH 04/11] add filter.py filtering alarms method getFilters() added --- config/config.template.ini | 7 +++++++ includes/filter.py | 17 +++++++++++++++++ includes/globals.py | 7 +++++-- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 includes/filter.py diff --git a/config/config.template.ini b/config/config.template.ini index cafa98f..cede352 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -24,6 +24,13 @@ poc_filter_range_start = 0000000 poc_filter_range_end = 9999999 +[Filters] +#NAME = TYP;PLUGIN;REGEX +zvei_local_filter = ZVEI;template;25[0-9F]{3} +zvei_mysql = ZVEI;MySQL;23[0-9F]{3} +fms_filter = FMS;template;25[0-9F]{3} + + [Plugins] #can take on or off the plugins (0|1) MySQL = 0 diff --git a/includes/filter.py b/includes/filter.py new file mode 100644 index 0000000..c4baadc --- /dev/null +++ b/includes/filter.py @@ -0,0 +1,17 @@ +#!/usr/bin/python +# -*- coding: cp1252 -*- + +import logging # Global logger + +from includes import globals # Global variables + + +def getFilters(): + logging.debug("reading config file") + try: + for key,val in globals.config.items("Filters"): + logging.debug(" - %s = %s", key, val) + filter = val.split(";") + globals.filterList.append({"name": key, "typ": filter[0], "plugin": filter[1], "regex": filter[2]}) + except: + logging.exception("cannot read config file") diff --git a/includes/globals.py b/includes/globals.py index 14fb308..f4af170 100644 --- a/includes/globals.py +++ b/includes/globals.py @@ -15,5 +15,8 @@ zvei_time_old = 0 poc_id_old = 0 poc_time_old = 0 -#pluginHandler -pluginList = {} \ No newline at end of file +#pluginLoader +pluginList = {} + +#filter +filterList = [] \ No newline at end of file From 7adb710be16db2445259a217df552f65656f9b6e Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sat, 23 May 2015 08:58:46 +0200 Subject: [PATCH 05/11] insert filter.checkFilters() --- includes/filter.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/includes/filter.py b/includes/filter.py index c4baadc..eefd95c 100644 --- a/includes/filter.py +++ b/includes/filter.py @@ -3,6 +3,8 @@ import logging # Global logger +import re #Regex for Filter Check + from includes import globals # Global variables @@ -15,3 +17,29 @@ def getFilters(): globals.filterList.append({"name": key, "typ": filter[0], "plugin": filter[1], "regex": filter[2]}) except: logging.exception("cannot read config file") + + +def checkFilters(data,typ,plugin): + try: + logging.debug("search Filter for %s to %s", typ, plugin) + + foundFilter = False + for i in globals.filterList: + if i["typ"] == typ and i["plugin"] == plugin: + foundFilter = True + logging.debug("found Filter: %s = %s", i["name"], i["regex"]) + if re.search(i["regex"], data): + logging.debug("Filter passed") + return True + else: + logging.debug("Filter not passed") + + if foundFilter: + logging.debug("no Filter passed") + return False + else: + logging.debug("no Filter found") + return True + + except: + logging.exception("") \ No newline at end of file From fbdc08d05a2788318cd06f1dd507790eebc80d88 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sat, 23 May 2015 09:04:01 +0200 Subject: [PATCH 06/11] debug edit in filter.py --- includes/filter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/filter.py b/includes/filter.py index eefd95c..a804466 100644 --- a/includes/filter.py +++ b/includes/filter.py @@ -29,10 +29,10 @@ def checkFilters(data,typ,plugin): foundFilter = True logging.debug("found Filter: %s = %s", i["name"], i["regex"]) if re.search(i["regex"], data): - logging.debug("Filter passed") + logging.debug("Filter passed: %s", i["name"]) return True else: - logging.debug("Filter not passed") + logging.debug("Filter not passed: %s", i["name"]) if foundFilter: logging.debug("no Filter passed") From 45159aa16e32feee86a2099407c9ee16914ef52f Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sat, 23 May 2015 09:07:15 +0200 Subject: [PATCH 07/11] edit config --- config/config.template.ini | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/config/config.template.ini b/config/config.template.ini index cede352..febde63 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -25,10 +25,9 @@ poc_filter_range_end = 9999999 [Filters] -#NAME = TYP;PLUGIN;REGEX +#No Filter for a Typ/Plugin Combination = all Data pass +#INDIVIDUAL_NAME = TYP;PLUGIN;REGEX zvei_local_filter = ZVEI;template;25[0-9F]{3} -zvei_mysql = ZVEI;MySQL;23[0-9F]{3} -fms_filter = FMS;template;25[0-9F]{3} [Plugins] From 206463f8e90d8cf56cc8b1f95f89e473f54d1cbb Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sat, 23 May 2015 09:09:13 +0200 Subject: [PATCH 08/11] load filters in boswatch.py --- boswatch.py | 6 +++++- includes/filter.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/boswatch.py b/boswatch.py index 2a8e2de..3cf9867 100755 --- a/boswatch.py +++ b/boswatch.py @@ -136,11 +136,15 @@ try: fh.setLevel(globals.config.getint("BOSWatch","loglevel")) except: logging.exception("cannot set loglevel of fileHandler") - + #load plugins from includes import pluginLoader pluginLoader.loadPlugins() + #load filters + from includes import filter + filter.getFilters() + try: #start rtl_fm logging.debug("starting rtl_fm") diff --git a/includes/filter.py b/includes/filter.py index a804466..03beced 100644 --- a/includes/filter.py +++ b/includes/filter.py @@ -42,4 +42,4 @@ def checkFilters(data,typ,plugin): return True except: - logging.exception("") \ No newline at end of file + logging.exception("Error in Filter checking") \ No newline at end of file From 02a84b6ec926f4e74600b00ca515d86b60531fdb Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sat, 23 May 2015 09:34:48 +0200 Subject: [PATCH 09/11] add filter check to alarm add filter.checkFilters() to alarmHandler.processAlarm() --- includes/alarmHandler.py | 10 ++++++---- includes/filter.py | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/includes/alarmHandler.py b/includes/alarmHandler.py index 8890ee4..6c648cf 100644 --- a/includes/alarmHandler.py +++ b/includes/alarmHandler.py @@ -7,8 +7,10 @@ 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) + for pluginName, plugin in globals.pluginList.items(): + from includes import filter + if filter.checkFilters(data,typ,pluginName): + logging.debug("call Plugin: %s", pluginName) + plugin.run(typ,freq,data) + logging.debug("return from: %s", pluginName) logging.debug("[END ALARM]") \ No newline at end of file diff --git a/includes/filter.py b/includes/filter.py index 03beced..6de5d44 100644 --- a/includes/filter.py +++ b/includes/filter.py @@ -23,6 +23,11 @@ def checkFilters(data,typ,plugin): try: logging.debug("search Filter for %s to %s", typ, plugin) + #extract the correct data for filtering + if typ == "FMS": data = data["fms"] + if typ == "ZVEI": data = data["zvei"] + if typ == "POC": data = data["poc"] + foundFilter = False for i in globals.filterList: if i["typ"] == typ and i["plugin"] == plugin: From 205114bad5f066846e09fb005f3c81b4191fd69f Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sat, 23 May 2015 09:35:46 +0200 Subject: [PATCH 10/11] edit plugin_test.py for filter check --- plugin_test.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin_test.py b/plugin_test.py index 4981052..624ca8b 100644 --- a/plugin_test.py +++ b/plugin_test.py @@ -14,6 +14,7 @@ import time #timestamp for doublealarm from includes import globals # Global variables from includes import pluginLoader from includes import alarmHandler +from includes import filter #create new logger logger = logging.getLogger() @@ -52,6 +53,8 @@ except: pluginLoader.loadPlugins() +filter.getFilters() + # ----- Test Data ----- # #typ = "FMS" From 5adad2f2fa5e86040e5ed6a15ba2094f333b9701 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sat, 23 May 2015 09:40:59 +0200 Subject: [PATCH 11/11] edit readme.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 732c90b..22b50d9 100644 --- a/README.md +++ b/README.md @@ -17,20 +17,20 @@ unless you are developer you can use the develop-Branch - may be unstable! - Plugin support for easy Functions extension - Filtering double alarms with adjustable time - Filtering Range of POCSAG RIC“s +- Filtering Data for each Typ/Plugin combination - All configurations in seperate config File - Data validation (plausibility test) - Logfiles for better Troubleshooting - verbose/quiet Mode for more/none information ##### Features for the Future: -- extensive filtering options - more Plugins ###Plugins ##### Implemented Plugins: - MySQL (insert Data into MySQL Database [FMS|ZVEI|POC]) -- BosMon (send Data to BosMon Server [POC]) +- BosMon (send Data to BosMon Server [ZVEI|POC]) - httpRequest (send a request to an URL [FMS|ZVEI|POC]) ##### Plugins for the Future: