authentication NTFY

This commit is contained in:
Fabian Sasse
2022-11-15 11:31:53 +01:00
parent c43c4d9eb3
commit 879687e0af
2 changed files with 20 additions and 4 deletions

View File

@@ -29,6 +29,7 @@ import smtplib
import csv
import json
import requests
from base64 import b64encode
#===============================================================================
@@ -1488,14 +1489,26 @@ def email_reporting ():
closeDB()
#-------------------------------------------------------------------------------
def send_ntfy (_Text):
requests.post("{}/{}".format( NTFY_HOST,NTFY_TOPIC),
data=_Text,
headers={
headers = {
"Title": "Pi.Alert Notification",
"Actions": "view, Open Dashboard, "+ REPORT_DASHBOARD_URL,
"Priority": "urgent",
"Tags": "warning"
})
}
# if username and password are set generate hash and update header
if NTFY_USER and NTFY_PASSWORD:
# Generate hash for basic auth
usernamepassword = "{}:{}".format(NTFY_USER,NTFY_PASSWORD)
basichash = b64encode(bytes(NTFY_USER + ':' + NTFY_PASSWORD, "utf-8")).decode("ascii")
# add authorization header with hash
headers["Authorization"] = "Basic {}".format(basichash)
requests.post("{}/{}".format( NTFY_HOST,NTFY_TOPIC),
data=_Text,
headers=headers)
send_ntfy("selfhosted ntfy test")
def send_pushsafer (_Text):
url = 'https://www.pushsafer.com/api'

View File

@@ -56,6 +56,9 @@ APPRISE_URL = 'mailto://smtp-relay.sendinblue.com:587?from=user@gmai
REPORT_NTFY = False
NTFY_HOST = 'https://ntfy.sh'
NTFY_TOPIC = 'replace_my_secure_topicname_91h889f28'
# set username and password if authentication is used https://docs.ntfy.sh/config/#users-and-roles
NTFY_USER = ''
NTFY_PASSWORD = ''
# PUSHSAFER (https://www.pushsafer.com/) settings
# ----------------------