这篇文章将为大家详细讲解有关Linux shell环境下Zabbix Api有什么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
在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
关于“Linux shell环境下Zabbix Api有什么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。