mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Notification rework + docs + devDetails
This commit is contained in:
@@ -70,12 +70,6 @@ WEBHOOK_PAYLOAD = 'json'
|
||||
WEBHOOK_REQUEST_METHOD = 'GET'
|
||||
WEBHOOK_SECRET = ''
|
||||
|
||||
# Apprise
|
||||
REPORT_APPRISE = False
|
||||
APPRISE_HOST = ''
|
||||
APPRISE_URL = ''
|
||||
APPRISE_PAYLOAD = 'html'
|
||||
|
||||
# NTFY
|
||||
REPORT_NTFY = False
|
||||
NTFY_HOST = 'https://ntfy.sh'
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import conf
|
||||
from helper import noti_obj
|
||||
from logger import logResult, mylog
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
def check_config():
|
||||
if conf.APPRISE_URL == '' or conf.APPRISE_HOST == '':
|
||||
mylog('none', ['[Check Config] Error: Apprise service not set up correctly. Check your pialert.conf APPRISE_* variables.'])
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
def send(msg: noti_obj):
|
||||
html = msg.html
|
||||
text = msg.text
|
||||
|
||||
payloadData = ''
|
||||
|
||||
# limit = 1024 * 1024 # 1MB limit (1024 bytes * 1024 bytes = 1MB)
|
||||
limit = conf.APPRISE_SIZE
|
||||
|
||||
# truncate size
|
||||
if conf.APPRISE_PAYLOAD == 'html':
|
||||
if len(msg.html) > limit:
|
||||
payloadData = msg.html[:limit] + " <h1> (text was truncated)</h1>"
|
||||
else:
|
||||
payloadData = msg.html
|
||||
if conf.APPRISE_PAYLOAD == 'text':
|
||||
if len(msg.text) > limit:
|
||||
payloadData = msg.text[:limit] + " (text was truncated)"
|
||||
else:
|
||||
payloadData = msg.text
|
||||
|
||||
# Define Apprise compatible payload (https://github.com/caronc/apprise-api#stateless-solution)
|
||||
|
||||
_json_payload = {
|
||||
"urls": conf.APPRISE_URL,
|
||||
"title": "Pi.Alert Notifications",
|
||||
"format": conf.APPRISE_PAYLOAD,
|
||||
"body": payloadData
|
||||
}
|
||||
|
||||
try:
|
||||
# try runnning a subprocess
|
||||
p = subprocess.Popen(["curl","-i","-X", "POST" ,"-H", "Content-Type:application/json" ,"-d", json.dumps(_json_payload), conf.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) # TO-DO should be changed to mylog
|
||||
|
||||
# Log the stdout and stderr
|
||||
mylog('debug', [stdout, stderr]) # TO-DO should be changed to mylog
|
||||
except subprocess.CalledProcessError as e:
|
||||
# An error occurred, handle it
|
||||
mylog('none', [e.output])
|
||||
@@ -28,8 +28,6 @@ from publishers.email import (check_config as email_check_config,
|
||||
send as send_email )
|
||||
from publishers.ntfy import (check_config as ntfy_check_config,
|
||||
send as send_ntfy )
|
||||
from publishers.apprise import (check_config as apprise_check_config,
|
||||
send as send_apprise)
|
||||
from publishers.webhook import (check_config as webhook_check_config,
|
||||
send as send_webhook)
|
||||
from publishers.pushsafer import (check_config as pushsafer_check_config,
|
||||
@@ -263,9 +261,7 @@ def get_notifications (db):
|
||||
write_file (logPath + '/report_output.txt', final_text)
|
||||
write_file (logPath + '/report_output.html', final_html)
|
||||
|
||||
return noti_obj(final_json, final_text, final_html)
|
||||
|
||||
|
||||
return noti_obj(final_json, final_text, final_html)
|
||||
|
||||
# mylog('minimal', ['[Notification] Udating API files'])
|
||||
# send_api()
|
||||
@@ -307,28 +303,6 @@ def get_notifications (db):
|
||||
# mylog('verbose', ['[Notification] No changes to report'])
|
||||
|
||||
|
||||
|
||||
# #-------------------------------------------------------------------------------
|
||||
# def check_config(service):
|
||||
|
||||
# if service == 'email':
|
||||
# return email_check_config()
|
||||
|
||||
# if service == 'apprise':
|
||||
# return apprise_check_config()
|
||||
|
||||
# if service == 'webhook':
|
||||
# return webhook_check_config()
|
||||
|
||||
# if service == 'ntfy':
|
||||
# return ntfy_check_config ()
|
||||
|
||||
# if service == 'pushsafer':
|
||||
# return pushsafer_check_config()
|
||||
|
||||
# if service == 'mqtt':
|
||||
# return mqtt_check_config()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Replacing table headers
|
||||
def format_table (html, thValue, props, newThValue = ''):
|
||||
|
||||
Reference in New Issue
Block a user