您的位置:首页 > 移动开发 > IOS开发

nagios 监控页面脚本

2013-11-04 10:50 344 查看
在企业应用当中,监控网站服务有时只靠端口的存活是不够的。

本脚本利用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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: