Skip to content

Commit 3d5db2e

Browse files
committed
Add documentation and test case about notifications via ntfy
https://ntfy.sh/
1 parent 4f582d4 commit 3d5db2e

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

CHANGES.rst

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ in progress
1111
level for filtered messages. Thanks, @jlrgraham.
1212
- CI and tests: Improvements and maintenance
1313
- Documentation: Improve section about Apprise
14+
- Documentation: Notifications to ntfy via Apprise. Thanks, @binwiederhier, @particledecay,
15+
and @caronc.
1416

1517
2022-10-05 0.30.0
1618
=================

HANDBOOK.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ _mqttwarn_ supports a number of services (listed alphabetically below):
378378
* [mythtv](#mythtv)
379379
* [nntp](#nntp)
380380
* [nsca](#nsca)
381+
* [ntfy](#ntfy)
381382
* [desktopnotify](#desktopnotify)
382383
* [osxsay](#osxsay)
383384
* [pastebinpub](#pastebinpub)
@@ -562,7 +563,7 @@ Apprise to E-Mail, an HTTP endpoint, and a Discord channel.
562563
563564
```ini
564565
[defaults]
565-
launch = apprise-mail, apprise-json, apprise-discord
566+
launch = apprise-mail, apprise-json, apprise-discord, apprise-ntfy
566567
567568
[config:apprise-mail]
568569
; Dispatch message as e-mail.
@@ -589,9 +590,16 @@ baseuri = 'json://localhost:1234/mqtthook'
589590
module = 'apprise'
590591
baseuri = 'discord://4174216298/JHMHI8qBe7bk2ZwO5U711o3dV_js'
591592
593+
[config:apprise-ntfy]
594+
; Dispatch message to ntfy.
595+
; https://github.com/caronc/apprise/wiki/URLBasics
596+
; https://github.com/caronc/apprise/wiki/Notify_ntfy
597+
module = 'apprise_single'
598+
baseuri = 'ntfy://user:password/ntfy.example.org/topic1/topic2'
599+
592600
[apprise-single-test]
593601
topic = apprise/single/#
594-
targets = apprise-mail:demo, apprise-json, apprise-discord
602+
targets = apprise-mail:demo, apprise-json, apprise-discord, apprise-ntfy
595603
format = Alarm from {device}: {payload}
596604
title = Alarm from {device}
597605
```
@@ -624,6 +632,7 @@ module = 'apprise_multi'
624632
targets = {
625633
'demo-http' : [ { 'baseuri': 'json://localhost:1234/mqtthook' }, { 'baseuri': 'json://daq.example.org:5555/foobar' } ],
626634
'demo-discord' : [ { 'baseuri': 'discord://4174216298/JHMHI8qBe7bk2ZwO5U711o3dV_js' } ],
635+
'demo-ntfy' : [ { 'baseuri': 'ntfy://user:password/ntfy.example.org/topic1/topic2' } ],
627636
'demo-mailto' : [ {
628637
'baseuri': 'mailtos://smtp_username:smtp_password@mail.example.org',
629638
'recipients': ['foo@example.org', 'bar@example.org'],
@@ -634,7 +643,7 @@ targets = {
634643
635644
[apprise-multi-test]
636645
topic = apprise/multi/#
637-
targets = apprise-multi:demo-http, apprise-multi:demo-discord, apprise-multi:demo-mailto
646+
targets = apprise-multi:demo-http, apprise-multi:demo-discord, apprise-multi:demo-mailto, apprise-multi:demo-ntfy
638647
format = Alarm from {device}: {payload}
639648
title = Alarm from {device}
640649
```
@@ -2026,6 +2035,15 @@ def check_temperature(data):
20262035
Requires:
20272036
* [pynsca](https://github.com/djmitche/pynsca).
20282037
2038+
2039+
### `ntfy`
2040+
2041+
Support for [ntfy] is provided through Apprise, see [apprise_single](#apprise_single)
2042+
and [apprise_multi](#apprise_multi).
2043+
2044+
[ntfy]: https://ntfy.sh/
2045+
2046+
20292047
### `desktopnotify`
20302048
20312049
It invokes desktop notifications, using the fine

README.rst

+5
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ you an idea how to pass relevant information on the command line using JSON::
189189
pip install mqttwarn-contrib
190190
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"}'
191191

192+
# Submit notification to "ntfy", using Apprise service plugin.
193+
mqttwarn --plugin=apprise \
194+
--config='{"baseuri": "ntfy://user:password@ntfy.example.org/topic1/topic2"}' \
195+
--options='{"addrs": [], "title": "Example notification", "message": "Hello world"}'
196+
192197

193198
Also, the ``--config-file`` parameter can be used to optionally specify the
194199
path to a configuration file.

tests/services/test_apprise_multi.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def test_apprise_multi_basic_success(apprise_asset, apprise_mock, srv, caplog):
1717
addrs=[
1818
{"baseuri": "json://localhost:1234/mqtthook"},
1919
{"baseuri": "json://daq.example.org:5555/foobar"},
20+
{"baseuri": "ntfy://user:password@ntfy.example.org/topic1/topic2"},
2021
],
2122
title="⚽ Message title ⚽",
2223
message="⚽ Notification message ⚽",
@@ -28,15 +29,18 @@ def test_apprise_multi_basic_success(apprise_asset, apprise_mock, srv, caplog):
2829
call(asset=mock.ANY),
2930
call().add("json://localhost:1234/mqtthook"),
3031
call().add("json://daq.example.org:5555/foobar"),
32+
call().add("ntfy://user:password@ntfy.example.org/topic1/topic2"),
3133
call().notify(body="⚽ Notification message ⚽", title="⚽ Message title ⚽"),
3234
call().notify().__bool__(),
3335
]
3436

3537
assert outcome is True
3638
assert (
3739
"Sending notification to Apprise. target=None, addresses=["
38-
"{'baseuri': 'json://localhost:1234/mqtthook'}, {'baseuri': 'json://daq.example.org:5555/foobar'}]"
39-
in caplog.messages
40+
"{'baseuri': 'json://localhost:1234/mqtthook'}, "
41+
"{'baseuri': 'json://daq.example.org:5555/foobar'}, "
42+
"{'baseuri': 'ntfy://user:password@ntfy.example.org/topic1/topic2'}"
43+
"]" in caplog.messages
4044
)
4145
assert "Successfully sent message using Apprise" in caplog.messages
4246

0 commit comments

Comments
 (0)