BOSWatch/plugins/firEmergency/firEmergency.py

121 lines
3.4 KiB
Python
Raw Normal View History

2015-06-04 19:03:32 +02:00
#!/usr/bin/python
# -*- coding: UTF-8 -*-
2015-06-04 19:03:32 +02:00
"""
firEmergency-Plugin to dispatch ZVEI- and POCSAG - messages to firEmergency
firEmergency configuration:
- set input to "FMS32" at Port 5555
2015-06-04 19:03:32 +02:00
@autor: Smith-fms
@requires: firEmergency-Configuration has to be set in the config.ini
"""
import logging # Global logger
import socket
from includes import globals # Global variables
from includes.helper import configHandler
###
2015-06-29 12:19:44 +02:00
#
# onLoad (init) function of plugin
# will be called one time by the pluginLoader on start
2015-06-29 12:19:44 +02:00
#
def onLoad():
"""
While loading the plugins by pluginLoader.loadPlugins()
this onLoad() routine is called one time for initialize the plugin
2015-06-29 12:19:44 +02:00
@requires: nothing
2015-07-02 09:02:49 +02:00
2015-06-29 12:19:44 +02:00
@return: nothing
"""
# nothing to do for this plugin
return
2015-07-02 09:02:49 +02:00
2015-06-29 12:19:44 +02:00
2015-06-04 19:03:32 +02:00
##
#
# Main function of firEmergency-plugin
# will be called by the alarmHandler
#
def run(typ,freq,data):
"""
This function is the implementation of the firEmergency-Plugin.
It will send the data to an firEmergency-Instance.
2015-07-02 09:02:49 +02:00
2015-06-04 19:03:32 +02:00
The configuration for the firEmergency-Connection is set in the config.ini.
@type typ: string (ZVEI|POC)
@param typ: Typ of the dataset for sending to firEmergency
@type data: map of data (structure see interface.txt)
@param data: Contains the parameter for dispatch to firEmergency.
@type freq: string
@keyword freq: frequency is not used in this plugin
@requires: firEmergency-Configuration has to be set in the config.ini
2015-07-02 09:02:49 +02:00
2015-06-04 19:03:32 +02:00
@return: nothing
"""
try:
if configHandler.checkConfig("firEmergency"): #read and debug the config
2015-06-04 19:03:32 +02:00
try:
#
# connect to firEmergency
#
firSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
firSocket.connect((globals.config.get("firEmergency", "firserver"), globals.config.getint("firEmergency", "firport")))
except:
logging.error("cannot connect to firEmergency")
logging.debug("cannot connect to firEmergency", exc_info=True)
# Without connection, plugin couldn't work
return
2015-07-02 09:02:49 +02:00
else:
#
# Format given data-structure to xml-string for firEmergency
#
if typ == "FMS":
logging.debug("FMS not supported by firEmgency")
2015-07-02 09:02:49 +02:00
elif typ == "ZVEI":
logging.debug("ZVEI to firEmergency")
try:
firXML = "<event>\n<address>"+data["zvei"]+"</address>\n<description>"+data["description"]+"</description>\n<message>"+data["zvei"]+" alarmiert.</message>\n</event>\n"
2015-07-04 01:25:21 +02:00
firSocket.send(firXML)
except:
logging.error("%s to firEmergency failed", typ)
logging.debug("%s to firEmergency failed", typ, exc_info=True)
# Without connection, plugin couldn't work
return
2015-07-02 09:02:49 +02:00
elif typ == "POC":
logging.debug("POC to firEmergency")
try:
# !!! Subric+"XX" because of an Issuse in firEmergency !!!
firXML = "<event>\n<address>"+data["ric"]+"</address>\n<status>"+data["function"]+"XX</status>\n<description>"+data["description"]+"</description>\n<message>"+data["msg"]+"</message>\n</event>\n"
2015-07-04 01:25:21 +02:00
firSocket.send(firXML)
except:
logging.error("%s to firEmergency failed", typ)
logging.debug("%s to firEmergency failed", typ, exc_info=True)
# Without connection, plugin couldn't work
return
2015-06-04 19:03:32 +02:00
else:
2015-07-02 09:02:49 +02:00
logging.warning("Invalid Typ: %s", typ)
2015-06-04 19:03:32 +02:00
finally:
logging.debug("close firEmergency-Connection")
2015-07-02 09:02:49 +02:00
try:
firSocket.close()
except:
pass
2015-06-04 19:03:32 +02:00
except:
logging.error("unknown error")
2015-07-02 09:02:49 +02:00
logging.debug("unknown error", exc_info=True)