From 958f5893e6f46a4c639f259584ee76ddcb27476c Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Fri, 18 Dec 2020 08:23:42 +0100 Subject: [PATCH] bundles/zfs: adjust warning period for check_zfs_old_snapshots --- bundles/zfs/files/check_zfs_old_snapshots | 25 +++++++++-------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/bundles/zfs/files/check_zfs_old_snapshots b/bundles/zfs/files/check_zfs_old_snapshots index e07302b..53ac59f 100644 --- a/bundles/zfs/files/check_zfs_old_snapshots +++ b/bundles/zfs/files/check_zfs_old_snapshots @@ -8,11 +8,9 @@ from sys import exit output = check_output(['zfs', 'get', 'creation', '-Hpr', '-t', 'snapshot']) now = int(datetime.now().timestamp()) -warn_age = now - (60 * 60 * 24 * 60) -crit_age = now - (60 * 60 * 24 * 90) +warn_age = now - (60 * 60 * 24 * 90) warn_snapshots = set() -crit_snapshots = set() return_code = 0 @@ -28,6 +26,11 @@ for line in output.decode('utf-8').split("\n"): if 'zfs-auto-snap' in items[0]: continue + # SNAPSHOT_FOR_RESET is used by bundle automatic-reset-of-zfs-dataset + # to reset datasets to a known good state (used for test systems). + if 'SNAPSHOT_FOR_RESET' in items[0]: + continue + # These are docker-internal snapshots and should not be touched by # us. if match(r'^tank/docker/[a-z0-9]+(-init)?@[0-9]+', items[0]): @@ -41,23 +44,15 @@ for line in output.decode('utf-8').split("\n"): creation_date = int(items[2]) - if creation_date < crit_age: - crit_snapshots.add(items[0]) - elif creation_date < warn_age: + if creation_date < warn_age: warn_snapshots.add(items[0]) -# We have to do additional loops in here to have CRITICAL items on top. -for snap in sorted(crit_snapshots): - print('CRITICAL - {} is older than 90 days'.format(snap)) - for snap in sorted(warn_snapshots): - print('WARN - {} is older than 60 days'.format(snap)) + print('WARN - {} is older than 90 days'.format(snap)) -if len(crit_snapshots) > 0: - return_code = 2 -elif len(warn_snapshots) > 0: +if len(warn_snapshots) > 0: return_code = 1 else: - print('OK - no snapshots are older than 60 days') + print('OK - no snapshots are older than 90 days') exit(return_code)