Command output is inconsistent when thresholds are given and using different arguments
for pools, for example:
crash@tesla:~/work/check_zpools$ sudo zpool status
pool: mail
state: DEGRADED
status: One or more devices could not be used because the label is missing or
invalid. Sufficient replicas exist for the pool to continue
functioning in a degraded state.
action: Replace the device using 'zpool replace'.
see: https://openzfs.github.io/openzfs-docs/msg/ZFS-8000-4J
scan: scrub repaired 0B in 00:00:00 with 0 errors on Wed Feb 22 14:24:16 2023
config:
NAME STATE READ WRITE CKSUM
mail DEGRADED 0 0 0
mirror-0 DEGRADED 0 0 0
nbd0 UNAVAIL 0 0 40 corrupted data
nbd1 ONLINE 0 0 0
errors: No known data errors
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p mail -c 45 -w 40 || echo $?
ZFS POOL mail health is DEGRADED|mail=50%
2
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p ALL -c 45 -w 40 || echo $?
ZFS POOL ALARM: POOL mail usage is CRITICAL (50%)|mail=50%
2
Also the output only considers the first error and reports only that. Here we have two
possible issues, one is that the pool is DEGRADED, the other is that the usage is too high.
After my changes the output is more consistent and hopefully contains all issues:
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p mail -c 45 -w 40 || echo $?
ZFS POOL ALARM: mail health is DEGRADED mail usage is CRITICAL (50%) |mail=50%
2
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p mail -c 65 -w 60 || echo $?
ZFS POOL ALARM: mail health is DEGRADED |mail=50%
2
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p ALL -c 45 -w 40 || echo $?
ZFS POOL ALARM: mail health is DEGRADED POOL mail usage is CRITICAL (50%) |mail=50%
2
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p ALL -c 65 -w 60 || echo $?
ZFS POOL ALARM: mail health is DEGRADED |mail=50%
2
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p ALL || echo $?
ZFS POOL ALARM: mail health is DEGRADED|mail=50%
2
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p mail || echo $?
ZFS POOL ALARM: mail health is DEGRADED|mail=50%
2
crash@tesla:~/work/check_zpools$ sudo zpool status
pool: mail
state: ONLINE
scan: resilvered 244M in 00:00:07 with 0 errors on Wed Feb 22 15:28:24 2023
config:
NAME STATE READ WRITE CKSUM
mail ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
nbd0 ONLINE 0 0 0
nbd1 ONLINE 0 0 0
errors: No known data errors
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p mail && echo $?
ALL ZFS POOLS OK (mail)|mail=50%
0
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p ALL && echo $?
ALL ZFS POOLS OK (mail)|mail=50%
0
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p mail -w 40 -c 45 || echo $?
ZFS POOL ALARM: mail usage is CRITICAL (50%) |mail=50%
2
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p ALL -w 40 -c 45 || echo $?
ZFS POOL ALARM: POOL mail usage is CRITICAL (50%) |mail=50%
2
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p ALL -w 60 -c 65 && echo $?
ALL ZFS POOLS OK (mail)|mail=50%
0
crash@tesla:~/work/check_zpools$ ./check_zpools.sh -p mail -w 60 -c 65 && echo $?
ALL ZFS POOLS OK (mail)|mail=50%
0
I will add a pr shortly.