parent
56961ccca1
commit
459710d8e6
@ -0,0 +1,31 @@
|
||||
# Gotify Attributes
|
||||
|
||||
Configuring [Gotify](https://gotify.net/) is optional but can allow you to send the [webhooks](webhooks.md)
|
||||
straight to gotify..
|
||||
|
||||
A `gotify` mapping is in the root of the config file.
|
||||
|
||||
Below is a `gotify` mapping example and the full set of attributes:
|
||||
|
||||
```yaml
|
||||
gotify:
|
||||
url: ####################################
|
||||
apikey: ####################################
|
||||
```
|
||||
|
||||
| Attribute | Allowed Values | Required |
|
||||
|:----------|:-----------------------------------------|:------------------------------------------:|
|
||||
| `url` | Gotify Server Url | :fontawesome-solid-circle-check:{ .green } |
|
||||
| `apikey` | Gotify Application API Key | :fontawesome-solid-circle-check:{ .green } |
|
||||
|
||||
Once you have added the apikey your config.yml you have to add `gotify` to any [webhook](webhooks.md) to send that
|
||||
notification to Gotify.
|
||||
|
||||
```yaml
|
||||
webhooks:
|
||||
error: gotify
|
||||
version: gotify
|
||||
run_start: gotify
|
||||
run_end: gotify
|
||||
changes: gotify
|
||||
```
|
@ -0,0 +1,42 @@
|
||||
from json import JSONDecodeError
|
||||
from modules import util
|
||||
from modules.util import Failed
|
||||
from retrying import retry
|
||||
|
||||
logger = util.logger
|
||||
|
||||
class Gotify:
|
||||
def __init__(self, config, params):
|
||||
self.config = config
|
||||
self.apikey = params["apikey"]
|
||||
self.url = params["url"]
|
||||
logger.secret(self.apikey)
|
||||
try:
|
||||
self.request(path="message")
|
||||
except JSONDecodeError:
|
||||
raise Failed("Gotify Error: Invalid JSON response received")
|
||||
|
||||
def notification(self, json):
|
||||
return self.request(json=json)
|
||||
|
||||
@retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed)
|
||||
def request(self, json=None, path="message"):
|
||||
if not json:
|
||||
json = {
|
||||
"message": "Well hello there.",
|
||||
"priority": 1,
|
||||
"title": "This is first contact"
|
||||
}
|
||||
response = self.config.post(f"{self.url}{path}?token={self.apikey}", json=json)
|
||||
try:
|
||||
response_json = response.json()
|
||||
except JSONDecodeError as e:
|
||||
logger.error(response.content)
|
||||
logger.debug(e)
|
||||
raise e
|
||||
if response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error"):
|
||||
logger.debug(f"Response: {response_json}")
|
||||
raise Failed(f"({response.status_code} [{response.reason}]) {response_json}")
|
||||
if not response_json["id"]:
|
||||
raise Failed("Gotify Error: Invalid apikey")
|
||||
return response
|
Loading…
Reference in new issue