nagios 监控页面脚本

在企业应用当中,监控网站服务有时只靠端口的存活是不够的。

本脚本利用python监控网页url,靠网页返回关键字判断服务器服务状态是否正常,虽然简单但可满足很多需求:

[root@localhost nagios]# cat check_web
'''
Create 20131101
@cuc yangyang.feng
'''
#!/usr/bin/env python
import commands
import sys
from optparse import OptionParser
import urllib
import re


filehandle = urllib.urlopen("http://192.168.20.200/index.html")
content=filehandle.read()
filehandle.close()
#print(content)
if __name__ == '__main__':
if content.find('status:0 ok')>=0:
# if content.index('status:0 ok')==0:
print 'status:0 ok'
sys.exit(0)
else:
print 'No'
sys.exit(1)

猜你喜欢

转载自blog.csdn.net/u011648187/article/details/14120907
今日推荐