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

Simple steps to implement H5 WeChat public account authorization

Preface Yesterday, there was a project that requi...

IIS7 IIS8 http automatically jumps to HTTPS (port 80 jumps to port 443)

IIS7 needs to confirm whether the "URL REWRI...

Summary of commonly used SQL in MySQL operation tables

1. View the types of fields in the table describe...

Example of implementing the skeleton screen of WeChat applet

Table of contents What is a skeleton screen How t...

Basic use of javascript array includes and reduce

Table of contents Preface Array.prototype.include...

Docker runs operations with specified memory

as follows: -m, --memory Memory limit, the format...

How to configure Http, Https, WS, and WSS in Nginx

Written in front In today's Internet field, N...

Table related arrangement and Javascript operation table, tr, td

Table property settings that work well: Copy code ...

How to use echarts to visualize components in Vue

echarts component official website address: https...

Implementing file content deduplication and intersection and difference in Linux

1. Data Deduplication In daily work, there may be...