bundles/zfs: adjust warning period for check_zfs_old_snapshots
This commit is contained in:
parent
487e4d0df6
commit
958f5893e6
1 changed files with 10 additions and 15 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue