From d618f707739394fd3fce49fe6b0e39b56c83b521 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Mon, 8 Apr 2024 18:20:44 +0200 Subject: [PATCH] bw/bundles/mqtt-monitoring: execute daily tasks independent of normal check_system tasks --- .../mqtt-monitoring/files/check_system_daily.sh | 11 +++++++++++ bundlewrap/bundles/mqtt-monitoring/items.py | 9 ++++----- bundlewrap/bundles/mqtt-monitoring/metadata.py | 11 +++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) create mode 100755 bundlewrap/bundles/mqtt-monitoring/files/check_system_daily.sh diff --git a/bundlewrap/bundles/mqtt-monitoring/files/check_system_daily.sh b/bundlewrap/bundles/mqtt-monitoring/files/check_system_daily.sh new file mode 100755 index 00000000..54cfbe1c --- /dev/null +++ b/bundlewrap/bundles/mqtt-monitoring/files/check_system_daily.sh @@ -0,0 +1,11 @@ +#!/bin/bash + + +[[ -n "$DEBUG" ]] && set -x + +for file in /usr/local/sbin/check_system_daily.d/*.sh +do + if [ -x "${file}" ]; then + . "${file}" + fi +done diff --git a/bundlewrap/bundles/mqtt-monitoring/items.py b/bundlewrap/bundles/mqtt-monitoring/items.py index 5ae6dd52..c2885adc 100644 --- a/bundlewrap/bundles/mqtt-monitoring/items.py +++ b/bundlewrap/bundles/mqtt-monitoring/items.py @@ -11,15 +11,14 @@ } files['/usr/local/sbin/alert_shutdown.sh'] = { - 'content_type': 'mako', 'mode': '0755', } files['/usr/local/sbin/check_system.sh'] = { - 'content_type': 'jinja2', - 'context': { - 'event': node.metadata.get('event'), - }, + 'mode': '0755', +} + +files['/usr/local/sbin/check_system_daily.sh'] = { 'mode': '0755', } diff --git a/bundlewrap/bundles/mqtt-monitoring/metadata.py b/bundlewrap/bundles/mqtt-monitoring/metadata.py index ee71fad6..9469bb93 100644 --- a/bundlewrap/bundles/mqtt-monitoring/metadata.py +++ b/bundlewrap/bundles/mqtt-monitoring/metadata.py @@ -23,9 +23,16 @@ 'check_system_and_send_mqtt_message': { 'command': '/usr/local/sbin/check_system.sh', 'when': 'minutely', - 'environment': { - 'DAILY_TASK_TIME': str(6+(node.magic_number%3)).rjust(2, '0') + str(node.magic_number%60).rjust(2, '0'), + 'requires': { + 'network.target', }, + }, + 'check_system_daily_tasks': { + 'command': '/usr/local/sbin/check_system_daily.sh', + 'when': '{}:{}:00'.format( + str(6+(node.magic_number%3)).rjust(2, '0'), + str(node.magic_number%60).rjust(2, '0'), + ), 'requires': { 'network.target', },