From eba5b7947a3db9551be173b5f0b0a71e40753aff Mon Sep 17 00:00:00 2001 From: JHCD Date: Mon, 29 Jun 2015 17:15:20 +0200 Subject: [PATCH] enhancement of doubleFilter - expand id for pocsag: new pocID+function als "id" - if wanted, enable doubleFilter_check_msg in config.ini it will check if the new msg is a substring of the old one if not it will pass --- config/config.template.ini | 13 ++++++++++--- includes/decoders/poc.py | 4 ++-- includes/doubleFilter.py | 25 ++++++++++++++++--------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/config/config.template.ini b/config/config.template.ini index 7f354fd..206ede9 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -28,10 +28,17 @@ useDescription = 0 # for double check save the last n IDs # it is used in combination with double_ignore_time # 1 is required if you want to use the double alarm filter -double_ignore_entries = 10 +doubleFilter_ignore_entries = 10 -#time to ignore same alarm (only ID is checked) (sek) -double_ignore_time = 5 +# time to ignore same alarm (only ID is checked) (sek) +doubleFilter_ignore_time = 5 + +# ignore msg is only usefull for POCSAG (0|1) +# 0: double check ignores the msg-text (only check ID + function) +# 1: if you want to differentiate between with/ without msg +# f.e. if they use quick-alarm (without text, then same ric with msg) +# you will get more then one alarm anyway if the msg is different (receiving-problems) +doubleFilter_check_msg = 0 [FMS] # look-up-table for adding a description diff --git a/includes/decoders/poc.py b/includes/decoders/poc.py index c8dee0d..ee2e7be 100644 --- a/includes/decoders/poc.py +++ b/includes/decoders/poc.py @@ -104,7 +104,7 @@ def decode(freq, decoded): if re.search("[0-9]{7}", poc_id): #if POC is valid if isAllowed(poc_id): # check for double alarm - if doubleFilter.checkID("POC", poc_id): + if doubleFilter.checkID("POC", poc_id+poc_sub, poc_text): logging.info("POCSAG%s: %s %s %s ", bitrate, poc_id, poc_sub, poc_text) data = {"ric":poc_id, "function":poc_sub, "msg":poc_text, "bitrate":bitrate, "description":poc_id} # Add function as character a-d to dataset @@ -122,7 +122,7 @@ def decode(freq, decoded): logging.debug("processing alarm failed", exc_info=True) pass # in every time save old data for double alarm - doubleFilter.newEntry(poc_id) + doubleFilter.newEntry(poc_id+poc_sub, poc_text) else: logging.debug("POCSAG%s: %s is not allowed", bitrate, poc_id) else: diff --git a/includes/doubleFilter.py b/includes/doubleFilter.py index 861c1ba..b1248ac 100644 --- a/includes/doubleFilter.py +++ b/includes/doubleFilter.py @@ -17,10 +17,10 @@ import time # timestamp for doublealarm from includes import globals # Global variables # -# ListStructure [0..n] = (ID, TimeStamp) +# ListStructure [0..n] = (ID, TimeStamp, msg) # -def checkID(typ, id): +def checkID(typ, id, msg=""): """ check if id was called in the last x sec and n entries @@ -32,25 +32,32 @@ def checkID(typ, id): timestamp = int(time.time()) # Get Timestamp for i in range(len(globals.doubleList)): - (xID, xTimestamp) = globals.doubleList[i] + (xID, xTimestamp, xMsg) = globals.doubleList[i] # given ID found? # return False if the first entry in double_ignore_time is found, we will not check for younger ones... - if id == xID and timestamp < xTimestamp + globals.config.getint("BOSWatch", "double_ignore_time"): - logging.info("%s double alarm: %s within %s second(s)", typ, xID, timestamp-xTimestamp) - return False + if id == xID and timestamp < xTimestamp + globals.config.getint("BOSWatch", "doubleFilter_ignore_time"): + # if wanted, we have to check the msg additional + if "POC" in typ and globals.config.getint("BOSWatch", "doubleFilter_check_msg"): + # if msg is a substring of xMsg we found a double + if msg in xMsg: + logging.info("%s double alarm (id+msg): %s within %s second(s)", typ, xID, timestamp-xTimestamp) + return False + else: + logging.info("%s double alarm (id): %s within %s second(s)", typ, xID, timestamp-xTimestamp) + return False return True -def newEntry(id): +def newEntry(id, msg = ""): """ new entry in double alarm list @return: nothing """ timestamp = int(time.time()) # Get Timestamp - globals.doubleList.append((id, timestamp)) + globals.doubleList.append((id, timestamp, msg)) # now check if list has more than n entries: - if len(globals.doubleList) > globals.config.getint("BOSWatch", "double_ignore_entries"): + if len(globals.doubleList) > globals.config.getint("BOSWatch", "doubleFilter_ignore_entries"): # we have to kill the oldest one globals.doubleList.pop(0) \ No newline at end of file