本文主要是介绍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)
这篇关于nagios 监控页面脚本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!