leiweibau / Pi.Alert

Scan the devices connected to your WIFI / LAN and alert you the connection of unknown devices. It also warns if a "always connected" device disconnects. In addition, it is possible to check web services for availability. For this purpose HTTP status codes and the response time of the service are evaluated.
https://leiweibau.net
GNU General Public License v3.0
434 stars 31 forks source link

NTFY not sending alerts #186

Closed modem7 closed 1 year ago

modem7 commented 1 year ago

Heya,

This may be an ID10T issue, but I can't seem to get NTFY to work.

I've set the following:

# NTFY
#---------------------------
REPORT_NTFY         = True
REPORT_NTFY_WEBMON  = True
NTFY_HOST           = 'https://ntfy.myserver.com'
NTFY_TOPIC          = 'topicname'
NTFY_USER           = 'username'
NTFY_PASSWORD       = 'userpassword'
NTFY_PRIORITY       = 'default'

I've tried the following and this works:

curl -u username:password -d "Look ma, with auth" https://ntfy.myserver.com/topicname

image

Note, I haven't installed NTFY-cli on the server. I have checked requests is installed:

# pip show requests
Name: requests
Version: 2.31.0
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: Apache 2.0
Location: /usr/local/lib/python3.11/dist-packages
Requires: certifi, charset-normalizer, idna, urllib3
Required-by: fritzconnection, pyunifi

Unsure where I may be going wrong.

On another note, would it also be possible to allow for bearer tokens as well as username + password?

leiweibau commented 1 year ago

Since I have never used "ntfy" myself, I just created an account at Ntfy.sh and entered the data accordingly into the Pi.Alert configuration. Here the event notification and also the test notification works completely without problems.

Have you tried to send a test notification via "pialert-cli"? Errors may be displayed here, which can be used to further isolate the problem.

modem7 commented 1 year ago

Apologies - this was my own fault. Seems that my Cloudflare bot rules were a bit too tight.

This is the script that finally helped me figure it out (it's crude, but my Python knowledge is next to zero, no doubt it could be improved):

#!/usr/bin/env python3

import requests
from requests_toolbelt.utils import dump

# To generate the auth token, use echo "Basic $(echo -n 'testuser:fakepassword' | base64)"
# As per https://docs.ntfy.sh/publish/#authentication

response = requests.post("https://ntfy.example.com/topicname",
data="Look ma, with auth",
headers={
    "Authorization": "Basic authtoken"
})
print(dump.dump_all(response).decode("utf-8"))
leiweibau commented 1 year ago

No problem