From c0366fab9632308b9883350a0ed9bc8e38064416 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 20 Jul 2022 18:31:03 +1000 Subject: [PATCH] add ntfy support --- back/pialert.py | 17 ++++++++++++++++- config/pialert.conf | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/back/pialert.py b/back/pialert.py index 8d69f575..136747fa 100644 --- a/back/pialert.py +++ b/back/pialert.py @@ -27,6 +27,7 @@ import socket import io import smtplib import csv +import requests #=============================================================================== @@ -1369,6 +1370,11 @@ def email_reporting (): send_email (mail_text, mail_html) else : print (' Skip mail...') + if REPORT_NTFY : + print (' Sending report by NTFY...') + send_ntfy (mail_text) + else : + print (' Skip NTFY...') else : print (' No changes to report...') @@ -1387,7 +1393,16 @@ def email_reporting (): # Commit changes sql_connection.commit() closeDB() - +#------------------------------------------------------------------------------- +def send_ntfy (_Text): + requests.post("https://ntfy.sh/{}".format(NTFY_TOPIC), + data=_Text, + headers={ + "Title": "Pi.Alert Notification", + "Click": REPORT_DASHBOARD_URL, + "Priority": "urgent", + "Tags": "warning" + }) #------------------------------------------------------------------------------- def format_report_section (pActive, pSection, pTable, pText, pHTML): global mail_text diff --git a/config/pialert.conf b/config/pialert.conf index 65c0bf03..f3226790 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_NTFY = False +REPORT_DASHBOARD_URL = 'http://pi.alert/' +NTFY_TOPIC = 'replace_my_secure_topicname_91h889f28' + # QUERY_MYIP_SERVER = 'https://diagnostic.opendns.com/myip' QUERY_MYIP_SERVER = 'http://ipv4.icanhazip.com' DDNS_ACTIVE = False @@ -36,6 +40,7 @@ PIHOLE_DB = '/etc/pihole/pihole-FTL.db' DHCP_ACTIVE = False DHCP_LEASES = '/etc/pihole/dhcp.leases' + # arp-scan options & samples # # Scan local network (default)