LoginSignup
0
0

More than 1 year has passed since last update.

[Zabbix]ZabbixAPIで対象のテンプレートが適用されているホストを調べる方法

Last updated at Posted at 2022-05-31

テンプレート名を指定してテンプレート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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0