Get the IP and host name of all hosts on Zabbix

Get the IP and host name of all hosts on Zabbix

zabbix

Zabbix ([`zæbiks]) is an enterprise-level open source solution that provides distributed system monitoring and network monitoring capabilities based on a WEB interface.

Zabbix can monitor various network parameters to ensure the safe operation of the server system; and provide a flexible notification mechanism to allow system administrators to quickly locate/solve various existing problems.

Zabbix consists of two parts, Zabbix server and the optional component Zabbix agent.

Zabbix server can provide remote server/network status monitoring, data collection and other functions through SNMP, Zabbix agent, ping, port monitoring and other methods. It can run on Linux, Solaris, HP-UX, AIX, Free BSD, Open BSD, OS X and other platforms.

The following code shows you how to get the IP and host names of all hosts on zabbix. The code is as follows:

#coding:utf-8
#Get the IP and host name of all hosts on zabbix import requests
import json
import csv
import time
def get_token():
  data = {
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
      "user": username,
      "password": password
    },
    "id": 0
  }
  r = requests.get(zaurl, headers=header, data=json.dumps(data))
  auth = json.loads(r.text)
  return auth["result"]
def getHosts(token):
  data = {
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
      "output": [
        "hostid",
        "host"
      ],
      "selectInterfaces": [
        "interfaceid",
        "ip"
      ]
    },
    "id": 2,
    "auth": token,
  }
  request = requests.post(zaurl, headers=header, data=json.dumps(data))
  dict = json.loads(request.content)
# print (dict['result'])
  return dict['result']
if __name__ == "__main__":
  zaurl="http://xx.xx.xx.xx/zabbix/api_jsonrpc.php"
  header = {"Content-Type": "application/json"}
  username = "xx"
  password = "xx"
  token = get_token()
  hostlist = getHosts(token)
  datafile = "zabbix.txt"
  fdata = open(datafile,'w')
  for i in hostlist:
    hostid = i['hostid']
    hostip = i['host']
    fdata.write(hostip + ' ' + hostid + '\n')
  fdata.close()

Summarize

The above is the example code for getting the IP and host name of all hosts on zabbix introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Zabbix monitors Linux hosts based on snmp
  • Detailed steps for adding hosts you need to monitor in zabbix
  • Detailed explanation of zabbix executing scripts or instructions on remote hosts
  • Python gets the host through the zabbix api
  • Detailed explanation of how to call zabbix API to obtain the host
  • How to set up Zabbix to monitor Linux hosts
  • Graphical steps of zabbix monitoring vmware exsi host

<<:  Detailed explanation of cross-usage of Ref in React

>>:  How to enable the slow query log function in MySQL

Recommend

Example of using CSS3 to create Pikachu animated wallpaper

text OK, next it’s time to show the renderings. O...

Detailed process of installing nginx1.9.1 on centos8

1.17.9 More delicious, really Nginx download addr...

Analysis of the difference between absolute path and relative path in HTML

As shown in the figure: There are many files conne...

HTML image img tag_Powernode Java Academy

summary Project description format <img src=&q...

About the configuration problem of MyBatis connecting to MySql8.0 version

When learning mybatis, I encountered an error, th...

WeChat Mini Programs Implement Star Rating

This article shares the specific code for WeChat ...

Notes on using $refs in Vue instances

During the development process, we often use the ...

The most commonly used HTML tags to create web pages

1. Optimization of commonly used HTML tags HTML s...

Which one should I choose between MySQL unique index and normal index?

Imagine a scenario where, when designing a user t...

Steps to create a Vite project

Table of contents Preface What does yarn create d...

How to use vue-video-player to achieve live broadcast

Table of contents 1. Install vue-video-player 2. ...