change uptimekuma method names to 'push_*' instead of 'ping'
Some checks are pending
build / test (push) Waiting to run
build / docs (push) Blocked by required conditions

This commit is contained in:
Paul Wilde 2024-06-24 11:07:09 +01:00
parent 8f423c7293
commit b50996b864
3 changed files with 29 additions and 29 deletions

View file

@ -1745,8 +1745,8 @@ properties:
- fail - fail
uniqueItems: true uniqueItems: true
description: | description: |
List of one or more monitoring states to ping for: "start", List of one or more monitoring states to push for: "start",
"finish", and/or "fail". Defaults to pinging for all "finish", and/or "fail". Defaults to pushing for all
states. states.
example: example:
- start - start

View file

@ -6,7 +6,7 @@ logger = logging.getLogger(__name__)
def initialize_monitor( def initialize_monitor(
ping_url, config, config_filename, monitoring_log_level, dry_run push_url, config, config_filename, monitoring_log_level, dry_run
): # pragma: no cover ): # pragma: no cover
''' '''
No initialization is necessary for this monitor. No initialization is necessary for this monitor.
@ -14,21 +14,21 @@ def initialize_monitor(
pass pass
def ping_monitor(hook_config, config, config_filename, state, monitoring_log_level, dry_run): def push_monitor(hook_config, config, config_filename, state, monitoring_log_level, dry_run):
''' '''
Ping the configured Uptime Kuma push_url. Make a get request to the configured Uptime Kuma push_url.
Use the given configuration filename in any log entries. Use the given configuration filename in any log entries.
If this is a dry run, then don't actually ping anything. If this is a dry run, then don't actually push anything.
''' '''
run_states = hook_config.get('states', ['start', 'finish', 'fail']) run_states = hook_config.get('states', ['start', 'finish', 'fail'])
if state.name.lower() not in run_states: if state.name.lower() not in run_states:
return return
dry_run_label = ' (dry run; not actually pinging)' if dry_run else '' dry_run_label = ' (dry run; not actually pushing)' if dry_run else ''
status = 'down' if state.name.lower() == 'fail' else 'up' status = 'down' if state.name.lower() == 'fail' else 'up'
push_url = hook_config.get('push_url', 'https://example.uptime.kuma/api/push/abcd1234') push_url = hook_config.get('push_url', 'https://example.uptime.kuma/api/push/abcd1234')
query = f'status={status}&msg={state.name.lower()}' query = f'status={status}&msg={state.name.lower()}'
logger.info( logger.info(
f'{config_filename}: Pinging Uptime Kuma push_url {push_url}?{query} {dry_run_label}' f'{config_filename}: Pushing Uptime Kuma push_url {push_url}?{query} {dry_run_label}'
) )
logger.debug(f'{config_filename}: Full Uptime Kuma state URL {push_url}?{query}') logger.debug(f'{config_filename}: Full Uptime Kuma state URL {push_url}?{query}')
if dry_run: if dry_run:
@ -43,7 +43,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
def destroy_monitor( def destroy_monitor(
ping_url_or_uuid, config, config_filename, monitoring_log_level, dry_run push_url_or_uuid, config, config_filename, monitoring_log_level, dry_run
): # pragma: no cover ): # pragma: no cover
''' '''
No destruction is necessary for this monitor. No destruction is necessary for this monitor.

View file

@ -7,13 +7,13 @@ DEFAULT_PUSH_URL = 'https://example.uptime.kuma/api/push/abcd1234'
CUSTOM_PUSH_URL = 'https://uptime.example.com/api/push/efgh5678' CUSTOM_PUSH_URL = 'https://uptime.example.com/api/push/efgh5678'
def test_ping_monitor_hits_default_uptimekuma_on_fail(): def test_push_monitor_hits_default_uptimekuma_on_fail():
hook_config = {} hook_config = {}
flexmock(module.requests).should_receive('get').with_args( flexmock(module.requests).should_receive('get').with_args(
f'{DEFAULT_PUSH_URL}?status=down&msg=fail' f'{DEFAULT_PUSH_URL}?status=down&msg=fail'
).and_return(flexmock(ok=True)).once() ).and_return(flexmock(ok=True)).once()
module.ping_monitor( module.push_monitor(
hook_config, hook_config,
{}, {},
'config.yaml', 'config.yaml',
@ -23,13 +23,13 @@ def test_ping_monitor_hits_default_uptimekuma_on_fail():
) )
def test_ping_monitor_hits_custom_uptimekuma_on_fail(): def test_push_monitor_hits_custom_uptimekuma_on_fail():
hook_config = {'push_url': CUSTOM_PUSH_URL} hook_config = {'push_url': CUSTOM_PUSH_URL}
flexmock(module.requests).should_receive('get').with_args( flexmock(module.requests).should_receive('get').with_args(
f'{CUSTOM_PUSH_URL}?status=down&msg=fail' f'{CUSTOM_PUSH_URL}?status=down&msg=fail'
).and_return(flexmock(ok=True)).once() ).and_return(flexmock(ok=True)).once()
module.ping_monitor( module.push_monitor(
hook_config, hook_config,
{}, {},
'config.yaml', 'config.yaml',
@ -39,13 +39,13 @@ def test_ping_monitor_hits_custom_uptimekuma_on_fail():
) )
def test_ping_monitor_custom_uptimekuma_on_start(): def test_push_monitor_custom_uptimekuma_on_start():
hook_config = {'push_url': CUSTOM_PUSH_URL} hook_config = {'push_url': CUSTOM_PUSH_URL}
flexmock(module.requests).should_receive('get').with_args( flexmock(module.requests).should_receive('get').with_args(
f'{CUSTOM_PUSH_URL}?status=up&msg=start' f'{CUSTOM_PUSH_URL}?status=up&msg=start'
).and_return(flexmock(ok=True)).once() ).and_return(flexmock(ok=True)).once()
module.ping_monitor( module.push_monitor(
hook_config, hook_config,
{}, {},
'config.yaml', 'config.yaml',
@ -55,13 +55,13 @@ def test_ping_monitor_custom_uptimekuma_on_start():
) )
def test_ping_monitor_custom_uptimekuma_on_finish(): def test_push_monitor_custom_uptimekuma_on_finish():
hook_config = {'push_url': CUSTOM_PUSH_URL} hook_config = {'push_url': CUSTOM_PUSH_URL}
flexmock(module.requests).should_receive('get').with_args( flexmock(module.requests).should_receive('get').with_args(
f'{CUSTOM_PUSH_URL}?status=up&msg=finish' f'{CUSTOM_PUSH_URL}?status=up&msg=finish'
).and_return(flexmock(ok=True)).once() ).and_return(flexmock(ok=True)).once()
module.ping_monitor( module.push_monitor(
hook_config, hook_config,
{}, {},
'config.yaml', 'config.yaml',
@ -71,11 +71,11 @@ def test_ping_monitor_custom_uptimekuma_on_finish():
) )
def test_ping_monitor_does_not_hit_custom_uptimekuma_on_fail_dry_run(): def test_push_monitor_does_not_hit_custom_uptimekuma_on_fail_dry_run():
hook_config = {'push_url': CUSTOM_PUSH_URL} hook_config = {'push_url': CUSTOM_PUSH_URL}
flexmock(module.requests).should_receive('get').never() flexmock(module.requests).should_receive('get').never()
module.ping_monitor( module.push_monitor(
hook_config, hook_config,
{}, {},
'config.yaml', 'config.yaml',
@ -85,11 +85,11 @@ def test_ping_monitor_does_not_hit_custom_uptimekuma_on_fail_dry_run():
) )
def test_ping_monitor_does_not_hit_custom_uptimekuma_on_start_dry_run(): def test_push_monitor_does_not_hit_custom_uptimekuma_on_start_dry_run():
hook_config = {'push_url': CUSTOM_PUSH_URL} hook_config = {'push_url': CUSTOM_PUSH_URL}
flexmock(module.requests).should_receive('get').never() flexmock(module.requests).should_receive('get').never()
module.ping_monitor( module.push_monitor(
hook_config, hook_config,
{}, {},
'config.yaml', 'config.yaml',
@ -99,11 +99,11 @@ def test_ping_monitor_does_not_hit_custom_uptimekuma_on_start_dry_run():
) )
def test_ping_monitor_does_not_hit_custom_uptimekuma_on_finish_dry_run(): def test_push_monitor_does_not_hit_custom_uptimekuma_on_finish_dry_run():
hook_config = {'push_url': CUSTOM_PUSH_URL} hook_config = {'push_url': CUSTOM_PUSH_URL}
flexmock(module.requests).should_receive('get').never() flexmock(module.requests).should_receive('get').never()
module.ping_monitor( module.push_monitor(
hook_config, hook_config,
{}, {},
'config.yaml', 'config.yaml',
@ -113,14 +113,14 @@ def test_ping_monitor_does_not_hit_custom_uptimekuma_on_finish_dry_run():
) )
def test_ping_monitor_with_connection_error_logs_warning(): def test_push_monitor_with_connection_error_logs_warning():
hook_config = {'push_url': CUSTOM_PUSH_URL} hook_config = {'push_url': CUSTOM_PUSH_URL}
flexmock(module.requests).should_receive('get').with_args( flexmock(module.requests).should_receive('get').with_args(
f'{CUSTOM_PUSH_URL}?status=down&msg=fail' f'{CUSTOM_PUSH_URL}?status=down&msg=fail'
).and_raise(module.requests.exceptions.ConnectionError) ).and_raise(module.requests.exceptions.ConnectionError)
flexmock(module.logger).should_receive('warning').once() flexmock(module.logger).should_receive('warning').once()
module.ping_monitor( module.push_monitor(
hook_config, hook_config,
{}, {},
'config.yaml', 'config.yaml',
@ -130,7 +130,7 @@ def test_ping_monitor_with_connection_error_logs_warning():
) )
def test_ping_monitor_with_other_error_logs_warning(): def test_push_monitor_with_other_error_logs_warning():
hook_config = {'push_url': CUSTOM_PUSH_URL} hook_config = {'push_url': CUSTOM_PUSH_URL}
response = flexmock(ok=False) response = flexmock(ok=False)
response.should_receive('raise_for_status').and_raise( response.should_receive('raise_for_status').and_raise(
@ -141,7 +141,7 @@ def test_ping_monitor_with_other_error_logs_warning():
).and_return(response) ).and_return(response)
flexmock(module.logger).should_receive('warning').once() flexmock(module.logger).should_receive('warning').once()
module.ping_monitor( module.push_monitor(
hook_config, hook_config,
{}, {},
'config.yaml', 'config.yaml',
@ -151,11 +151,11 @@ def test_ping_monitor_with_other_error_logs_warning():
) )
def test_ping_monitor_with_invalid_run_state(): def test_push_monitor_with_invalid_run_state():
hook_config = {'push_url': CUSTOM_PUSH_URL} hook_config = {'push_url': CUSTOM_PUSH_URL}
flexmock(module.requests).should_receive('get').never() flexmock(module.requests).should_receive('get').never()
module.ping_monitor( module.push_monitor(
hook_config, hook_config,
{}, {},
'config.yaml', 'config.yaml',