2015-05-22 21:32:37 +02:00
|
|
|
#!/usr/bin/python
|
2015-07-13 10:19:45 +02:00
|
|
|
# -*- coding: UTF-8 -*-
|
2015-05-22 21:32:37 +02:00
|
|
|
|
2015-05-27 07:48:24 +02:00
|
|
|
"""
|
2015-06-14 20:21:21 +02:00
|
|
|
Handler for the filter and plugins at an alarm
|
2015-05-27 07:48:24 +02:00
|
|
|
|
|
|
|
|
@author: Bastian Schroll
|
2015-06-14 20:21:21 +02:00
|
|
|
@author: Jens Herrmann
|
2015-05-27 07:48:24 +02:00
|
|
|
|
|
|
|
|
@requires: none
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import logging # Global logger
|
2015-07-30 18:55:36 +02:00
|
|
|
from threading import Thread
|
2015-05-22 21:32:37 +02:00
|
|
|
|
|
|
|
|
from includes import globals # Global variables
|
|
|
|
|
|
2015-07-30 18:55:36 +02:00
|
|
|
##
|
|
|
|
|
#
|
|
|
|
|
# decide to run AlarmHandler sync or async
|
|
|
|
|
#
|
|
|
|
|
def processAlarmHandler(typ, freq, data):
|
|
|
|
|
"""
|
|
|
|
|
Function to decide if the alarm process will call sync
|
|
|
|
|
|
|
|
|
|
@type typ: string (FMS|ZVEI|POC)
|
|
|
|
|
@param typ: Typ of the dataset
|
|
|
|
|
@type freq: string
|
|
|
|
|
@param freq: frequency of the SDR Stick
|
|
|
|
|
@type data: map of data (structure see interface.txt)
|
|
|
|
|
@param data: Contains the parameter
|
|
|
|
|
|
|
|
|
|
@requires: active plugins in pluginList
|
|
|
|
|
@requires: Configuration has to be set in the config.ini
|
|
|
|
|
|
|
|
|
|
@return: nothing
|
|
|
|
|
@exception: Exception if starting a Thread failed
|
|
|
|
|
"""
|
|
|
|
|
if globals.config.getboolean("BOSWatch","processAlarmAsync") == True:
|
|
|
|
|
logging.debug("starting processAlarm async")
|
|
|
|
|
try:
|
|
|
|
|
Thread(target=processAlarm, args=(typ, freq, data)).start()
|
|
|
|
|
except:
|
|
|
|
|
logging.error("Error in starting alarm processing async")
|
|
|
|
|
logging.debug("Error in starting alarm processing async", exc_info=True)
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
processAlarm(typ, freq, data)
|
|
|
|
|
|
|
|
|
|
|
2015-06-14 20:21:21 +02:00
|
|
|
##
|
|
|
|
|
#
|
|
|
|
|
# main function for central filtering and calling the plugins
|
|
|
|
|
#
|
2015-07-30 18:55:36 +02:00
|
|
|
def processAlarm(typ, freq, data):
|
2015-05-27 07:48:24 +02:00
|
|
|
"""
|
2015-06-14 20:21:21 +02:00
|
|
|
Function to process filters and plugins at Alarm
|
2015-05-27 07:48:24 +02:00
|
|
|
|
|
|
|
|
@type typ: string (FMS|ZVEI|POC)
|
|
|
|
|
@param typ: Typ of the dataset
|
|
|
|
|
@type freq: string
|
|
|
|
|
@param freq: frequency of the SDR Stick
|
|
|
|
|
@type data: map of data (structure see interface.txt)
|
|
|
|
|
@param data: Contains the parameter
|
|
|
|
|
|
2015-06-14 20:21:21 +02:00
|
|
|
@requires: active plugins in pluginList
|
2015-07-02 09:02:49 +02:00
|
|
|
|
2015-05-27 07:48:24 +02:00
|
|
|
@return: nothing
|
2015-06-23 22:50:33 +02:00
|
|
|
@exception: Exception if Alarm processing itself failed
|
2015-05-27 07:48:24 +02:00
|
|
|
"""
|
2015-05-26 11:41:05 +02:00
|
|
|
try:
|
|
|
|
|
logging.debug("[ ALARM ]")
|
2015-06-14 20:21:21 +02:00
|
|
|
# Go to all plugins in pluginList
|
2015-05-26 11:41:05 +02:00
|
|
|
for pluginName, plugin in globals.pluginList.items():
|
2015-06-14 20:21:21 +02:00
|
|
|
# if enabled use RegEx-filter
|
2015-05-26 11:41:05 +02:00
|
|
|
if globals.config.getint("BOSWatch","useRegExFilter"):
|
|
|
|
|
from includes import filter
|
2015-07-02 09:02:49 +02:00
|
|
|
if filter.checkFilters(typ,data,pluginName,freq):
|
2015-05-26 11:41:05 +02:00
|
|
|
logging.debug("call Plugin: %s", pluginName)
|
2015-06-23 18:37:32 +02:00
|
|
|
try:
|
|
|
|
|
plugin.run(typ,freq,data)
|
|
|
|
|
logging.debug("return from: %s", pluginName)
|
|
|
|
|
except:
|
|
|
|
|
# call next plugin, if one has thrown an exception
|
|
|
|
|
pass
|
2015-06-14 20:21:21 +02:00
|
|
|
else: # RegEX filter off - call plugin directly
|
2015-05-24 21:24:26 +02:00
|
|
|
logging.debug("call Plugin: %s", pluginName)
|
2015-06-23 18:37:32 +02:00
|
|
|
try:
|
|
|
|
|
plugin.run(typ,freq,data)
|
|
|
|
|
logging.debug("return from: %s", pluginName)
|
|
|
|
|
except:
|
|
|
|
|
# call next plugin, if one has thrown an exception
|
|
|
|
|
pass
|
2015-05-26 11:41:05 +02:00
|
|
|
logging.debug("[END ALARM]")
|
|
|
|
|
except:
|
2015-07-30 18:55:36 +02:00
|
|
|
logging.error("Error in alarm processing")
|
|
|
|
|
logging.debug("Error in alarm processing", exc_info=True)
|
|
|
|
|
pass
|