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",

  • one
    1. crawling into SQL is probably a bad idea, because Where is the guarantee that the base structure will not change in the next version of Zabbix? 2. API is better to use, because it is more stable than item 1 3. take better Python. If the API really gives out JSON, then it is easier to process it with scripting languages ​​than through the sed'it 4. console. To absolutely surely help - please give an example of the output ... - gecube
  • Thanks for the response, an example added to the question. Total hostid turns 1297 - this is the number of devices in monitoring. At the same time, I definitely know that not all devices are assigned a given item - Dan
  • Better to pastebin lay out, because SO "ate" part of output - gecube
  • I didn’t mean it a bit - I wanted the conclusion of Zabbiks. Because if it is in the form of JSON, then you simply load it as a JSON array in the Python script and then you can simply process it in it. Example pythonicway.com/education/basics/17-python-json-parse Then you just go over the array that came out of the JSON string and select the elements with "hostid"> 50 - gecube

0