Tell me how to display all the hosts for which the value of a particular ITEM is greater than 50.
The situation is the situation, there is some template that is tied to 1000 hosts. There is an item in this template. I need to get a list of hosts for which the last value of this item is more than 50. I tried to do it through the API, as advised on the Zabbix forum. Through the API received a template ID, and item ID. But what to do next is not clear. Here's what I got:
#DES 3200 CPU get script echo "D-Link DES 3200 CPU util Get Script" zbxUser='' zbxPass='' zbxAPI='http://localhost/zabbix/api_jsonrpc.php' DATA=`date +%y%m%d%H%M%S` # Get auth token from zabbix curlOutput=`curl -sS -i -X POST -H 'Content-Type: application/json-rpc' -d "{\"params\": {\"password\": \"$zbxPass\", \"user\": \"$zbxUser\"}, \"jsonrpc\":\"2.0\", \"method\": \"user.login\", \"id\": 0}" $zbxAPI` authToken=`echo $curlOutput | sed -n 's/.*result":"\(.*\)",.*/\1/p'` # Get all monitored and problem state triggers curlData="{\"jsonrpc\": \"2.0\", \"method\": \"template.get\", \"params\": {\"search\":{\"name\":\"D-Link DES3200\"}},\"output\":[\"template.id\"], \"auth\":\"$authToken\", \"id\": 1}" curlOutput=`curl -sS -i -X POST -H 'Content-Type: application/json-rpc' -d "$curlData" $zbxAPI` echo "$curlOutput" > $DATA.log TEMPLATE=`cat $DATA.log| sed "s/,/,\n/g;s/}/\n/g" | grep "templateid" | sed s/[^0-9]//g` echo "Template ID : $TEMPLATE" rm $DATA.log #Get Item ID curlData2="{\"jsonrpc\": \"2.0\", \"method\": \"item.get\", \"params\": {\"templateids\":\"$TEMPLATE\",\"search\":{\"name\":\"CPU 5 min\"},\"searchWildcardsEnabled\":1,\"selectHosts\":[\"host\"]},\"output\":[\"lastvalue\"], \"auth\":\"$authToken\", \"id\": 2}" curlOutput2=`curl -sS -i -X POST -H 'Content-Type: application/json-rpc' -d "$curlData2" $zbxAPI` echo "$curlOutput2" > $DATA_2.log #echo $curlOutput2 ITEMID=`cat $DATA_2.log| sed "s/,/,\n/g;s/}/\n/g" | grep itemid | sed s/[^0-9]//g` echo "Item ID : $ITEMID" rm $DATA_2.log #Get host id curlData3="{\"jsonrpc\": \"2.0\", \"method\": \"host.get\",\"params\": {\"monitored_hosts\":1}, \"output\":[\"hostid\"],\"filter\":{\"itemids\":\"$ITEMID\"}, \"auth\":\"$authToken\", \"id\": 3}" curlOutput3=`curl -sS -i -X POST -H 'Content-Type: application/json-rpc' -d "$curlData3" $zbxAPI` echo "$curlOutput3" > $DATA_3.log echo $curlOutput3 | sed "s/,/,\n/g;s/}/\n/g" | grep hostid | grep -v "proxy_hostid" Prompt, can through SQL request easier? What would such a query look like?
Example output of Template ID: 12223 Item ID: 585027
"result": [{"hostid": "10084", {"hostid": "10117",
{"hostid": "10119",
{"hostid": "10157",
{"hostid": "10161",
{"hostid": "10162",
{"hostid": "10163",
{"hostid": "10164",
{"hostid": "10165",
{"hostid": "10166",
{"hostid": "10451",