Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1068576
  • 博文数量: 186
  • 博客积分: 4939
  • 博客等级: 上校
  • 技术积分: 2075
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-08 17:15
文章分类

全部博文(186)

文章存档

2018年(1)

2017年(3)

2016年(11)

2015年(42)

2014年(21)

2013年(9)

2012年(18)

2011年(46)

2010年(35)

分类: Python/Ruby

2011-07-07 15:37:28

  1. #!/usr/local/bin/python

  2. # --*-- coding=utf-8 --*--

  3. ############## by xiaofu ,contact at msn:xiaofu68#live.cn ####################

  4. # 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

  5. import urllib2,sys

  6. class Handler(object):

  7.         def __init__(self,vip):

  8.                 self.vip=vip

  9.         def check_site(self):

  10.                 proxy= urllib2.ProxyHandler({"http" : 'http://%s:80'%self.vip })

  11.                 opener = urllib2.build_opener(proxy)

  12.                 urllib2.install_opener(opener)

  13.                 Req=urllib2.Request("")

  14.                 f=urllib2.urlopen(Req, timeout=60)

  15.                 return f.code

  16. region=sys.argv[1]

  17. x=region.split('_')

  18. ip=x[1]

  19. sample=Handler(ip)

  20. try:

  21.   res_code=sample.check_site()

  22.   if str(res_code) == '200' :

  23.     print region,"seems ok"

  24.     sys.exit(0)

  25. # else:

  26. # print "not ok"

  27. except Exception,e:

  28.     print 'could not visit sina.com via',region,' please check keepalived &
添加到$Path/libexec下,在commands.cfg注册,添加相关服务即可。
阅读(2133) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~