def get_url(url): name = url["name"] url = url["url"] html = requests.get(url=url,timeout=10) if html.status_code == 200: if name == "首页": if html.content: print get_default_arg()+name+" 检查正常" else: print get_default_arg()+name+" 检查失败,请及时处理" msg={'name':name+" 检查异常","errmsg":get_default_arg()+name+" 异常"} result = send_mail.delay(msg) print result.status else: res = json.loads(html.content) if res: print get_default_arg()+name+" 检查正常" else: print get_default_arg()+name+" 检查失败,请及时处理" msg={'name':name+" 检查异常","errmsg":get_default_arg()+name+" 异常"} result = send_mail.delay(msg) print result.status else: html = requests.post(url) if html.status_code == 200: res = json.loads(html.content) if res: print get_default_arg() +name+" 检查正常" else: print get_default_arg() +name+" 检查失败,请及时处理" msg={'name':name+" 检查异常","errmsg":get_default_arg()+name+" 异常"} result = send_mail.delay(msg) print result.status
def get_url(url): name = url["name"] url = url["url"] html = s_requests.get(url=url, timeout=10) #先用GET方法尝试 if html.status_code == 200: #如果http状态码为200,进一步判断 if name == "首页": if html.content: print get_default_arg() + name + " 检查正常" else: print get_default_arg() + name + " 检查失败,请及时处理" msg = { 'name': name + " 检查异常", "errmsg": get_default_arg() + name + " 异常" } result = send_mail.delay(msg) print result.status else: res = json.loads(html.content) #将返回的数据进行json解析,失败则报警 if res: print get_default_arg() + name + " 检查正常" else: print get_default_arg() + name + " 检查失败,请及时处理" msg = { 'name': name + " 检查异常", "errmsg": get_default_arg() + name + " 异常" } result = send_mail.delay(msg) #调用异步发送邮件报警的在这里 print result.status else: html = s_requests.post(url) #使用POST方法尝试 if html.status_code == 200: res = json.loads(html.content) if res: print get_default_arg() + name + " 检查正常" else: print get_default_arg() + name + " 检查失败,请及时处理" msg = { 'name': name + " 检查异常", "errmsg": get_default_arg() + name + " 异常" } result = send_mail.delay(msg) #调用异步发送邮件报警的在这里 print result.status
else: res = json.loads(html.content) if res: print get_default_arg()+name+" 检查正常" else: print get_default_arg()+name+" 检查失败,请及时处理" msg={'name':name+" 检查异常","errmsg":get_default_arg()+name+" 异常"} result = send_mail.delay(msg) print result.status else: html = requests.post(url) if html.status_code == 200: res = json.loads(html.content) if res: print get_default_arg() +name+" 检查正常" else: print get_default_arg() +name+" 检查失败,请及时处理" msg={'name':name+" 检查异常","errmsg":get_default_arg()+name+" 异常"} result = send_mail.delay(msg) print result.status if __name__ == "__main__": for url in index_xhr: try: get_url(url) except Exception as e: print e msg={'name':"警告!!!ToC_PC"+" "+url["name"]+"失败","errmsg":get_default_arg()+"\n"+e.message} result = send_mail.delay(msg)
print result.status else: html = s_requests.post(url) #使用POST方法尝试 if html.status_code == 200: res = json.loads(html.content) if res: print get_default_arg() + name + " 检查正常" else: print get_default_arg() + name + " 检查失败,请及时处理" msg = { 'name': name + " 检查异常", "errmsg": get_default_arg() + name + " 异常" } result = send_mail.delay(msg) #调用异步发送邮件报警的在这里 print result.status if __name__ == "__main__": s_requests = user_login(data) for url in index_xhr: try: get_url(url) except Exception as e: print e msg = { 'name': "警告!!!检查TOB_APP" + " " + url["name"] + "失败", "errmsg": get_default_arg() + "\n" + e.message } result = send_mail.delay(msg) #调用异步发送邮件报警的在这里