2020-06-14 16:07:49 +02:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
"""Get zfs pool status."""
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
|
##
|
|
|
|
|
## Written by Zachary LaCelle
|
2020-06-14 16:09:01 +02:00
|
|
|
|
## Written by Boris Tassou
|
|
|
|
|
## Copyright 2020
|
2020-06-14 16:06:10 +02:00
|
|
|
|
## Licensed under GPL (see below)
|
|
|
|
|
##
|
|
|
|
|
## Nagios script to monitor ZFS pools/filesystems
|
|
|
|
|
## in Linux.
|
|
|
|
|
##
|
|
|
|
|
## Tested operating systems/ZFS versions:
|
2020-06-14 16:07:49 +02:00
|
|
|
|
## * See README.md
|
2020-06-14 16:06:10 +02:00
|
|
|
|
##
|
|
|
|
|
## This program is free software: you can redistribute it and/or modify
|
|
|
|
|
## it under the terms of the GNU General Public License as published by
|
|
|
|
|
## the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
## (at your option) any later version.
|
|
|
|
|
##
|
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
|
##
|
|
|
|
|
## You should have received a copy of the GNU General Public License
|
|
|
|
|
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
##
|
|
|
|
|
########################################################################
|
|
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
|
import argparse
|
2020-06-14 16:07:49 +02:00
|
|
|
|
import logging
|
|
|
|
|
import sys
|
|
|
|
|
# from sys import exit
|
|
|
|
|
# from array import *
|
|
|
|
|
# from types import *
|
|
|
|
|
# import array
|
|
|
|
|
# import types
|
|
|
|
|
# from os import geteuid
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Commands to run
|
|
|
|
|
# CHANGE THESE IF YOU NEED TO
|
|
|
|
|
##
|
2020-06-14 16:07:49 +02:00
|
|
|
|
zpoolCommand = '/sbin/zpool'
|
|
|
|
|
zfsCommand = '/sbin/zfs'
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Variables to print at the end
|
|
|
|
|
##
|
2020-06-14 16:07:49 +02:00
|
|
|
|
nagiosStatus = ('OK', 'WARNING', 'CRITICAL', 'UNKNOWN')
|
|
|
|
|
stateNum = 0
|
|
|
|
|
msg = ''
|
|
|
|
|
perfdata = ''
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Filled from command line arguments
|
|
|
|
|
##
|
2020-06-14 16:07:49 +02:00
|
|
|
|
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):
|
|
|
|
|
"""Check value bounds."""
|
2020-06-14 16:06:10 +02:00
|
|
|
|
for value in valueArr:
|
|
|
|
|
if value < minVal:
|
|
|
|
|
return False
|
|
|
|
|
elif value > maxVal:
|
|
|
|
|
return False
|
|
|
|
|
return True
|
|
|
|
|
|
2020-06-14 16:07:49 +02:00
|
|
|
|
|
|
|
|
|
def ConvertToGB(valueStr):
|
|
|
|
|
"""Convert to GB."""
|
2020-06-14 16:06:10 +02:00
|
|
|
|
value = valueStr[:-1]
|
|
|
|
|
value = value.replace(',', '.')
|
|
|
|
|
if valueStr.endswith('G'):
|
|
|
|
|
return float(value)
|
|
|
|
|
elif valueStr.endswith('T'):
|
2020-06-14 16:07:49 +02:00
|
|
|
|
gigs = float(value)*1024
|
2020-06-14 16:06:10 +02:00
|
|
|
|
return float(gigs)
|
|
|
|
|
elif valueStr.endswith('M'):
|
2020-06-14 16:07:49 +02:00
|
|
|
|
gigs = float(value) / 1024.0
|
2020-06-14 16:06:10 +02:00
|
|
|
|
return float(gigs)
|
|
|
|
|
elif valueStr.endswith('K'):
|
2020-06-14 16:07:49 +02:00
|
|
|
|
gigs = float(value) / (1024.0 * 1024.0)
|
2020-06-14 16:06:10 +02:00
|
|
|
|
return float(gigs)
|
|
|
|
|
|
2020-06-14 16:07:49 +02:00
|
|
|
|
|
|
|
|
|
def RaiseStateNum(stateNumIn, stateNum):
|
|
|
|
|
"""Raise state num."""
|
2020-06-14 16:06:10 +02:00
|
|
|
|
if stateNumIn > stateNum:
|
|
|
|
|
return stateNumIn
|
|
|
|
|
return stateNum
|
|
|
|
|
|
2020-06-14 16:07:49 +02:00
|
|
|
|
|
2020-06-14 16:06:10 +02:00
|
|
|
|
###################################################################################
|
|
|
|
|
##
|
|
|
|
|
# Parse command line args
|
|
|
|
|
##
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
|
prog='check_zfs',
|
|
|
|
|
description='Check the ZFS pool specified by an argument.',
|
2020-06-14 16:07:49 +02:00
|
|
|
|
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])",
|
|
|
|
|
type=int, nargs=2)
|
|
|
|
|
parser.add_argument('--fragmentation', help="monitor fragmentation of zpool (%%, int [0-100])",
|
|
|
|
|
type=int, nargs=2)
|
2020-06-14 16:06:10 +02:00
|
|
|
|
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:
|
2020-06-14 16:07:49 +02:00
|
|
|
|
checkCapacity = True
|
|
|
|
|
capWarnThreshold = args.capacity[0]
|
|
|
|
|
capCritThreshold = args.capacity[1]
|
|
|
|
|
capArr = ['i', [capWarnThreshold, capCritThreshold]]
|
2020-06-14 16:06:10 +02:00
|
|
|
|
retVal = CheckArgBounds(capArr, 0, 100)
|
|
|
|
|
if retVal is False:
|
|
|
|
|
stateNum = RaiseStateNum(3, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
logging.warning("%s : Capacity thresholds must be between 0 and 100 (as a percent).",
|
|
|
|
|
nagiosStatus[stateNum])
|
2020-06-14 16:06:10 +02:00
|
|
|
|
parser.print_help()
|
|
|
|
|
exit(stateNum)
|
|
|
|
|
retVal = True
|
|
|
|
|
if args.fragmentation is not None:
|
2020-06-14 16:07:49 +02:00
|
|
|
|
checkFragmentation = True
|
|
|
|
|
fragWarnThreshold = args.fragmentation[0]
|
|
|
|
|
fragCritThreshold = args.fragmentation[1]
|
|
|
|
|
fragArr = ['i', [fragWarnThreshold, fragCritThreshold]]
|
2020-06-14 16:06:10 +02:00
|
|
|
|
retVal = CheckArgBounds(fragArr, 0, 100)
|
|
|
|
|
if retVal is False:
|
|
|
|
|
stateNum = RaiseStateNum(3, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
logging.warning("%s : Fragmentation thresholds must be between 0 and 100 (as a percent).",
|
|
|
|
|
nagiosStatus[stateNum])
|
2020-06-14 16:06:10 +02:00
|
|
|
|
parser.print_help()
|
|
|
|
|
exit(stateNum)
|
|
|
|
|
|
|
|
|
|
###################################################################################
|
|
|
|
|
##
|
|
|
|
|
# Get generic info about the ZFS environment
|
|
|
|
|
zfsEntries = []
|
2020-06-14 16:07:49 +02:00
|
|
|
|
fullCommand = ['/usr/bin/sudo', '-n', zfsCommand, 'list']
|
2020-06-14 16:06:10 +02:00
|
|
|
|
try:
|
2020-06-14 16:07:49 +02:00
|
|
|
|
childProcess = subprocess.Popen(fullCommand, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
|
|
|
|
stderr=subprocess.PIPE)
|
2020-06-14 16:06:10 +02:00
|
|
|
|
except OSError:
|
|
|
|
|
stateNum = RaiseStateNum(3, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
logging.warning("%s : process must be run as root. Possible solution: add the following to your\
|
|
|
|
|
visudo: nagios ALL=NOPASSWD: /sbin/zfs", nagiosStatus[stateNum])
|
2020-06-14 16:06:10 +02:00
|
|
|
|
exit(stateNum)
|
|
|
|
|
|
|
|
|
|
zfsString = childProcess.communicate()[0]
|
|
|
|
|
zfsRetval = childProcess.returncode
|
|
|
|
|
|
|
|
|
|
if zfsRetval is 1:
|
|
|
|
|
stateNum = RaiseStateNum(3, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
logging.warning("%s : process must be run as root. Possible solution: add the following to\
|
|
|
|
|
your visudo: nagios ALL=NOPASSWD: /sbin/zfs", nagiosStatus[stateNum])
|
2020-06-14 16:06:10 +02:00
|
|
|
|
exit(stateNum)
|
|
|
|
|
|
|
|
|
|
zfsLines = zfsString.splitlines()
|
|
|
|
|
for idx, line in enumerate(zfsLines):
|
|
|
|
|
if idx != 0:
|
2020-06-14 16:07:49 +02:00
|
|
|
|
zfsEntry = line.split()
|
2020-06-14 16:06:10 +02:00
|
|
|
|
zfsEntries.append(zfsEntry)
|
|
|
|
|
|
|
|
|
|
# Make sure the pool we specified is valid
|
2020-06-14 16:07:49 +02:00
|
|
|
|
validPool = False
|
2020-06-14 16:06:10 +02:00
|
|
|
|
for entry in zfsEntries:
|
2020-06-14 16:07:49 +02:00
|
|
|
|
if entry[0].decode() == args.pool:
|
|
|
|
|
validPool = True
|
2020-06-14 16:06:10 +02:00
|
|
|
|
if not validPool:
|
|
|
|
|
stateNum = RaiseStateNum(3, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
logging.warning("%s : Pool %s is invalid. Please select a valid pool.",
|
|
|
|
|
nagiosStatus[stateNum], args.pool)
|
2020-06-14 16:06:10 +02:00
|
|
|
|
exit(stateNum)
|
|
|
|
|
|
|
|
|
|
###################################################################################
|
|
|
|
|
##
|
|
|
|
|
# Get info on zpool
|
|
|
|
|
|
2020-06-14 16:07:49 +02:00
|
|
|
|
fullCommand = ['/usr/bin/sudo', '-n', zpoolCommand, 'list', args.pool]
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
childProcess = subprocess.Popen(fullCommand, stdin=subprocess.PIPE,
|
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
except OSError:
|
|
|
|
|
stateNum = RaiseStateNum(3, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
logging.warning("%s : process must be run as root. Possible solution: add the following to\
|
|
|
|
|
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", nagiosStatus[stateNum])
|
2020-06-14 16:06:10 +02:00
|
|
|
|
exit(stateNum)
|
|
|
|
|
zpoolString = childProcess.communicate()[0]
|
|
|
|
|
zpoolRetval = childProcess.returncode
|
|
|
|
|
|
|
|
|
|
if zpoolRetval is 1:
|
|
|
|
|
stateNum = RaiseStateNum(3, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
logging.warning("%s : process must be run as root. Possible solution: add the following to\
|
|
|
|
|
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", nagiosStatus[stateNum])
|
2020-06-14 16:06:10 +02:00
|
|
|
|
exit(stateNum)
|
|
|
|
|
|
2020-06-14 16:07:49 +02:00
|
|
|
|
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 = ''
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
|
|
|
|
for idx, fieldName in enumerate(zpoolMeta):
|
2020-06-14 16:07:49 +02:00
|
|
|
|
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 == '':
|
2020-06-14 16:06:10 +02:00
|
|
|
|
stateNum = RaiseStateNum(3, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
logging.warning("%s : Missing required field in zpool output: HEALTH", nagiosStatus[stateNum])
|
2020-06-14 16:06:10 +02:00
|
|
|
|
exit(stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
if checkCapacity and cap == '':
|
2020-06-14 16:06:10 +02:00
|
|
|
|
stateNum = RaiseStateNum(3, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
logging.warning("%s Cannot monitor capacity without zpool output: CAP.\
|
|
|
|
|
Outputs are %s", nagiosStatus[stateNum], zpoolMetaStr)
|
2020-06-14 16:06:10 +02:00
|
|
|
|
exit(stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
if checkFragmentation and frag == '':
|
2020-06-14 16:06:10 +02:00
|
|
|
|
stateNum = RaiseStateNum(3, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
logging.warning("%s : Cannot monitor fragmentation without zpool output: FRAG.\
|
|
|
|
|
Outputs are %s", nagiosStatus[stateNum], zpoolMetaStr)
|
2020-06-14 16:06:10 +02:00
|
|
|
|
exit(stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
|
|
|
|
|
# Get compressratio on zpool
|
|
|
|
|
|
|
|
|
|
checkForCompression = ['/usr/bin/sudo', '-n', zfsCommand, 'get', 'compression', args.pool]
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
childProcess = subprocess.Popen(checkForCompression, stdin=subprocess.PIPE,
|
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
except OSError:
|
2020-06-14 16:06:10 +02:00
|
|
|
|
stateNum = RaiseStateNum(3, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
logging.warning("%s : process must be run as root. Possible solution: add the following to\
|
|
|
|
|
your visudo: nagios ALL=NOPASSWD: /sbin/zpool", nagiosStatus[stateNum])
|
2020-06-14 16:06:10 +02:00
|
|
|
|
exit(stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
zpoolString = childProcess.communicate()[0]
|
|
|
|
|
zpoolRetval = childProcess.returncode
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
childProcess = subprocess.Popen(getCompressRatioCommand, stdin=subprocess.PIPE,
|
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
except OSError:
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
for idx, fieldName in enumerate(zpoolMeta):
|
|
|
|
|
if fieldName == 'NAME':
|
|
|
|
|
compressRatioName = zpoolEntry[idx]
|
|
|
|
|
elif fieldName == 'VALUE':
|
|
|
|
|
compressRatioValue = zpoolEntry[idx]
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
|
|
|
|
###################################################################################
|
|
|
|
|
##
|
|
|
|
|
# OK, finally in the actual status checking of the zpool
|
|
|
|
|
|
|
|
|
|
# Let's build up our perfdata, regardless of what we're checking
|
2020-06-14 16:07:49 +02:00
|
|
|
|
fragPercent = ''
|
|
|
|
|
if frag != '':
|
|
|
|
|
fragPercent = frag.replace("%", "")
|
|
|
|
|
fragPerfStr = "frag="+str(fragPercent)+"%;"
|
2020-06-14 16:06:10 +02:00
|
|
|
|
if checkFragmentation:
|
2020-06-14 16:07:49 +02:00
|
|
|
|
fragPerfStr = fragPerfStr+str(fragWarnThreshold)+";"+str(fragCritThreshold)+";"
|
2020-06-14 16:06:10 +02:00
|
|
|
|
else:
|
2020-06-14 16:07:49 +02:00
|
|
|
|
fragPerfStr += (";;")
|
|
|
|
|
perfdata += (fragPerfStr)
|
|
|
|
|
perfdata += " "
|
|
|
|
|
|
|
|
|
|
capPercent = ''
|
|
|
|
|
if cap != '':
|
|
|
|
|
capPercent = cap.replace("%", "")
|
|
|
|
|
capPerfStr = "cap="+str(capPercent)+"%;"
|
2020-06-14 16:06:10 +02:00
|
|
|
|
if checkCapacity:
|
2020-06-14 16:07:49 +02:00
|
|
|
|
capPerfStr = capPerfStr+str(capWarnThreshold)+";"+str(capCritThreshold)+";"
|
2020-06-14 16:06:10 +02:00
|
|
|
|
else:
|
2020-06-14 16:07:49 +02:00
|
|
|
|
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 compressRatioValue != '':
|
|
|
|
|
compressRatioNoX = compressRatioValue.rstrip('x')
|
|
|
|
|
perfdata += "compress_ratio="+str(compressRatioNoX)
|
|
|
|
|
perfdata += " "
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
|
|
|
|
# Sizes can be in K, M, G, or T (maybe P, but I'm not doing this yet)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
if size != '':
|
2020-06-14 16:06:10 +02:00
|
|
|
|
sizeGB = ConvertToGB(size)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
perfdata += "size="+str(sizeGB)+"GB;;;"
|
|
|
|
|
perfdata += " "
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
2020-06-14 16:07:49 +02:00
|
|
|
|
if alloc != '':
|
2020-06-14 16:06:10 +02:00
|
|
|
|
allocGB = ConvertToGB(alloc)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
perfdata += "alloc="+str(allocGB)+"GB;;;"
|
|
|
|
|
perfdata += " "
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
2020-06-14 16:07:49 +02:00
|
|
|
|
if free != '':
|
2020-06-14 16:06:10 +02:00
|
|
|
|
freeGB = ConvertToGB(free)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
perfdata += "free="+str(freeGB)+"GB;;;"
|
|
|
|
|
perfdata += " "
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Do mandatory checks
|
2020-06-14 16:07:49 +02:00
|
|
|
|
healthNum = -1
|
|
|
|
|
if health == 'ONLINE':
|
|
|
|
|
healthNum = 0
|
|
|
|
|
elif health == 'OFFLINE':
|
2020-06-14 16:06:10 +02:00
|
|
|
|
stateNum = RaiseStateNum(1, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
healthNum = 1
|
|
|
|
|
elif health == 'REMOVED':
|
2020-06-14 16:06:10 +02:00
|
|
|
|
stateNum = RaiseStateNum(1, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
healthNum = 2
|
|
|
|
|
elif health == 'UNAVAIL':
|
2020-06-14 16:06:10 +02:00
|
|
|
|
stateNum = RaiseStateNum(1, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
healthNum = 3
|
|
|
|
|
elif health == 'DEGRADED':
|
2020-06-14 16:06:10 +02:00
|
|
|
|
stateNum = RaiseStateNum(2, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
healthNum = 4
|
|
|
|
|
elif health == 'FAULTED':
|
2020-06-14 16:06:10 +02:00
|
|
|
|
stateNum = RaiseStateNum(2, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
healthNum = 5
|
|
|
|
|
perfdata += "health="+str(healthNum)+";1;3;"
|
|
|
|
|
perfdata += " "
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Initial part of msg
|
2020-06-14 16:07:49 +02:00
|
|
|
|
msg = "POOL: " + str(name)
|
|
|
|
|
healthMsgFilled = False
|
2020-06-14 16:06:10 +02:00
|
|
|
|
if healthNum > 0:
|
2020-06-14 16:07:49 +02:00
|
|
|
|
msg += ", STATUS: "+str(health)
|
|
|
|
|
healthMsgFilled = True
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Do optional checks
|
2020-06-14 16:07:49 +02:00
|
|
|
|
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 != '':
|
2020-06-14 16:06:10 +02:00
|
|
|
|
if int(capPercent) > int(capCritThreshold):
|
2020-06-14 16:07:49 +02:00
|
|
|
|
capMsgFilled = True
|
2020-06-14 16:06:10 +02:00
|
|
|
|
stateNum = RaiseStateNum(2, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
msg += ", CAP CRIT: " + str(cap)
|
2020-06-14 16:06:10 +02:00
|
|
|
|
elif int(capPercent) > int(capWarnThreshold):
|
2020-06-14 16:07:49 +02:00
|
|
|
|
capMsgFilled = True
|
2020-06-14 16:06:10 +02:00
|
|
|
|
stateNum = RaiseStateNum(1, stateNum)
|
2020-06-14 16:07:49 +02:00
|
|
|
|
msg += ", CAP WARN: "+str(cap)
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Build up rest of message
|
|
|
|
|
if not healthMsgFilled:
|
2020-06-14 16:07:49 +02:00
|
|
|
|
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)
|
2020-06-14 16:06:10 +02:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
# Print our output and return
|
2020-06-14 16:07:49 +02:00
|
|
|
|
logging.warning("%s: %s | %s", nagiosStatus[stateNum], msg, perfdata)
|
2020-06-14 16:06:10 +02:00
|
|
|
|
exit(stateNum)
|