From 4fcfddbe0804431be8419d5c7db7635741665c3b Mon Sep 17 00:00:00 2001 From: Soumik Dutta Date: Mon, 6 Mar 2023 19:58:57 +0530 Subject: [PATCH] return early if unsupported state is passed Signed-off-by: Soumik Dutta --- borgmatic/hooks/cronhub.py | 8 ++++++++ borgmatic/hooks/cronitor.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/borgmatic/hooks/cronhub.py b/borgmatic/hooks/cronhub.py index b93788e..8ec5aac 100644 --- a/borgmatic/hooks/cronhub.py +++ b/borgmatic/hooks/cronhub.py @@ -27,6 +27,14 @@ def ping_monitor(hook_config, config_filename, state, monitoring_log_level, dry_ Ping the configured Cronhub URL, modified with the monitor.State. Use the given configuration filename in any log entries. If this is a dry run, then don't actually ping anything. ''' + if state not in MONITOR_STATE_TO_CRONHUB: + logger.debug( + '{}: Ignoring unsupported monitoring {} in Cronhub hook'.format( + config_filename, state.name.lower() + ) + ) + return + dry_run_label = ' (dry run; not actually pinging)' if dry_run else '' formatted_state = '/{}/'.format(MONITOR_STATE_TO_CRONHUB[state]) ping_url = ( diff --git a/borgmatic/hooks/cronitor.py b/borgmatic/hooks/cronitor.py index 8866a6a..f5164e4 100644 --- a/borgmatic/hooks/cronitor.py +++ b/borgmatic/hooks/cronitor.py @@ -27,6 +27,14 @@ def ping_monitor(hook_config, config_filename, state, monitoring_log_level, dry_ Ping the configured Cronitor URL, modified with the monitor.State. Use the given configuration filename in any log entries. If this is a dry run, then don't actually ping anything. ''' + if state not in MONITOR_STATE_TO_CRONITOR: + logger.debug( + '{}: Ignoring unsupported monitoring {} in Cronitor hook'.format( + config_filename, state.name.lower() + ) + ) + return + dry_run_label = ' (dry run; not actually pinging)' if dry_run else '' ping_url = '{}/{}'.format(hook_config['ping_url'], MONITOR_STATE_TO_CRONITOR[state])