博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
利用ZABBIX的RPC-JSON作API扩展应用示例
阅读量:7114 次
发布时间:2019-06-28

本文共 2725 字,大约阅读时间需要 9 分钟。

计划将ZABBIX的一些状态可以在另一个应用的显示GRAPH及链接。

故而在网上找了几个文档,作了一个测试。

https://www.zabbix.com/documentation/2.4/manual/api/reference/graph/get

http://www.xue163.com/334/1654/3340800.html

 

复制代码
#!/usr/bin/env python#coding: utf-8import requestsimport jsonclass zabbixtools:    def __init__(self):        self.url = "http://10.1.1.1/api_jsonrpc.php"        self.headers = {
"Content-Type": "application/json"} self.authID = self.user_login() def user_login(self): data = { "jsonrpc": "2.0", "method": "user.login", "params": { "user": "guest", "password": "xxxxxxxx" }, "id": 0 } try: response = requests.post( self.url, data=json.dumps(data), headers=self.headers).json() except requests.RequestException as e: print(e) else: authID = response['result'] return authID def host_get(self,hostname): data = { "jsonrpc": "2.0", "method": "host.get", "params": { "output": "extend", "filter": { "host": [hostname,] } }, "auth": self.authID, "id": 1 } try: response = requests.post( self.url, data=json.dumps(data), headers=self.headers).json() except requests.RequestException as e: print(e) else: hostID = response['result'][0]['hostid'] return hostID def graph_get(self,hostid): data = { "jsonrpc": "2.0", "method": "graph.get", "params": { "output": "extend", "hostids": hostid, "sortfield": "name" }, "auth": self.authID, "id": 2 } try: response = requests.post( self.url, data=json.dumps(data), headers=self.headers).json() except requests.RequestException as e: print(e) else: graphID = [] for item in response['result']: graph_dict = {} graph_dict[item['graphid']] = item['name'] graphID.append(graph_dict) #print graphID return graphID def main(): test = zabbixtools() hostID = test.host_get("cnsz032955") graphID = test.graph_get(hostID) for graph_item in graphID: for key in graph_item: print graph_item[key],": http://10.1.1.1/charts.php?hostid={hostID}&graphid={graphID}".format(hostID=hostID, graphID=key)if __name__ == "__main__": main()
复制代码

载图:

 

转载地址:http://bbzel.baihongyu.com/

你可能感兴趣的文章
python3 打印99乘法表
查看>>
Linux命令总结-2
查看>>
基于glusterfs和gearman的离线任务运算分布式化方案介绍
查看>>
小学生信息技术课的有效教学
查看>>
天堂与地狱的区别
查看>>
java io小实例
查看>>
127小时
查看>>
Windows Server 2008 R2 SP1中的具体改进
查看>>
安装Discuz论坛系统
查看>>
信息系统上线时的准备
查看>>
(转)cocos2d-x2.0.3创建android程序缺失java文件的问题
查看>>
我的友情链接
查看>>
基于Metronic的Bootstrap开发框架经验总结(3)--下拉列表Select2插件的使用
查看>>
查看 MySQL 数据库中每个表占用的空间大小
查看>>
Linux登陆图形,佛祖保佑
查看>>
海洋迅雷VIP帐号获取器
查看>>
强制活动目录的站点复制
查看>>
在图形中添加一个图例
查看>>
os 模块 python file 与文件路径
查看>>
nginx 跳转配置
查看>>