Skip to content

Commit

Permalink
Add gotify reporter (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
franco-righetti authored Aug 13, 2024
1 parent 654ce44 commit b67aeab
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format mostly follows [Keep a Changelog](http://keepachangelog.com/en/1.0.0/
- Added tags to jobs and the ability to select them at the command line (#789 by jamstah)
- New filter `re.findall` (Requested in #804 by f0sh, contributed in #805 by jamstah)
- Added tags to jobs and the ability to select them at the command line (#789, #824 by jamstah)
- New reporter: `gotify` (#823 by franco-righetti)

### Changed

Expand Down
27 changes: 27 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,32 @@ 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
------

[Gotify](https://gotify.net/) is a server for sending and receiving messages in real-time through WebSockets.

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

0 comments on commit b67aeab

Please sign in to comment.