host.get
説明
integer/array host.get(object parameters)
このメソッドを使用すると、指定したパラメータに従ってホストを取得できます。
このメソッドは、あらゆる種類のユーザーが利用できます。メソッドの呼び出し権限は、ユーザーのロール設定で取り消すことができます。詳細は User roles を参照してください。
パラメータ
(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>"}, ...]。空の配列を指定すると、すべてのホストを返します。 指定可能な演算子の値: 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 プロパティを返します。Template オブジェクトのフィールドに加えて、 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.