[@bjyf_43_77 zabbix_api_script]# cat change_VisibleName.sh
#!/bin/bash
ZABBIX_API="http://10.134.115.94/api_jsonrpc.php"
CURL_REQ="curl -s -i -X POST -H 'Content-type:application/json' -d"
HostName=$1
VisibleName=$2
function Usage()
{
echo -e "\033[33mError.Usage:sh $0 IpList VisibleName\033[0m"
echo -e "\033[34mSuch:sh $0 10.134.73.23 Lingxi_SuggLingxi_10.134.73.23\033[0m"
exit 1
}
if [ $# -ne 2 ];then
Usage
fi
#Get the HOST_ID
HOST_ID='{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"filter": {
"host": [
"'$HostName'"
]
}
},
"auth": "00000000000000000000000000000000",
"id": 1
}'
H_ID=$(curl -s -i -X POST -H 'Content-type:application/json' -d "$HOST_ID" "$ZABBIX_API"|sed -rn '/"hostid"/s/.*:"(.*)","proxy_.*/\1/gp')
echo $H_ID
#Change visible name
DATA='{
"jsonrpc": "2.0",
"method": "host.update",
"params": {
"hostid": "'$H_ID'",
"name":"'$VisibleName'"
},
"auth": "00000000000000000000000000000000",
"id": 1
}'
curl -s -i -X POST -H 'Content-type:application/json' -d "$DATA" "$ZABBIX_API"
[@bjyf_43_77 zabbix_api_script]#
zabbix可见名修改API实现
最新推荐文章于 2021-12-23 09:48:08 发布