From 25ea5af2dba7973e70265b27aaf774030a29d7f8 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sun, 15 Aug 2021 16:22:34 +0200 Subject: [PATCH] bundles/smartd: add cronjob to schedule a monthly long test --- bundles/smartd/metadata.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/bundles/smartd/metadata.py b/bundles/smartd/metadata.py index f1e91e7..d44a5fc 100644 --- a/bundles/smartd/metadata.py +++ b/bundles/smartd/metadata.py @@ -66,7 +66,7 @@ def telegraf(metadata): if not node.has_bundle('telegraf'): raise DoNotRunAgain - if metadata.get('smartd/disks', {}): + if metadata.get('smartd/disks', set()): return { 'telegraf': { 'input_plugins': { @@ -80,3 +80,22 @@ def telegraf(metadata): } return {} + + +@metadata_reactor.provides( + 'cron/smartd', +) +def monthly_long_test(metadata): + lines = set() + + for number, disk in enumerate(sorted(metadata.get('smartd/disks', set()))): + lines.add('0 3 {} * * root /usr/sbin/smartctl --test=long {} >/dev/null'.format( + number+1, # enumerate() starts at 0 + disk, + )) + + return { + 'cron': { + 'smartd': '\n'.join(sorted(lines)), + }, + }