当前位置: 当前位置:首页 >IT科技类资讯 >为你解放双手,Python自动获取指定主机Zabbix监控图 正文

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

2025-11-04 07:31:21 来源:多维IT资讯作者:人工智能 点击:864次
为你解放双手,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()     # 上面获取的b2b供应网是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.
作者:域名
------分隔线----------------------------
头条新闻
图片新闻
新闻排行榜