me小怪兽

导航

zabbix批量添加被监控主机

#配置zabbix批量添加脚本

[root@localhost]# vim  add-host.sh 

#!/bin/bash

auth_code=$(
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "admin",            #zabbix登录用户
"password": "FAbBQIWvn187dxGF"    #zabbix密码
},
"id": 1,
"auth": null
}' http://192.168.12.2:20002/api_jsonrpc.php | python -m json.tool |grep result |awk -F":" '{print $2}' |awk -F"\"" '{print $2}'  #zabbix地址
)


IP="
10.0.0.22    #需要添加的ip地址
10.0.0.23
10.0.0.24
10.0.0.25
"

for node_ip in $IP;do
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "'${node_ip}'",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "'${node_ip}'",
"dns": "",
"port": "10050"    #zabbix-agent端口
}
],
"groups": [
{
"groupid": "53"    #主机群组id
}
],
"templates": [
{
"templateid": "10001"  #模板id号
}
]
},
"auth": "'${auth_code}'",
"id": 1
}' http://192.168.12.2:20002/api_jsonrpc.php | python -m json.tool    #zabbix地址

done

 

 [root@localhost]# chmod +x add-host.sh 

 

posted on 2022-09-06 14:48  me小怪兽  阅读(191)  评论(0编辑  收藏  举报