add: ntfy and webhook support

This commit is contained in:
deadbeet
2022-03-28 16:11:00 +02:00
committed by jokob-sk
parent 4b204b8a29
commit c25fbe4cb8
3 changed files with 32 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ ENV USER=pi USER_ID=1000 USER_GID=1000 TZ=Europe/London PORT=20211
# Todo, do we still need all these packages? I can already see sudo which isn't needed
RUN apt-get update \
&& apt-get install --no-install-recommends ca-certificates curl libwww-perl arp-scan perl apt-utils cron sudo nginx-light php php-cgi php-fpm php-sqlite3 sqlite3 dnsutils net-tools python3 iproute2 nmap python3-pip zip -y \
&& apt-get install --no-install-recommends ca-certificates curl libwww-perl arp-scan perl apt-utils cron sudo nginx-light php php-cgi php-fpm php-sqlite3 php-curl sqlite3 dnsutils net-tools python3 iproute2 nmap python3-pip zip -y \
&& pip3 install requests \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 10 \
&& apt-get clean autoclean \

View File

@@ -27,8 +27,10 @@ import socket
import io
import smtplib
import csv
import json
import requests
#===============================================================================
# CONFIG CONSTANTS
#===============================================================================
@@ -272,7 +274,7 @@ def cleanup_database ():
try:
strdaystokeepEV = str(DAYS_TO_KEEP_EVENTS)
except NameError: # variable not defined, use a default
strdaystokeepEV = str(3650) # 10 years
strdaystokeepEV = str(365) # 1 year
# Cleanup Online History
print ('\nCleanup Online_History...')
@@ -1384,6 +1386,11 @@ def email_reporting ():
send_email (mail_text, mail_html)
else :
print (' Skip mail...')
if REPORT_WEBHOOK :
print (' Sending report by webhook...')
send_webhook (mail_text)
else :
print (' Skip webhook...')
if REPORT_NTFY :
print (' Sending report by NTFY...')
send_ntfy (mail_text)
@@ -1527,6 +1534,27 @@ def SafeParseGlobalBool(boolVariable):
return eval(boolVariable)
return False
#-------------------------------------------------------------------------------
def send_webhook (_Text):
#Define slack-compatible payload
_json_payload={
"username": "Pi.Alert",
"text": "There are new notifications",
"attachments": [{
"title": "Pi.Alert Notifications",
"title_link": REPORT_DASHBOARD_URL,
"text": _Text
}]
}
# Using the Slack-Compatible Webhook endpoint for Discord so that the same payload can be used for both
if(WEBHOOK_URL.startswith('https://discord.com/api/webhooks/') and not WEBHOOK_URL.endswith("/slack")):
_WEBHOOK_URL = f"{WEBHOOK_URL}/slack"
else:
_WEBHOOK_URL = WEBHOOK_URL
requests.post(_WEBHOOK_URL, json.dumps(_json_payload))
#===============================================================================
# DB
#===============================================================================

View File

@@ -33,8 +33,8 @@ REPORT_DASHBOARD_URL = 'http://pi.alert/'
# Webhook settings
# ----------------------
REPORT_WEBHOOK = True
WEBHOOK_URL = http://100.89.112.105:5678/webhook-test/a1db46b8-14bb-4651-a079-9ab5b01fada3
REPORT_WEBHOOK = False
WEBHOOK_URL = 'http://n8n.local:5555/webhook-test/aaaaaaaa-aaaa-aaaa-aaaaa-aaaaaaaaaaaa'
# NTFY (https://ntfy.sh/) settings
# ----------------------