def graphgethttp():
    datas = db.readtaskid(config.cronhttp)
    for i in range(0, len(datas)):
        data = ""+config.httphost+"-"+str(datas[i])+"/taskId="+str(datas[i])+",type=http,url="+config.cronhttp+""
        task = db.readhttpgetid(data)
        for p in range(0, len(task)):
            req = urllib2.Request(config.graph_ips + str(task[p]) + "&start=-3600&cf=")
            print config.graph_ips + str(task[p]) + "&start=-3600&cf="
            count = 0
            try:
                response = urllib2.urlopen(req).readline()
                ss = json.loads(response)
                if len(ss["series"]) < 1:
                    print "graph nodata"
                    os._exists(0)
                for j in range(0,11):
                    value = ss["series"][0]["data"][j]
                    if value[1] == "null":
                        count = count + 1
                if count < 11 and ss["title"].index(data):
                    print "graph response suss"
                else:
                    print "graph response fail"
            except Exception, e:
                print e
                print "graph response fail"
def graphgetdns():
    datas = db.readtaskid(config.crondns)
    for i in range(0, len(datas)):
        data = "dns-"+config.crondns+"/hostname="+config.crondns+",taskId="+str(datas[i])+",type=dns"
        task = db.readgetid(data)
        req = urllib2.Request(config.graph_ips + str(task) + "&start=-3600&cf=")
        count = 0
        try:
            response = urllib2.urlopen(req).readline()
            ss = json.loads(response)
            if len(ss["series"]) < 1:
                print "graph nodata"
                os._exit(0)
            for j in range(0, 11):
                value = ss["series"][0]["data"][j]
                if value[1] == "null":
                    count = count + 1
            if count < 11 and ss["title"] == data:
                print "graph response suss"
            else:
                print "graph response fail"
        except Exception, e:
            print e
            print "graph response fail"
Exemple #3
0
 def test_cronping(self):
     #登陆
     #driver = webdriver.Firefox()
     driver = self.driver
     #driver.get(config.baseurl + "/")
     driver.get(self.base_url + "/")
     driver.implicitly_wait(30)
     driver.switch_to_window(driver.window_handles[0])
     driver.find_element_by_id("name").clear()
     driver.find_element_by_id("name").send_keys(config.user)
     driver.find_element_by_id("password").clear()
     driver.find_element_by_id("password").send_keys(config.passwd)
     driver.find_element_by_id("sign").click()
     driver.implicitly_wait(30)
     driver.find_element_by_link_text(u"监控配置").click()
     time.sleep(5)
     driver.switch_to_window(driver.window_handles[0])
     driver.find_element_by_link_text(u"监控图管理").click()
     time.sleep(5)
     driver.switch_to_window(driver.window_handles[0])
     driver.find_element_by_link_text(u"报表管理").click()
     time.sleep(5)
     driver.switch_to_window(driver.window_handles[1])
     #判断ip管理中是否存在此ip,不存在新增
     if db.readip(config.cronip) == 0:
         driver.find_element_by_link_text("IP管理").click()
         driver.find_element_by_id("ip_name").clear()
         driver.find_element_by_id("ip_name").send_keys(config.cronip)
         driver.find_element_by_css_selector("div.pull-right > button.btn.btn-default").click()
     #新增定时任务
     if addtask.addping('{"dst":"'+config.cronip+'"}',"60","ping",config.cronhost1) == False or addtask.addping('{"dst":"'+config.cronip+'"}',"60","ping",config.cronhost2) == False:
         print "post pingcrontask fail"
         driver.quit()
         os._exit(0)
     else:
         print "post pingcrontask suss"
     time.sleep(5)
     #判断定时任务新增是否成功
     if len(db.readtaskid(config.cronip)) < 2:
         print "add pingcrontask fail"
         driver.quit()
         os._exit(0)
     else:
         print "add pingcrontask suss"
     #新增监控图
     datas = db.readtaskid(config.cronip)
     data = ''
     counts = ''
     for i in range(0, len(datas)):
         if i < len(datas)-1:
             data += "metric="+config.cronip+" metric="+str(datas[i])+"\n"
         if i == len(datas)-1:
             data += "metric="+config.cronip+" metric="+str(datas[i])+""
         if i < len(datas)-1:
             counts +="metric="+config.cronip+" metric="+str(datas[i])+"|"
         if i == len(datas)-1:
             counts +="metric="+config.cronip+" metric="+str(datas[i])+""
     if addtask.addmonitor(config.pingname,config.dashhost,"3600",data,"h","true") ==False:
         print "post pingmonitortask fail"
         driver.quit()
         os._exit(0)
     else:
         print "post pingmonitortask suss"
     time.sleep(5)
     #判断监控图任务是否新增成功
     if db.readmonitor(counts) == config.pingname:
         print "add pingmonitortask suss"
     else:
         print "add pingmonitortask fail"
         driver.quit()
         os._exit(0)
     time.sleep(300)
     #查看报表展现
     driver.switch_to_window(driver.window_handles[3])
     driver.find_element_by_xpath("//div[@id='container']/div/div/ul/li/div/button").click()
     driver.find_element_by_css_selector("li.screen > a > small").click()
     driver.find_element_by_xpath("//div[@id='container']/div/div/ul/li[2]/div/button").click()
     driver.find_element_by_css_selector("div.btn-group.open > ul.dropdown-menu > li.screen > a > small").click()
     assertresult.graphget()
     time.sleep(2)
     #删除监控图管理
     driver.switch_to_window(driver.window_handles[2])
     time.sleep(2)
     driver.find_element_by_id("g_name").clear()
     driver.find_element_by_id("g_name").send_keys(config.pingname)
     driver.find_element_by_css_selector("button.btn.btn-info").click()
     time.sleep(2)
     driver.find_element_by_name("btSelectAll").click()
     time.sleep(2)
     driver.find_element_by_css_selector("button.btn.btn-warning").click()
     self.assertRegexpMatches(self.close_alert_and_get_its_text(), u"确认删除1个图表配置?")
     #删除定时任务
     deletetask.crondel(config.cronip)
     time.sleep(2)
     #退出登录
     driver.switch_to_window(driver.window_handles[0])
     time.sleep(2)
     driver.find_element_by_link_text(u"用户登录/退出").click()
     driver.find_element_by_link_text(u"退出").click()
     driver.quit()
Exemple #4
0
 def test_crondns(self):
     #登陆
     driver = self.driver
     driver.get(self.base_url + "/")
     driver.implicitly_wait(30)
     driver.switch_to_window(driver.window_handles[0])
     driver.find_element_by_id("name").clear()
     driver.find_element_by_id("name").send_keys(config.user)
     driver.find_element_by_id("password").clear()
     driver.find_element_by_id("password").send_keys(config.passwd)
     driver.find_element_by_id("sign").click()
     driver.implicitly_wait(30)
     driver.find_element_by_link_text(u"监控配置").click()
     time.sleep(5)
     driver.switch_to_window(driver.window_handles[0])
     driver.find_element_by_link_text(u"监控图管理").click()
     time.sleep(5)
     driver.switch_to_window(driver.window_handles[0])
     driver.find_element_by_link_text(u"报表管理").click()
     time.sleep(5)
     driver.switch_to_window(driver.window_handles[1])
     #新增定时任务
     if addtask.adddns('{ "url":"'+config.cronhttp+'","host":"'+config.httphost+'","referer":"","cookie":"","userAgent":"","maxSpeed":104857,"timeout":20,"method":"GET"}',config.cronhost2,"300","http") == False:
         print "post httpcrontask fail"
         driver.quit()
         os._exit(0)
     else:
         print "post httpcrontask suss"
     time.sleep(5)
     #判断定时任务新增是否成功
     if len(db.readtaskid(config.cronhttp)) < 1:
         print "add httpcrontask fail"
         driver.quit()
         os._exit(0)
     else:
         print "add httpcrontask suss"
     #新增监控图
     datas = db.readtaskid(config.cronhttp)
     data = ''
     counts = ''
     for i in range(0, len(datas)):
         if i < len(datas)-1:
             data += "metric="+config.httphost+" metric="+str(datas[i])+"\n"
         if i == len(datas)-1:
             data += "metric="+config.httphost+" metric="+str(datas[i])+""
         if i < len(datas)-1:
             counts +="metric="+config.httphost+" metric="+str(datas[i])+"|"
         if i == len(datas)-1:
             counts +="metric="+config.httphost+" metric="+str(datas[i])+""
     if addtask.addmonitor(config.httpname,config.dashhost2,"3600",data,"h","true") ==False:
         print "post httpmonitortask fail"
         driver.quit()
         os._exit(0)
     else:
         print "post httpmonitortask suss"
     time.sleep(5)
     #判断监控图任务是否新增成功
     if db.readmonitor(counts) == config.httpname:
         print "add httpmonitortask suss"
     else:
         print "add httpmonitortask fail"
         driver.quit()
         os._exit(0)
     time.sleep(300)
     #查看报表展现
     driver.switch_to_window(driver.window_handles[3])
     driver.find_element_by_xpath("//div[@id='container']/div/div/ul/li/div/button").click()
     driver.find_element_by_css_selector("li.screen > a > small").click()
     driver.find_element_by_xpath("//div[@id='container']/div/div/ul/li[2]/div/button").click()
     driver.find_element_by_css_selector("div.btn-group.open > ul.dropdown-menu > li.screen > a > small").click()
     assertresult.graphgethttp()
     time.sleep(2)
     # 删除监控图管理
     driver.switch_to_window(driver.window_handles[2])
     time.sleep(2)
     driver.find_element_by_id("g_name").clear()
     driver.find_element_by_id("g_name").send_keys(config.httpname)
     driver.find_element_by_css_selector("button.btn.btn-info").click()
     time.sleep(2)
     driver.find_element_by_name("btSelectAll").click()
     time.sleep(2)
     driver.find_element_by_css_selector("button.btn.btn-warning").click()
     self.assertRegexpMatches(self.close_alert_and_get_its_text(), u"确认删除1个图表配置?")
     #删除定时任务
     deletetask.crondel(config.cronhttp)
     time.sleep(2)
     #退出登录
     driver.switch_to_window(driver.window_handles[0])
     time.sleep(2)
     driver.find_element_by_link_text(u"用户登录/退出").click()
     driver.find_element_by_link_text(u"退出").click()
     driver.quit()