前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Zabbix调用api检索方法

Zabbix调用api检索方法

作者头像
星哥玩云
发布2022-07-26 18:04:00
1.3K0
发布2022-07-26 18:04:00
举报
文章被收录于专栏:开源部署

环境

zabbix:172.16.128.16;zabbix_web:172.16.16.16/zabbix

用户名:Admin 密码:zabbix

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

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

{     "jsonrpc": "2.0",     "method": "user.login",     "params": {         "user": "Admin",         "password": "zabbix"     },     "id": 1,     "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": 1  #id - 相应请求的标识符 }

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

{     "jsonrpc": "2.0",     "method": "host.get",     "params": {         "output": [             "hostid",             "host"         ],         "selectInterfaces": [             "interfaceid",             "ip"         ]     },     "id": 1,     "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

c.由获取到的 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值

d.获取监控项历史数据

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

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条数据

e.检索多个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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档