Add Healthchecks monitoring hook "send_logs" option to enable/disable sending borgmatic logs to the Healthchecks server (#460).

This commit is contained in:
Dan Helfman 2022-05-24 14:44:33 -07:00
parent 666f0dd751
commit 157e59ac88
4 changed files with 30 additions and 2 deletions

2
NEWS
View File

@ -3,6 +3,8 @@
logs to send to the Healthchecks server.
* #402: Remove the error when "archive_name_format" is specified but a retention prefix isn't.
* #420: Warn when an unsupported variable is used in a hook command.
* #460: Add Healthchecks monitoring hook "send_logs" option to enable/disable sending borgmatic
logs to the Healthchecks server.
* #525: Add Healthchecks monitoring hook "states" option to only enable pinging for particular
monitoring states (start, finish, fail).
* #528: Improve the error message when a configuration override contains an invalid value.

View File

@ -892,6 +892,12 @@ properties:
Healthchecks ping URL or UUID to notify when a
backup begins, ends, or errors.
example: https://hc-ping.com/your-uuid-here
send_logs:
type: boolean
description: |
Send borgmatic logs to Healthchecks as part the
"finish" state. Defaults to true.
example: false
ping_body_limit:
type: integer
description: |

View File

@ -71,9 +71,13 @@ def format_buffered_logs_for_payload():
def initialize_monitor(hook_config, config_filename, monitoring_log_level, dry_run):
'''
Add a handler to the root logger that stores in memory the most recent logs emitted. That
way, we can send them all to Healthchecks upon a finish or failure state.
Add a handler to the root logger that stores in memory the most recent logs emitted. That way,
we can send them all to Healthchecks upon a finish or failure state. But skip this if the
"send_logs" option is false.
'''
if hook_config.get('send_logs') is False:
return
ping_body_limit = max(
hook_config.get('ping_body_limit', DEFAULT_PING_BODY_LIMIT_BYTES)
- len(PAYLOAD_TRUNCATION_INDICATOR),

View File

@ -106,6 +106,22 @@ def test_initialize_monitor_creates_log_handler_with_zero_ping_body_limit():
)
def test_initialize_monitor_creates_log_handler_when_send_logs_true():
flexmock(module).should_receive('Forgetful_buffering_handler').once()
module.initialize_monitor(
{'send_logs': True}, 'test.yaml', monitoring_log_level=1, dry_run=False
)
def test_initialize_monitor_bails_when_send_logs_false():
flexmock(module).should_receive('Forgetful_buffering_handler').never()
module.initialize_monitor(
{'send_logs': False}, 'test.yaml', monitoring_log_level=1, dry_run=False
)
def test_ping_monitor_hits_ping_url_for_start_state():
flexmock(module).should_receive('Forgetful_buffering_handler')
hook_config = {'ping_url': 'https://example.com'}