From 4b8f64795b738f25839a631bd0b6ee02f7d30878 Mon Sep 17 00:00:00 2001 From: grosj <56541936+grosj@users.noreply.github.com> Date: Tue, 15 Oct 2019 08:40:12 +0200 Subject: [PATCH 1/9] Add Section for Divera-Plugin --- config/config.template.ini | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/config/config.template.ini b/config/config.template.ini index 9e05679..955fc5f 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -175,6 +175,7 @@ Pushover = 0 Telegram = 0 yowsup = 0 hue = 0 +Divera = 0 # for developing - template-module template = 0 @@ -463,6 +464,32 @@ timeoff = 1 # configure 0 to keep the switch on for infinite time or configure >=1 to keep it for the value in seconds to on, before switching to off. keepon = 60 +[Divera] +#See https://www.divera247.com/documentation/local-management-alarm-api.html for Api-Documentation +# Divera API Key +accesskey = + +# Section for POCSAG +# Adapt Pocsag Subric (a,b,c,d) to Divera Priorities (true/false) +SubA = true +SubB = false +SubC = false +SubD = false + +poc_type = %DESCR%: %MSG% +poc_text = %DATE% %TIME% - %DESCR%: %MSG% + +# Section for ZVEI +# default prio for all ZVEI - except you specify it different +zvei_prio = true +zvei_type = Alarm: %ZVEI% +zvei_test = %DATE% %TIME%: %ZVEI% + +# Section for FMS +fms_prio = true +fms_type = FMS: %FMS% +fms_text = %DATE% %TIME%: %FMS%%BR%Status: %STATUS% - Direction: %DIRT% - TSI: %TSI% %LPAR%%DESCR%%RPAR% + ##################### ##### Not ready yet # ##################### From 656fe482c2ad9ee190497afd3db9ad0af4da6daf Mon Sep 17 00:00:00 2001 From: grosj <56541936+grosj@users.noreply.github.com> Date: Tue, 15 Oct 2019 08:42:09 +0200 Subject: [PATCH 2/9] Plugin for Divera --- plugins/Divera/Divera.py | 152 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 plugins/Divera/Divera.py diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py new file mode 100644 index 0000000..01db14b --- /dev/null +++ b/plugins/Divera/Divera.py @@ -0,0 +1,152 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- + +""" +Divera-Plugin to send FMS-, ZVEI- and POCSAG - messages to Divera +@author: Marco Grosjohann +@requires: Divera-Configuration has to be set in the config.ini +""" + +import logging # Global logger +import httplib # for the HTTP request +import urllib +from includes import globalVars # Global variables + +# from includes.helper import timeHandler +from includes.helper import configHandler +from includes.helper import wildcardHandler + + +## +# +# onLoad (init) function of plugin +# will be called one time by the pluginLoader on start +# +def onLoad(): + """ + While loading the plugins by pluginLoader.loadPlugins() + this onLoad() routine is called one time for initialize the plugin + @requires: nothing + @return: nothing + """ + # nothing to do for this plugin + return + + +## +# +# Main function of Divera-plugin +# will be called by the alarmHandler +# +def run(typ, freq, data): + """ + This function is the implementation of the Divera-Plugin. + It will send the data to Divera API + @type typ: string (FMS|ZVEI|POC) + @param typ: Typ of the dataset + @type data: map of data (structure see readme.md in plugin folder) + @param data: Contains the parameter + @type freq: string + @keyword freq: frequency of the SDR Stick + @requires: Divera-Configuration has to be set in the config.ini + @return: nothing + """ + try: + if configHandler.checkConfig("Divera"): # read and debug the config + + if typ == "FMS": + # + # building message for FMS + # + text = globalVars.config.get("Divera", "fms_text") + type = globalVars.config.get("Divera", "fms_type") + priority = globalVars.config.get("Divera", "fms_prio") + + elif typ == "ZVEI": + # + # building message for ZVEI + # + text = globalVars.config.get("Divera", "zvei_text") + type = globalVars.config.get("Divera", "zvei_type") + priority = globalVars.config.get("Divera","zvei_std_prio") + + elif typ == "POC": + # + # 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 = 'false' + + text = globalVars.config.get("Divera", "poc_text") + type = globalVars.config.get("Divera", "poc_type") + + else: + logging.warning("Invalid type: %s", typ) + return + + try: + # + # Divera-Request + # + logging.debug("send Divera for %s", typ) + + # replace the wildcards + text = wildcardHandler.replaceWildcards(text, data) + type = wildcardHandler.replaceWildcards(type, data) + + # Logging data to send + logging.debug("Type : %s", type) + logging.debug("Text : %s", text) + logging.debug("Priority: %s", priority) + + # check priority value + if (priority != 'false') and (priority != 'true'): + priority = 'false' + + # start the connection + conn = httplib.HTTPSConnection("www.divera247.com:443") + conn.request("GET", "/api/alarm", + urllib.urlencode({ + "accesskey": globalVars.config.get("Divera", "accesskey"), + "type": type, + "text": text, + "priority": priority, + })) + + except: + logging.error("cannot send Divera request") + logging.debug("cannot send Divera request", exc_info=True) + return + + try: + # + # check Divera-Response + # + response = conn.getresponse() + if str(response.status) == "200": # Check Divera Response and print a Log or Error + logging.debug("Divera response: %s - %s", str(response.status), str(response.reason)) + else: + logging.warning("Divera response: %s - %s", str(response.status), str(response.reason)) + except: # otherwise + logging.error("cannot get Divera response") + logging.debug("cannot get Divera response", exc_info=True) + return + + finally: + logging.debug("close Divera-Connection") + try: + request.close() + except: + pass + + except: + logging.error("unknown error") + logging.debug("unknown error", exc_info=True) From 9f251bd544d9c3d6bc27263e81d0855fd6a6b3d7 Mon Sep 17 00:00:00 2001 From: Florian Date: Tue, 15 Oct 2019 10:16:12 +0200 Subject: [PATCH 3/9] Update Divera.py correcting line indents --- plugins/Divera/Divera.py | 110 +++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index 01db14b..98b8a15 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -68,20 +68,20 @@ def run(typ, freq, data): # text = globalVars.config.get("Divera", "zvei_text") type = globalVars.config.get("Divera", "zvei_type") - priority = globalVars.config.get("Divera","zvei_std_prio") + priority = globalVars.config.get("Divera","zvei_std_prio") elif typ == "POC": # # building message for POC # - if data["function"] == '1': - priority = globalVars.config.get("Divera", "SubA") + if data["function"] == '1': + priority = globalVars.config.get("Divera", "SubA") elif data["function"] == '2': - priority = globalVars.config.get("Divera", "SubB") + 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") + elif data["function"] == '4': + priority = globalVars.config.get("Divera", "SubD") else: priority = 'false' @@ -90,62 +90,62 @@ def run(typ, freq, data): else: logging.warning("Invalid type: %s", typ) - return + return - try: - # - # Divera-Request - # - logging.debug("send Divera for %s", typ) + try: + # + # Divera-Request + # + logging.debug("send Divera for %s", typ) - # replace the wildcards - text = wildcardHandler.replaceWildcards(text, data) - type = wildcardHandler.replaceWildcards(type, data) - - # Logging data to send - logging.debug("Type : %s", type) - logging.debug("Text : %s", text) - logging.debug("Priority: %s", priority) + # replace the wildcards + text = wildcardHandler.replaceWildcards(text, data) + type = wildcardHandler.replaceWildcards(type, data) + + # Logging data to send + logging.debug("Type : %s", type) + logging.debug("Text : %s", text) + logging.debug("Priority: %s", priority) - # check priority value - if (priority != 'false') and (priority != 'true'): - priority = 'false' + # check priority value + if (priority != 'false') and (priority != 'true'): + priority = 'false' - # start the connection - conn = httplib.HTTPSConnection("www.divera247.com:443") - conn.request("GET", "/api/alarm", - urllib.urlencode({ - "accesskey": globalVars.config.get("Divera", "accesskey"), - "type": type, - "text": text, - "priority": priority, - })) + # start the connection + conn = httplib.HTTPSConnection("www.divera247.com:443") + conn.request("GET", "/api/alarm", + urllib.urlencode({ + "accesskey": globalVars.config.get("Divera", "accesskey"), + "type": type, + "text": text, + "priority": priority, + })) - except: - logging.error("cannot send Divera request") - logging.debug("cannot send Divera request", exc_info=True) - return + except: + logging.error("cannot send Divera request") + logging.debug("cannot send Divera request", exc_info=True) + return + try: + # + # check Divera-Response + # + response = conn.getresponse() + if str(response.status) == "200": # Check Divera Response and print a Log or Error + logging.debug("Divera response: %s - %s", str(response.status), str(response.reason)) + else: + logging.warning("Divera response: %s - %s", str(response.status), str(response.reason)) + except: # otherwise + logging.error("cannot get Divera response") + logging.debug("cannot get Divera response", exc_info=True) + return + + finally: + logging.debug("close Divera-Connection") try: - # - # check Divera-Response - # - response = conn.getresponse() - if str(response.status) == "200": # Check Divera Response and print a Log or Error - logging.debug("Divera response: %s - %s", str(response.status), str(response.reason)) - else: - logging.warning("Divera response: %s - %s", str(response.status), str(response.reason)) - except: # otherwise - logging.error("cannot get Divera response") - logging.debug("cannot get Divera response", exc_info=True) - return - - finally: - logging.debug("close Divera-Connection") - try: - request.close() - except: - pass + request.close() + except: + pass except: logging.error("unknown error") From 6b638c55b2750d1f6e77997c70b62efe6bed2c2b Mon Sep 17 00:00:00 2001 From: grosj <56541936+grosj@users.noreply.github.com> Date: Tue, 15 Oct 2019 10:46:38 +0200 Subject: [PATCH 4/9] Update line feeds --- plugins/Divera/Divera.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index 98b8a15..8f92188 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -68,7 +68,7 @@ def run(typ, freq, data): # text = globalVars.config.get("Divera", "zvei_text") type = globalVars.config.get("Divera", "zvei_type") - priority = globalVars.config.get("Divera","zvei_std_prio") + priority = globalVars.config.get("Divera","zvei_std_prio") elif typ == "POC": # @@ -90,7 +90,7 @@ def run(typ, freq, data): else: logging.warning("Invalid type: %s", typ) - return + return try: # From 3d769976396804594e6e324e3f8bb12b1390776b Mon Sep 17 00:00:00 2001 From: grosj <56541936+grosj@users.noreply.github.com> Date: Tue, 15 Oct 2019 11:18:16 +0200 Subject: [PATCH 5/9] Changlog zum Divera-Plugin --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5c49c3..286d723 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +### __[Unreleased]__ - 15.10.2019 +##### Added +- Divera-Plugin: Plugin zum Ansteuern der Divera-Api. [#415](https://github.com/Schrolli91/BOSWatch/pull/415) ### __[v2.4.3]__ - 22.09.2019 ##### Added From 0181075d3e669313eea119e10baf88092e216263 Mon Sep 17 00:00:00 2001 From: grosj <56541936+grosj@users.noreply.github.com> Date: Mon, 21 Oct 2019 15:15:57 +0200 Subject: [PATCH 6/9] Update config.template.ini --- config/config.template.ini | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/config/config.template.ini b/config/config.template.ini index 955fc5f..28a3a2f 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -465,7 +465,9 @@ timeoff = 1 keepon = 60 [Divera] -#See https://www.divera247.com/documentation/local-management-alarm-api.html for Api-Documentation +# See https://api.divera247.com/ for Api-Documentation +# Title: Alarm-Stichwort (max. 50 Zeichen, in der kostenlosen Version max. 30 Zeichen) + # Divera API Key accesskey = @@ -476,18 +478,18 @@ SubB = false SubC = false SubD = false -poc_type = %DESCR%: %MSG% +poc_title = %DESCR%: %MSG% poc_text = %DATE% %TIME% - %DESCR%: %MSG% # Section for ZVEI # default prio for all ZVEI - except you specify it different zvei_prio = true -zvei_type = Alarm: %ZVEI% +zvei_title = Alarm: %ZVEI% zvei_test = %DATE% %TIME%: %ZVEI% # Section for FMS fms_prio = true -fms_type = FMS: %FMS% +fms_title = FMS: %FMS% fms_text = %DATE% %TIME%: %FMS%%BR%Status: %STATUS% - Direction: %DIRT% - TSI: %TSI% %LPAR%%DESCR%%RPAR% ##################### From 0dfe1ee89cd5cf24a8751ce3f41aabbca4b41c1e Mon Sep 17 00:00:00 2001 From: grosj <56541936+grosj@users.noreply.github.com> Date: Mon, 21 Oct 2019 15:19:27 +0200 Subject: [PATCH 7/9] Anpassung auf Divera-Schnittstelle Die Divera-API ist unter https://api.divera247.com beschrieben. Anpassungen an diese Schnittstellenbeschreibung. Aus type wurde title. --- plugins/Divera/Divera.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index 8f92188..a31dca8 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -59,7 +59,7 @@ def run(typ, freq, data): # building message for FMS # text = globalVars.config.get("Divera", "fms_text") - type = globalVars.config.get("Divera", "fms_type") + title = globalVars.config.get("Divera", "fms_title") priority = globalVars.config.get("Divera", "fms_prio") elif typ == "ZVEI": @@ -67,7 +67,7 @@ def run(typ, freq, data): # building message for ZVEI # text = globalVars.config.get("Divera", "zvei_text") - type = globalVars.config.get("Divera", "zvei_type") + title = globalVars.config.get("Divera", "zvei_title") priority = globalVars.config.get("Divera","zvei_std_prio") elif typ == "POC": @@ -86,7 +86,7 @@ def run(typ, freq, data): priority = 'false' text = globalVars.config.get("Divera", "poc_text") - type = globalVars.config.get("Divera", "poc_type") + title = globalVars.config.get("Divera", "poc_title") else: logging.warning("Invalid type: %s", typ) @@ -100,10 +100,10 @@ def run(typ, freq, data): # replace the wildcards text = wildcardHandler.replaceWildcards(text, data) - type = wildcardHandler.replaceWildcards(type, data) + title = wildcardHandler.replaceWildcards(title, data) # Logging data to send - logging.debug("Type : %s", type) + logging.debug("Title : %s", title) logging.debug("Text : %s", text) logging.debug("Priority: %s", priority) @@ -116,7 +116,7 @@ def run(typ, freq, data): conn.request("GET", "/api/alarm", urllib.urlencode({ "accesskey": globalVars.config.get("Divera", "accesskey"), - "type": type, + "title": title, "text": text, "priority": priority, })) From ddbddbbcdd8ea986a546e2bd4cecd372fb5deed5 Mon Sep 17 00:00:00 2001 From: grosj <56541936+grosj@users.noreply.github.com> Date: Mon, 4 Nov 2019 08:19:41 +0100 Subject: [PATCH 8/9] =?UTF-8?q?Keinen=20Default=20f=C3=BCr=20priority?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ist kein Wert oder ein anderer Wert als true/false für priority gesetzt, wird ein Divera-Alarm ausgelassen. --- plugins/Divera/Divera.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index a31dca8..60092ed 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -83,7 +83,7 @@ def run(typ, freq, data): elif data["function"] == '4': priority = globalVars.config.get("Divera", "SubD") else: - priority = 'false' + priority = '' text = globalVars.config.get("Divera", "poc_text") title = globalVars.config.get("Divera", "poc_title") @@ -109,7 +109,8 @@ def run(typ, freq, data): # check priority value if (priority != 'false') and (priority != 'true'): - priority = 'false' + logging.info("No Priority set for type '%s'! Skipping Divera-Alarm!", typ) + return # start the connection conn = httplib.HTTPSConnection("www.divera247.com:443") From 3fc0e6d27a17dae678a4ed0181471d5cbef5ff75 Mon Sep 17 00:00:00 2001 From: grosj <56541936+grosj@users.noreply.github.com> Date: Mon, 4 Nov 2019 08:25:38 +0100 Subject: [PATCH 9/9] Update config.template.ini Beschreibung zum Divera-Plugin angepasst. Typo korrigiert. --- config/config.template.ini | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/config/config.template.ini b/config/config.template.ini index 28a3a2f..2ae9af2 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -467,6 +467,9 @@ keepon = 60 [Divera] # See https://api.divera247.com/ for Api-Documentation # Title: Alarm-Stichwort (max. 50 Zeichen, in der kostenlosen Version max. 30 Zeichen) +# Text: Alarm-Text (in der kostenlosen Version wird dies nicht übernommen) +# Priority: true / false. +# Wird ein anderer Wert oder gar keiner gesetzt, so wird die Divera-Alarmierung nicht durchgeführt. # Divera API Key accesskey = @@ -475,8 +478,8 @@ accesskey = # Adapt Pocsag Subric (a,b,c,d) to Divera Priorities (true/false) SubA = true SubB = false -SubC = false -SubD = false +SubC = +SubD = poc_title = %DESCR%: %MSG% poc_text = %DATE% %TIME% - %DESCR%: %MSG% @@ -485,7 +488,7 @@ poc_text = %DATE% %TIME% - %DESCR%: %MSG% # default prio for all ZVEI - except you specify it different zvei_prio = true zvei_title = Alarm: %ZVEI% -zvei_test = %DATE% %TIME%: %ZVEI% +zvei_text = %DATE% %TIME%: %ZVEI% # Section for FMS fms_prio = true