テンプレート名を指定してテンプレートID取得
curl -sS -d '
{
"jsonrpc": "2.0",
"method": "template.get",
"params":
{
"output": "extend",
"filter":
{
"name":
["<テンプレート名>"]
}
},
"auth": "<認証キー>",
"id": 1
}
' -H "Content-Type:application/json-rpc" https://<zabbixのIP>/zabbix/api_jsonrpc.php | python -mjson.tool | grep templateid | gawk -F'"' '{print $4}'
取得したIDを利用してテンプレートIDに紐づくホスト一覧を取得
curl -sS -d '
{
"jsonrpc":"2.0",
"method":"host.get",
"params":
{
"output":"extend",
"selectInterfaces":"extend",
"templateids":"<テンプレートID>"
},
"auth": "<認証キー>",
"id": 1
}
' -H "Content-Type:application/json-rpc" https://<zabbixのIP>/zabbix/api_jsonrpc.php | jq -r -c '.result[] | .host' | more