宝塔自定义告警:脚本+任务计划+企业微信+公众号

B站影视 2024-11-29 22:17 3

摘要:#coding: utf-8#@name 获取指定URL地址的响应内容#@author hwliang(hwl@bt.cn)#@print stringimport osimport sysos.chdir('/www/server/panel')sys.pa

#coding: utf-8#@name 获取指定URL地址的响应内容#@author hwliang(hwl@bt.cn)#@print stringimport osimport sysos.chdir('/www/server/panel')sys.path.insert(0,'class/')import publicimport requestsurl = 'https://www.baidu.com/'try:#去掉HTTPS的证书环节req_status = requests.get(url,timeout=30,verify=False)content = req_status.text # 获取响应内容的文本部分first_50_chars = content[:50] # 提取前50个字符first_150_chars = content[:150] # 提取前50个字符#获取状态 print(req_status.status_code)msg = 'baidu.com状态是:' + str(req_status.status_code) +';\n200(成功);400(错误请求) ;\n' + first_50_charsmsg2 = 'baidu.com状态是:' + str(req_status.status_code) +";\n200(成功);400(错误请求) ;\n" + first_150_chars#发送公众号 200(成功) 服务器已成功处理了请求。通常,这表示服务器提供了请求的网页. 400(错误请求) 服务器不理解请求的语法res_msg = public.push_msg('wx_account',{'msg':msg})#企业微信res_msg2 = public.push_msg('weixin',{'msg':msg2})if 'status' in res_msg and res_msg['status']:print("done")else:print('发送情况:')print(res_msg)except Exception as ex:print('异常:')print(ex)sys.exit(1)

来源:孙晏欣

相关推荐