BOSWatch/includes/filter.py

45 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/python
# -*- coding: cp1252 -*-
import logging # Global logger
2015-05-23 08:58:46 +02:00
import re #Regex for Filter Check
from includes import globals # Global variables
2015-05-26 07:19:24 +02:00
def loadFilters():
try:
2015-05-26 11:41:05 +02:00
logging.debug("loading filters")
for key,val in globals.config.items("Filters"):
logging.debug(" - %s = %s", key, val)
filter = val.split(";")
2015-05-25 10:37:20 +02:00
globals.filterList.append({"name": key, "typ": filter[0], "dataField": filter[1], "plugin": filter[2], "regex": filter[3]})
except:
logging.exception("cannot read config file")
2015-05-23 08:58:46 +02:00
def checkFilters(data,typ,plugin):
try:
logging.debug("search Filter for %s to %s", typ, plugin)
foundFilter = False
for i in globals.filterList:
if i["typ"] == typ and i["plugin"] == plugin:
foundFilter = True
logging.debug("found Filter: %s = %s", i["name"], i["regex"])
2015-05-25 10:37:20 +02:00
if re.search(i["regex"], data[i["dataField"]]):
2015-05-23 09:04:01 +02:00
logging.debug("Filter passed: %s", i["name"])
2015-05-23 08:58:46 +02:00
return True
else:
2015-05-23 09:04:01 +02:00
logging.debug("Filter not passed: %s", i["name"])
2015-05-23 08:58:46 +02:00
if foundFilter:
logging.debug("no Filter passed")
return False
else:
logging.debug("no Filter found")
return True
except:
2015-05-23 09:09:13 +02:00
logging.exception("Error in Filter checking")