Get the App
SLTechnology News&Howtos  ›  Servers  › 

What is the use of Zabbix Api in Linux shell environment

Shulou Source: shulou.com Published: 2022-06-01 18:18:53 10月05日 Update

This article will explain in detail about the use of Zabbix Api in the Linux shell environment. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

You can call it directly in the linux shell environment, according to the official website: you need to log in and obtain an authentication token before accessing any data in Zabbix. This can be done using the user.login method.

[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.phpHTTP/1.1 200 OKDate: Fri 26 Oct 2018 07:46:05 GMTServer: Apache/2.4.6 (CentOS) PHP/5.6.36X-Powered-By: PHP/5.6.36Access-Control-Allow-Origin: * Access-Control-Allow-Headers: Content-TypeAccess-Control-Allow-Methods: POSTAccess-Control-Max-Age: 1000Content-Length: 68Content-Type: application/json {"jsonrpc": "2.0", "result": "77bfe44db3f5c016477110c5748ac3e1", "id": 0}

According to the official website, the user authentication token "77bfe44db3f5c016477110c5748ac3e1" is returned, which is required for all subsequent api requests.

According to the gourd painting ladle, another query, this time with the above authentication token:

[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.phpHTTP/1.1 200 OKDate: Fri 26 Oct 2018 08:17:23 GMTServer: Apache/2.4.6 (CentOS) PHP/5.6.36X-Powered-By: PHP/5.6.36Access-Control-Allow-Origin: * Access-Control-Allow-Headers: Content-TypeAccess-Control-Allow-Methods: POSTAccess-Control-Max-Age: 1000Content-Length: 111Content-Type: application/json {"jsonrpc": "2.0", "result": [{"hostid": "10084", "host": "Zabbix server" "interfaces": [{"ip": "127.0.0.1"}]}], "id": 4}

Hostname Zabbix server, host Ip 127.0.0.1 is returned

In fact, how to use API should be based on the official website documents, such as apiinfo.version, which clearly states that this method can be used for unauthenticated users and must be called without the "auth" parameter in sending JSON-RPC requests.

Examples are as follows:

[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.phpHTTP/1.1 200 OKDate: Fri 26 Oct 2018 08:40:17 GMTServer: Apache/2.4.6 (CentOS) PHP/5.6.36X-Powered-By: PHP/5.6.36Access-Control-Allow-Origin: * Access-Control-Allow-Headers: Content-TypeAccess-Control-Allow-Methods: POSTAccess-Control-Max-Age: 1000Content-Length: 42Content-Type: application/json {"jsonrpc": "2.0", "result": "3.4.14", "id": 5}

Shows that the Zabbix API version of the target host is 3.4.14

This is the end of this article on "what is the use of Zabbix Api in the Linux shell environment". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Identity authentication environment host token article more user good practical clear according to the gourd content parameters actual actually situation data document article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB NVidia MySQL Shulou Tech Info OPPO Reno