ホストグループに所属するホスト数の取得

質問させてください。

ホストグループに所属するホスト数の取得を行いたいと考えています。

あるホストグループの
有効になっているホスト数、無効になっているホスト数など
Zabbixのアイテムでは取得できそうなものがなかったため
APIを利用して取得するしかないかなと
考えているのですが、
何かよい方法はないでしょうか。

これらのホスト数が一定ではないため、
Zabbixのアイテムとして取得し、
グラフになればと思うのですが。

もし、何かアドバイス等あれば
よろしくお願いします。

コメント表示オプション

お好みのコメント表示方法を選び「設定の保存」をクリックすると変更が反映されます。
ユーザー TNK の写真

APIで取得する場合の流れです。

ログイン:

curl -s -XGET -H 'Content-type:application/json-rpc' -d '{"jsonrpc":"2.0","method":"user.login","params":{"user":"ユーザー名","password":"パスワード"},"id": 1}' http://localhost/zabbix/api_jsonrpc.php

※一度ログインしたら返却値のauthの値を以下のAPI呼び出しで利用します。

ホストグループ名を指定してホストグループの情報を取得:

curl -s -XGET -H 'Content-type:application/json-rpc' -d '{"jsonrpc": "2.0","method": "hostgroup.get","params": {"output": "extend","filter": {"name": ["ホストグループ名"]}},"auth": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","id": 1}' http://localhost/zabbix/api_jsonrpc.php

ホストグループIDを指定して有効なホストのリストを取得:

curl -s -XGET -H 'Content-type:application/json-rpc' -d '{"jsonrpc": "2.0","method": "host.get","params": {"output": "extend","groupids": ["ホストグループのID"],"filter":{"status":"0"}},"auth": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","id": 1}' http://localhost/zabbix/api_jsonrpc.php

ホストグループIDを指定して有効なホストの件数を取得:

curl -s -XGET -H 'Content-type:application/json-rpc' -d '{"jsonrpc": "2.0","method": "host.get","params": {"output": "extend","groupids": ["ホストグループのID"],"filter":{"status":"0"}},"auth": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","id": 1}' http://localhost/zabbix/api_jsonrpc.php | jq '.result | length'

ホストグループIDを指定して無効なホストのリストを取得:

curl -s -XGET -H 'Content-type:application/json-rpc' -d '{"jsonrpc": "2.0","method": "host.get","params": {"output": "extend","groupids": ["ホストグループのID"],"filter":{"status":"1"}},"auth": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","id": 1}' http://localhost/zabbix/api_jsonrpc.php

ホストグループIDを指定して無効なホストの件数を取得:

curl -s -XGET -H 'Content-type:application/json-rpc' -d '{"jsonrpc": "2.0","method": "host.get","params": {"output": "extend","groupids": ["ホストグループのID"],"filter":{"status":"1"}},"auth": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","id": 1}' http://localhost/zabbix/api_jsonrpc.php | jq '.result | length'

ご参考まで。