forked from Schrolli91/BOSWatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alarmHandler.py
100 lines (86 loc) · 2.99 KB
/
alarmHandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
Handler for the filter and plugins at an alarm
@author: Bastian Schroll
@author: Jens Herrmann
@requires: none
"""
import logging # Global logger
import time # timestamp
from includes import globalVars # Global variables
from copy import deepcopy # copy objects to avoid issues if the objects will be changed by the plugin's during runtime and during asynch/threaded processing
##
#
# 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 readme.md in plugin folder)
@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 globalVars.config.getboolean("BOSWatch","processAlarmAsync") == True:
logging.debug("starting processAlarm async")
try:
from threading import Thread
Thread(target=processAlarm, args=(typ, freq, deepcopy(data))).start()
except:
logging.error("Error in starting alarm processing async")
logging.debug("Error in starting alarm processing async", exc_info=True)
else:
processAlarm(typ, freq, data)
##
#
# main function for central filtering and calling the plugins
#
def processAlarm(typ, freq, data):
"""
Function to process filters and plugins at Alarm
@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 readme.md in plugin folder)
@param data: Contains the parameter
@requires: active plugins in pluginList
@return: nothing
@exception: Exception if Alarm processing itself failed
"""
try:
logging.debug("[ ALARM ]")
# timestamp, to make sure, that all plugins use the same time
data['timestamp'] = int(time.time())
# Go to all plugins in pluginList
for pluginName, plugin in globalVars.pluginList.items():
# if enabled use RegEx-filter
if globalVars.config.getint("BOSWatch","useRegExFilter"):
from includes import regexFilter
if regexFilter.checkFilters(typ, data, pluginName, freq):
logging.debug("call Plugin: %s", pluginName)
try:
plugin.run(typ, freq, deepcopy(data))
logging.debug("return from: %s", pluginName)
except:
# call next plugin, if one has thrown an exception
pass
else: # RegEX filter off - call plugin directly
logging.debug("call Plugin: %s", pluginName)
try:
plugin.run(typ, freq, deepcopy(data))
logging.debug("return from: %s", pluginName)
except:
# call next plugin, if one has thrown an exception
pass
logging.debug("[END ALARM]")
except:
logging.error("Error in alarm processing")
logging.debug("Error in alarm processing", exc_info=True)