mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-01-20 15:20:16 +01:00
simple filter for pocsag
- implement allow-/deny-list - move rangefilter restructure config.ini to follow code-structure implemented switch to turn on/off regEx-filter
This commit is contained in:
parent
a628be6ff2
commit
72ef930c7f
|
|
@ -142,8 +142,9 @@ try:
|
|||
pluginLoader.loadPlugins()
|
||||
|
||||
#load filters
|
||||
from includes import filter
|
||||
filter.getFilters()
|
||||
if globals.config.getint("BOSWatch","useRegExFilter"):
|
||||
from includes import filter
|
||||
filter.getFilters()
|
||||
|
||||
try:
|
||||
#start rtl_fm
|
||||
|
|
@ -175,7 +176,7 @@ try:
|
|||
#RAW Data from Multimon-NG
|
||||
#ZVEI2: 25832
|
||||
#FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST2=III(mit NA,ohneSIGNAL)) CRC correct\n'
|
||||
decoded = str(multimon_ng.stdout.readline()) #Get line data from multimon stdout
|
||||
#decoded = str(multimon_ng.stdout.readline()) #Get line data from multimon stdout
|
||||
|
||||
#only for develop
|
||||
#decoded = "ZVEI2: 25832"
|
||||
|
|
|
|||
|
|
@ -11,23 +11,39 @@
|
|||
#50 = critical
|
||||
loglevel = 10
|
||||
|
||||
#time to ignore same alarm in a row (sek)
|
||||
fms_double_ignore_time = 5
|
||||
#Using RegEx-Filter (0|1)
|
||||
#Filter-configuration in section "Filters"
|
||||
useRegExFilter = 1
|
||||
|
||||
[FMS]
|
||||
#time to ignore same alarm in a row (sek)
|
||||
zvei_double_ignore_time = 5
|
||||
double_ignore_time = 5
|
||||
|
||||
[ZVEI]
|
||||
#time to ignore same alarm in a row (sek)
|
||||
poc_double_ignore_time = 10
|
||||
#start and end of the filter range
|
||||
poc_filter_range_start = 0000000
|
||||
poc_filter_range_end = 9999999
|
||||
double_ignore_time = 5
|
||||
|
||||
[POC]
|
||||
#time to ignore same alarm in a row (sek)
|
||||
double_ignore_time = 5
|
||||
|
||||
#some very simple filters:
|
||||
#Allow only this RICs (empty: allow all, separator ",")
|
||||
#f.e.: allow_ric = 1234566,1234567,1234568
|
||||
allow_ric =
|
||||
#Deny this RICs (empty: allow all, separator ",")
|
||||
#f.e.: deny_ric = 1234566,1234567,1234568
|
||||
deny_ric =
|
||||
|
||||
#start and end of an allowed filter range
|
||||
filter_range_start = 0000000
|
||||
filter_range_end = 9999999
|
||||
|
||||
|
||||
[Filters]
|
||||
#No Filter for a Typ/Plugin Combination = all Data pass
|
||||
#INDIVIDUAL_NAME = TYP;PLUGIN;REGEX
|
||||
#testfilter = ZVEI;template;25[0-9F]{3} #only ZVEI to template with 25###
|
||||
zvei_local_filter = ZVEI;template;25[0-9F]{3}
|
||||
|
||||
|
||||
[Plugins]
|
||||
|
|
|
|||
|
|
@ -8,8 +8,14 @@ from includes import globals # Global variables
|
|||
def processAlarm(typ,freq,data):
|
||||
logging.debug("[ ALARM ]")
|
||||
for pluginName, plugin in globals.pluginList.items():
|
||||
from includes import filter
|
||||
if filter.checkFilters(data,typ,pluginName):
|
||||
#if enabled use RegEx-Filter
|
||||
if globals.config.getint("BOSWatch","useRegExFilter"):
|
||||
from includes import filter
|
||||
if filter.checkFilters(data,typ,pluginName):
|
||||
logging.debug("call Plugin: %s", pluginName)
|
||||
plugin.run(typ,freq,data)
|
||||
logging.debug("return from: %s", pluginName)
|
||||
else:
|
||||
logging.debug("call Plugin: %s", pluginName)
|
||||
plugin.run(typ,freq,data)
|
||||
logging.debug("return from: %s", pluginName)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ def decode(freq, decoded):
|
|||
if "CRC correct" in decoded: #check CRC is correct
|
||||
fms_id = fms_service+fms_country+fms_location+fms_vehicle+fms_status+fms_direction #build FMS id
|
||||
if re.search("[0-9a-f]{8}[0-9a-f]{1}[01]{1}", fms_id): #if FMS is valid
|
||||
if fms_id == globals.fms_id_old and timestamp < globals.fms_time_old + globals.config.getint("BOSWatch", "fms_double_ignore_time"): #check for double alarm
|
||||
if fms_id == globals.fms_id_old and timestamp < globals.fms_time_old + globals.config.getint("FMS", "double_ignore_time"): #check for double alarm
|
||||
logging.info("FMS double alarm: %s within %s second(s)", globals.fms_id_old, timestamp-globals.fms_time_old)
|
||||
globals.fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -7,9 +7,36 @@ import re #Regex for validation
|
|||
|
||||
from includes import globals # Global variables
|
||||
|
||||
# Simple Filter
|
||||
def isAllowed(poc_id):
|
||||
"""Simple filter for POCSAG"""
|
||||
# 1.) If allowed RICs is set, only they will path,
|
||||
# If RIC is the right one return True, else False
|
||||
if globals.config.get("POC", "allow_ric"):
|
||||
if poc_id in globals.config.get("POC", "allow_ric"):
|
||||
logging.debug("RIC %s is allowed", poc_id)
|
||||
return True
|
||||
else:
|
||||
logging.debug("RIC %s is not in the allowed list", poc_id)
|
||||
return False
|
||||
# 2.) If denied RIC, return False
|
||||
elif poc_id in globals.config.get("POC", "deny_ric"):
|
||||
logging.debug("RIC %s is denied by config.ini", poc_id)
|
||||
return False
|
||||
# 3.) Check Range, return False if outside def. range
|
||||
elif int(poc_id) < globals.config.getint("POC", "filter_range_start"):
|
||||
logging.debug("RIC %s out of filter range (start)", poc_id)
|
||||
return False
|
||||
elif int(poc_id) > globals.config.getint("POC", "filter_range_end"):
|
||||
logging.debug("RIC %s out of filter range (end)", poc_id)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
#POCSAG Decoder Function
|
||||
#validate -> check double alarm -> log
|
||||
def decode(freq, decoded):
|
||||
"""Decode for structure of typ POCSAG"""
|
||||
bitrate = 0
|
||||
timestamp = int(time.time())#Get Timestamp
|
||||
|
||||
|
|
@ -39,22 +66,21 @@ def decode(freq, decoded):
|
|||
poc_text = ""
|
||||
|
||||
if re.search("[0-9]{7}", poc_id): #if POC is valid
|
||||
if int(poc_id) >= globals.config.getint("BOSWatch", "poc_filter_range_start"):
|
||||
if int(poc_id) <= globals.config.getint("BOSWatch", "poc_filter_range_end"):
|
||||
if poc_id == globals.poc_id_old and timestamp < globals.poc_time_old + globals.config.getint("BOSWatch", "poc_double_ignore_time"): #check for double alarm
|
||||
logging.info("POCSAG%s double alarm: %s within %s second(s)", bitrate, globals.poc_id_old, timestamp-globals.poc_time_old)
|
||||
globals.poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new
|
||||
else:
|
||||
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}
|
||||
from includes import alarmHandler
|
||||
alarmHandler.processAlarm("POC",freq,data)
|
||||
|
||||
globals.poc_id_old = poc_id #save last id
|
||||
globals.poc_time_old = timestamp #save last time
|
||||
if isAllowed(poc_id):
|
||||
#check for double alarm
|
||||
if poc_id == globals.poc_id_old and timestamp < globals.poc_time_old + globals.config.getint("POC", "double_ignore_time"):
|
||||
logging.info("POCSAG%s double alarm: %s within %s second(s)", bitrate, globals.poc_id_old, timestamp-globals.poc_time_old)
|
||||
#in case of double alarm, poc_double_ignore_time set new
|
||||
globals.poc_time_old = timestamp
|
||||
else:
|
||||
logging.info("POCSAG%s: %s out of filter range (high)", bitrate, poc_id)
|
||||
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}
|
||||
from includes import alarmHandler
|
||||
alarmHandler.processAlarm("POC",freq,data)
|
||||
|
||||
globals.poc_id_old = poc_id #save last id
|
||||
globals.poc_time_old = timestamp #save last time
|
||||
else:
|
||||
logging.info("POCSAG%s: %s out of filter range (low)", bitrate, poc_id)
|
||||
logging.info("POCSAG%s: %s is not allowed", bitrate, poc_id)
|
||||
else:
|
||||
logging.warning("No valid POCSAG%s RIC: %s", bitrate, poc_id)
|
||||
|
|
@ -14,7 +14,7 @@ def decode(freq, decoded):
|
|||
|
||||
zvei_id = decoded[7:12] #ZVEI Code
|
||||
if re.search("[0-9F]{5}", zvei_id): #if ZVEI is valid
|
||||
if zvei_id == globals.zvei_id_old and timestamp < globals.zvei_time_old + globals.config.getint("BOSWatch", "zvei_double_ignore_time"): #check for double alarm
|
||||
if zvei_id == globals.zvei_id_old and timestamp < globals.zvei_time_old + globals.config.getint("ZVEI", "double_ignore_time"): #check for double alarm
|
||||
logging.info("ZVEI double alarm: %s within %s second(s)", globals.zvei_id_old, timestamp-globals.zvei_time_old)
|
||||
globals.zvei_time_old = timestamp #in case of double alarm, zvei_double_ignore_time set new
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in a new issue