[root@keepalived1 ~]# cat zabbix-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",
"password": "zabbix"
},
"id": 1,
"auth": null
}' http://10.0.0.20:800/api_jsonrpc.php | python -m json.tool |grep result |awk -F":" '{print $2}' |awk -F"\"" '{print $2}'
)
IP="
10.0.0.22
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"
}
],
"groups": [
{
"groupid": "2"
}
],
"templates": [
{
"templateid": "10281"
}
]
},
"auth": "'${auth_code}'",
"id": 1
}' http://10.0.0.20:800/api_jsonrpc.php | python -m json.tool
done