作者:容易 2013-05-14 8:30:51
#!/usr/bin/python
from optparse import OptionParser
import sys,os
usage = "Usage: %prog -f file_full_path [-w] [-c]"
parser = OptionParser()
parser.add_option("-f", "--file",
type="string",
dest="file",
help="please specify file's full path,example /var/log/message")
parser.add_option("-w", "--warning",
type="int",
dest="warning",
default=1024,
help="please specify warning thresholds for file size(MB),example 1024 ")
parser.add_option("-c", "--critical",
type="int",
dest="critical",
default=1500,
help="please specify critical thresholds for file size()MB,example 1500")
(options, args) = parser.parse_args()
Warning=options.warning
Critical=options.critical
file_name=options.file
try:
size=os.path.getsize(file_name)
except:
print "please check file!"
sys.exit(3)
file_size=round(size/1024/1024.0,0)
if size > Critical:
print "CRITICAL - File %s current size is $f greater than $d." % (file_name,file_size,Critical)
sys.exit(2)
elif size > Warning:
print "Warning - File %s current size is $f greater than $d." % (file_name,file_size,Warning)
sys.exit(1)
elif size < Warning:
print "OK - File %s current size is %f." % (file_name,file_size)
sys.exit(0)
else:
print "Unknow - File %s current state is unknow." % (file_name)
sys.exit(3)
.
usage = "usage: %prog [options] arg1 arg2"
One Response