From 173e552018fc85ec09448203dc0340a57d57c325 Mon Sep 17 00:00:00 2001 From: Florian Date: Sun, 14 Jan 2018 23:33:39 +0100 Subject: [PATCH 1/4] Enabling FMS and ZVEI for Pushover - enabling alarmtype-specific titles and messages (and prios) --- config/config.template.ini | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/config/config.template.ini b/config/config.template.ini index 8f210937..496070b9 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -377,14 +377,24 @@ api_key = # Pushover Userkey or Groupkey to receive message user_key = -# Title of the message -title = BOSWatch Message - +# Section for POCSAG # Adapt Pocsag Subric (a,b,c,d) to Pushover Priorities (see https://pushover.net/api#priority) -SubA = 0 -SubB = 2 -SubC = 1 -SubD = 0 +SubA = 1 +SubB = 1 +SubC = 2 +SubD = -2 +poc_title = Alarm: %RIC%%LPAR%%FUNCCHAR%%RPAR% +poc_message = %DATE% %TIME% - %DESCR%: %MSG% + +# Section for ZVEI +zvei_prio = 1 +zvei_title = Alarm: %ZVEI% +zvei_message = %DATE% %TIME%: %ZVEI% + +# Section for FMS +fms_prio = 1 +fms_title = FMS: %FMS% +fms_message = %DATE% %TIME%: %FMS%%BR%Status: %STATUS% - Direction: %DIRT% - TSI: %TSI% %LPAR%%DESCR%%RPAR% # how often should Pushover re-alert in seconds (emergency-messages) retry = 30 From 098fcc2c460710b30795d71ae124b39447e06455 Mon Sep 17 00:00:00 2001 From: Florian Date: Sun, 14 Jan 2018 23:35:31 +0100 Subject: [PATCH 2/4] Increasing functions for FMS and ZVEI - reading new sections from config - enabling wildcard-handling - sending POCSAG, ZVEI and FMS --- plugins/Pushover/Pushover.py | 91 ++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 30 deletions(-) diff --git a/plugins/Pushover/Pushover.py b/plugins/Pushover/Pushover.py index 1f97c956..d1edb668 100644 --- a/plugins/Pushover/Pushover.py +++ b/plugins/Pushover/Pushover.py @@ -16,6 +16,7 @@ #from includes.helper import timeHandler from includes.helper import configHandler +from includes.helper import wildcardHandler ## # @@ -59,31 +60,62 @@ def run(typ,freq,data): try: if configHandler.checkConfig("Pushover"): #read and debug the config - try: + if typ == "FMS": + # + # building message for FMS + # + + message = globalVars.config.get("Pushover", "fms_message") + title = globalVars.config.get("Pushover", "fms_title") + priority = globalVars.config.get("Pushover", "fms_prio") + logging.debug("Sending message: %s", message) + + elif typ == "ZVEI": + # + # building message for ZVEI + # + message = globalVars.config.get("Pushover", "zvei_message") + title = globalVars.config.get("Pushover", "zvei_title") + priority = globalVars.config.get("Pushover", "zvei_prio") + logging.debug("Sending message: %s", message) + + elif typ == "POC": + # # Pushover-Request # - logging.debug("send Pushover %s", typ) - - if data["function"] == '1': - priority = globalVars.config.get("Pushover", "SubA") - elif data["function"] == '2': - priority = globalVars.config.get("Pushover", "SubB") - elif data["function"] == '3': - priority = globalVars.config.get("Pushover", "SubC") - elif data["function"] == '4': - priority = globalVars.config.get("Pushover", "SubD") - else: - priority = 0 - + logging.debug("send Pushover for %s", typ) + + if data["function"] == '1': + priority = globalVars.config.get("Pushover", "SubA") + elif data["function"] == '2': + priority = globalVars.config.get("Pushover", "SubB") + elif data["function"] == '3': + priority = globalVars.config.get("Pushover", "SubC") + elif data["function"] == '4': + priority = globalVars.config.get("Pushover", "SubD") + else: + priority = 0 + message = globalVars.config.get("Pushover", "poc_message") + title = globalVars.config.get("Pushover", "poc_title") + + else: + logging.warning("Invalid type: %s", typ) + + try: + # replace the wildcards + message = wildcardHandler.replaceWildcards(message,data) + title = wildcardHandler.replaceWildcards(title,data) + + # start the connection conn = httplib.HTTPSConnection("api.pushover.net:443") conn.request("POST", "/1/messages.json", urllib.urlencode({ "token": globalVars.config.get("Pushover", "api_key"), "user": globalVars.config.get("Pushover", "user_key"), - "message": ""+data["description"]+"
"+data["msg"].replace(";", "
"), + "message": message, "html": globalVars.config.get("Pushover", "html"), - "title": globalVars.config.get("Pushover", "title"), + "title": title, "priority": priority, "retry": globalVars.config.get("Pushover", "retry"), "expire": globalVars.config.get("Pushover", "expire") @@ -94,20 +126,19 @@ def run(typ,freq,data): logging.debug("cannot send Pushover request", exc_info=True) return - else: - try: - # - # check Pushover-Response - # - response = conn.getresponse() - if str(response.status) == "200": #Check Pushover Response and print a Log or Error - logging.debug("Pushover response: %s - %s" , str(response.status), str(response.reason)) - else: - logging.warning("Pushover response: %s - %s" , str(response.status), str(response.reason)) - except: #otherwise - logging.error("cannot get Pushover response") - logging.debug("cannot get Pushover response", exc_info=True) - return + try: + # + # check Pushover-Response + # + response = conn.getresponse() + if str(response.status) == "200": #Check Pushover Response and print a Log or Error + logging.debug("Pushover response: %s - %s" , str(response.status), str(response.reason)) + else: + logging.warning("Pushover response: %s - %s" , str(response.status), str(response.reason)) + except: #otherwise + logging.error("cannot get Pushover response") + logging.debug("cannot get Pushover response", exc_info=True) + return finally: logging.debug("close Pushover-Connection") From f92ce0d5f8ca3da203943b3694a39e5a8a34874a Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Mon, 15 Jan 2018 06:55:52 +0100 Subject: [PATCH 3/4] edit CL --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a778e710..c4e9d3a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,13 @@ ### __[v2.3.1]__ - Unreleased ##### Added - Config Eintrag um Port für MySQL Plugin festzulegen [#345](https://github.com/Schrolli91/BOSWatch/pull/345) +- FMS und ZVEI Support für Pushover Plugin [#352](https://github.com/Schrolli91/BOSWatch/pull/352) +- Benutzerdefinierte Nachrichten für Pushover Plugin in config [#352](https://github.com/Schrolli91/BOSWatch/pull/352) ##### Changed ##### Deprecated ##### Removed ##### Fixed -- Fehler beim auslesen der netIdent_RIC im MySQL Plugin [#347](https://github.com/Schrolli91/BOSWatch/pull/347) +- Fehler beim Auslesen der netIdent_RIC im MySQL Plugin [#347](https://github.com/Schrolli91/BOSWatch/pull/347) ##### Security From cf1b5b3fc4960f6c688d242b227c00d4e8e24666 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Mon, 15 Jan 2018 06:56:12 +0100 Subject: [PATCH 4/4] PEP8 changes to pushover --- .gitignore | 2 + plugins/Pushover/Pushover.py | 241 ++++++++++++++++++----------------- 2 files changed, 123 insertions(+), 120 deletions(-) diff --git a/.gitignore b/.gitignore index 3b70e903..f37fd5c5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ log/ \.pydevproject \.settings/ + +\.idea/ diff --git a/plugins/Pushover/Pushover.py b/plugins/Pushover/Pushover.py index d1edb668..d220de6e 100644 --- a/plugins/Pushover/Pushover.py +++ b/plugins/Pushover/Pushover.py @@ -9,31 +9,32 @@ @requires: Pushover-Configuration has to be set in the config.ini """ -import logging # Global logger -import httplib #for the HTTP request +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 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 + """ + While loading the plugins by pluginLoader.loadPlugins() + this onLoad() routine is called one time for initialize the plugin - @requires: nothing + @requires: nothing - @return: nothing - """ - # nothing to do for this plugin - return + @return: nothing + """ + # nothing to do for this plugin + return ## @@ -41,112 +42,112 @@ def onLoad(): # Main function of Pushover-plugin # will be called by the alarmHandler # -def run(typ,freq,data): - """ - This function is the implementation of the Pushover-Plugin. - It will send the data to Pushover 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: Pushover-Configuration has to be set in the config.ini - - @return: nothing - """ - try: - if configHandler.checkConfig("Pushover"): #read and debug the config - - if typ == "FMS": - # - # building message for FMS - # - - message = globalVars.config.get("Pushover", "fms_message") - title = globalVars.config.get("Pushover", "fms_title") - priority = globalVars.config.get("Pushover", "fms_prio") - logging.debug("Sending message: %s", message) - - elif typ == "ZVEI": - # - # building message for ZVEI - # - message = globalVars.config.get("Pushover", "zvei_message") - title = globalVars.config.get("Pushover", "zvei_title") - priority = globalVars.config.get("Pushover", "zvei_prio") - logging.debug("Sending message: %s", message) - - elif typ == "POC": - - # - # Pushover-Request - # - logging.debug("send Pushover for %s", typ) - - if data["function"] == '1': - priority = globalVars.config.get("Pushover", "SubA") - elif data["function"] == '2': - priority = globalVars.config.get("Pushover", "SubB") - elif data["function"] == '3': - priority = globalVars.config.get("Pushover", "SubC") - elif data["function"] == '4': - priority = globalVars.config.get("Pushover", "SubD") - else: - priority = 0 - message = globalVars.config.get("Pushover", "poc_message") - title = globalVars.config.get("Pushover", "poc_title") - - else: - logging.warning("Invalid type: %s", typ) - - try: - # replace the wildcards - message = wildcardHandler.replaceWildcards(message,data) - title = wildcardHandler.replaceWildcards(title,data) - - # start the connection - conn = httplib.HTTPSConnection("api.pushover.net:443") - conn.request("POST", "/1/messages.json", - urllib.urlencode({ - "token": globalVars.config.get("Pushover", "api_key"), - "user": globalVars.config.get("Pushover", "user_key"), - "message": message, - "html": globalVars.config.get("Pushover", "html"), - "title": title, - "priority": priority, - "retry": globalVars.config.get("Pushover", "retry"), - "expire": globalVars.config.get("Pushover", "expire") - }),{"Content-type": "application/x-www-form-urlencoded"}) - - except: - logging.error("cannot send Pushover request") - logging.debug("cannot send Pushover request", exc_info=True) - return - - try: - # - # check Pushover-Response - # - response = conn.getresponse() - if str(response.status) == "200": #Check Pushover Response and print a Log or Error - logging.debug("Pushover response: %s - %s" , str(response.status), str(response.reason)) - else: - logging.warning("Pushover response: %s - %s" , str(response.status), str(response.reason)) - except: #otherwise - logging.error("cannot get Pushover response") - logging.debug("cannot get Pushover response", exc_info=True) - return - - finally: - logging.debug("close Pushover-Connection") - try: - request.close() - except: - pass - - except: - logging.error("unknown error") - logging.debug("unknown error", exc_info=True) +def run(typ, freq, data): + """ + This function is the implementation of the Pushover-Plugin. + It will send the data to Pushover 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: Pushover-Configuration has to be set in the config.ini + + @return: nothing + """ + try: + if configHandler.checkConfig("Pushover"): # read and debug the config + + if typ == "FMS": + # + # building message for FMS + # + + message = globalVars.config.get("Pushover", "fms_message") + title = globalVars.config.get("Pushover", "fms_title") + priority = globalVars.config.get("Pushover", "fms_prio") + logging.debug("Sending message: %s", message) + + elif typ == "ZVEI": + # + # building message for ZVEI + # + message = globalVars.config.get("Pushover", "zvei_message") + title = globalVars.config.get("Pushover", "zvei_title") + priority = globalVars.config.get("Pushover", "zvei_prio") + logging.debug("Sending message: %s", message) + + elif typ == "POC": + + # + # Pushover-Request + # + logging.debug("send Pushover for %s", typ) + + if data["function"] == '1': + priority = globalVars.config.get("Pushover", "SubA") + elif data["function"] == '2': + priority = globalVars.config.get("Pushover", "SubB") + elif data["function"] == '3': + priority = globalVars.config.get("Pushover", "SubC") + elif data["function"] == '4': + priority = globalVars.config.get("Pushover", "SubD") + else: + priority = 0 + message = globalVars.config.get("Pushover", "poc_message") + title = globalVars.config.get("Pushover", "poc_title") + + else: + logging.warning("Invalid type: %s", typ) + + try: + # replace the wildcards + message = wildcardHandler.replaceWildcards(message, data) + title = wildcardHandler.replaceWildcards(title, data) + + # start the connection + conn = httplib.HTTPSConnection("api.pushover.net:443") + conn.request("POST", "/1/messages.json", + urllib.urlencode({ + "token": globalVars.config.get("Pushover", "api_key"), + "user": globalVars.config.get("Pushover", "user_key"), + "message": message, + "html": globalVars.config.get("Pushover", "html"), + "title": title, + "priority": priority, + "retry": globalVars.config.get("Pushover", "retry"), + "expire": globalVars.config.get("Pushover", "expire") + }), {"Content-type": "application/x-www-form-urlencoded"}) + + except: + logging.error("cannot send Pushover request") + logging.debug("cannot send Pushover request", exc_info=True) + return + + try: + # + # check Pushover-Response + # + response = conn.getresponse() + if str(response.status) == "200": # Check Pushover Response and print a Log or Error + logging.debug("Pushover response: %s - %s", str(response.status), str(response.reason)) + else: + logging.warning("Pushover response: %s - %s", str(response.status), str(response.reason)) + except: # otherwise + logging.error("cannot get Pushover response") + logging.debug("cannot get Pushover response", exc_info=True) + return + + finally: + logging.debug("close Pushover-Connection") + try: + request.close() + except: + pass + + except: + logging.error("unknown error") + logging.debug("unknown error", exc_info=True)