Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use zabbix api to add hundreds of monitoring hosts in batch

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use zabbix api to add hundreds of monitoring hosts in batches. I hope you will get something after reading this article. Let's discuss it together.

When the company is very large, it will be troublesome to add monitoring hosts manually every time. We can use zabbix's api to add monitoring hosts in batches.

This time, we will virtualize 100 hosts with one host, and automatically add monitoring hosts by means of api.

To master this method, you don't need to know python or write python scripts.

1. Get the api of adding hosts in batch

You can get it from the official website.

Https://www.zabbix.com/documentation/4.0/zh/manual/api/reference/host/create

{"jsonrpc": "2.0"," method ":" host.create "," params ": {" host ":" 192.168.81.180 "," interfaces ": [{" type ": 1," main ": 1," useip ": 1 "ip": "192.168.81.180", "dns": "", "port": "10050"}], "groups": [{"groupid": "15"}] "templates": [{"templateid": "10271"}]}, "auth": "'$token'", "id": 1}

Api required field description

Explanation:

"host": "192.168.81.160", # host name

"interfaces": [

{

"type": 1, # using agent client

"main": 1, # default

"useip": 1, # ip address

"ip": "192.168.81.160", address of # agent

"dns":

"port": "10050" # agent port

}

]

"groups": [

{

"groupid": "15" # id of the host group

}

]

"templates": [

{

"templateid": "10271" # template id

}

]

two。 Create a hundred servers

We don't have a hundred servers, but we can create a hundred network cards, all on one machine, with a hundred ip.

[root@k8s-master ~] # for i in {100.200} doifconfig ens33:$i 192.168.81.$iifconfig ens33 updone

3. Write a script to add hosts in batch 3.1. Write the ip of a hundred machines to a file [root@k8s-master ~] # echo 192.168.81. {100. 200} | xargs-N1 > / root/host.txt3.2. Install zabbix-agent [root@k8s-master] # yum-y install zabbix-agent [root@k8s-master] # vim / etc/zabbix/zabbix_agentd.conf Server=192.168.81.250 [root@k8s-master] # systemctl restart zabbix-agent3.3 on the machine. Write a script to add hosts in batch [root@k8s-master ~] # vim zabbix_host_creates.sh #! / bin/bash# add zabbix hosts in batch # Log in to token= `echo $json | grep result | awk-F' "'{print $10}'`# add hosts for ip in `cat / root/ host.txt`docurl-s-X POST-H 'Content-Type: application/json'-d'{" jsonrpc ":" 2.0 "," method ":" host.create " "params": {"host": "'$ip'", "interfaces": [{"type": 1, "main": 1, "useip": 1, "ip": "'$ip'", "dns": "" "port": "10050"}], "groups": [{"groupid": "15"}], "templates": [{"templateid": "10271"}]} "auth": "'$token'", "id": 1} 'http://192.168.81.250/zabbix/api_jsonrpc.php | python-m json.tooldone3.4. Execute the script [root@k8s-master ~] # chmod aquix zabbix_host_creates.sh [root@k8s-master ~] # sh zabbix_host_creates.sh

Script output

3.5. Check whether the monitoring host is created successfully in batch

All valid statu

After reading this article, I believe you have a certain understanding of "how to use zabbix api to add hundreds of monitoring hosts in batch". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report