diff --git a/docu/docs/modul/regex_filter.md b/docu/docs/modul/regex_filter.md index 172901f..f554452 100644 --- a/docu/docs/modul/regex_filter.md +++ b/docu/docs/modul/regex_filter.md @@ -20,12 +20,6 @@ Vereinfacht kann man sagen, dass einzelnen Router ODER-verknüpft und die jeweil ## Konfiguration -|Feld|Beschreibung|Default| -|----|------------|-------| -|filter|Enthält eine Liste der einzelnen Filter|| - -#### `filter:` - |Feld|Beschreibung|Default| |----|------------|-------| |name|Beliebiger Name des Filters|| @@ -43,17 +37,16 @@ Vereinfacht kann man sagen, dass einzelnen Router ODER-verknüpft und die jeweil - type: module res: filter.regexFilter config: - filter: - - name: "Zvei filter" - checks: - - field: zvei - regex: "65[0-9]{3}" # all zvei with starting 65 - - name: "FMS Stat 3" - checks: - - field: mode - regex: "fms" # check if mode is fms - - field: status - regex: "3" # check if status is 3 + - name: "Zvei filter" + checks: + - field: zvei + regex: "65[0-9]{3}" # all zvei with starting 65 + - name: "FMS Stat 3" + checks: + - field: mode + regex: "fms" # check if mode is fms + - field: status + regex: "3" # check if status is 3 ``` --- diff --git a/module/descriptor.py b/module/descriptor.py new file mode 100644 index 0000000..a0d7d15 --- /dev/null +++ b/module/descriptor.py @@ -0,0 +1,55 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +"""! + ____ ____ ______ __ __ __ _____ + / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / + / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < + / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / +/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ + German BOS Information Script + by Bastian Schroll + +@file: template_module.py +@date: 01.03.2019 +@author: Bastian Schroll +@description: Template Module File +""" +import logging +from module.module import Module + +# ###################### # +# Custom plugin includes # + +# ###################### # + +logging.debug("- %s loaded", __name__) + + +class BoswatchModule(Module): + """!Description of the Module""" + def __init__(self, config): + """!Do not change anything here!""" + super().__init__(__name__, config) # you can access the config class on 'self.config' + + def onLoad(self): + """!Called by import of the plugin""" + pass + + def doWork(self, bwPacket): + """!start an run of the module. + + @param bwPacket: A BOSWatch packet instance""" + if bwPacket.get("mode") == "fms": + pass + elif bwPacket.get("mode") == "zvei": + pass + elif bwPacket.get("mode") == "pocsag": + pass + elif bwPacket.get("mode") == "msg": + pass + + return bwPacket + + def onUnload(self): + """!Called by destruction of the plugin""" + pass diff --git a/module/filter/regexFilter.py b/module/filter/regexFilter.py index 7f9556c..b0f74bf 100644 --- a/module/filter/regexFilter.py +++ b/module/filter/regexFilter.py @@ -26,7 +26,7 @@ logging.debug("- %s loaded", __name__) class BoswatchModule(Module): - """!Description of the Module""" + """!Regex based filter mechanism""" def __init__(self, config): """!Do not change anything here!""" super().__init__(__name__, config) # you can access the config class on 'self.config' @@ -39,11 +39,11 @@ class BoswatchModule(Module): """!start an run of the module. @param bwPacket: A BOSWatch packet instance""" - for filter in self.config.get("filter"): + for regexFilter in self.config: checkFailed = False - logging.debug("try filter '%s' with %d check(s)", filter.get("name"), len(filter.get("checks"))) + logging.debug("try filter '%s' with %d check(s)", regexFilter.get("name"), len(regexFilter.get("checks"))) - for check in filter.get("checks"): + for check in regexFilter.get("checks"): fieldData = bwPacket.get(check.get("field")) if not fieldData or not re.search(check.get("regex"), fieldData): @@ -54,9 +54,9 @@ class BoswatchModule(Module): logging.debug("[+] field '%s' with regex '%s'", check.get("field"), check.get("regex")) if not checkFailed: - logging.debug("[PASSED] filter '%s'", filter.get("name")) + logging.debug("[PASSED] filter '%s'", regexFilter.get("name")) return None # None -> Router will go on with this packet - logging.debug("[FAILED] filter '%s'", filter.get("name")) + logging.debug("[FAILED] filter '%s'", regexFilter.get("name")) return False # False -> Router will stop further processing