I've been attempting to read through the documentation to figure out how I can use the API to poll a list of servers that fall into a particular class. In this case, we use the tag name ServerClass and tag value of MySQL. Can someone please help me out with an example and put it into the docs? I hope this solution will help others. :-)
Code:
$ cat test9.sh
#!/bin/bash
source auth.sh
read -r -d '' DATA <<EOF
{
"auth": $AUTH,
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output":["hostid","host"],
"selectTags": ["tag", "value"],
"selectInheritedTags": ["tag", "value"],
"tags": [{"tag": "ServerClass", "value": "MySQL"}]
},
"id": 1
}
EOF
echo "DATA=$DATA"
echo -e '------------------------------------------------------------------------'
curl -Lk -s -X POST -H 'Content-Type:application/json' -d "$DATA" $API_URL | jq '.result'
$ ./test9.sh
DATA={
"auth": "21...e5",
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output":["hostid","host"],
"selectTags": ["tag", "value"],
"selectInheritedTags": ["tag", "value"],
"tags": [{"tag": "ServerClass", "value": "MySQL"}]
},
"id": 1
}
------------------------------------------------------------------------
... returns *way* too many hosts. I want to limit it to just servers with the tag or inherited tag.
Comment