在linux shell环境下直接调用就可以,根据官网所述:在访问Zabbix中的任何数据之前,你需要登录并获取身份验证令牌。这可以使用该 user.login 方法完成。
[root@localhost ~]# curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0","method":"user.login","params":{"user":"Admin","password":"zabbix"},"auth": null,"id":0}' http://192.168.149.129/zabbix/api_jsonrpc.php
HTTP/1.1 200 OK
Date: Fri, 26 Oct 2018 07:46:05 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.6.36
X-Powered-By: PHP/5.6.36
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 68
Content-Type: application/json
{"jsonrpc":"2.0","result":"77bfe44db3f5c016477110c5748ac3e1","id":0}
根据官网所述,返回了用户身份验证令牌"77bfe44db3f5c016477110c5748ac3e1",后面所有的api请求都需要带着它。
依葫芦画瓢又查询了一个,这次带着上面的身份验证令牌:
[root@localhost ~]# curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0","method":"host.get","params":{"output":["host"],"selectInterfaces":["ip"]},"auth":
"77bfe44db3f5c016477110c5748ac3e1","id":4}' http://192.168.149.129/zabbix/api_jsonrpc.p
hp
HTTP/1.1 200 OK
Date: Fri, 26 Oct 2018 08:17:23 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.6.36
X-Powered-By: PHP/5.6.36
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 111
Content-Type: application/json
{"jsonrpc":"2.0","result":[{"hostid":"10084","host":"Zabbix server","interfaces":[{"ip":"127.0.0.1"}]}],"id":4}
返回了主机名Zabbix server,主机Ip 127.0.0.1
实际上,API怎么用还是要以官网文档为准,比如apiinfo.version,官网写的很清楚:此方法可用于未经身份验证的用户,必须在发送 JSON-RPC 请求中不加“auth”参数的情况下调用。
示例如下:
[root@localhost ~]# curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0","method":"apiinfo.version","params":[],"id":5}' http://192.168.149.129/zabbix/api_
jsonrpc.php
HTTP/1.1 200 OK
Date: Fri, 26 Oct 2018 08:40:17 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.6.36
X-Powered-By: PHP/5.6.36
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 42
Content-Type: application/json
{"jsonrpc":"2.0","result":"3.4.14","id":5}
显示目标主机的Zabbix API 版本是3.4.14
附官网链接:
https://www.zabbix.com/documentation/3.4/zh/manual/api
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对软件开发网的支持。如果你想了解更多相关内容请查看下面相关链接
您可能感兴趣的文章:linux shell之通过标识测试文件系统属性的方法示例linux shell中if的各种判断linux shell之pushd、popd和dirs的使用讲解linux shell之控制台打印各种颜色字体和背景的实现方法Linux Shell在目录下使用for循环结合if查找文件的巧用Linux shell命令统计某列去重后的值Linux shell脚本的建立与执行Linux shell数组与关联数组的用法实例Android之在linux终端执行shell脚本直接打印当前运行app的日志的实现方法linux的cut命令用法总结