- #!/usr/local/bin/python
- # --*-- coding=utf-8 --*--
- ############## by xiaofu ,contact at msn:xiaofu68#live.cn ####################
- # Description : This visit website via proxy servers specified in advance, it polls backends periodically and if they responsed with http code 200 ,cdn clusters are marked "good",otherwise ,they are marked "bad",which will trigger warning and critical state and send alters to sys admins
- import urllib2,sys
- class Handler(object):
- def __init__(self,vip):
- self.vip=vip
- def check_site(self):
- proxy= urllib2.ProxyHandler({"http" : 'http://%s:80'%self.vip })
- opener = urllib2.build_opener(proxy)
- urllib2.install_opener(opener)
- Req=urllib2.Request("")
- f=urllib2.urlopen(Req, timeout=60)
- return f.code
- region=sys.argv[1]
- x=region.split('_')
- ip=x[1]
- sample=Handler(ip)
- try:
- res_code=sample.check_site()
- if str(res_code) == '200' :
- print region,"seems ok"
- sys.exit(0)
- # else:
- # print "not ok"
- except Exception,e:
- print 'could not visit sina.com via',region,' please check keepalived &
添加到$Path/libexec下,在commands.cfg注册,添加相关服务即可。
阅读(2182) | 评论(0) | 转发(0) |