• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

python通过zabbix api获取主机

python 搞代码 4年前 (2022-01-08) 21次浏览 已收录 0个评论

这篇文章主要为大家详细介绍了python通过zabbix api获取主机,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

zabbix强大地方在于有强大的api,zabbix 的api可以拿到za来源gaodaimacom搞#^代%!码&网bbix大部分数据,目前我所需的数据基本可以通过api获取,以下是通过zabbix api获取的主机信息python代码,其他数据也如此类推,api使用方法可参见官网文档:

 #!/usr/bin/env python #-*- coding: utf-8 -*- import json import urllib2 from urllib2 import URLError from login import zabbix_login t=zabbix_login() def hostid_get(): data = json.dumps( { "jsonrpc": "2.0", "method": "host.get", "params": { "output": "extend", "groupids":14, "filter":{"flags": "4" }, }, "auth":t.user_login(), "id": 1, }) request = urllib2.Request(t.url, data) for key in t.header: request.add_header(key, t.header[key]) try: result = urllib2.urlopen(request) except URLError as e: if hasattr(e, 'reason'): print 'zabbix server is faile' print 'Reason: ', e.reason elif hasattr(e, 'code'): print 'zabbix server not request.' print 'Error code: ', e.code else: response = json.loads(result.read()) result.close() hostid=[] hostname=[] for host in response['result']: hostid.append(host['hostid']) hostname.append(host['name']) return hostid,hostname if __name__ == "__main__": a,b=hostid_get() i=0 n=len(b) for i in range(n): print a[i],b[i]

以上就是python通过zabbix api获取主机的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python通过zabbix api获取主机
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址