refactor regexFilter config

This commit is contained in:
Bastian Schroll 2019-10-27 20:12:54 +01:00
parent e7b3a6335b
commit 42209615ab
No known key found for this signature in database
GPG key ID: 0AE96912A20E9F5F
3 changed files with 71 additions and 23 deletions

View file

@ -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
```
---

55
module/descriptor.py Normal file
View file

@ -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

View file

@ -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