2015-06-04 19:03:32 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
# -*- coding: cp1252 -*-
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
firEmergency-Plugin to dispatch ZVEI- and POCSAG - messages to firEmergency
|
|
|
|
|
|
2015-07-05 09:02:21 +02:00
|
|
|
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
|
|
|
|
|
|
2015-06-29 23:24:48 +02:00
|
|
|
###
|
2015-06-29 12:19:44 +02:00
|
|
|
#
|
2015-06-29 23:24:48 +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()
|
2015-06-29 23:24:48 +02:00
|
|
|
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
|
|
|
|
|
"""
|
2015-06-29 23:24:48 +02:00
|
|
|
# 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:
|
|
|
|
|
#
|
|
|
|
|
#ConfigParser
|
|
|
|
|
#
|
|
|
|
|
logging.debug("reading config file")
|
|
|
|
|
try:
|
|
|
|
|
for key,val in globals.config.items("firEmergency"):
|
|
|
|
|
logging.debug(" - %s = %s", key, val)
|
|
|
|
|
except:
|
2015-06-23 22:27:48 +02:00
|
|
|
logging.error("cannot read config file")
|
|
|
|
|
logging.debug("cannot read config file", exc_info=True)
|
2015-06-29 12:25:21 +02:00
|
|
|
else: # Without config, plugin couldn't work
|
2015-06-04 19:03:32 +02:00
|
|
|
|
2015-06-29 12:25:21 +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:
|
2015-06-29 12:25:21 +02:00
|
|
|
#
|
|
|
|
|
# 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
|
|
|
|
2015-06-29 12:25:21 +02:00
|
|
|
elif typ == "ZVEI":
|
|
|
|
|
logging.debug("ZVEI to firEmergency")
|
|
|
|
|
try:
|
2015-07-04 22:22:29 +02:00
|
|
|
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)
|
2015-06-29 12:25:21 +02:00
|
|
|
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
|
|
|
|
2015-06-29 12:25:21 +02:00
|
|
|
elif typ == "POC":
|
|
|
|
|
logging.debug("POC to firEmergency")
|
|
|
|
|
try:
|
2015-07-05 09:02:21 +02:00
|
|
|
# !!! Subric+"XX" because of an Issuse in firEmergency !!!
|
2015-07-04 22:22:29 +02:00
|
|
|
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)
|
2015-06-29 12:25:21 +02:00
|
|
|
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
|
|
|
|
2015-06-29 12:25:21 +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
|
|
|
|
2015-06-29 12:25:21 +02:00
|
|
|
finally:
|
|
|
|
|
logging.debug("close firEmergency-Connection")
|
2015-07-02 09:02:49 +02:00
|
|
|
try:
|
2015-06-29 12:25:21 +02:00
|
|
|
firSocket.close()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
2015-06-04 19:03:32 +02:00
|
|
|
|
|
|
|
|
except:
|
2015-06-23 22:27:48 +02:00
|
|
|
logging.error("unknown error")
|
2015-07-02 09:02:49 +02:00
|
|
|
logging.debug("unknown error", exc_info=True)
|