mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
add: ntfy and webhook support
This commit is contained in:
@@ -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
|
# Todo, do we still need all these packages? I can already see sudo which isn't needed
|
||||||
|
|
||||||
RUN apt-get update \
|
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 \
|
&& pip3 install requests \
|
||||||
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 10 \
|
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 10 \
|
||||||
&& apt-get clean autoclean \
|
&& apt-get clean autoclean \
|
||||||
|
|||||||
@@ -27,8 +27,10 @@ import socket
|
|||||||
import io
|
import io
|
||||||
import smtplib
|
import smtplib
|
||||||
import csv
|
import csv
|
||||||
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
# CONFIG CONSTANTS
|
# CONFIG CONSTANTS
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
@@ -272,7 +274,7 @@ def cleanup_database ():
|
|||||||
try:
|
try:
|
||||||
strdaystokeepEV = str(DAYS_TO_KEEP_EVENTS)
|
strdaystokeepEV = str(DAYS_TO_KEEP_EVENTS)
|
||||||
except NameError: # variable not defined, use a default
|
except NameError: # variable not defined, use a default
|
||||||
strdaystokeepEV = str(3650) # 10 years
|
strdaystokeepEV = str(365) # 1 year
|
||||||
|
|
||||||
# Cleanup Online History
|
# Cleanup Online History
|
||||||
print ('\nCleanup Online_History...')
|
print ('\nCleanup Online_History...')
|
||||||
@@ -1384,6 +1386,11 @@ def email_reporting ():
|
|||||||
send_email (mail_text, mail_html)
|
send_email (mail_text, mail_html)
|
||||||
else :
|
else :
|
||||||
print (' Skip mail...')
|
print (' Skip mail...')
|
||||||
|
if REPORT_WEBHOOK :
|
||||||
|
print (' Sending report by webhook...')
|
||||||
|
send_webhook (mail_text)
|
||||||
|
else :
|
||||||
|
print (' Skip webhook...')
|
||||||
if REPORT_NTFY :
|
if REPORT_NTFY :
|
||||||
print (' Sending report by NTFY...')
|
print (' Sending report by NTFY...')
|
||||||
send_ntfy (mail_text)
|
send_ntfy (mail_text)
|
||||||
@@ -1527,6 +1534,27 @@ def SafeParseGlobalBool(boolVariable):
|
|||||||
return eval(boolVariable)
|
return eval(boolVariable)
|
||||||
return False
|
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
|
# DB
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ REPORT_DASHBOARD_URL = 'http://pi.alert/'
|
|||||||
|
|
||||||
# Webhook settings
|
# Webhook settings
|
||||||
# ----------------------
|
# ----------------------
|
||||||
REPORT_WEBHOOK = True
|
REPORT_WEBHOOK = False
|
||||||
WEBHOOK_URL = http://100.89.112.105:5678/webhook-test/a1db46b8-14bb-4651-a079-9ab5b01fada3
|
WEBHOOK_URL = 'http://n8n.local:5555/webhook-test/aaaaaaaa-aaaa-aaaa-aaaaa-aaaaaaaaaaaa'
|
||||||
|
|
||||||
# NTFY (https://ntfy.sh/) settings
|
# NTFY (https://ntfy.sh/) settings
|
||||||
# ----------------------
|
# ----------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user