Merge pull request #451 from lgremme/divera

Divera Plugin
This commit is contained in:
Bastian Schroll 2020-06-03 07:57:59 +02:00 committed by GitHub
commit dac24eda19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 125 additions and 30 deletions

View file

@ -3,6 +3,7 @@
### __[v2.5.2]__ - unreleased ### __[v2.5.2]__ - unreleased
##### Added ##### Added
##### Changed ##### Changed
- Divera Plugin: Add individual alarms for FMS, ZVEI and POC. [#451](https://github.com/Schrolli91/BOSWatch/pull/451)
- install.sh: local git repo available at /opt/boswatch (or at your own path). Updates easier with `git pull` in /opt/boswatch. [#452](https://github.com/Schrolli91/BOSWatch/pull/452) - install.sh: local git repo available at /opt/boswatch (or at your own path). Updates easier with `git pull` in /opt/boswatch. [#452](https://github.com/Schrolli91/BOSWatch/pull/452)
##### Deprecated ##### Deprecated
##### Removed ##### Removed

View file

@ -494,17 +494,23 @@ SubD =
poc_title = %DESCR%: %MSG% poc_title = %DESCR%: %MSG%
poc_text = %DATE% %TIME% - %DESCR%: %MSG% poc_text = %DATE% %TIME% - %DESCR%: %MSG%
# poc_ric is alarm-RIC in divera
poc_ric = %DESCR%
# Section for ZVEI # Section for ZVEI
# default prio for all ZVEI - except you specify it different # default prio for all ZVEI - except you specify it different
zvei_prio = true zvei_prio = true
zvei_title = Alarm: %ZVEI% zvei_title = Alarm: %ZVEI%
zvei_text = %DATE% %TIME%: %ZVEI% zvei_text = %DATE% %TIME%: %ZVEI%
# zvei_id working at 6 characters or more; later name of alarm-RIC in divera
zvei_id = %DESCR%
# Section for FMS # Section for FMS
fms_prio = true fms_prio = true
fms_title = FMS: %FMS% fms_title = FMS: %FMS%
fms_text = %DATE% %TIME%: %FMS%%BR%Status: %STATUS% - Direction: %DIRT% - TSI: %TSI% %LPAR%%DESCR%%RPAR% fms_text = %DATE% %TIME%: %FMS%%BR%Status: %STATUS% - Direction: %DIRT% - TSI: %TSI% %LPAR%%DESCR%%RPAR%
# fms_vehicle is alarm-RIC in divera
fms_vehicle = %DESCR%
[gpiocontrol] [gpiocontrol]

View file

@ -16,6 +16,24 @@ from includes import globalVars # Global variables
from includes.helper import configHandler from includes.helper import configHandler
from includes.helper import wildcardHandler from includes.helper import wildcardHandler
def isSignal(poc_id):
"""
@type poc_id: string
@param poc_id: POCSAG Ric
@requires: Configuration has to be set in the config.ini
@return: True if the Ric is Signal, other False
@exception: none
"""
# If RIC is Signal return True, else False
if globalVars.config.get("POC", "netIdent_ric"):
if poc_id in globalVars.config.get("POC", "netIdent_ric"):
logging.info("RIC %s is net ident", poc_id)
return True
else:
logging.info("RIC %s is no net ident", poc_id)
return False
## ##
# #
@ -61,6 +79,7 @@ def run(typ, freq, data):
text = globalVars.config.get("Divera", "fms_text") text = globalVars.config.get("Divera", "fms_text")
title = globalVars.config.get("Divera", "fms_title") title = globalVars.config.get("Divera", "fms_title")
priority = globalVars.config.get("Divera", "fms_prio") priority = globalVars.config.get("Divera", "fms_prio")
vehicle = globalVars.config.get("Divera", "fms_vehicle")
elif typ == "ZVEI": elif typ == "ZVEI":
# #
@ -68,25 +87,33 @@ def run(typ, freq, data):
# #
text = globalVars.config.get("Divera", "zvei_text") text = globalVars.config.get("Divera", "zvei_text")
title = globalVars.config.get("Divera", "zvei_title") title = globalVars.config.get("Divera", "zvei_title")
priority = globalVars.config.get("Divera","zvei_std_prio") priority = globalVars.config.get("Divera","zvei_prio")
zvei_id = globalVars.config.get("Divera","zvei_id")
elif typ == "POC": elif typ == "POC":
# if isSignal(data["ric"]):
# building message for POC
# logging.debug("RIC is net ident")
if data["function"] == '1': return
priority = globalVars.config.get("Divera", "SubA")
elif data["function"] == '2':
priority = globalVars.config.get("Divera", "SubB")
elif data["function"] == '3':
priority = globalVars.config.get("Divera", "SubC")
elif data["function"] == '4':
priority = globalVars.config.get("Divera", "SubD")
else: else:
priority = '' #
# building message for POC
#
if data["function"] == '1':
priority = globalVars.config.get("Divera", "SubA")
elif data["function"] == '2':
priority = globalVars.config.get("Divera", "SubB")
elif data["function"] == '3':
priority = globalVars.config.get("Divera", "SubC")
elif data["function"] == '4':
priority = globalVars.config.get("Divera", "SubD")
else:
priority = ''
text = globalVars.config.get("Divera", "poc_text") text = globalVars.config.get("Divera", "poc_text")
title = globalVars.config.get("Divera", "poc_title") title = globalVars.config.get("Divera", "poc_title")
ric = globalVars.config.get("Divera", "poc_ric")
else: else:
logging.warning("Invalid type: %s", typ) logging.warning("Invalid type: %s", typ)
@ -97,30 +124,91 @@ def run(typ, freq, data):
# Divera-Request # Divera-Request
# #
logging.debug("send Divera for %s", typ) logging.debug("send Divera for %s", typ)
# replace the wildcards
text = wildcardHandler.replaceWildcards(text, data)
title = wildcardHandler.replaceWildcards(title, data)
# Logging data to send # Replace wildcards & Logging data to send
title = wildcardHandler.replaceWildcards(title, data)
logging.debug("Title : %s", title) logging.debug("Title : %s", title)
text = wildcardHandler.replaceWildcards(text, data)
logging.debug("Text : %s", text) logging.debug("Text : %s", text)
logging.debug("Priority: %s", priority)
if typ == "FMS":
vehicle = wildcardHandler.replaceWildcards(vehicle, data)
logging.debug("Vehicle : %s", vehicle)
elif typ == "POC":
ric = wildcardHandler.replaceWildcards(ric, data)
logging.debug("RIC : %s", ric)
elif typ == "ZVEI":
zvei_id = wildcardHandler.replaceWildcards(zvei_id, data)
logging.debug("ZVEI_ID : %s", zvei_id)
else:
logging.info("No wildcards to replace and no Typ selected!")
# check priority value # check priority value
if (priority != 'false') and (priority != 'true'): if (priority != 'false') and (priority != 'true'):
logging.info("No Priority set for type '%s'! Skipping Divera-Alarm!", typ) logging.info("No Priority set for type '%s'! Skipping Divera-Alarm!", typ)
return return
# start the connection # Check FMS
conn = httplib.HTTPSConnection("www.divera247.com:443") if typ == "FMS":
conn.request("GET", "/api/alarm", if (vehicle == ''):
urllib.urlencode({ logging.info("No Vehicle set!")
"accesskey": globalVars.config.get("Divera", "accesskey"),
"title": title, # Check POC
"text": text, elif typ == "POC":
"priority": priority, if (ric == ''):
})) logging.info("No RIC set!")
# Check ZVEI
elif typ == "ZVEI":
if (zvei_id == ''):
logging.info("No ZVEI_ID set!")
else:
logging.info("No ZVEI, FMS or POC alarm")
# start connection to Divera
if typ == "FMS":
# start the connection FMS
conn = httplib.HTTPSConnection("www.divera247.com:443")
conn.request("GET", "/api/fms",
urllib.urlencode({
"accesskey": globalVars.config.get("Divera", "accesskey"),
"vehicle_ric": vehicle,
"status_id": data["status"],
"status_note": data["directionText"],
"title": title,
"text": text,
"priority": priority,
}))
elif typ == "ZVEI":
# start connection ZVEI; zvei_id in Divera is alarm-RIC!
conn = httplib.HTTPSConnection("www.divera247.com:443")
conn.request("GET", "/api/alarm",
urllib.urlencode({
"accesskey": globalVars.config.get("Divera", "accesskey"),
"title": title,
"ric": zvei_id,
"text": text,
"priority": priority,
}))
elif typ == "POC":
# start connection POC
conn = httplib.HTTPSConnection("www.divera247.com:443")
conn.request("GET", "/api/alarm",
urllib.urlencode({
"accesskey": globalVars.config.get("Divera", "accesskey"),
"title": title,
"ric": ric,
"text": text,
"priority": priority,
}))
else:
loggin.debug("No Type is set", exc_info=True)
return
except: except:
logging.error("cannot send Divera request") logging.error("cannot send Divera request")