环境

zabbix:172.16.128.16;zabbix_web:172.16.16.16/zabbix

用户名:Admin 密码:zabbix

获取的数据仅做参考,以Linux发送HTTP的POST请求为例

1.登录并获取身份验证令牌

{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin",
"password": "zabbix"
},
"id": ,
"auth": null
}
curl -H "Content-Type: application/json-rpc" -d '{"jsonrpc":"2.0","method":"user.login","params":{"user":"Admin","password":"zabbix"},"id":1,"auth":null}' http://172.16.128.16/zabbix/api_jsonrpc.php

如果你正确提供了凭据,API返回的响应将包含用户身份验证令牌

{
"jsonrpc": "2.0",  #jsonrpc - JSON-RPC协议的版本
"result": "7ef823a58b59c1a17f519fe4d0e3cc44",  #result - 方法返回的数据
"id":   #id - 相应请求的标识符
}

2.检索所有已配置主机ID,主机名和接口

{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": [
"hostid",
"host"
],
"selectInterfaces": [
"interfaceid",
"ip"
]
},
"id": ,
"auth": "7ef823a58b59c1a17f519fe4d0e3cc44"  #auth - 属性现在设置为我们通过调用user.login方法获得的身份验证令牌
}
curl -H "Content-Type: application/json-rpc" -d '{"jsonrpc":"2.0","method":"host.get","params":{"output":["hostid","host"],"selectInterfaces":["interfaceid","ip"]},"id":1,"auth":"7ef823a58b59c1a17f519fe4d0e3cc44"}' http://172.16.128.16/zabbix/api_jsonrpc.php

3.由获取到的 hostid 利用 item.get 得到 itemid 以及其 lastvalue

curl -H 'Content-Type: application/json-rpc' -d '{"jsonrpc": "2.0","method":"host.get","params":{"output":["hostid"],"filter": {"host":"50278791-59ab-2966-e86a-e04cd01eff6a"}},"auth": "7ef823a58b59c1a17f519fe4d0e3cc44","id":1}' http://172.16.128.16/zabbix/api_jsonrpc.php  #通过host名称,检索hostid
curl -H "Content-Type: application/json-rpc" -d '{"jsonrpc": "2.0","method": "item.get","params": {"output": "extend","hostids": "27789","search": {"key_": "vmware.vm.cpu.usage"},"sortfield": "name"},"id":1,"auth":"7ef823a58b59c1a17f519fe4d0e3cc44"}' http://172.16.128.16/zabbix/api_jsonrpc.php  #通过hostid,获取itemid 及其lastvalue值
curl -H "Content-Type: application/json-rpc" -d '{"jsonrpc": "2.0","method": "item.get","params": {"output": "extend","hostids": "27789","itemids": "1095468","sortfield": "name"},"id":1,"auth":"7ef823a58b59c1a17f519fe4d0e3cc44"}' http://172.16.128.16/zabbix/api_jsonrpc.php  #通过hostid和itemid,检索lastvalue值

4.获取监控项历史数据

{
"jsonrpc": "2.0",
"method": "history.get",
"params": {
"output": "extend",
"history": ,  #对象类型
"itemids": "",
"sortfield": "clock",
"sortorder": "DESC",
"limit": 10  #数据数量
},
"auth": "7ef823a58b59c1a17f519fe4d0e3cc44",
"id":
}

curl -H "Content-Type: application/json-rpc" -d '{"jsonrpc": "2.0","method": "history.get","params": {"output": "extend","history": 3,"itemids": "1095468","sortfield": "clock","sortorder": "DESC","limit":10},"id":1,"auth":"7ef823a58b59c1a17f519fe4d0e3cc44"}' http://172.16.128.16/zabbix/api_jsonrpc.php  #从无符号数字监控项中获取最近10条数据

5.检索多个itemid

curl -H "Content-Type: application/json-rpc" -d '{"jsonrpc":"2.0","method":"history.get","params":{"output":"extend","hostids":"1095468","itemids":["26353","26352","26357","26356","26355","26354","26359","26358","25754","25750","25751","25748","25768","25755","25752","25759","25760","25753","25761","26348","26350","26349","26351","25749","25767","25756","25757","25758","25769","25770","25771"],"sortfield":"clock","sortorder":"DESC","limit": 31},"id":1,"auth":"7ef823a58b59c1a17f519fe4d0e3cc44"}' http://172.16.128.16/zabbix/api_jsonrpc.php

最新文章

  1. Sublime text追踪函数插件:ctags
  2. HDU 1258 Sum It Up
  3. Gson 和 FastJson 性能测试
  4. ASP.NET运行时详解 生命周期入口分析
  5. SimpleDateFormat出错
  6. bzoj2734 集合选数
  7. 修改MySQL数据库的密码
  8. MYSQL基础笔记(二)-SQL基本操作
  9. Shell变量命名规则
  10. poj2418 map 快排水过
  11. ORM版学员管理系统 3
  12. vue项目性能优化,优化项目加载慢的问题
  13. Hadoop生态圈-单点登录框架之CAS(Central Authentication Service)部署
  14. day28(ajax之js原生代码实现)
  15. 关于angular的$resource中的isArray属性问题
  16. npm用法及离线安装方法
  17. <sourceDirectory>src/main/java</sourceDirectory> mvn 配置 包路径
  18. R基础-适合于纯小白
  19. 《浅析Entity Framework Core中的并发处理》引起的思考
  20. Hdu1255 覆盖的面积

热门文章

  1. SpaceSyntax【空间句法】之DepthMapX学习:第一篇 数据的输入 与 能做哪些分析
  2. 只用最适合的!全面对比主流 .NET 报表控件
  3. getopt与getopt_long
  4. linux 上安装多个不同版本的mysql 踩的坑
  5. python接口自动化(九)--python中字典和json的区别(详解)
  6. 《代码整洁之道》(Clean Code)- 读书笔记
  7. 【工利其器】必会工具之(三)systrace篇(1)官网翻译
  8. Data Warehouse
  9. 关于获取资源文件,Class.getResource和ClassLoader.getResource的区别
  10. Linux 用户与组的基本操作及文件权限位的设置方法