zabbix 使用之——批量添加主机

添加主机

条件

上脚本

#!/bin/bash 
token=$( curl -s -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": 
        {
            "user": "Admin",
            "password": "zabbix" 
        },
    "id": 1            
}' http://192.168.47.150/zabbix/api_jsonrpc.php |cut -d ',' -f2 |cut -d":"  -f2 |cut -d "\"" -f 2 )

address=$(cat /root/ip.txt) 
for  ip in $address 
do
#flag="myql"
#echo $flag
curl -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": "2"
            }
        ],
        "templates": [
            {
                "templateid": "10001"
            }
        ]
    },
    "auth": "'$token'",
    "id": 1
}' http://192.168.47.150/zabbix/api_jsonrpc.php
done

  • 查看部分代码图
  • 运行
  • 查看zabbix server
  • 有数据了
posted @ 2020-04-21 19:12  猫九x  阅读(1518)  评论(0编辑  收藏  举报