Notifications: Added Apprise support.

pull/87/head
desimaniac 6 years ago
parent 66a7120520
commit e0438c8a38

@ -31,6 +31,7 @@
- [Movies](#movies) - [Movies](#movies)
- [Shows](#shows) - [Shows](#shows)
- [Notifications](#notifications) - [Notifications](#notifications)
- [Apprise](#apprise)
- [Pushover](#pushover) - [Pushover](#pushover)
- [Slack](#slack) - [Slack](#slack)
- [Radarr](#radarr) - [Radarr](#radarr)
@ -664,15 +665,79 @@ Use filters to specify the movie/shows's country of origin or blacklist (i.e. fi
## Notifications ## Notifications
```json
"notifications": {
"apprise": {
"service": "apprise",
"url": "",
"title": ""
},
"verbose": false
},
```
Notification alerts for Traktarr tasks. Notification alerts for Traktarr tasks.
_Note: Manual commands need the `--notifications` flag._ For auto (i.e. scheduled) runs, notifications are enabled automatically when notification services are listed in this section.
For manual (i.e. CLI) commands, you need to add the `--notifications` flag.
Supported `services`:
- `apprise`
- `pushover`
- `slack`
_Note: The key name can be anything, but the `service` key must be must be the exact service name (e.g. `pushover`). See below for example._
```json
"notifications": {
"anyname": {
"service": "pushover",
}
},
```
### General
`verbose` - Toggle detailed notifications.
Currently, only Pushover and Slack are supported; others can be added in the future. - Default is `true`.
_Note: The key name (i.e the name right under notifications) can be anything, but the `"service":` must be the exact service name (e.g. `"pushover"`)._ - Set to `false` if you want to reduce the amount of detailed notifications (e.g. just the total vs the names of the movies/shows added).
```json
"notifications": {
"verbose": true
},
```
### Apprise
```json
"notifications": {
"apprise": {
"service": "apprise",
"url": "",
"title": ""
},
"verbose": false
},
```
`url` - Apprise service URL (see [here](https://github.com/caronc/apprise)).
- Required.
`title` - Notification Title.
- Optional.
- Default is `Traktarr`.
### Pushover
```json ```json
"notifications": { "notifications": {
@ -682,26 +747,21 @@ _Note: The key name (i.e the name right under notifications) can be anything, bu
"user_token": "", "user_token": "",
"priority": 0 "priority": 0
}, },
"slack": { "verbose": false
"service": "slack",
"webhook_url": ""
},
"verbose": true
}, },
``` ```
`verbose` - Toggle detailed notifications. Default is `true`. `app_token` - App Token from [Pushover.net](https://pushover.net).
- Set to `false`, if you want to reduce the amount of detailed notifications (e.g. the names of the movies/shows added vs just the total). - Required.
`user_token` - User Token from [Pushover.net](https://pushover.net).
### Pushover - Required.
`app_token` - Retrieve from Pushover.net. Required.
`user_token` - Retrieve from Pushover.net. Required. `priority` - [Priority](https://pushover.net/api#priority) of the notifications.
`priority` - Priority for the messages (see https://pushover.net/api#priority). Optional. - Optional.
- Choices are: `-2`, `-1`, `0`, `1`, `2`. - Choices are: `-2`, `-1`, `0`, `1`, `2`.
@ -713,6 +773,7 @@ _Note: The key name (i.e the name right under notifications) can be anything, bu
### Slack ### Slack
```json ```json
"notifications": {
"slack": { "slack": {
"service": "slack", "service": "slack",
"webhook_url": "", "webhook_url": "",
@ -720,17 +781,31 @@ _Note: The key name (i.e the name right under notifications) can be anything, bu
"sender_name": "Traktarr", "sender_name": "Traktarr",
"sender_icon": ":movie_camera:" "sender_icon": ":movie_camera:"
}, },
"verbose": true "verbose": false
}, },
``` ```
`webhook_url` - Webhook URL you get after creating an "Incoming Webhook" under "Custom Integrations" on Slack's Website. Required. `webhook_url` - [Webhook URL](https://my.slack.com/services/new/incoming-webhook/).
`channel` - Slack channel. Optional. Default is none. - Required.
`channel` - Slack channel to send the notifications to.
`sender_name` - Name the sender of the message. Optional. Default is `Traktarr`. - Optional.
- Default is blank.
`sender_name` - Sender's name for the notifications.
- Optional.
- Default is `Traktarr`.
`sender_icon` - Icon to use for the notifications.
`sender_icon` - Icon to use for the message. Optional. Default is `:movie_camera:` - Optional.
- Default is `:movie_camera:`

@ -1,11 +1,13 @@
from misc.log import logger from misc.log import logger
from .apprise import Apprise
from .pushover import Pushover from .pushover import Pushover
from .slack import Slack from .slack import Slack
log = logger.get_logger(__name__) log = logger.get_logger(__name__)
SERVICES = { SERVICES = {
'apprise': Apprise,
'pushover': Pushover, 'pushover': Pushover,
'slack': Slack 'slack': Slack
} }

@ -0,0 +1,32 @@
import apprise
from misc.log import logger
log = logger.get_logger(__name__)
class Apprise:
NAME = "Apprise"
def __init__(self, url, title='Traktarr'):
self.url = url
self.title = title
log.debug("Initialized Apprise notification agent")
def send(self, **kwargs):
if not self.url:
log.error("You must specify a URL when initializing this class")
return False
# send notification
try:
apobj = apprise.Apprise()
apobj.add(self.url)
apobj.notify(
title=self.title,
body=kwargs['message'],
)
except Exception:
log.exception("Error sending notification to %r", self.url)
return False

@ -4,4 +4,5 @@ attrdict==2.0.0
click==6.7 click==6.7
requests~=2.20.0 requests~=2.20.0
pyfiglet pyfiglet
cashier~=1.3 cashier~=1.3
apprise==0.7.7
Loading…
Cancel
Save