zabbix脚本获取web status code,异常告警

个人博客地址

http://www.darkghost.life

python代码,需要安装requests库

 1 #!/usr/bin/env python 
 2 #-*-coding:utf-8-*-
 3 import requests,os,sys
 4 url = sys.argv[1]
 5 
 6 def webcode():
 7     try:
 8         ret = requests.get(url,timeout=5)
 9         code = ret.status_code
10         return code
11     except:
12         code = 1
13         return code
14         os._exit(0)
15 if __name__  == "__main__":
16     print(webcode())

zabbix配置文件略

前端配置

 

 

报警配置

 

posted @ 2021-07-13 18:15  无限's-blog  阅读(110)  评论(0编辑  收藏  举报