From 04c88aee06759d13a4ad3f5ed342b1507aa3dbbd Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Sat, 13 Aug 2022 19:07:04 +1000 Subject: [PATCH] implemented apprise notifications + readme updates --- .github/workflows/docker.yml | 2 +- README.md | 10 +++++----- back/pialert.py | 35 +++++++++++++++++++++++++++++++---- config/pialert.conf | 10 +++++++++- dockerfiles/README.md | 6 +++--- front/maintenance.php | 2 +- 6 files changed, 50 insertions(+), 15 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0d79320e..b971a490 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -36,7 +36,7 @@ jobs: with: # list of Docker images to use as base name for tags images: | - jokobsk/pi.alert + jokobsk/pi.alert_dev # generate Docker tags based on the following events/attributes tags: | type=raw,value=latest diff --git a/README.md b/README.md index 2de53dc8..293e3d96 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,13 @@ JavaScript)* Docker last pushed -🥇 Pi.Alert credit goes to [pucherot/Pi.Alert](https://github.com/pucherot/Pi.Alert).
-🐳 Docker Image: [jokobsk/Pi.Alert](https://registry.hub.docker.com/r/jokobsk/pi.alert).
+🥇 Pi.Alert credit goes to [pucherot/Pi.Alert](https://github.com/pucherot/Pi.Alert)
+🐳 Docker Image: [jokobsk/Pi.Alert](https://registry.hub.docker.com/r/jokobsk/pi.alert)
📄 [Dockerfile](https://github.com/jokob-sk/Pi.Alert/blob/main/Dockerfile)
-📚 [Dockerfile instructions](https://github.com/jokob-sk/Pi.Alert/blob/main//dockerfiles/README.md). +📚 [Dockerfile instructions](https://github.com/jokob-sk/Pi.Alert/blob/main//dockerfiles/README.md) -Dark mode (and Device presence over time) within this fork courtesy of [leiweibau](https://github.com/leiweibau/Pi.Alert) +Dark mode (and much more) within this fork courtesy of [leiweibau](https://github.com/leiweibau/Pi.Alert) ## How it works The system continuously scans the network for: @@ -61,7 +61,7 @@ In charge of: - Scan the network searching connected devices using the scanning methods described - Store the information in the DB - - Report the changes detected by e-mail and/or other services (Pushsafer, NTFY, Gotify, Webhooks ([sample JSON](docs/webhook_json_sample.json))) + - Report the changes detected by e-mail and/or other services ([Apprise](https://hub.docker.com/r/caronc/apprise), [Pushsafer](https://www.pushsafer.com/), [NTFY](https://ntfy.sh/), Webhooks ([sample JSON](docs/webhook_json_sample.json))) - Optional speedtest for Device "Internet" - DB cleanup tasks via cron - a pialert-cli that helps to configure login and password diff --git a/back/pialert.py b/back/pialert.py index e0b06ffb..e7552aee 100644 --- a/back/pialert.py +++ b/back/pialert.py @@ -1424,6 +1424,11 @@ def email_reporting (): send_email (mail_text, mail_html) else : print (' Skip mail...') + if REPORT_APPRISE : + print (' Sending report by Apprise...') + send_apprise (mail_html) + else : + print (' Skip Apprise...') if REPORT_WEBHOOK : print (' Sending report by webhook...') send_webhook (json_final) @@ -1602,10 +1607,24 @@ def send_webhook (_json): stdout, stderr = p.communicate() # write stdout and stderr into .log files for debugging if needed - if stderr != None: - append_file_binary (LOG_PATH + '/stderr.log', stderr) - if stdout != None: - append_file_binary (LOG_PATH + '/stdout.log', stdout) + logResult (stdout, stderr) + +#------------------------------------------------------------------------------- +def send_apprise (html): + #Define Apprise compatible payload (https://github.com/caronc/apprise-api#stateless-solution) + _json_payload={ + "urls": APPRISE_URL, + "title": "Pi.Alert Notifications", + "format": "html", + "body": html + } + + p = subprocess.Popen(["curl","-i","-X", "POST" ,"-H", "Content-Type:application/json" ,"-d", json.dumps(_json_payload), APPRISE_HOST], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + + stdout, stderr = p.communicate() + + # write stdout and stderr into .log files for debugging if needed + logResult (stdout, stderr) #=============================================================================== @@ -1744,6 +1763,14 @@ def add_json_list (row, list): return list +#------------------------------------------------------------------------------- + +def logResult (stdout, stderr): + if stderr != None: + append_file_binary (LOG_PATH + '/stderr.log', stderr) + if stdout != None: + append_file_binary (LOG_PATH + '/stdout.log', stdout) + #=============================================================================== # BEGIN diff --git a/config/pialert.conf b/config/pialert.conf index 14b32b54..8146b353 100644 --- a/config/pialert.conf +++ b/config/pialert.conf @@ -36,6 +36,12 @@ REPORT_DASHBOARD_URL = 'http://pi.alert/' REPORT_WEBHOOK = False WEBHOOK_URL = 'http://n8n.local:5555/webhook-test/aaaaaaaa-aaaa-aaaa-aaaaa-aaaaaaaaaaaa' +# Apprise settings +#----------------------- +REPORT_APPRISE = False +APPRISE_HOST = 'http://localhost:8000/notify' +APPRISE_URL = 'mailto://smtp-relay.sendinblue.com:587?from=user@gmail.com&name=apprise&user=user@gmail.com&pass=password&to=user@gmail.com' + # NTFY (https://ntfy.sh/) settings # ---------------------- REPORT_NTFY = False @@ -64,6 +70,7 @@ DHCP_ACTIVE = False DHCP_LEASES = '/etc/pihole/dhcp.leases' # arp-scan options & samples +# ---------------------- # # Scan local network (default) # SCAN_SUBNETS = '--localnet' @@ -78,4 +85,5 @@ SCAN_SUBNETS = '--localnet' # Maintenance Tasks Cron # ---------------------- -DAYS_TO_KEEP_EVENTS = 90 \ No newline at end of file +DAYS_TO_KEEP_EVENTS = 90 + diff --git a/dockerfiles/README.md b/dockerfiles/README.md index d241e65b..53759d1e 100644 --- a/dockerfiles/README.md +++ b/dockerfiles/README.md @@ -12,10 +12,10 @@ # 🐳 A docker image for Pi.Alert -🥇 Pi.Alert credit goes to [pucherot/Pi.Alert](https://github.com/pucherot/Pi.Alert).
-🐳 Docker Image: [jokobsk/Pi.Alert](https://registry.hub.docker.com/r/jokobsk/pi.alert).
+🥇 Pi.Alert credit goes to [pucherot/Pi.Alert](https://github.com/pucherot/Pi.Alert)
+🐳 Docker Image: [jokobsk/Pi.Alert](https://registry.hub.docker.com/r/jokobsk/pi.alert)
📄 [Dockerfile](https://github.com/jokob-sk/Pi.Alert/blob/main/Dockerfile)
-📚 [Dockerfile instructions](https://github.com/jokob-sk/Pi.Alert/blob/main//dockerfiles/README.md). +📚 [Dockerfile instructions](https://github.com/jokob-sk/Pi.Alert/blob/main//dockerfiles/README.md) Big thanks to @Macleykun for help and tips&tricks for Dockerfile(s): diff --git a/front/maintenance.php b/front/maintenance.php index 9a0bb56b..e22763cb 100644 --- a/front/maintenance.php +++ b/front/maintenance.php @@ -573,7 +573,7 @@ function PiaToggleArpScan() // laod footer asynchronously not to block the page load/other sections window.onload = function asyncFooter() { - $("#lastCommit").append('GitHub last commit'); + $("#lastCommit").append('GitHub last commit'); $("#lastDockerUpdate").append( 'Docker last pushed');