nagiosプラグインcheck_io_utils.py
2386 ワード
#!/usr/bin/python
# -*- coding:utf-8 -*-
from optparse import OptionParser
import subprocess
import sys
"""
Nagios plugin to report the io utils by shell command iostat
by jastme
"""
parser = OptionParser(usage="%prog -w <warning threshold> -c <critical threshold> [ -h ]",version="%prog ")
parser.add_option("-d", "--partion",action="store", type="string", dest="partion", help="choose the parion from the disk")
parser.add_option("-w", "--warning",action="store", type="string", dest="warn_threshold", help="Warning threshold in percentage")
parser.add_option("-c", "--critical",action="store", type="string", dest="crit_threshold", help="Critical threshold in percentage")
(options, args) = parser.parse_args()
def ioutil():
utils=subprocess.Popen("iostat -x 1 2 -d %s | grep %s | awk 'NR==2{print $NF}'" %(options.partion,options.partion),shell=True,stdout=subprocess.PIPE)
utils.wait()
utilss=utils.communicate()[0][:-1]
return eval(utilss)
def jastme():
util=ioutil()
if not options.crit_threshold:
print "UNKNOWN: Missing critical threshold value."
sys.exit(3)
if not options.warn_threshold:
print "UNKNOWN: Missing warning threshold value."
sys.exit(3)
if int(util) >= int(options.crit_threshold):
print "Criticl, the partion %s IO_utils is nearly %s%% | io_utils=%s%%;%s;%s;0" %(options.partion,util,util,options.warn_threshold,options.crit_threshold)
sys.exit(2)
elif int(options.crit_threshold) > int(util) >= int(options.warn_threshold):
print "Warning, the partion %s IO_utils is nearly %s%% | io_utils=%s%%;%s;%s;0" %(options.partion,util,util,options.warn_threshold,options.crit_threshold)
sys.exit(1)
else:
print "OK, the partion %s IO_utils is nearly %s%% | io_utils=%s%%;%s;%s;0" %(options.partion,util,util,options.warn_threshold,options.crit_threshold)
sys.exit(0)
if __name__ == '__main__':
jastme()