From 1928d1b581c989be2b21894130d500722807064a Mon Sep 17 00:00:00 2001 From: leiweibau <105860611+leiweibau@users.noreply.github.com> Date: Wed, 20 Jul 2022 21:21:21 +0200 Subject: [PATCH] basic support for pushsafer.com Currently, only a message with the link to the pi.alert page is sent. I am still struggling with the display of more detailed information. --- back/pialert.py | 28 ++++++++++++++++++++++++++++ config/pialert.conf | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/back/pialert.py b/back/pialert.py index 9e885b27..7fc7ecef 100644 --- a/back/pialert.py +++ b/back/pialert.py @@ -27,6 +27,8 @@ import socket import io import smtplib import csv +from urllib.parse import urlencode +from urllib.request import Request, urlopen #=============================================================================== @@ -1359,6 +1361,11 @@ def email_reporting (): print (' Skip mail...') else : print (' No changes to report...') + if REPORT_PUSHSAFER : + print (' Sending report by PUSHSAFER...') + send_pushsafer (mail_text) + else : + print (' Skip PUSHSAFER...') # Clean Pending Alert Events @@ -1376,6 +1383,27 @@ def email_reporting (): sql_connection.commit() closeDB() +#------------------------------------------------------------------------------- + +def send_pushsafer (_Text): + url = 'https://www.pushsafer.com/api' + post_fields = { + "t" : 'Pi.Alert Message', + "m" : 'Something has changed', + "s" : 11, + "v" : 3, + "i" : 148, + "c" : '#ef7f7f', + "d" : 'a', + "u" : REPORT_DASHBOARD_URL, + "ut" : 'Open Pi.Alert', + "k" : PUSHSAFER_TOKEN, + } + + request = Request(url, urlencode(post_fields).encode()) + json = urlopen(request).read().decode() + # print(json) + #------------------------------------------------------------------------------- def format_report_section (pActive, pSection, pTable, pText, pHTML): global mail_text diff --git a/config/pialert.conf b/config/pialert.conf index 65c0bf03..d58f0f3d 100644 --- a/config/pialert.conf +++ b/config/pialert.conf @@ -23,6 +23,10 @@ REPORT_FROM = 'Pi.Alert <' + SMTP_USER +'>' REPORT_TO = 'user@gmail.com' REPORT_DEVICE_URL = 'http://pi.alert/deviceDetails.php?mac=' +REPORT_PUSHSAFER = False +REPORT_DASHBOARD_URL = '' +PUSHSAFER_TOKEN = 'ApiKey' + # QUERY_MYIP_SERVER = 'https://diagnostic.opendns.com/myip' QUERY_MYIP_SERVER = 'http://ipv4.icanhazip.com' DDNS_ACTIVE = False