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 gotify reporter #823

Merged
merged 8 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
25 changes: 25 additions & 0 deletions docs/source/reporters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ At the moment, the following reporters are built-in:

- **discord**: Send a message to a Discord channel
- **email**: Send summary via e-mail / SMTP / sendmail
- **gotify**: Send a message to a gotify server
- **ifttt**: Send summary via IFTTT
- **mailgun**: Send e-mail via the Mailgun service
- **matrix**: Send a message to a room using the Matrix protocol
Expand Down Expand Up @@ -210,6 +211,30 @@ Embedded content might be easier to read and identify individual reports. Subjec

When `colored` is true reports will be embedded in code section (with diff syntax) to enable colors.

Gotify
------

franco-righetti marked this conversation as resolved.
Show resolved Hide resolved
To push notifications to a gotify server you need an application token.

You can create one for urlwatch like so:

1. Log into your gotify server's Web-UI.
2. Navigate to the “APPS” tab.
3. Click on the “CREATE APPLICATION” button.
4. Fill out the fields and press “CREATE”.
6. Click on the eye icon of the newly created entry and copy the token.

Here is a sample configuration:

.. code:: yaml

gotify:
enabled: true
priority: 4
server_url: "http://127.0.0.1:8090"
title: null
token: "Aa1yyikLFjEm35A"

IFTTT
-----

Expand Down
30 changes: 30 additions & 0 deletions lib/urlwatch/reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,3 +1134,33 @@ def submit(self):
exitcode = process.wait()
if exitcode != 0:
logger.error('Shell reporter {} exited with {}'.format(cmd, exitcode))


class GotifyReporter(MarkdownReporter):
"""Send a message to a gotify server"""
MAX_LENGTH = 16*1024

__kind__ = 'gotify'

def submit(self):
body_markdown = '\n'.join(super().submit(self.MAX_LENGTH))
if not body_markdown:
logger.debug('Not sending message to gotify server (no changes)')
return

server_url = self.config['server_url']
url = f'{server_url}/message'

token = self.config['token']
headers = {'Authorization': f'Bearer {token}'}

requests.post(url, headers=headers, json={
"extras": {
"client::display": {
"contentType": "text/markdown"
}
},
'message': body_markdown,
'priority': self.config['priority'],
'title': self.config['title']
})
7 changes: 7 additions & 0 deletions lib/urlwatch/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@
'webhook_url': '',
'max_message_length': 2000,
},
'gotify': {
'enabled': False,
'priority': 0,
'server_url': '',
'title': None,
'token': ''
},
'matrix': {
'enabled': False,
'homeserver': '',
Expand Down
Loading