利用ZABBIX的RPC-JSON作API扩展应用示例
计划将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-8 import requests import json class 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()
载图:
利用ZABBIX的RPC-JSON作API扩展应用示例的更多相关文章
- 利用 Django REST framework 编写 RESTful API
利用 Django REST framework 编写 RESTful API Updateat 2015/12/3: 增加 filter 最近在玩 Django,不得不说 rest_framewor ...
- Spark RDD API扩展开发
原文链接: Spark RDD API扩展开发(1) Spark RDD API扩展开发(2):自定义RDD 我们都知道,Apache Spark内置了很多操作数据的API.但是很多时候,当我们在现实 ...
- 利用JavaScriptSerializer类 进行Json对象的序列化和反序列化和过滤
项目下载:JavaScriptSerializer_对JSON对象序列化与反序列化及过滤器 利用<JavascriptSerializer类> 进行Json对象的序列化和反序列化 1. 首 ...
- 利用Vert.x构建简单的API 服务、分布式服务
目前已经使用Vertx已经一年多了,虽然没有太多的造诣,但也已在项目中推广了下:从最初的vertx搭建web服务,到项目上线运营,还算比较稳定.再到后来尝试搭建基于vertx的分布式服务,一路下来也积 ...
- Python第十四天 序列化 pickle模块 cPickle模块 JSON模块 API的两种格式
Python第十四天 序列化 pickle模块 cPickle模块 JSON模块 API的两种格式 目录 Pycharm使用技巧(转载) Python第一天 安装 shell 文件 Py ...
- 16 利用Zabbix完成windows监控
点击返回:自学Zabbix之路 16 利用Zabbix完成windows监控 1.安装zabbix_agentd 1.1.下载zabbix_agentd监控客户端软件安装包(windows操作系统客户 ...
- 17 利用Zabbix完成VMare监控
点击返回:自学Zabbix之路 17 利用Zabbix完成VMare监控 最近在研究通过Zabbix监控VMware vSphere,Zabbix Documentation 3.0 从文档中我们看到 ...
- 利用zabbix监控oracle数据库
一.概述 zabbix是一款非常强大,同时也是应用最为广泛的开源监控软件,本文将给大家介绍如何利用zabbix监控oracle数据库. 二.环境介绍 以下是我安装的环境,实际部署时并不需要跟我的环境一 ...
- DataTable和DataRow利用反射直接转换为Model对象的扩展方法类
DataTable和DataRow利用反射直接转换为Model对象的扩展方法类 /// <summary> /// 类 说 明:给DataTable和DataRow扩展方法,直接转换为 ...
随机推荐
- Android之Http网络编程(一)
Android应用作为一个客户端程序绝大部分都是需要进行网络请求和访问的,而http通信是一种比较常见并常用的通信方式. 在Android中http网络编程中有两种实现方式,一种是使用HttpURLC ...
- SQL Server 错误检测与修复
简介 在一个理想的世界中,不会存在任何数据库的损坏,就像我们不会将一些严重意外情况列入我们生活中的日常一样,而一旦这类事情发生,一定会对我们的生活造成非常显著的影响,在SQL Server中也同样如此 ...
- C#集合之Hashtable
Hashtable是一个键值对集合,其泛型版本是Dictionary<K, V>,下面说下常用的一些方法; 1.Add(),向Hashtable添加元素,需要注意的是因为它是键值对集合,所 ...
- ###STL学习--vector
点击查看Evernote原文. #@author: gr #@date: 2014-08-11 #@email: forgerui@gmail.com vector的相关问题.<stl学习> ...
- .net 生成pdf表格
只需要建一个类文件就搞定了 public class CreatePDF { public static CreatePDF Current { get { return new CreatePDF( ...
- HttpClient Post Get请求方法,留在以后可能会用到
/// <summary> /// Post请求返回实体 /// </summary> /// <param name="url">请求地址&l ...
- jquery的effect-color对easyui没效果.自己冒险写个边框的颜色闪烁.
"jquery-ui-effect-color.js" 是从jqueryui下载的color动画部分(自己改了个名字). 链接 <!DOCTYPE html> < ...
- ubuntu获取硬盘的uuid。
1.用UUID来标识硬盘有很多好处,它是一个硬盘的唯一代号,所以当硬盘插口位置变化时,虽然sda可能会变成sdc,但这个码是不会变的.所以在 fstab中用/dev/sda1这样的硬盘标识可能会有混乱 ...
- leetcode problem 42 -- Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- 转载 shell sort
http://blog.sina.com.cn/s/blog_6d09b5750100x6zg.html 首先是shell排序实现多列排序,这里添加竖线以作分割,如下文件test: a|gggg|4| ...