diff --git a/bundles/systemd-timers/files/check_systemd_timer b/bundles/systemd-timers/files/check_systemd_timer new file mode 100644 index 0000000..6cee33e --- /dev/null +++ b/bundles/systemd-timers/files/check_systemd_timer @@ -0,0 +1,12 @@ +Timer=$1 + +Triggers=$(systemctl show ${Timer}.timer --property=Triggers --value) +if systemctl is-failed "$Triggers" +then + InvocationID=$(systemctl show "$Triggers" --property=InvocationID --value) + ExitCode=$(systemctl show "$Triggers" -p ExecStartEx --value | sed 's/^{//' | sed 's/}$//' | tr ';' '\n' | xargs -n 1 | grep '^status=' | cut -d '=' -f 2) + journalctl INVOCATION_ID="$InvocationID" --output cat + exit 1 +else + exit 0 +fi diff --git a/bundles/systemd-timers/items.py b/bundles/systemd-timers/items.py index 697c1fa..f53c496 100644 --- a/bundles/systemd-timers/items.py +++ b/bundles/systemd-timers/items.py @@ -2,3 +2,7 @@ svc_systemd['cron'] = { 'enabled': False, 'running': False, } + +files['/usr/lib/nagios/plugins/check_systemd_timer'] = { + 'mode': '0755', +} diff --git a/bundles/systemd-timers/metadata.py b/bundles/systemd-timers/metadata.py index 230c950..50d298c 100644 --- a/bundles/systemd-timers/metadata.py +++ b/bundles/systemd-timers/metadata.py @@ -48,3 +48,19 @@ def systemd(metadata): 'services': services, }, } + + +@metadata_reactor.provides( + 'monitoring/services', +) +def monitoring(metadata): + return { + 'monitoring': { + 'services': { + f'{name}.timer': { + 'vars.command': f'/usr/lib/nagios/plugins/check_systemd_timer {name}' + } + for name in metadata.get('systemd-timers') + }, + }, + }