#!/usr/bin/env python3 from subprocess import check_output WARN_AT=80 CRITICAL_AT=90 output = [] exitcode = 0 for line in check_output(['/usr/sbin/zpool', 'list', '-Hpo', 'name,size,alloc']).decode().splitlines(): pool, size, alloc = line.split('\t') used_percent = int(int(alloc)/int(size)*100) if used_percent > CRITICAL_AT: exitcode = max(exitcode, 2) elif used_percent > WARN_AT: exitcode = max(exitcode, 1) if used_percent > WARN_AT: output.append( f'{pool} is {used_percent}% full' ) print('\n'.join(output)) exit(exitcode)