host.get

説明

integer/array host.get(object parameters)

このメソッドは、与えられたパラメータにしたがってホストを取得することができます。

このメソッドは、すべてのタイプのユーザーが利用できます。メソッドを呼び出す権限は、ユーザーの役割の設定で取り消すことができます。詳細はユーザーの役割を参照してください。

パラメーター

(object) 望ましい出力を定義するパラメーター。

このメソッドは以下のパラメーターをサポートします。

パラメーター 説明
groupids ID/array 指定したグループに属するホストのみを返します。
dserviceids ID/array 指定した検出サービスに関連するホストのみを返します。
graphids ID/array 指定したグラフを持つホストのみを返します。
hostids ID/array 指定したホストIDを持つホストのみを返します。
httptestids ID/array 指定したWebチェックを持つホストのみを返します。
interfaceids ID/array 指定したインターフェースを使用するホストのみを返します。
itemids ID/array 指定したアイテムを持つホストのみを返します。
maintenanceids ID/array 指定したメンテナンスの影響を受けるホストのみを返します。
monitored_hosts flag 監視対象のホストのみを返します。
proxyids ID/array 指定したプロキシによって監視されているホストのみを返します。
proxy_groupids ID/array 指定したプロキシグループによって監視されているホストのみを返します。
templated_hosts flag ホストとテンプレートの両方を返します。
templateids ID/array 指定したテンプレートにリンクされているホストのみを返します。
triggerids ID/array 指定したトリガーを持つホストのみを返します。
with_items flag アイテムを持つホストのみを返します。

with_monitored_itemsおよびwith_simple_graph_itemsパラメーターを上書きします。
with_item_prototypes flag アイテムプロトタイプを持つホストのみを返します。

with_simple_graph_item_prototypesパラメーターを上書きします。
with_simple_graph_item_prototypes flag 作成が有効で情報の型が数値のアイテムプロトタイプを持つホストのみを返します。
with_graphs flag グラフを持つホストのみを返します。
with_graph_prototypes flag グラフプロトタイプを持つホストのみを返します。
with_httptests flag Webチェックを持つホストのみを返します。

with_monitored_httptestsパラメーターを上書きします。
with_monitored_httptests flag 有効なWebチェックを持つホストのみを返します。
with_monitored_items flag 有効なアイテムを持つホストのみを返します。

with_simple_graph_itemsパラメーターを上書きします。
with_monitored_triggers flag 有効なトリガーを持つホストのみを返します。トリガーで使用されているすべてのアイテムも有効でなければなりません。
with_simple_graph_items flag 情報の型が数値のアイテムを持つホストのみを返します。
with_triggers flag トリガーを持つホストのみを返します。

with_monitored_triggersパラメーターを上書きします。
withProblemsSuppressed boolean trueに設定した場合、抑制された問題を持つホストのみを返します。
evaltype integer タグ評価方法

指定可能な値:
0 - (デフォルト) And/Or;
2 - Or。
severities integer/array 指定した深刻度の問題のみを持つホストを返します。問題オブジェクトがトリガーの場合のみ適用されます。
tags object/array 指定したタグを持つホストのみを返します。
フォーマット: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...]
空の配列はすべてのホストを返します。

指定可能なoperator値:
0 - (デフォルト) 含む;
1 - 等しい;
2 - 含まない;
3 - 等しくない;
4 - 存在する;
5 - 存在しない。
inheritedTags boolean 指定したtagsがリンクされているすべてのテンプレートにも存在するホストを返します。

指定可能な値:
true - リンクされたテンプレートにも指定したtagsが必要;
false - (デフォルト) リンクされたテンプレートのタグは無視されます。
selectDiscoveryData query ホスト検出オブジェクトデータを持つdiscoveryDataプロパティを返します。ホスト検出オブジェクトは、検出されたホストを、そのホストが検出されたホストプロトタイプにリンクします。

以下のプロパティを持ちます:
host - (string) ホストのID;
parent_hostid - (string) ホストが作成されたホストプロトタイプのID;
status - (int) ホスト検出ステータス:
0 - (デフォルト) ホストは検出済み,
1 - ホストはもはや検出されていない;
ts_delete - (timestamp) もはや検出されていないホストが削除される時刻;
ts_disable - (timestamp) もはや検出されていないホストが無効化される時刻;
disable_source - (int) ホストがLLDルールまたは手動で無効化されたかどうかの指標:
0 - (デフォルト) 自動的に無効化,
1 - LLDルールによって無効化。
selectDiscoveryRule query ホストを作成した低レベル検出ルール(VMware監視のホストプロトタイプから)のdiscoveryRuleプロパティを返します。
selectDiscoveryRules query ホストのLLDルールを持つdiscoveryRulesプロパティを返します。countをサポートします。
selectGraphs query ホストのグラフを持つgraphsプロパティを返します。

countをサポートします。
selectHostGroups query ホストが属するホストグループデータを持つhostgroupsプロパティを返します。
selectHttpTests query ホストのWebシナリオを持つhttpTestsプロパティを返します。

countをサポートします。
selectInterfaces query ホストインターフェースを持つinterfacesプロパティを返します。

countをサポートします。
selectInventory query ホストインベントリデータを持つinventoryプロパティを返します。
selectItems query ホストアイテムを持つitemsプロパティを返します。

countをサポートします。
selectMacros query ホストマクロを持つmacrosプロパティを返します。
selectParentTemplates query ホストがリンクされているテンプレートを持つparentTemplatesプロパティを返します。

テンプレートオブジェクトのフィールドに加え、link_type - (integer) テンプレートがホストにリンクされている方法を含みます。
指定可能な値:
0 - (デフォルト) 手動でリンク;
1 - LLDによって自動的にリンク。

countをサポートします。
selectDashboards query dashboardsプロパティを返します。

countをサポートします。
selectTags query ホストタグを持つtagsプロパティを返します。
selectInheritedTags query ホストにリンクされているすべてのテンプレートに存在するタグを持つinheritedTagsプロパティを返します。
selectTriggers query ホストトリガーを持つtriggersプロパティを返します。

countをサポートします。
selectValueMaps query ホストの値のマッピングを持つvaluemapsプロパティを返します。
filter object 指定したフィルターと完全一致する結果のみを返します。

オブジェクトを受け入れ、キーはプロパティ名、値は一致させる値または値の配列です。

textデータ型のプロパティはサポートしません。

追加プロパティをサポートします: ホストインターフェースのプロパティ。
limitSelects integer サブセレクトによって返されるレコード数を制限します。

以下のサブセレクトに適用されます:
selectParentTemplates - 結果はhostでソートされます;
selectInterfaces;
selectItems - nameでソート;
selectDiscoveryRules - nameでソート;
selectTriggers - descriptionでソート;
selectGraphs - nameでソート;
selectDashboards - nameでソート。
search object 指定したパターンに一致する結果を返します(大文字小文字を区別しません)。

オブジェクトを受け入れ、キーはプロパティ名、値は検索する文字列です。追加オプションが指定されていない場合、LIKE "%…%"検索を実行します。

stringおよびtextデータ型のプロパティのみをサポートします。

追加プロパティをサポートします: ホストインターフェースのプロパティ。
searchInventory object 指定したパターンに一致するインベントリデータを持つホストを返します(大文字小文字を区別しません)。

オブジェクトを受け入れ、キーはプロパティ名、値は検索する文字列です。追加オプションが指定されていない場合、LIKE "%…%"検索を実行します。

stringおよびtextデータ型のプロパティのみをサポートします。
sortfield string/array 指定したプロパティで結果をソートします。

指定可能な値: hostid, host, name, status
countOutput boolean これらのパラメーターはリファレンス解説で説明されています。
editable boolean
excludeSearch boolean
limit integer
output query
preservekeys boolean
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean
selectDiscoveries query ホストの低レベル検出ルールを持つdiscoveriesプロパティを返します。

countをサポートします。

このクエリは非推奨です。代わりにselectDiscoveryRulesを使用してください。
selectHostDiscovery query ホスト検出オブジェクトデータを持つhostDiscoveryプロパティを返します。

このクエリは非推奨です。代わりにselectDiscoveryDataを使用してください。

戻り値

(integer/array) 次のいずれかを返します:

  • オブジェクトの配列
  • countOutputパラメーターが使用されている場合、取得したオブジェクトの数

名前によるデータの取得

"Zabbix server"と"Linux server"という名前の2つのホストに関するすべてのデータを取得します。

リクエスト :

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "filter": {
            "host": [
                "Zabbix server",
                "Linux server"
            ]
        }
    },
    "id": 1
}

レスポンス :

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10160",
            "proxyid": "0",
            "host": "Zabbix server",
            "status": "0",
            "ipmi_authtype": "-1",
            "ipmi_privilege": "2",
            "ipmi_username": "",
            "ipmi_password": "",
            "maintenanceid": "0",
            "maintenance_status": "0",
            "maintenance_type": "0",
            "maintenance_from": "0",
            "name": "Zabbix server",
            "flags": "0",
            "description": "The Zabbix monitoring server.",
            "tls_connect": "1",
            "tls_accept": "1",
            "tls_issuer": "",
            "tls_subject": "",
            "proxy_groupid": "0",
            "monitored_by": "0",
            "inventory_mode": "1",
            "active_available": "1",
            "assigned_proxyid": "0"
        },
        {
            "hostid": "10167",
            "proxyid": "0",
            "host": "Linux server",
            "status": "0",
            "ipmi_authtype": "-1",
            "ipmi_privilege": "2",
            "ipmi_username": "",
            "ipmi_password": "",
            "maintenanceid": "0",
            "maintenance_status": "0",
            "maintenance_type": "0",
            "maintenance_from": "0",
            "name": "Linux server",
            "flags": "0",
            "description": "",
            "tls_connect": "1",
            "tls_accept": "1",
            "tls_issuer": "",
            "tls_subject": "",
            "proxy_groupid": "0",
            "monitored_by": "0",
            "inventory_mode": "1",
            "active_available": "1",
            "assigned_proxyid": "0"
        }
    ],
    "id": 1
}

ホストグループの取得

ホスト"Zabbix server"が所属するホストグループ取得します。

リクエスト :

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "selectHostGroups": "extend",
        "filter": {
            "host": [
                "Zabbix server"
            ]
        }
    },
    "id": 1
}

レスポンス :

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10085",
            "hostgroups": [
                {
                    "groupid": "2",
                    "name": "Linux servers",
                    "flags": "0",
                    "uuid": "dc579cd7a1a34222933f24f52a68bcd8"
                },
                {
                    "groupid": "4",
                    "name": "Zabbix servers",
                    "flags": "0",
                    "uuid": "6f6799aa69e844b4b3918f779f2abf08"
                }
            ]
        }
    ],
    "id": 1
}

リンク先テンプレートの取得

ホスト"10084"にリンクしているテンプレートのIDおよび名前を取得します。

リクエスト :

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "selectParentTemplates": [
            "templateid",
            "name"
        ],
        "hostids": "10084"
    },
    "id": 1
}

レスポンス :

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10084",
            "parentTemplates": [
                {
                    "name": "Linux",
                    "templateid": "10001"
                },
                {
                    "name": "Zabbix Server",
                    "templateid": "10047"
                }
            ]
        }
    ],
    "id": 1
}

テンプレートでホストの取得

テンプレート"10001"(Linux by Zabbix agent) がリンクされているホストを取得します。

リクエスト :

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid", "name"],
        "templateids": "10001"
    },
    "id": 1
}

レスポンス :

{
    "jsonrpc": "2.0",
    "result": [
        {
            "templateid": "10001",
            "hosts": [
                {
                    "hostid": "10084",
                    "name": "Zabbix server"
                },
                {
                    "hostid": "10603",
                    "name": "Host 1"
                },
                {
                    "hostid": "10604",
                    "name": "Host 2"
                }
            ]
        }
    ],
    "id": 1
}

ホストインベントリのデータで検索

ホストインベントリの"OS"フィールドに"Linux"が含まれるホストを検索します

リクエスト :

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": [
            "host"
        ],
        "selectInventory": [
            "os"
        ],
        "searchInventory": {
            "os": "Linux"
        }
    },
    "id": 1
}

レスポンス :

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10084",
            "host": "Zabbix server",
            "inventory": {
                "os": "Linux Ubuntu"
            }
        },
        {
            "hostid": "10107",
            "host": "Linux server",
            "inventory": {
                "os": "Linux Mint"
            }
        }
    ],
    "id": 1
}

ホストタグで検索

タグ"host-name"が"linux-server"と等しいホストを取得します。

リクエスト:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "selectTags": "extend",
        "evaltype": 0,
        "tags": [
            {
                "tag": "host-name",
                "value": "linux-server",
                "operator": 1
            }
        ]
    },
    "id": 1
}

レスポンス:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10085",
            "tags": [
                {
                    "tag": "host-name",
                    "value": "linux-server",
                    "automatic": "0"
                },
                {
                    "tag": "os",
                    "value": "rhel-7",
                    "automatic": "0"
                }
            ]
        }
    ],
    "id": 1
}

Retrieve hosts that have these tags not only on host level but also in their linked parent templates.

Request:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["name"],
        "tags": [
            {
                "tag": "os",
                "value": "rhel-7",
                "operator": 1
            }
        ],
        "inheritedTags": true
    },
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10623",
            "name": "PC room 1"
        },
        {
            "hostid": "10601",
            "name": "Office"
        }
    ],
    "id": 1
}

タグとテンプレートタグでホストの検索

タグと親テンプレートにリンクされているすべてのタグでホストを取得します。

リクエスト:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["name"],
        "hostids": 10502,
        "selectTags": ["tag", "value"],
        "selectInheritedTags": ["tag", "value"]
    },
    "id": 1
}

レスポンス:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10502",
            "name": "Desktop",
            "tags": [
                {
                    "tag": "host-name",
                    "value": "linux-server"
                },
                {
                    "tag": "os",
                    "value": "rhel-7"
                }
            ],
            "inheritedTags": [
                {
                    "tag": "class",
                    "value": "os"
                },
                {
                    "tag": "target",
                    "value": "linux"
                },
                {
                    "tag": "os",
                    "value": "rhel-7"
                }
            ]
        }
    ],
    "id": 1
}

障害の深刻度でホストの検索

"Disaster"の障害を持つホストを取得します。

リクエスト :

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["name"],
        "severities": 5
    },
    "id": 1
}

レスポンス :

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10160",
            "name": "Zabbix server"
        }
    ],
    "id": 1
}

"Average"と"High"の障害を持つホストを取得します。

リクエスト :

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["name"],
        "severities": [3, 4]
    },
    "id": 1
}

レスポンス :

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "20170",
            "name": "Database"
        },
        {
            "hostid": "20183",
            "name": "workstation"
        }
    ],
    "id": 1
}

参照

ソース

CHost::get() in ui/include/classes/api/services/CHost.php.