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

View file

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

View file

@ -1,6 +1,6 @@
from enum import Enum 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): 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 '' 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') push_code = hook_config.get('push_code')
logger.info(f'{config_filename}: Pinging Uptime Kuma push_code {push_code}{dry_run_label}') 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}: 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: if not dry_run:
logging.getLogger('urllib3').setLevel(logging.ERROR) logging.getLogger('urllib3').setLevel(logging.ERROR)
try: 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: if not response.ok:
response.raise_for_status() response.raise_for_status()
except requests.exceptions.RequestException as error: except requests.exceptions.RequestException as error: