Added Uptime Kuma hook

This commit is contained in:
Paul Wilde 2024-06-21 21:10:14 +01:00
parent 6eb76454bb
commit 27c90b7cf1
4 changed files with 20 additions and 12 deletions

View file

@ -1678,10 +1678,10 @@ properties:
documentation for details.
uptimekuma:
type: object
required: ['ping_url', 'push_code']
required: ['server', 'push_code']
additionalProperties: false
properties:
ping_url:
server:
type: string
description: |
Uptime Kuma base URL or UUID to notify when a backup
@ -1691,9 +1691,10 @@ properties:
type: string
description: |
Uptime Kuma "Push Code" from the push URL you have been given.
For example, the push code for:
'https://uptime.kuma/api/push/0evpM0MIdE?status=up&msg=OK&ping='
would be '0evpM0MIdE'
For example, the push code for
https://uptime.kuma/api/push/12345678?status=up&msg=OK&ping=
would be 12345678
example: 12345678
states:
type: array
items:
@ -1708,10 +1709,12 @@ properties:
"finish", and/or "fail". Defaults to pinging for all
states.
example:
- start, finish, fail
- start
- finish
- fail
description: |
Configuration for a monitoring integration with Uptime Kuma using
the 'Push' monitor type.
the Push monitor type.
See more information here: https://uptime.kuma.pet
cronitor:
type: object

View file

@ -13,6 +13,7 @@ from borgmatic.hooks import (
pagerduty,
postgresql,
sqlite,
uptimekuma
)
logger = logging.getLogger(__name__)
@ -30,6 +31,7 @@ HOOK_NAME_TO_MODULE = {
'postgresql_databases': postgresql,
'sqlite_databases': sqlite,
'loki': loki,
'uptimekuma': uptimekuma,
}

View file

@ -1,6 +1,6 @@
from enum import Enum
MONITOR_HOOK_NAMES = ('apprise', 'healthchecks', 'cronitor', 'cronhub', 'pagerduty', 'ntfy', 'loki')
MONITOR_HOOK_NAMES = ('apprise', 'healthchecks', 'cronitor', 'cronhub', 'pagerduty', 'ntfy', 'loki', 'uptimekuma')
class State(Enum):

View file

@ -26,19 +26,22 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
dry_run_label = ' (dry run; not actually pinging)' if dry_run else ''
status = state.name.lower() == "fail" ? "down" : "up"
status = "up"
if state.name.lower() == "fail":
status = "down"
base_url = hook_config.get('server', 'https://example.uptime.kuma') & "/api/push"
base_url = hook_config.get('server', 'https://example.uptime.kuma') + "/api/push"
push_code = hook_config.get('push_code')
logger.info(f'{config_filename}: Pinging Uptime Kuma push_code {push_code}{dry_run_label}')
logger.debug(f'{config_filename}: Using Uptime Kuma ping URL {base_url}/{push_code}')
logger.debug(f'{config_filename}: Full Uptime Kuma state URL {base_url}/{push_code}?status={status}&msg={state.name}&ping=')
logger.debug(f'{config_filename}: Full Uptime Kuma state URL {base_url}/{push_code}?status={status}&msg={state.name.lower()}&ping=')
if not dry_run:
logging.getLogger('urllib3').setLevel(logging.ERROR)
try:
response = requests.post(f'{base_url}/{push_code}?status={status}&msg={state.name}&ping=')
response = requests.get(f'{base_url}/{push_code}?status={status}&msg={state.name.lower()}&ping=')
if not response.ok:
response.raise_for_status()
except requests.exceptions.RequestException as error: