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

Centos7.5 installs mysql5.7.24 binary package deployment

1. Environmental preparation: Operating system: C...

Summary of 16 XHTML1.0 and HTML Compatibility Guidelines

1. Avoid declaring the page as XML type . The pag...

Summary of common Mysql DDL operations

Library Management Create a library create databa...

How to deploy nextcloud network disk using docker

NextCloud You can share any files or folders on y...

Detailed tutorial for installing mysql5.7.18 on centos7.3

1 Check the Linux distribution version [root@type...

How to decompress multiple files using the unzip command in Linux

Solution to the problem that there is no unzip co...

TypeScript generic parameter default types and new strict compilation option

Table of contents Overview Create a type definiti...

Tutorial on using the frameset tag in HTML

Frameset pages are somewhat different from ordina...

Use dockercompose to build springboot-mysql-nginx application

In the previous article, we used Docker to build ...

How to add sudo permissions to a user in Linux environment

sudo configuration file The default configuration...

How to delete garbled or special character files in Linux

Due to encoding reasons, garbled characters will ...

Canonical enables Linux desktop apps with Flutter (recommended)

Google's goal with Flutter has always been to...

Detailed explanation of the use of Vue3 state management

Table of contents background Provide / Inject Ext...