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: diff --git a/boswatch.py b/boswatch.py index 90dabc8..3cf9867 100755 --- a/boswatch.py +++ b/boswatch.py @@ -125,15 +125,26 @@ 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() + #load filters + from includes import filter + filter.getFilters() + try: #start rtl_fm logging.debug("starting rtl_fm") @@ -191,4 +202,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..febde63 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -3,6 +3,14 @@ ######################## [BOSWatch] +#set loglevel for logfile +#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 @@ -16,6 +24,12 @@ poc_filter_range_start = 0000000 poc_filter_range_end = 9999999 +[Filters] +#No Filter for a Typ/Plugin Combination = all Data pass +#INDIVIDUAL_NAME = TYP;PLUGIN;REGEX +zvei_local_filter = ZVEI;template;25[0-9F]{3} + + [Plugins] #can take on or off the plugins (0|1) MySQL = 0 @@ -42,18 +56,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 @@ -61,6 +72,11 @@ zvei_url = www.google.de poc_url = www.google.de +##################### +##### Not ready yet # +##################### + + [template] data1 = test123 data2 = test345 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 new file mode 100644 index 0000000..6de5d44 --- /dev/null +++ b/includes/filter.py @@ -0,0 +1,50 @@ +#!/usr/bin/python +# -*- coding: cp1252 -*- + +import logging # Global logger + +import re #Regex for Filter Check + +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") + + +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: + foundFilter = True + logging.debug("found Filter: %s = %s", i["name"], i["regex"]) + if re.search(i["regex"], data): + logging.debug("Filter passed: %s", i["name"]) + return True + else: + logging.debug("Filter not passed: %s", i["name"]) + + if foundFilter: + logging.debug("no Filter passed") + return False + else: + logging.debug("no Filter found") + return True + + except: + logging.exception("Error in Filter checking") \ No newline at end of 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 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" 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: