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 | 指定した深刻度の障害のみを持つホストを返します。problemオブジェクトがトリガーである場合にのみ適用されます。 |
| 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
}
ホストレベルだけでなく、リンクされた親テンプレートにもこれらのタグを持つホストを取得します。
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["name"],
"tags": [
{
"tag": "os",
"value": "rhel-7",
"operator": 1
}
],
"inheritedTags": true
},
"id": 1
}
レスポンス:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10623",
"name": "PC room 1"
},
{
"hostid": "10601",
"name": "Office"
}
],
"id": 1
}
タグ "component" を持つホストを除外して取得します。
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["hostid"],
"selectTags": "extend",
"evaltype": 0,
"tags": [
{
"tag": "component",
"value": "",
"operator": 5
}
]
},
"id": 1
}
レスポンス:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10084",
"tags": [
{
"tag": "class",
"value": "os",
"automatic": "0"
},
{
"tag": "target",
"value": "linux",
"automatic": "0"
}
]
},
{
"hostid": "10629",
"tags": [
{
"tag": "class",
"value": "application",
"automatic": "0"
},
{
"tag": "target",
"value": "browser",
"automatic": "0"
}
]
}
],
"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
}
ホストのアイテムの取得
"Zabbix server" ホストのアイテムを取得します。リクエストは、アイテムのプロパティ itemid、name、status に限定されています。レスポンスサイズが大きいため、この例ではアイテムの一部のみを示しています。
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["hostid"],
"selectItems": ["itemid","name","status"],
"filter": {
"host": [
"Zabbix server"
]
}
},
"id": 1
}
レスポンス:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10084",
"items": [
{
"itemid": "42227",
"name": "Host name of Zabbix agent running",
"status": "0"
},
{
"itemid": "42237",
"name": "Zabbix agent ping",
"status": "0"
},
{
"itemid": "42250",
"name": "Version of Zabbix agent running",
"status": "0"
},
{
"itemid": "42251",
"name": "Maximum number of open file descriptors",
"status": "0"
},
{
"itemid": "42252",
"name": "Maximum number of processes",
"status": "0"
},
{
"itemid": "69869",
"name": "Interface enp0s3: Inbound packets discarded",
"status": "0"
},
{
"itemid": "69870",
"name": "Interface enp0s3: Inbound packets with errors",
"status": "0"
},
{
"itemid": "69871",
"name": "Interface enp0s3: Bits received",
"status": "0"
},
{
"itemid": "69872",
"name": "Interface enp0s3: Outbound packets discarded",
"status": "0"
},
{
"itemid": "69873",
"name": "Interface enp0s3: Outbound packets with errors",
"status": "0"
},
{
"itemid": "69874",
"name": "Interface enp0s3: Bits sent",
"status": "0"
},
{
"itemid": "42253",
"name": "Number of processes",
"status": "0"
},
{
"itemid": "42254",
"name": "Number of running processes",
"status": "0"
},
{
"itemid": "42255",
"name": "System boot time",
"status": "0"
}
]
}
],
"id": 1
}
関連項目
ソース
CHost::get() in ui/include/classes/api/services/CHost.php.