Use of Zabbix Api in Linux shell environment

Use of Zabbix Api in Linux shell environment

You can call it directly in the Linux shell environment. According to the official website: Before accessing any data in Zabbix, you need to log in and obtain an authentication token. 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.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}

According to the official website, the user authentication token "77bfe44db3f5c016477110c5748ac3e1" is returned, and all subsequent API requests need to carry it.

I queried another one in the same way, this time with the authentication token from above:

[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}

The returned host name is Zabbix server, and the host IP is 127.0.0.1

In fact, how to use the API still depends on the official website documentation, such as apiinfo.version. The official website clearly states: This method can be used for unauthenticated users and must be called without adding the "auth" parameter in the JSON-RPC request.

Here is an example:

[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}

The Zabbix API version of the target host is 3.4.14

Attached official website link:

https://www.zabbix.com/documentation/3.4/en/manual/api

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Installation and configuration method of Zabbix Agent on Linux platform
  • Zabbix monitors the process of Linux system services
  • How to install Zabbix monitoring in Linux
  • How to set up Zabbix to monitor Linux hosts
  • Zabbix configuration DingTalk alarm function implementation code
  • Detailed examples of Zabbix remote command execution
  • Detailed explanation of zabbix executing scripts or instructions on remote hosts
  • Detailed explanation of Zabbix installation and deployment practices
  • Zabbix monitors Linux hosts based on snmp

<<:  Example of using Vue built-in component keep-alive

>>:  React error boundary component processing

Recommend

Sample code for CSS dynamic loading bar effect

Using the knowledge of CSS variables, I will dire...

jQuery custom magnifying glass effect

This article example shares the specific code of ...

Introduction to Apache deployment of https in cryptography

Table of contents Purpose Experimental environmen...

Related operations of adding and deleting indexes in mysql

Table of contents 1. The role of index 2. Creatin...

Causes and solutions for slow MySQL queries

There are many reasons for slow query speed, the ...

Detailed explanation of upgrading Python and installing pip under Linux

Linux version upgrade: 1. First, confirm that the...

How to build a standardized vmware image for kubernetes under rancher

When learning kubernetes, we need to practice in ...

Detailed explanation of generic cases in TypeScript

Definition of Generics // Requirement 1: Generics...