您现在的位置是:亿华云 > IT科技类资讯

为你解放双手,Python自动获取指定主机Zabbix监控图

亿华云2025-10-04 00:46:41【IT科技类资讯】9人已围观

简介复制#获取authkey ZABBIX_URL=https://www.zabbix.cn ZABBIX_USERNAME="user"

为你解放双手,Python自动获取指定主机Zabbix监控图
复制#获取authkey  ZABBIX_URL = https://www.zabbix.cn ZABBIX_USERNAME = "user" ZABBIX_PASSWORD = "password" url = "{ }/api_jsonrpc.php".format(ZABBIX_URL)  header = { "Content-Type": "application/json"}  # auth userandpassword data = {      "jsonrpc": "2.0",为解     "method": "user.login",     "params": {          "user": ZABBIX_USERNAME,         "password": ZABBIX_PASSWORD    },     "id": 1,  }  # 由于API接收的是json字符串,服务器托管故需要转化一下  value = json.dumps(data).encode(utf-8)  # 对请求进行包装  req = request.Request(url,放双 headers=header, data=value)  # 验证并获取Auth ID  try:     # 打开包装过的url     result = request.urlopen(req)  except Exception as e:     print("Auth Failed, Please Check Your Name And Password:", e)  else:     response = result.read()     # 上面获取的源码库是bytes类型数据,云服务器提供商动获定主故需要decode转化成字符串     page = response.decode(utf-8)     # 将此json字符串转化为python字典     page = json.loads(page)     result.close()     print("Auth Successful. The Auth ID Is: { }".format(page.get(result)))  1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.

很赞哦!(61388)