Browse Source

More improvements

master 1.2
Alarig Le Lay 2 years ago
parent
commit
0dddd6ade2
No known key found for this signature in database
GPG Key ID: C865491BF197B54F
  1. 621
      check_zfs.py

621
check_zfs.py

@ -5,8 +5,8 @@ @@ -5,8 +5,8 @@
########################################################################
##
## Written by Zachary LaCelle
## Written by Boris Tassou
## Copyright 2020
## Migration to Python3 by Boris Tassou
## Copyright 2016
## Licensed under GPL (see below)
##
## Nagios script to monitor ZFS pools/filesystems
@ -45,433 +45,434 @@ import sys @@ -45,433 +45,434 @@ import sys
# Commands to run
# CHANGE THESE IF YOU NEED TO
##
zpoolCommand = '/sbin/zpool'
zfsCommand = '/sbin/zfs'
ZPOOLCOMMANDE = '/sbin/zpool'
ZFSCOMMANDE = '/sbin/zfs'
##
# Variables to print at the end
##
nagiosStatus = ('OK', 'WARNING', 'CRITICAL', 'UNKNOWN')
stateNum = 0
msg = ''
perfdata = ''
NAGIOSSTATUS = ('OK', 'WARNING', 'CRITICAL', 'UNKNOWN')
STATENUM = 0
MSG = ''
PERFDATA = ''
##
# Filled from command line arguments
##
checkCapacity = False
capWarnThreshold = 50
capCritThreshold = 80
checkFragmentation = False
fragWarnThreshold = 50
fragCritThreshold = 80
CHECKCAPACITY = False
CAPWARNTHRESHOLD = 50
CAPCRITTHRESHOLD = 80
CHECKFRAGMENTATION = False
FRAGWARNTHRESHOLD = 50
FRAGCRITTHRESHOLD = 80
logging.basicConfig(stream=sys.stdout, format='%(message)s', level=logging.WARN)
def CheckArgBounds(valueArr, minVal, maxVal):
def checkargbounds(valuearr, minval, maxval):
"""Check value bounds."""
for value in valueArr:
if value < minVal:
for value in valuearr:
if value < minval:
return False
elif value > maxVal:
elif value > maxval:
return False
return True
def ConvertToGB(valueStr):
def converttogb(valuestr):
"""Convert to GB."""
value = valueStr[:-1]
value = valuestr[:-1]
value = value.replace(',', '.')
if valueStr.endswith('G'):
if valuestr.endswith('G'):
return float(value)
elif valueStr.endswith('T'):
elif valuestr.endswith('T'):
gigs = float(value)*1024
return float(gigs)
elif valueStr.endswith('M'):
elif valuestr.endswith('M'):
gigs = float(value) / 1024.0
return float(gigs)
elif valueStr.endswith('K'):
elif valuestr.endswith('K'):
gigs = float(value) / (1024.0 * 1024.0)
return float(gigs)
def RaiseStateNum(stateNumIn, stateNum):
def raisestatenum(statenumin, statenum):
"""Raise state num."""
if stateNumIn > stateNum:
return stateNumIn
return stateNum
if statenumin > statenum:
return statenumin
return statenum
###################################################################################
##
# Parse command line args
##
parser = argparse.ArgumentParser(
PARSER = argparse.ArgumentParser(
prog='check_zfs',
description='Check the ZFS pool specified by an argument.',
epilog='Note that monitor flags (e.g. capacity) require 2 arguments:\
warning threshold, and critical threshold')
parser.add_argument('--capacity', help="monitor utilization of zpool (%%, int [0-100])",
PARSER.add_argument('--capacity', help="monitor utilization of zpool (%%, int [0-100])",
type=int, nargs=2)
parser.add_argument('--fragmentation', help="monitor fragmentation of zpool (%%, int [0-100])",
PARSER.add_argument('--fragmentation', help="monitor fragmentation of zpool (%%, int [0-100])",
type=int, nargs=2)
parser.add_argument('pool', help="name of the zpool to check", type=str)
args = parser.parse_args()
retVal = True
if args.capacity is not None:
checkCapacity = True
capWarnThreshold = args.capacity[0]
capCritThreshold = args.capacity[1]
capArr = ['i', [capWarnThreshold, capCritThreshold]]
retVal = CheckArgBounds(capArr, 0, 100)
if retVal is False:
stateNum = RaiseStateNum(3, stateNum)
PARSER.add_argument('pool', help="name of the zpool to check", type=str)
ARGS = PARSER.parse_args()
RETVAL = True
if ARGS.capacity is not None:
CHECKCAPACITY = True
CAPWARNTHRESHOLD = ARGS.capacity[0]
CAPCRITTHRESHOLD = ARGS.capacity[1]
CAPARR = ['i', [CAPWARNTHRESHOLD, CAPCRITTHRESHOLD]]
RETVAL = checkargbounds(CAPARR, 0, 100)
if RETVAL is False:
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : Capacity thresholds must be between 0 and 100 (as a percent).",
nagiosStatus[stateNum])
parser.print_help()
exit(stateNum)
retVal = True
if args.fragmentation is not None:
checkFragmentation = True
fragWarnThreshold = args.fragmentation[0]
fragCritThreshold = args.fragmentation[1]
fragArr = ['i', [fragWarnThreshold, fragCritThreshold]]
retVal = CheckArgBounds(fragArr, 0, 100)
if retVal is False:
stateNum = RaiseStateNum(3, stateNum)
NAGIOSSTATUS[STATENUM])
PARSER.print_help()
sys.exit(STATENUM)
RETVAL = True
if ARGS.fragmentation is not None:
CHECKFRAGMENTATION = True
FRAGWARNTHRESHOLD = ARGS.fragmentation[0]
FRAGCRITTHRESHOLD = ARGS.fragmentation[1]
FRAGARR = ['i', [FRAGWARNTHRESHOLD, FRAGCRITTHRESHOLD]]
RETVAL = checkargbounds(FRAGARR, 0, 100)
if RETVAL is False:
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : Fragmentation thresholds must be between 0 and 100 (as a percent).",
nagiosStatus[stateNum])
parser.print_help()
exit(stateNum)
NAGIOSSTATUS[STATENUM])
PARSER.print_help()
sys.exit(STATENUM)
###################################################################################
##
# Get generic info about the ZFS environment
zfsEntries = []
fullCommand = ['/usr/bin/sudo', '-n', zfsCommand, 'list']
ZFSENTRIES = []
FULLCOMMAND = ['/usr/bin/sudo', '-n', ZFSCOMMANDE, 'list']
try:
childProcess = subprocess.Popen(fullCommand, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
CHILDPROCESS = subprocess.Popen(FULLCOMMAND, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except OSError:
stateNum = RaiseStateNum(3, stateNum)
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : process must be run as root. Possible solution: add the following to your\
visudo: nagios ALL=NOPASSWD: /sbin/zfs", nagiosStatus[stateNum])
exit(stateNum)
visudo: nagios ALL=NOPASSWD: /sbin/zfs", NAGIOSSTATUS[STATENUM])
sys.exit(STATENUM)
zfsString = childProcess.communicate()[0]
zfsRetval = childProcess.returncode
ZFSSTRING = CHILDPROCESS.communicate()[0]
ZFSRETVAL = CHILDPROCESS.returncode
if zfsRetval is 1:
stateNum = RaiseStateNum(3, stateNum)
if ZFSRETVAL is 1:
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : process must be run as root. Possible solution: add the following to\
your visudo: nagios ALL=NOPASSWD: /sbin/zfs", nagiosStatus[stateNum])
exit(stateNum)
your visudo: nagios ALL=NOPASSWD: /sbin/zfs", NAGIOSSTATUS[STATENUM])
sys.exit(STATENUM)
zfsLines = zfsString.splitlines()
for idx, line in enumerate(zfsLines):
if idx != 0:
zfsEntry = line.split()
zfsEntries.append(zfsEntry)
ZFSLINES = ZFSSTRING.splitlines()
for IDX, LINE in enumerate(ZFSLINES):
if IDX != 0:
ZFSENTRY = LINE.split()
ZFSENTRIES.append(ZFSENTRY)
# Make sure the pool we specified is valid
validPool = False
for entry in zfsEntries:
if entry[0].decode() == args.pool:
validPool = True
if not validPool:
stateNum = RaiseStateNum(3, stateNum)
VALIDPOOL = False
for ENTRY in ZFSENTRIES:
if ENTRY[0].decode() == ARGS.pool:
VALIDPOOL = True
if not VALIDPOOL:
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : Pool %s is invalid. Please select a valid pool.",
nagiosStatus[stateNum], args.pool)
exit(stateNum)
NAGIOSSTATUS[STATENUM], ARGS.pool)
sys.exit(STATENUM)
###################################################################################
##
# Get info on zpool
fullCommand = ['/usr/bin/sudo', '-n', zpoolCommand, 'list', args.pool]
FULLCOMMAND = ['/usr/bin/sudo', '-n', ZPOOLCOMMANDE, 'list', ARGS.pool]
try:
childProcess = subprocess.Popen(fullCommand, stdin=subprocess.PIPE,
CHILDPROCESS = subprocess.Popen(FULLCOMMAND, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError:
stateNum = RaiseStateNum(3, stateNum)
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : process must be run as root. Possible solution: add the following to\
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", nagiosStatus[stateNum])
exit(stateNum)
zpoolString = childProcess.communicate()[0]
zpoolRetval = childProcess.returncode
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", NAGIOSSTATUS[STATENUM])
sys.exit(STATENUM)
ZPOOLSTRING = CHILDPROCESS.communicate()[0]
ZPOOLRETVAL = CHILDPROCESS.returncode
if zpoolRetval is 1:
stateNum = RaiseStateNum(3, stateNum)
if ZPOOLRETVAL is 1:
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : process must be run as root. Possible solution: add the following to\
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", nagiosStatus[stateNum])
exit(stateNum)
zpoolLines = zpoolString.splitlines()
zpoolMeta = zpoolLines[0].decode().split()
zpoolMetaStr = ','.join(zpoolMeta)
zpoolEntry = zpoolLines[1].decode().split()
zpoolEntryStr = ','.join(zpoolEntry)
name = ''
size = ''
alloc = ''
free = ''
expandsz = ''
frag = ''
cap = ''
dedup = ''
health = ''
altroot = ''
for idx, fieldName in enumerate(zpoolMeta):
if fieldName == 'NAME':
name = zpoolEntry[idx]
elif fieldName == 'SIZE':
size = zpoolEntry[idx]
elif fieldName == 'ALLOC':
alloc = zpoolEntry[idx]
elif fieldName == 'FREE':
free = zpoolEntry[idx]
elif fieldName == 'EXPANDSZ':
expandsz = zpoolEntry[idx]
elif fieldName == 'FRAG':
frag = zpoolEntry[idx]
elif fieldName == 'CAP':
cap = zpoolEntry[idx]
elif fieldName == 'DEDUP':
dedup = zpoolEntry[idx]
elif fieldName == 'HEALTH':
health = zpoolEntry[idx]
elif fieldName == 'ALTROOT':
altroot = zpoolEntry[idx]
if name == '':
stateNum = RaiseStateNum(3, stateNum)
logging.warning("%s : Missing required field in zpool output: NAME", nagiosStatus[stateNum])
exit(stateNum)
if health == '':
stateNum = RaiseStateNum(3, stateNum)
logging.warning("%s : Missing required field in zpool output: HEALTH", nagiosStatus[stateNum])
exit(stateNum)
if checkCapacity and cap == '':
stateNum = RaiseStateNum(3, stateNum)
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", NAGIOSSTATUS[STATENUM])
sys.exit(STATENUM)
ZPOOLLINES = ZPOOLSTRING.splitlines()
ZPOOLMETA = ZPOOLLINES[0].decode().split()
ZPOOLMETASTR = ','.join(ZPOOLMETA)
ZPOOLENTRY = ZPOOLLINES[1].decode().split()
ZPOOLENTRYSTR = ','.join(ZPOOLENTRY)
NAME = ''
SIZE = ''
ALLOC = ''
FREE = ''
EXPANDSZ = ''
FRAG = ''
CAP = ''
DEDUP = ''
HEALTH = ''
ALTROOT = ''
for IDX, FIELDNAME in enumerate(ZPOOLMETA):
if FIELDNAME == 'NAME':
NAME = ZPOOLENTRY[IDX]
elif FIELDNAME == 'SIZE':
SIZE = ZPOOLENTRY[IDX]
elif FIELDNAME == 'ALLOC':
ALLOC = ZPOOLENTRY[IDX]
elif FIELDNAME == 'FREE':
FREE = ZPOOLENTRY[IDX]
elif FIELDNAME == 'EXPANDSZ':
EXPANDSZ = ZPOOLENTRY[IDX]
elif FIELDNAME == 'FRAG':
FRAG = ZPOOLENTRY[IDX]
elif FIELDNAME == 'CAP':
CAP = ZPOOLENTRY[IDX]
elif FIELDNAME == 'DEDUP':
DEDUP = ZPOOLENTRY[IDX]
elif FIELDNAME == 'HEALTH':
HEALTH = ZPOOLENTRY[IDX]
elif FIELDNAME == 'ALTROOT':
ALTROOT = ZPOOLENTRY[IDX]
if NAME == '':
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : Missing required field in zpool output: NAME", NAGIOSSTATUS[STATENUM])
sys.exit(STATENUM)
if HEALTH == '':
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : Missing required field in zpool output: HEALTH", NAGIOSSTATUS[STATENUM])
sys.exit(STATENUM)
if CHECKCAPACITY and CAP == '':
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s Cannot monitor capacity without zpool output: CAP.\
Outputs are %s", nagiosStatus[stateNum], zpoolMetaStr)
exit(stateNum)
if checkFragmentation and frag == '':
stateNum = RaiseStateNum(3, stateNum)
Outputs are %s", NAGIOSSTATUS[STATENUM], ZPOOLMETASTR)
sys.exit(STATENUM)
if CHECKFRAGMENTATION and FRAG == '':
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : Cannot monitor fragmentation without zpool output: FRAG.\
Outputs are %s", nagiosStatus[stateNum], zpoolMetaStr)
exit(stateNum)
Outputs are %s", NAGIOSSTATUS[STATENUM], ZPOOLMETASTR)
sys.exit(STATENUM)
# Get compressratio on zpool
checkForCompression = ['/usr/bin/sudo', '-n', zfsCommand, 'get', 'compression', args.pool]
CHECKFORCOMPRESSION = ['/usr/bin/sudo', '-n', ZFSCOMMANDE, 'get', 'compression', ARGS.pool]
try:
childProcess = subprocess.Popen(checkForCompression, stdin=subprocess.PIPE,
CHILDPROCESS = subprocess.Popen(CHECKFORCOMPRESSION, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError:
stateNum = RaiseStateNum(3, stateNum)
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : process must be run as root. Possible solution: add the following to\
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", nagiosStatus[stateNum])
exit(stateNum)
zpoolString = childProcess.communicate()[0]
zpoolRetval = childProcess.returncode
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", NAGIOSSTATUS[STATENUM])
sys.exit(STATENUM)
ZPOOLSTRING = CHILDPROCESS.communicate()[0]
ZPOOLRETVAL = CHILDPROCESS.returncode
if zpoolRetval is 1:
stateNum = RaiseStateNum(3, stateNum)
if ZPOOLRETVAL is 1:
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : process must be run as root. Possible solution: add the following to\
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", nagiosStatus[stateNum])
exit(stateNum)
zpoolLines = zpoolString.splitlines()
zpoolMeta = zpoolLines[0].decode().split()
zpoolMetaStr = ','.join(zpoolMeta)
zpoolEntry = zpoolLines[1].decode().split()
zpoolEntryStr = ','.join(zpoolEntry)
compressName = ''
compressValue = ''
compressRatioName = ''
compressRatioValue = ''
for idx, fieldName in enumerate(zpoolMeta):
if fieldName == 'NAME':
compressName = zpoolEntry[idx]
elif fieldName == 'VALUE':
compressValue = zpoolEntry[idx]
if compressName == '':
stateNum = RaiseStateNum(3, stateNum)
logging.warning("%s : Missing required field in zpool output: NAME", nagiosStatus[stateNum])
exit(stateNum)
if compressValue == 'on':
getCompressRatioCommand = ['/usr/bin/sudo', '-n', zfsCommand, 'get', 'compressratio', args.pool]
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", NAGIOSSTATUS[STATENUM])
sys.exit(STATENUM)
ZPOOLLINES = ZPOOLSTRING.splitlines()
ZPOOLMETA = ZPOOLLINES[0].decode().split()
ZPOOLMETASTR = ','.join(ZPOOLMETA)
ZPOOLENTRY = ZPOOLLINES[1].decode().split()
ZPOOLENTRYSTR = ','.join(ZPOOLENTRY)
COMPRESSNAME = ''
COMPRESSVALUE = ''
COMPRESSRATIONAME = ''
COMPRESSRATIOVALUE = ''
for IDX, FIELDNAME in enumerate(ZPOOLMETA):
if FIELDNAME == 'NAME':
COMPRESSNAME = ZPOOLENTRY[IDX]
elif FIELDNAME == 'VALUE':
COMPRESSVALUE = ZPOOLENTRY[IDX]
if COMPRESSNAME == '':
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : Missing required field in zpool output: NAME", NAGIOSSTATUS[STATENUM])
sys.exit(STATENUM)
if COMPRESSVALUE == 'on':
GETCOMPRESSRATIOCOMMAND = ['/usr/bin/sudo', '-n', ZFSCOMMANDE, 'get',
'compressratio', ARGS.pool]
try:
childProcess = subprocess.Popen(getCompressRatioCommand, stdin=subprocess.PIPE,
CHILDPROCESS = subprocess.Popen(GETCOMPRESSRATIOCOMMAND, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError:
stateNum = RaiseStateNum(3, stateNum)
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : process must be run as root. Possible solution: add the following to\
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", nagiosStatus[stateNum])
exit(stateNum)
zpoolString = childProcess.communicate()[0]
zpoolRetval = childProcess.returncode
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", NAGIOSSTATUS[STATENUM])
sys.exit(STATENUM)
ZPOOLSTRING = CHILDPROCESS.communicate()[0]
ZPOOLRETVAL = CHILDPROCESS.returncode
if zpoolRetval is 1:
stateNum = RaiseStateNum(3, stateNum)
if ZPOOLRETVAL is 1:
STATENUM = raisestatenum(3, STATENUM)
logging.warning("%s : process must be run as root. Possible solution: add the following to\
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", nagiosStatus[stateNum])
exit(stateNum)
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", NAGIOSSTATUS[STATENUM])
sys.exit(STATENUM)
zpoolLines = zpoolString.splitlines()
zpoolMeta = zpoolLines[0].decode().split()
zpoolMetaStr = ','.join(zpoolMeta)
zpoolEntry = zpoolLines[1].decode().split()
zpoolEntryStr = ','.join(zpoolEntry)
ZPOOLLINES = ZPOOLSTRING.splitlines()
ZPOOLMETA = ZPOOLLINES[0].decode().split()
ZPOOLMETASTR = ','.join(ZPOOLMETA)
ZPOOLENTRY = ZPOOLLINES[1].decode().split()
ZPOOLENTRYSTR = ','.join(ZPOOLENTRY)
for idx, fieldName in enumerate(zpoolMeta):
if fieldName == 'NAME':
compressRatioName = zpoolEntry[idx]
elif fieldName == 'VALUE':
compressRatioValue = zpoolEntry[idx]
for IDX, fieldName in enumerate(ZPOOLMETA):
if FIELDNAME == 'NAME':
COMPRESSRATIONAME = ZPOOLENTRY[IDX]
elif FIELDNAME == 'VALUE':
COMPRESSRATIOVALUE = ZPOOLENTRY[IDX]
###################################################################################
##
# OK, finally in the actual status checking of the zpool
# Let's build up our perfdata, regardless of what we're checking
fragPercent = ''
if frag != '':
fragPercent = frag.replace("%", "")
fragPerfStr = "frag="+str(fragPercent)+"%;"
if checkFragmentation:
fragPerfStr = fragPerfStr+str(fragWarnThreshold)+";"+str(fragCritThreshold)+";"
FRAGPERCENT = ''
if FRAG != '':
FRAGPERCENT = FRAG.replace("%", "")
FRAGPERFSTR = "frag="+str(FRAGPERCENT)+"%;"
if CHECKFRAGMENTATION:
FRAGPERFSTR = FRAGPERFSTR + str(FRAGWARNTHRESHOLD) + ";" + str(FRAGCRITTHRESHOLD) + ";"
else:
fragPerfStr += (";;")
perfdata += (fragPerfStr)
perfdata += " "
capPercent = ''
if cap != '':
capPercent = cap.replace("%", "")
capPerfStr = "cap="+str(capPercent)+"%;"
if checkCapacity:
capPerfStr = capPerfStr+str(capWarnThreshold)+";"+str(capCritThreshold)+";"
FRAGPERFSTR += (";;")
PERFDATA += (FRAGPERFSTR)
PERFDATA += " "
CAPPERCENT = ''
if CAP != '':
CAPPERCENT = CAP.replace("%", "")
CAPPERFSTR = "cap=" + str(CAPPERCENT) + "%;"
if CHECKCAPACITY:
CAPPERFSTR = CAPPERFSTR + str(CAPWARNTHRESHOLD) + ";" + str(CAPCRITTHRESHOLD) + ";"
else:
capPerfStr += (";;")
perfdata += (capPerfStr)
perfdata += " "
CAPPERFSTR += (";;")
PERFDATA += (CAPPERFSTR)
PERFDATA += " "
# Perfdata for dedup & compression factor
if dedup != '':
dedup_no_x = dedup.rstrip('x')
perfdata += "dedup="+str(dedup_no_x)
perfdata += " "
if DEDUP != '':
DEDUP_NO_X = DEDUP.rstrip('x')
PERFDATA += "DEDUP=" + str(DEDUP_NO_X)
PERFDATA += " "
if compressRatioValue != '':
compressRatioNoX = compressRatioValue.rstrip('x')
perfdata += "compress_ratio="+str(compressRatioNoX)
perfdata += " "
if COMPRESSRATIOVALUE != '':
COMPRESSRATIONOX = COMPRESSRATIOVALUE.rstrip('x')
PERFDATA += "compress_ratio=" + str(COMPRESSRATIONOX)
PERFDATA += " "
# Sizes can be in K, M, G, or T (maybe P, but I'm not doing this yet)
if size != '':
sizeGB = ConvertToGB(size)
perfdata += "size="+str(sizeGB)+"GB;;;"
perfdata += " "
if SIZE != '':
SIZEGB = converttogb(SIZE)
PERFDATA += "size=" + str(SIZEGB) + "GB;;;"
PERFDATA += " "
if alloc != '':
allocGB = ConvertToGB(alloc)
perfdata += "alloc="+str(allocGB)+"GB;;;"
perfdata += " "
if ALLOC != '':
ALLOCGB = converttogb(ALLOC)
PERFDATA += "alloc=" + str(ALLOCGB) + "GB;;;"
PERFDATA += " "
if free != '':
freeGB = ConvertToGB(free)
perfdata += "free="+str(freeGB)+"GB;;;"
perfdata += " "
if FREE != '':
FREEGB = converttogb(FREE)
PERFDATA += "free=" + str(FREEGB) + "GB;;;"
PERFDATA += " "
##
# Do mandatory checks
healthNum = -1
if health == 'ONLINE':
healthNum = 0
elif health == 'OFFLINE':
stateNum = RaiseStateNum(1, stateNum)
healthNum = 1
elif health == 'REMOVED':
stateNum = RaiseStateNum(1, stateNum)
healthNum = 2
elif health == 'UNAVAIL':
stateNum = RaiseStateNum(1, stateNum)
healthNum = 3
elif health == 'DEGRADED':
stateNum = RaiseStateNum(2, stateNum)
healthNum = 4
elif health == 'FAULTED':
stateNum = RaiseStateNum(2, stateNum)
healthNum = 5
perfdata += "health="+str(healthNum)+";1;3;"
perfdata += " "
HEALTHNUM = -1
if HEALTH == 'ONLINE':
HEALTHNUM = 0
elif HEALTH == 'OFFLINE':
STATENUM = raisestatenum(1, STATENUM)
HEALTHNUM = 1
elif HEALTH == 'REMOVED':
STATENUM = raisestatenum(1, STATENUM)
HEALTHNUM = 2
elif HEALTH == 'UNAVAIL':
STATENUM = raisestatenum(1, STATENUM)
HEALTHNUM = 3
elif HEALTH == 'DEGRADED':
STATENUM = raisestatenum(2, STATENUM)
HEALTHNUM = 4
elif HEALTH == 'FAULTED':
STATENUM = raisestatenum(2, STATENUM)
HEALTHNUM = 5
PERFDATA += "health=" + str(HEALTHNUM) + ";1;3;"
PERFDATA += " "
##
# Initial part of msg
msg = "POOL: " + str(name)
healthMsgFilled = False
if healthNum > 0:
msg += ", STATUS: "+str(health)
healthMsgFilled = True
MSG = "POOL: " + str(NAME)
HEALTHMSGFILLED = False
if HEALTHNUM > 0:
MSG += ", STATUS: " + str(HEALTH)
HEALTHMSGFILLED = True
##
# Do optional checks
fragMsgFilled = False
capMsgFilled = False
if checkFragmentation and fragPercent != '':
if fragPercent.isdigit() is True:
if int(fragPercent) > int(fragCritThreshold):
fragMsgFilled = True
stateNum = RaiseStateNum(2, stateNum)
msg += ", FRAG CRIT: " + str(frag)
elif int(fragPercent) > int(fragWarnThreshold):
fragMsgFilled = True
stateNum = RaiseStateNum(1, stateNum)
msg += ", FRAG WARN: " + str(frag)
if checkCapacity and capPercent != '':
if int(capPercent) > int(capCritThreshold):
capMsgFilled = True
stateNum = RaiseStateNum(2, stateNum)
msg += ", CAP CRIT: " + str(cap)
elif int(capPercent) > int(capWarnThreshold):
capMsgFilled = True
stateNum = RaiseStateNum(1, stateNum)
msg += ", CAP WARN: "+str(cap)
FRAGMSGFILLED = False
CAPMSGFILLED = False
if CHECKFRAGMENTATION and FRAGPERFSTR != '':
if FRAGPERFSTR.isdigit() is True:
if int(FRAGPERFSTR) > int(FRAGCRITTHRESHOLD):
FRAGMSGFILLED = True
STATENUM = raisestatenum(2, STATENUM)
MSG += ", FRAG CRIT: " + str(FRAG)
elif int(FRAGPERFSTR) > int(FRAGWARNTHRESHOLD):
FRAGMSGFILLED = True
STATENUM = raisestatenum(1, STATENUM)
MSG += ", FRAG WARN: " + str(FRAG)
if CHECKCAPACITY and CAPPERCENT != '':
if int(CAPPERCENT) > int(CAPCRITTHRESHOLD):
CAPMSGFILLED = True
STATENUM = raisestatenum(2, STATENUM)
MSG += ", CAP CRIT: " + str(CAP)
elif int(CAPPERCENT) > int(CAPWARNTHRESHOLD):
CAPMSGFILLED = True
STATENUM = raisestatenum(1, STATENUM)
MSG += ", CAP WARN: " + str(CAP)
##
# Build up rest of message
if not healthMsgFilled:
msg += ", STATUS: " + str(health)
if size != '':
msg += ", SIZE: " + str(size)
if alloc != '':
msg += ", ALLOC: " + str(alloc)
if free != '':
msg += ", FREE: " + str(free)
if dedup != '':
msg += ", DEDUP: " + str(dedup)
if compressRatioValue != '':
msg += ", COMPRESS: " + str(compressRatioValue)
if frag != '' and not fragMsgFilled:
msg += ", FRAG: " + str(frag)
if cap != '' and not capMsgFilled:
msg += ", CAP: " + str(cap)
if not HEALTHMSGFILLED:
MSG += ", STATUS: " + str(HEALTH)
if SIZE != '':
MSG += ", SIZE: " + str(SIZE)
if ALLOC != '':
MSG += ", ALLOC: " + str(ALLOC)
if FREE != '':
MSG += ", FREE: " + str(FREE)
if DEDUP != '':
MSG += ", DEDUP: " + str(DEDUP)
if COMPRESSRATIOVALUE != '':
MSG += ", COMPRESS: " + str(COMPRESSRATIOVALUE)
if FRAG != '' and not FRAGMSGFILLED:
MSG += ", FRAG: " + str(FRAG)
if CAP != '' and not CAPMSGFILLED:
MSG += ", CAP: " + str(CAP)
##
# Print our output and return
logging.warning("%s: %s | %s", nagiosStatus[stateNum], msg, perfdata)
exit(stateNum)
logging.warning("%s: %s | %s", NAGIOSSTATUS[STATENUM], MSG, PERFDATA)
sys.exit(STATENUM)

Loading…
Cancel
Save