BOSWatch/includes/multicastAlarm.py

66 lines
2 KiB
Python
Raw Permalink Normal View History

2017-09-23 09:25:08 +02:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
multicastAlarm is the function to enable BOSwatch to work in networks that optimise the transmission of POCSAG telegrams
2017-09-23 09:25:08 +02:00
@author: Fabian Kessler
@requires: Configuration has to be set in the config.ini
"""
import logging # Global logger
import time # timestamp for multicastAlarm
from includes import globalVars # Global variables
2017-10-03 14:43:36 +02:00
#
# ListStructure [0..n] = (Data, TimeStamp)
#
2017-09-23 09:25:08 +02:00
multiList = []
2017-10-03 12:08:04 +02:00
def newEntrymultiList(data):
2017-09-23 09:25:08 +02:00
"""
add entry to multi alarm list and remove old entries
@return: nothing
"""
2017-10-03 22:08:38 +02:00
global multiList
2017-09-23 09:25:08 +02:00
timestamp = int(time.time())
# multicastAlarm processing if enabled and delimiter RIC has been received
if data['ric'] == globalVars.config.get("multicastAlarm", "multicastAlarm_delimiter_ric"):
del multiList[:]
logging.debug("delimiter RIC received - buffer cleared")
2017-09-23 09:25:08 +02:00
else:
2017-10-03 14:43:36 +02:00
multiList.append([data, timestamp])
2017-10-03 12:03:08 +02:00
logging.debug("Added %s to multiList", data['ric'])
2017-09-23 09:25:08 +02:00
# check for old entries in multiList
for (xData, xTimestamp) in multiList[:]:
if xTimestamp < timestamp-globalVars.config.getint("multicastAlarm", "multicastAlarm_ignore_time"):
2017-10-03 14:43:36 +02:00
multiList.remove([xData, xTimestamp])
logging.debug("RIC %s removed - %s sec. older than current timestamp", xData['ric'], xTimestamp-timestamp)
2017-09-23 09:25:08 +02:00
2017-10-03 12:10:08 +02:00
def multicastAlarmExec(freq, data):
2017-09-23 09:25:08 +02:00
"""
call alarmHandler for every entry in multiList
@return: nothing
"""
logging.debug("data before update from multiList: %s", data)
2017-10-03 19:32:09 +02:00
for (xData, _) in multiList:
#update data with values multiList
2017-10-03 14:43:36 +02:00
data['ric'] = xData['ric']
data['function'] = xData['function']
data['functionChar'] = xData['functionChar']
data['description'] = xData['description']
2017-09-23 09:25:08 +02:00
logging.debug("data after update from multiList: %s", data)
try:
from includes import alarmHandler
2017-10-03 12:10:08 +02:00
alarmHandler.processAlarmHandler("POC", freq, data)
2017-09-23 09:25:08 +02:00
except:
logging.error("processing alarm failed")
logging.debug("processing alarm failed", exc_info=True)
2018-08-11 16:43:38 +02:00
del multiList[:]
logging.debug("multicastAlarm finished - buffer cleared")