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
This commit is contained in:
JHCD 2015-06-29 17:15:20 +02:00
parent 407e22e1e4
commit eba5b7947a
3 changed files with 28 additions and 14 deletions

View file

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

View file

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