From 75de1c9688149ee8328247cf7719946910cf7fcb Mon Sep 17 00:00:00 2001 From: Ricardo Krippner Date: Thu, 29 Sep 2016 14:20:05 +0200 Subject: [PATCH 1/2] added Pushover Plugin --- plugins/Pushover/Pushover.py | 122 +++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 plugins/Pushover/Pushover.py diff --git a/plugins/Pushover/Pushover.py b/plugins/Pushover/Pushover.py new file mode 100644 index 0000000..50112d5 --- /dev/null +++ b/plugins/Pushover/Pushover.py @@ -0,0 +1,122 @@ +#!/usr/bin/python +# -*- coding: cp1252 -*- + +""" +Pushover-Plugin to send FMS-, ZVEI- and POCSAG - messages to Pushover Clients + +@author: Ricardo Krippner + +@requires: Pushover-Configuration has to be set in the config.ini +""" + +import time +import logging # Global logger +import httplib #for the HTTP request +import urllib +from includes import globals # Global variables + +from includes.helper import timeHandler +from includes.helper import configHandler + +## +# +# 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 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 interface.txt) + @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 + + try: + # + # Pushover-Request + # + logging.debug("send Pushover %s", typ) + + if data["function"] == '1': + priority = globals.config.get("Pushover", "SubA") + elif data["function"] == '2': + priority = globals.config.get("Pushover", "SubB") + elif data["function"] == '3': + priority = globals.config.get("Pushover", "SubC") + elif data["function"] == '4': + priority = globals.config.get("Pushover", "SubD") + else: + priority = 0 + + conn = httplib.HTTPSConnection("api.pushover.net:443") + conn.request("POST", "/1/messages.json", + urllib.urlencode({ + "token": globals.config.get("Pushover", "api_key"), + "user": globals.config.get("Pushover", "user_key"), + "message": ""+data["description"]+"
"+data["msg"].replace(";", "
"), + "html": globals.config.get("Pushover", "html"), + "title": globals.config.get("Pushover", "title"), + "priority": priority, + "retry": globals.config.get("Pushover", "retry"), + "expire": globals.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 + + 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 + + finally: + logging.debug("close Pushover-Connection") + try: + request.close() + except: + pass + + except: + logging.error("unknown error") + logging.debug("unknown error", exc_info=True) From 2088fd75ed898fa2bb0c791a913c9e5b09ed7b95 Mon Sep 17 00:00:00 2001 From: Ricardo Krippner Date: Thu, 29 Sep 2016 14:25:38 +0200 Subject: [PATCH 2/2] added Pushover Config --- config/config.template.ini | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/config/config.template.ini b/config/config.template.ini index 3be9c60..4e13415 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -126,6 +126,7 @@ BosMon = 0 firEmergency = 0 jsonSocket = 0 notifyMyAndroid = 0 +Pushover = 0 # for developing template-module template = 0 @@ -301,6 +302,31 @@ phonenumber1 = 0160321654987 # ! DO NOT USE ANY UMLAUT ! text1 = Rueckruf Leitstelle! +[Pushover] +# Pushover API Key +api_key = + +# Pushover Userkey or Groupkey to receive message +user_key = + +# Title of the message +title = BOSWatch Message + +# Adapt Pocsag Subric (a,b,c,d) to Pushover Priorities (see https://pushover.net/api#priority) +SubA = 0 +SubB = 2 +SubC = 1 +SubD = 0 + +# how often should Pushover re-alert in seconds (emergency-messages) +retry = 30 + +# when should Pushover stop to re-alert in seconds (emergency-messages) +expire = 90 + +# use HTML in messages (0/1) +html = 1 + ##################### ##### Not ready yet # #####################