diff --git a/boswatch/filter/doubeFilter.py b/boswatch/filter/doubeFilter.py new file mode 100644 index 0000000..a5d8ccb --- /dev/null +++ b/boswatch/filter/doubeFilter.py @@ -0,0 +1,54 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +"""! + ____ ____ ______ __ __ __ _____ + / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / + / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < + / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / +/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ + German BOS Information Script + by Bastian Schroll + +@file: doubleFilter.py +@date: 15.01.2018 +@author: Bastian Schroll +@description: Class to implement a filter for double alarms +@todo test, refactor and document +@todo check_msg is not implemented yet +""" +import logging +import time + +from boswatch.config import Config + +logging.debug("- %s loaded", __name__) + + +class DoubleFilter: + """!Double Filter Class""" + + def __init__(self, scanWord): + """!init""" + self._config = Config() + self._filterList = [] + self._scanWord = scanWord + + def check(self, bwPacket): + for listPacket in self._filterList: + if listPacket.get("timestamp") < (time.time() - self._config.getInt("doubleFilter", "IgnoreTime", "serverConfig")): + self._filterList.remove(listPacket) + logging.debug("entry to old remove") + continue + + if listPacket.get(self._scanWord) is bwPacket.get(self._scanWord): + self._filterList.remove(listPacket) + logging.debug("found a same and remove the old one") + + self._filterList.insert(0, bwPacket) + self._deleteTooMuch() + logging.debug(self._filterList) + + def _deleteTooMuch(self): + if len(self._filterList) > self._config.getInt("doubleFilter", "MaxEntry", "serverConfig"): + logging.debug("list full, delete one") + self._filterList.pop() diff --git a/boswatch/utils/wildcard.py b/boswatch/utils/wildcard.py index 478a517..b58b861 100644 --- a/boswatch/utils/wildcard.py +++ b/boswatch/utils/wildcard.py @@ -13,6 +13,7 @@ @date: 15.01.2018 @author: Bastian Schroll @description: Little Helper to replace wildcards in stings +@todo not completed yet """ import logging diff --git a/config/server.ini b/config/server.ini index ecb691e..9d4bce3 100644 --- a/config/server.ini +++ b/config/server.ini @@ -35,11 +35,11 @@ RegEx = UseDoubleFilter = 0 UseRegexFilter = 0 -[doubleFilter], +[doubleFilter] # max number of entrys to save for comparison MaxEntry = 30 # time to ignore same alarm in seconds -IgnoreTime = 30 +IgnoreTime = 10 # include pocsag msg in comparison CheckMsg = 0