Skip to content

Commit 40e2efd

Browse files
committed
[ntfy] Use file option to signal uploading a local file as attachment
1 parent 79ea76a commit 40e2efd

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ you an idea how to pass relevant information on the command line using JSON::
190190
mqttwarn --plugin=ntfy --options='{"addrs": {"url": "http://localhost:5555/testdrive"}, "title": "Example notification", "message": "Hello world"}' --data='{"attach": "https://unsplash.com/photos/spdQ1dVuIHw/download?w=320", "filename": "goat.jpg"}'
191191

192192
# Launch "ntfy" service plugin, and add attachment from local filesystem
193-
mqttwarn --plugin=ntfy --options='{"addrs": {"url": "http://localhost:5555/testdrive", "attachment": "goat.jpg"}, "title": "Example notification", "message": "Hello world"}'
193+
mqttwarn --plugin=ntfy --options='{"addrs": {"url": "http://localhost:5555/testdrive", "file": "goat.jpg"}, "title": "Example notification", "message": "Hello world"}'
194194

195195
# Launch "ssh" service plugin
196196
mqttwarn --plugin=ssh --config='{"host": "ssh.example.org", "port": 22, "user": "foo", "password": "bar"}' --options='{"addrs": ["command with substitution %s"], "payload": "{\"args\": \"192.168.0.1\"}"}'

docs/notifier-catalog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,7 @@ data will also get interpolated into.
18101810
targets = {
18111811
'test': {
18121812
'url': 'https://ntfy.sh/testdrive',
1813-
'attachment': '/tmp/ntfy-attachment-{slot}-{label}.png',
1813+
'file': '/tmp/ntfy-attachment-{slot}-{label}.png',
18141814
}
18151815
}
18161816
```

mqttwarn/services/ntfy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def decode_jobitem(item: ProcessorItem) -> NtfyRequest:
123123
raise TypeError(f"Unable to handle `targets` address descriptor data type `{type(item.addrs).__name__}`: {item.addrs}")
124124

125125
url = options["url"]
126-
attachment_path = options.get("attachment")
126+
attachment_path = options.get("file")
127127

128128
# Collect ntfy fields.
129129
fields: DataDict = OrderedDict()

tests/services/test_ntfy.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ def test_ntfy_decode_jobitem_attachment_success(attachment_dummy):
6363
"""
6464

6565
item = Item(
66-
addrs={"url": "http://localhost:9999/testdrive", "attachment": attachment_dummy.name},
66+
addrs={"url": "http://localhost:9999/testdrive", "file": attachment_dummy.name},
6767
)
6868

6969
ntfy_request = decode_jobitem(item)
7070

7171
assert ntfy_request.url == "http://localhost:9999/testdrive"
7272
assert ntfy_request.options["url"] == "http://localhost:9999/testdrive"
73-
assert ntfy_request.options["attachment"] == attachment_dummy.name
73+
assert ntfy_request.options["file"] == attachment_dummy.name
7474
assert ntfy_request.fields["filename"] == Path(attachment_dummy.name).name
7575
assert ntfy_request.attachment_data.read() == b"foo"
7676

@@ -81,14 +81,14 @@ def test_ntfy_decode_jobitem_attachment_failure(caplog):
8181
"""
8282

8383
item = Item(
84-
addrs={"url": "http://localhost:9999/testdrive", "attachment": "/tmp/mqttwarn-random-unknown"},
84+
addrs={"url": "http://localhost:9999/testdrive", "file": "/tmp/mqttwarn-random-unknown"},
8585
)
8686

8787
ntfy_request = decode_jobitem(item)
8888

8989
assert ntfy_request.url == "http://localhost:9999/testdrive"
9090
assert ntfy_request.options["url"] == "http://localhost:9999/testdrive"
91-
assert ntfy_request.options["attachment"] == "/tmp/mqttwarn-random-unknown"
91+
assert ntfy_request.options["file"] == "/tmp/mqttwarn-random-unknown"
9292
assert "filename" not in ntfy_request.fields
9393
assert ntfy_request.attachment_data is None
9494

@@ -101,15 +101,15 @@ def test_ntfy_decode_jobitem_attachment_with_filename_success(attachment_dummy):
101101
"""
102102

103103
item = Item(
104-
addrs={"url": "http://localhost:9999/testdrive", "attachment": attachment_dummy.name},
104+
addrs={"url": "http://localhost:9999/testdrive", "file": attachment_dummy.name},
105105
data={"filename": "testdrive.txt"},
106106
)
107107

108108
ntfy_request = decode_jobitem(item)
109109

110110
assert ntfy_request.url == "http://localhost:9999/testdrive"
111111
assert ntfy_request.options["url"] == "http://localhost:9999/testdrive"
112-
assert ntfy_request.options["attachment"] == attachment_dummy.name
112+
assert ntfy_request.options["file"] == attachment_dummy.name
113113
assert ntfy_request.fields["filename"] == "testdrive.txt"
114114
assert ntfy_request.attachment_data.read() == b"foo"
115115

@@ -275,7 +275,7 @@ def test_ntfy_plugin_success(srv, caplog, attachment_dummy):
275275
module = load_module_by_name("mqttwarn.services.ntfy")
276276

277277
item = Item(
278-
addrs={"url": "http://localhost:9999/testdrive", "attachment": attachment_dummy.name},
278+
addrs={"url": "http://localhost:9999/testdrive", "file": attachment_dummy.name},
279279
title="⚽ Message title ⚽",
280280
message="⚽ Notification message ⚽",
281281
data={"priority": "high", "tags": "foo,bar,äöü", "click": "https://example.org/testdrive"},

0 commit comments

Comments
 (0)