Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation and test case about notifications via ntfy #610

Merged
merged 1 commit into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ in progress
level for filtered messages. Thanks, @jlrgraham.
- CI and tests: Improvements and maintenance
- Documentation: Improve section about Apprise
- Documentation: Notifications to ntfy via Apprise. Thanks, @binwiederhier, @particledecay,
and @caronc.

2022-10-05 0.30.0
=================
Expand Down
24 changes: 21 additions & 3 deletions HANDBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ _mqttwarn_ supports a number of services (listed alphabetically below):
* [mythtv](#mythtv)
* [nntp](#nntp)
* [nsca](#nsca)
* [ntfy](#ntfy)
* [desktopnotify](#desktopnotify)
* [osxsay](#osxsay)
* [pastebinpub](#pastebinpub)
Expand Down Expand Up @@ -562,7 +563,7 @@ Apprise to E-Mail, an HTTP endpoint, and a Discord channel.

```ini
[defaults]
launch = apprise-mail, apprise-json, apprise-discord
launch = apprise-mail, apprise-json, apprise-discord, apprise-ntfy

[config:apprise-mail]
; Dispatch message as e-mail.
Expand All @@ -589,9 +590,16 @@ baseuri = 'json://localhost:1234/mqtthook'
module = 'apprise'
baseuri = 'discord://4174216298/JHMHI8qBe7bk2ZwO5U711o3dV_js'

[config:apprise-ntfy]
; Dispatch message to ntfy.
; https://github.com/caronc/apprise/wiki/URLBasics
; https://github.com/caronc/apprise/wiki/Notify_ntfy
module = 'apprise_single'
baseuri = 'ntfy://user:password/ntfy.example.org/topic1/topic2'

[apprise-single-test]
topic = apprise/single/#
targets = apprise-mail:demo, apprise-json, apprise-discord
targets = apprise-mail:demo, apprise-json, apprise-discord, apprise-ntfy
format = Alarm from {device}: {payload}
title = Alarm from {device}
```
Expand Down Expand Up @@ -624,6 +632,7 @@ module = 'apprise_multi'
targets = {
'demo-http' : [ { 'baseuri': 'json://localhost:1234/mqtthook' }, { 'baseuri': 'json://daq.example.org:5555/foobar' } ],
'demo-discord' : [ { 'baseuri': 'discord://4174216298/JHMHI8qBe7bk2ZwO5U711o3dV_js' } ],
'demo-ntfy' : [ { 'baseuri': 'ntfy://user:password/ntfy.example.org/topic1/topic2' } ],
'demo-mailto' : [ {
'baseuri': 'mailtos://smtp_username:[email protected]',
'recipients': ['[email protected]', '[email protected]'],
Expand All @@ -634,7 +643,7 @@ targets = {

[apprise-multi-test]
topic = apprise/multi/#
targets = apprise-multi:demo-http, apprise-multi:demo-discord, apprise-multi:demo-mailto
targets = apprise-multi:demo-http, apprise-multi:demo-discord, apprise-multi:demo-mailto, apprise-multi:demo-ntfy
format = Alarm from {device}: {payload}
title = Alarm from {device}
```
Expand Down Expand Up @@ -2026,6 +2035,15 @@ def check_temperature(data):
Requires:
* [pynsca](https://github.com/djmitche/pynsca).


### `ntfy`

Support for [ntfy] is provided through Apprise, see [apprise_single](#apprise_single)
and [apprise_multi](#apprise_multi).

[ntfy]: https://ntfy.sh/


### `desktopnotify`

It invokes desktop notifications, using the fine
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ you an idea how to pass relevant information on the command line using JSON::
pip install mqttwarn-contrib
mqttwarn --plugin=mqttwarn_contrib.services.cloudflare_zone --config='{"auth-email": "foo", "auth-key": "bar"}' --options='{"addrs": ["0815", "www.example.org", ""], "message": "192.168.0.1"}'

# Submit notification to "ntfy", using Apprise service plugin.
mqttwarn --plugin=apprise \
--config='{"baseuri": "ntfy://user:[email protected]/topic1/topic2"}' \
--options='{"addrs": [], "title": "Example notification", "message": "Hello world"}'
Comment on lines +192 to +195
Copy link
Member Author

@amotl amotl Nov 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitting a notification message to ntfy should work like this from the command line. Can someone who is following here, verify this command, and report back afterwards?



Also, the ``--config-file`` parameter can be used to optionally specify the
path to a configuration file.
Expand Down
8 changes: 6 additions & 2 deletions tests/services/test_apprise_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_apprise_multi_basic_success(apprise_asset, apprise_mock, srv, caplog):
addrs=[
{"baseuri": "json://localhost:1234/mqtthook"},
{"baseuri": "json://daq.example.org:5555/foobar"},
{"baseuri": "ntfy://user:[email protected]/topic1/topic2"},
],
title="⚽ Message title ⚽",
message="⚽ Notification message ⚽",
Expand All @@ -31,15 +32,18 @@ def test_apprise_multi_basic_success(apprise_asset, apprise_mock, srv, caplog):
call(asset=mock.ANY),
call().add("json://localhost:1234/mqtthook"),
call().add("json://daq.example.org:5555/foobar"),
call().add("ntfy://user:[email protected]/topic1/topic2"),
call().notify(body="⚽ Notification message ⚽", title="⚽ Message title ⚽"),
call().notify().__bool__(),
]

assert outcome is True
assert (
"Sending notification to Apprise. target=None, addresses=["
"{'baseuri': 'json://localhost:1234/mqtthook'}, {'baseuri': 'json://daq.example.org:5555/foobar'}]"
in caplog.messages
"{'baseuri': 'json://localhost:1234/mqtthook'}, "
"{'baseuri': 'json://daq.example.org:5555/foobar'}, "
"{'baseuri': 'ntfy://user:[email protected]/topic1/topic2'}"
"]" in caplog.messages
)
assert "Successfully sent message using Apprise" in caplog.messages

Expand Down