bundles/zfs: import bundle from work repository
This commit is contained in:
parent
b690ae25b0
commit
4934eb46fb
11 changed files with 841 additions and 0 deletions
40
bundles/zfs/files/check_zpool_space
Normal file
40
bundles/zfs/files/check_zpool_space
Normal file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
from subprocess import check_output
|
||||
from sys import argv, exit
|
||||
import re
|
||||
|
||||
|
||||
def to_bytes(size):
|
||||
suffixes = ['', 'K', 'M', 'G', 'T', 'P']
|
||||
number, suffix = re.match(r'([0-9\.]+)([A-Z]?)', size).groups()
|
||||
assert suffix in suffixes, 'Unexpected suffix "{}" in size "{}"'.format(suffix, size)
|
||||
return float(number) * 1024**suffixes.index(suffix)
|
||||
|
||||
|
||||
pool = argv[1]
|
||||
critical_perc = float(argv[2])
|
||||
|
||||
try:
|
||||
output = check_output(['zpool', 'list', '-Ho', 'size,alloc', pool])
|
||||
except:
|
||||
print('CRITICAL - "zpool" failed')
|
||||
exit(2)
|
||||
|
||||
size, alloc = output.decode('UTF-8').strip().split()
|
||||
|
||||
try:
|
||||
size_b = to_bytes(size)
|
||||
alloc_b = to_bytes(alloc)
|
||||
except:
|
||||
print('CRITICAL - Could not process output of "zpool list": {}'.format(output))
|
||||
exit(2)
|
||||
|
||||
percentage = alloc_b / size_b * 100
|
||||
if percentage > critical_perc:
|
||||
print('CRITICAL - Pool "{}" uses {:.2f}% of its space'.format(pool, percentage))
|
||||
exit(2)
|
||||
|
||||
print('OK - Pool "{}" uses {:.2f}% of its space'.format(pool, percentage))
|
||||
exit(0)
|
Loading…
Add table
Add a link
Reference in a new issue