From 572c40d1a475776c639de84bd7124d3dd9487f7b Mon Sep 17 00:00:00 2001 From: Lars Gremme Date: Wed, 29 Apr 2020 19:50:45 +0200 Subject: [PATCH 01/13] Add vehicle / ric to Divera Plugin --- config/config.template.ini | 3 +++ plugins/Divera/Divera.py | 54 +++++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/config/config.template.ini b/config/config.template.ini index af5da01..ffedcef 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -494,17 +494,20 @@ SubD = poc_title = %DESCR%: %MSG% poc_text = %DATE% %TIME% - %DESCR%: %MSG% +poc_ric = %DESCR% # Section for ZVEI # default prio for all ZVEI - except you specify it different zvei_prio = true zvei_title = Alarm: %ZVEI% zvei_text = %DATE% %TIME%: %ZVEI% +zvei_ric = %DESCR% # Section for FMS fms_prio = true fms_title = FMS: %FMS% fms_text = %DATE% %TIME%: %FMS%%BR%Status: %STATUS% - Direction: %DIRT% - TSI: %TSI% %LPAR%%DESCR%%RPAR% +fms_vehicle = %DESCR% [gpiocontrol] diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index 60092ed..b6861da 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -61,6 +61,7 @@ def run(typ, freq, data): text = globalVars.config.get("Divera", "fms_text") title = globalVars.config.get("Divera", "fms_title") priority = globalVars.config.get("Divera", "fms_prio") + vehicle = globalVars.config.get("Divera", "fms_vehicle") elif typ == "ZVEI": # @@ -69,6 +70,7 @@ def run(typ, freq, data): text = globalVars.config.get("Divera", "zvei_text") title = globalVars.config.get("Divera", "zvei_title") priority = globalVars.config.get("Divera","zvei_std_prio") + ric = globalVars.config.get("Divera","zvei_ric") elif typ == "POC": # @@ -87,6 +89,7 @@ def run(typ, freq, data): text = globalVars.config.get("Divera", "poc_text") title = globalVars.config.get("Divera", "poc_title") + ric = globalVars.config.get("Divera", "poc_ric") else: logging.warning("Invalid type: %s", typ) @@ -101,9 +104,18 @@ def run(typ, freq, data): # replace the wildcards text = wildcardHandler.replaceWildcards(text, data) title = wildcardHandler.replaceWildcards(title, data) + if typ == "FMS": + vehicle = wildcardHandler.replaceWildcards(vehicle, data) + else: + ric = wildcardHandler.replaceWildcards(ric, data) + # Logging data to send logging.debug("Title : %s", title) + if typ == "FMS": + logging.debug("Vehicle : %s", vehicle) + else: + logging.debug("RIC : %s", ric) logging.debug("Text : %s", text) logging.debug("Priority: %s", priority) @@ -112,15 +124,39 @@ def run(typ, freq, data): logging.info("No Priority set for type '%s'! Skipping Divera-Alarm!", typ) return - # start the connection - conn = httplib.HTTPSConnection("www.divera247.com:443") - conn.request("GET", "/api/alarm", - urllib.urlencode({ - "accesskey": globalVars.config.get("Divera", "accesskey"), - "title": title, - "text": text, - "priority": priority, - })) + # Check FMS + if typ == "FMS": + if (vehicle == ''): + logging.info("No Vehicle set!"); + + else: + if (ric == ''): + logging.info("No RIC set!"); + + # 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, + "title": title, + "text": text, + "priority": priority, + })) + + else: + # start connection ZVEI / 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, + })) except: logging.error("cannot send Divera request") From cf70393b2fe35facdca1fbcecd7b234e673214be Mon Sep 17 00:00:00 2001 From: Lars Gremme Date: Wed, 29 Apr 2020 19:57:44 +0200 Subject: [PATCH 02/13] remove std from divera plugin in zvei --- plugins/Divera/Divera.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index b6861da..0b4b1d5 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -69,7 +69,7 @@ def run(typ, freq, data): # text = globalVars.config.get("Divera", "zvei_text") title = globalVars.config.get("Divera", "zvei_title") - priority = globalVars.config.get("Divera","zvei_std_prio") + priority = globalVars.config.get("Divera","zvei_prio") ric = globalVars.config.get("Divera","zvei_ric") elif typ == "POC": From fd2392437f8511df9b409d8f858ad696a5d1c0d3 Mon Sep 17 00:00:00 2001 From: Lars Gremme Date: Wed, 29 Apr 2020 20:01:37 +0200 Subject: [PATCH 03/13] add notice for zvei_ric at 6 characters --- config/config.template.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/config/config.template.ini b/config/config.template.ini index ffedcef..80ac8c5 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -501,6 +501,7 @@ poc_ric = %DESCR% zvei_prio = true zvei_title = Alarm: %ZVEI% zvei_text = %DATE% %TIME%: %ZVEI% +# zvei_ric working at 6 characters or more zvei_ric = %DESCR% # Section for FMS From 2a3243477cedef0a2cc7000d89e3f1a06f775e34 Mon Sep 17 00:00:00 2001 From: Lars Gremme Date: Wed, 29 Apr 2020 20:49:07 +0200 Subject: [PATCH 04/13] FMS: add status_id/status_note; POC: add netfilter --- plugins/Divera/Divera.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index 0b4b1d5..6ce090e 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -16,6 +16,24 @@ from includes import globalVars # Global variables from includes.helper import configHandler 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 ## # @@ -141,13 +159,15 @@ def run(typ, freq, data): 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, })) - else: - # start connection ZVEI / POC + elif typ == "ZVEI": + # start connection POC conn = httplib.HTTPSConnection("www.divera247.com:443") conn.request("GET", "/api/alarm", urllib.urlencode({ @@ -157,6 +177,19 @@ def run(typ, freq, data): "text": text, "priority": priority, })) + + elif typ == "POC": + if isSignal(data["ric"]): + # 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, + })) except: logging.error("cannot send Divera request") From 8eb2901bcb4ff4e26412d9ceda03b500edad7d8c Mon Sep 17 00:00:00 2001 From: Lars Gremme Date: Thu, 30 Apr 2020 23:48:13 +0200 Subject: [PATCH 05/13] Add logging information --- plugins/Divera/Divera.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index 6ce090e..9759e5e 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -190,6 +190,13 @@ def run(typ, freq, data): "text": text, "priority": priority, })) + + else: + logging.debug("RIC is net ident") + + else: + loggin.debug("No Type is set", exc_info=True) + return except: logging.error("cannot send Divera request") From 18358abec20604c9dd5e0ce41a5f9f029dce30f1 Mon Sep 17 00:00:00 2001 From: Lars Gremme Date: Thu, 30 Apr 2020 23:49:20 +0200 Subject: [PATCH 06/13] Net RIC return --- plugins/Divera/Divera.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index 9759e5e..fc52aaa 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -193,6 +193,7 @@ def run(typ, freq, data): else: logging.debug("RIC is net ident") + return else: loggin.debug("No Type is set", exc_info=True) From ab96a4db389997a943e82c47e8bb22052a3ac17a Mon Sep 17 00:00:00 2001 From: Lars Gremme Date: Fri, 1 May 2020 11:38:36 +0200 Subject: [PATCH 07/13] Change netric to top --- plugins/Divera/Divera.py | 60 +++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index fc52aaa..90d33c6 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -91,23 +91,29 @@ def run(typ, freq, data): ric = globalVars.config.get("Divera","zvei_ric") 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 = '' + if isSignal(data["ric"]): + + # + # 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") - title = globalVars.config.get("Divera", "poc_title") - ric = globalVars.config.get("Divera", "poc_ric") + text = globalVars.config.get("Divera", "poc_text") + title = globalVars.config.get("Divera", "poc_title") + ric = globalVars.config.get("Divera", "poc_ric") + + else: + logging.debug("RIC is net ident") + return else: logging.warning("Invalid type: %s", typ) @@ -179,21 +185,17 @@ def run(typ, freq, data): })) elif typ == "POC": - if isSignal(data["ric"]): # 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, - })) + 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: - logging.debug("RIC is net ident") - return else: loggin.debug("No Type is set", exc_info=True) From 5136c6fb31dbc9b2b916de9466afb062b054b56c Mon Sep 17 00:00:00 2001 From: Lars Gremme Date: Sat, 2 May 2020 13:03:18 +0200 Subject: [PATCH 08/13] Change if-else after net RIC (wrong definition) --- plugins/Divera/Divera.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index 90d33c6..080e460 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -93,6 +93,9 @@ def run(typ, freq, data): elif typ == "POC": if isSignal(data["ric"]): + logging.debug("RIC is net ident") + return + else: # # building message for POC # @@ -110,10 +113,7 @@ def run(typ, freq, data): text = globalVars.config.get("Divera", "poc_text") title = globalVars.config.get("Divera", "poc_title") ric = globalVars.config.get("Divera", "poc_ric") - - else: - logging.debug("RIC is net ident") - return + else: logging.warning("Invalid type: %s", typ) From c2b3c70a9c661c737cc3975ba669508519a0645f Mon Sep 17 00:00:00 2001 From: Lars Gremme Date: Sat, 2 May 2020 14:02:58 +0200 Subject: [PATCH 09/13] Change description ZVEI --- plugins/Divera/Divera.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index 080e460..a8b0bb4 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -173,7 +173,7 @@ def run(typ, freq, data): })) elif typ == "ZVEI": - # start connection POC + # start connection ZVEI conn = httplib.HTTPSConnection("www.divera247.com:443") conn.request("GET", "/api/alarm", urllib.urlencode({ From b46dc26a50e2464aa5a8ec6e614b5c272e09c8b2 Mon Sep 17 00:00:00 2001 From: Lars Gremme Date: Mon, 4 May 2020 18:23:22 +0200 Subject: [PATCH 10/13] Add more Descriptions --- plugins/Divera/Divera.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index a8b0bb4..10d6e34 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -128,6 +128,8 @@ def run(typ, freq, data): # replace the wildcards text = wildcardHandler.replaceWildcards(text, data) title = wildcardHandler.replaceWildcards(title, data) + + # replace the wildcards in FMS; RIC is used for ZVEI/POC if typ == "FMS": vehicle = wildcardHandler.replaceWildcards(vehicle, data) else: @@ -136,10 +138,14 @@ def run(typ, freq, data): # Logging data to send logging.debug("Title : %s", title) + + # ZVEI, POC is logged, if not FMS is used if typ == "FMS": logging.debug("Vehicle : %s", vehicle) else: logging.debug("RIC : %s", ric) + + # Logging normal logging.debug("Text : %s", text) logging.debug("Priority: %s", priority) From 5bbb1b01062aab5a5b0238bf4cb226b3cf6d1875 Mon Sep 17 00:00:00 2001 From: Lars Gremme Date: Tue, 5 May 2020 17:55:59 +0200 Subject: [PATCH 11/13] if-clauses; change zvei_ric to zvei_id; combine wildcards with logging --- config/config.template.ini | 4 +-- plugins/Divera/Divera.py | 53 ++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/config/config.template.ini b/config/config.template.ini index 80ac8c5..f7572ab 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -501,8 +501,8 @@ poc_ric = %DESCR% zvei_prio = true zvei_title = Alarm: %ZVEI% zvei_text = %DATE% %TIME%: %ZVEI% -# zvei_ric working at 6 characters or more -zvei_ric = %DESCR% +# zvei_id working at 6 characters or more; later name of alarm-RIC in divera +zvei_id = %DESCR% # Section for FMS fms_prio = true diff --git a/plugins/Divera/Divera.py b/plugins/Divera/Divera.py index 10d6e34..5811f8f 100644 --- a/plugins/Divera/Divera.py +++ b/plugins/Divera/Divera.py @@ -88,7 +88,7 @@ def run(typ, freq, data): text = globalVars.config.get("Divera", "zvei_text") title = globalVars.config.get("Divera", "zvei_title") priority = globalVars.config.get("Divera","zvei_prio") - ric = globalVars.config.get("Divera","zvei_ric") + zvei_id = globalVars.config.get("Divera","zvei_id") elif typ == "POC": if isSignal(data["ric"]): @@ -124,30 +124,24 @@ def run(typ, freq, data): # Divera-Request # logging.debug("send Divera for %s", typ) - - # replace the wildcards - text = wildcardHandler.replaceWildcards(text, data) + + # Replace wildcards & Logging data to send title = wildcardHandler.replaceWildcards(title, data) - - # replace the wildcards in FMS; RIC is used for ZVEI/POC + logging.debug("Title : %s", title) + text = wildcardHandler.replaceWildcards(text, data) + logging.debug("Text : %s", text) + if typ == "FMS": vehicle = wildcardHandler.replaceWildcards(vehicle, data) - else: - ric = wildcardHandler.replaceWildcards(ric, data) - - - # Logging data to send - logging.debug("Title : %s", title) - - # ZVEI, POC is logged, if not FMS is used - if typ == "FMS": logging.debug("Vehicle : %s", vehicle) - else: + elif typ == "POC": + ric = wildcardHandler.replaceWildcards(ric, data) logging.debug("RIC : %s", ric) - - # Logging normal - logging.debug("Text : %s", text) - logging.debug("Priority: %s", priority) + 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 if (priority != 'false') and (priority != 'true'): @@ -157,11 +151,20 @@ def run(typ, freq, data): # Check FMS if typ == "FMS": if (vehicle == ''): - logging.info("No Vehicle set!"); + logging.info("No Vehicle set!") - else: + # Check POC + elif typ == "POC": if (ric == ''): - logging.info("No RIC set!"); + 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": @@ -179,13 +182,13 @@ def run(typ, freq, data): })) elif typ == "ZVEI": - # start connection 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": ric, + "ric": zvei_id, "text": text, "priority": priority, })) From 52039a056eb5ba76f06546f4ae6f1422f8be7c0d Mon Sep 17 00:00:00 2001 From: Lars Gremme Date: Tue, 5 May 2020 18:03:40 +0200 Subject: [PATCH 12/13] add description in config.template.ini --- config/config.template.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/config.template.ini b/config/config.template.ini index f7572ab..4c33f2a 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -494,6 +494,7 @@ SubD = poc_title = %DESCR%: %MSG% poc_text = %DATE% %TIME% - %DESCR%: %MSG% +# poc_ric is alarm-RIC in divera poc_ric = %DESCR% # Section for ZVEI @@ -508,6 +509,7 @@ zvei_id = %DESCR% fms_prio = true fms_title = FMS: %FMS% 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% From 784a38b3b3b7e50c47aa6a57c30198767c4607bd Mon Sep 17 00:00:00 2001 From: Lars Gremme Date: Tue, 5 May 2020 21:43:53 +0200 Subject: [PATCH 13/13] Update Changelog.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02a44a7..d98ade2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### __[v2.5.2]__ - unreleased ##### Added ##### Changed +- Divera Plugin: Add individual alarms for FMS, ZVEI and POC. [#451](https://github.com/Schrolli91/BOSWatch/pull/451) ##### Deprecated ##### Removed ##### Fixed