作者:容易 2013-05-14 8:20:40
if file_size > Critical:
print "CRITICAL - File %s current size is %s greater than %d MB." % (file_name,file_size,Critical)
sys.exit(2)
exit 2 代表严重告警
elif file_size > Warning:
print "Warning - File %s current size is %s greater than %d MB." % (file_name,file_size,Warning)
sys.exit(1)
exit 1 代表警告
elif file_size < Warning:
print "OK - File %s current size is %s MB." % (file_name,file_size)
sys.exit(0)
exit 0 代表健康
else:
print "Unknow - File %s current state is unknow." % (file_name)
sys.exit(3)
exit 3 代表未知状态
echo "10.98.2.8;check-vm_monitor;2;readonly database vm test" | /mnt/send_nsca -H 10.98.3.24 -d ";" -c /mnt/send_nsca.cfg >/dev/null
10.98.2.8 本机IP地址
check-vm_monitor 被监控服务的描述名
2 被监控服务的健康状态
readonly database vm test 错误描述
/mnt/send_nsca -H 10.98.3.24 -d ";" -c /mnt/send_nsca.cfg
-H 10.98.3.24 监控服务器的地址
-d ";" 分隔符号
—c /mnt/send_nsca.cfg 配置文件的位置
check_file_size.py
#!/usr/bin/python
from optparse import OptionParser
import sys,os
usage = "usage_example: %prog -w 1024 -c 1500 -f /var/log/message"
parser = OptionParser(usage=usage)
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),default value 1024 ")
parser.add_option("-c", "--critical",
type="int",
dest="critical",
default=1500,
help="please specify critical thresholds for file size()MB,default value 1500")
(options, args) = parser.parse_args()
Warning=options.warning
Critical=options.critical
file_name=options.file
if Critical <= Warning:
print "Error,Critical value must be greater than Warning."
sys.exit(3)
try:
value=os.path.getsize(file_name)
except:
print "Error,Can not find specify file,please verify file exists!"
sys.exit(3)
file_size=round(value/1024/1024.0,0)
if file_size > Critical:
print "CRITICAL - File %s current size is %s greater than %d MB." % (file_name,file_size,Critical)
sys.exit(2)
elif file_size > Warning:
print "Warning - File %s current size is %s greater than %d MB." % (file_name,file_size,Warning)
sys.exit(1)
elif file_size < Warning:
print "OK - File %s current size is %s MB." % (file_name,file_size)
sys.exit(0)
else:
print "Unknow - File %s current state is unknow." % (file_name)
sys.exit(3)
check_log.sh
#!/bin/bash
ip_addr='10.98.50.39'
ser_dsc='check-cm_debug_log'
info=`/usr/bin/python /usr/local/nagios/libexec/check_file_size.py -w 1600 -c 1800 -f /app/pnrp/log/cm_debug.log`
status=`echo $?`
echo "$ip_addr;$ser_dsc;$status;$info" | /usr/local/nagios/bin/send_nsca -H 10.98.3.24 -d ";" -c /usr/local/nagios/etc/send_nsca.cfg >/dev/null
One Response