integer/array template.get(object parameters)
このメソッドで、指定されたパラメーターに従ってテンプレートを取得できます。
このメソッドはどのタイプのユーザーでも利用可能です。このメソッドを呼び出す権限は、ユーザーロール設定で取り消すことができます。詳しくはユーザーの役割を参照してください。
(object) 目的の出力を定義するパラメーター。
このメソッドは、次のパラメーターをサポートしています。
| パラメータ | タイプ | 説明 |
|---|---|---|
| templateids | string/array | 指定されたテンプレート ID を持つテンプレートのみを返します |
| groupids | string/array | 指定されたホスト グループに属するテンプレートのみを返します |
| parentTemplateids | string/array | 指定されたテンプレートの親であるテンプレートのみを返します |
| hostids | string/array | 指定されたホスト/テンプレートにリンクされているテンプレートのみを返します |
| graphids | string/array | 指定されたグラフを含むテンプレートのみを返します。 |
| itemids | string/array | 指定された項目を含むテンプレートのみを返します。 |
| triggerids | string/array | 指定されたトリガーを含むテンプレートのみを返します。 |
| with_items | flag | アイテムを持つテンプレートのみを返します。 |
| with_triggers | flag | トリガーを持つテンプレートのみを返します。 |
| with_graphs | flag | グラフを持つテンプレートのみを返します。 |
| with_httptests | flag | Web シナリオを含むテンプレートのみを返します。 |
| evaltype | integer | タグ検索のルール 使用可能な値: 0 - (デフォルト) And/Or 2 - Or |
| tags | array/object | タグによる完全一致と、演算子の値に応じたタグ値による大文字と小文字の区別または区別なしで指定したタグを持つテンプレートのみを返します。 フォーマット: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...]配列が空の時はすべてのテンプレートを返します。 可能な演算子の値: 0 - (デフォルト) 含む 1 - 等しい 2 - 含まない 3 - 等しくない 4 - 存在する 5 - 存在しない |
| selectGroups | query | groups プロパティでテンプレートが属するホスト グループを返します。 |
| selectTags | query | tags プロパティでテンプレート タグを返します。 |
| selectHosts | query | hosts プロパティでテンプレートにリンクされているホストを返します。count をサポートします。 |
| selectTemplates | query | templates プロパティで、テンプレートが子であるテンプレートを返します。count をサポートします。 |
| selectParentTemplates | query | parent Templates プロパティで、テンプレートが親であるテンプレートを返します。count をサポートします。 |
| selectHttpTests | query | httpTests プロパティのテンプレートから Web シナリオを返します。count をサポートします。 |
| selectItems | query | items プロパティのテンプレートからアイテムを返します。count をサポートします。 |
| selectDiscoveries | query | discoveries プロパティでテンプレートからローレベルディスカバリを返します。count をサポートします。 |
| selectTriggers | query | triggers プロパティでテンプレートからトリガーを返します。count をサポートします。 |
| selectGraphs | query | graphs プロパティでテンプレートからグラフを返します。count をサポートします。 |
| selectMacros | query | macros プロパティでテンプレートからマクロを返します |
| selectDashboards | query | dashboards プロパティのテンプレートからダッシュボードを返します。count をサポートします。 |
| selectValueMaps | query | テンプレート値マップを含む valuemaps プロパティを返します。 |
| limitSelects | integer | 副問い合わせによって返されるレコードの数を制限します。 次の副問い合わせに適用されます。 selectTemplates - 結果は name でソートされます。selectHosts - host でソート。selectParentTemplates - host でソート。selectItems - name でソート。selectDiscoveries - name でソート。selectTriggers - description でソート。selectGraphs - name でソート。selectDashboards - name でソート。 |
| sortfield | string/array | 指定されたプロパティで結果を並べ替えます。 使用可能な値は次のとおりです: hostid、host、name、status。 |
| countOutput | boolean | すべてのgetメソッドに共通するこれらのパラメーターについてはリファレンス解説ページで詳しく説明されています。 |
| editable | boolean | |
| excludeSearch | boolean | |
| filter | object | |
| limit | integer | |
| output | query | |
| preservekeys | boolean | |
| search | object | |
| searchByAny | boolean | |
| searchWildcardsEnabled | boolean | |
| sortorder | string/array | |
| startSearch | boolean |
(integer/array) 次のいずれかを返します:
countOutputパラメータが使用されている場合、取得されたオブジェクトの数"Linux"と"Windows"という名前の 2 つのテンプレートに関するすべてのデータを取得します。
Request:
{ "jsonrpc": "2.0", "method": "template.get", "params": { "output": "extend", "filter": { "host": [ "Linux", "Windows" ] } }, "auth": "038e1d7b1735c6a5436ee9eae095879e", "id": 1 }Response:
{ "jsonrpc": "2.0", "result": [ { "proxy_hostid": "0", "host": "Linux", "status": "3", "disable_until": "0", "error": "", "available": "0", "errors_from": "0", "lastaccess": "0", "ipmi_authtype": "0", "ipmi_privilege": "2", "ipmi_username": "", "ipmi_password": "", "ipmi_disable_until": "0", "ipmi_available": "0", "snmp_disable_until": "0", "snmp_available": "0", "maintenanceid": "0", "maintenance_status": "0", "maintenance_type": "0", "maintenance_from": "0", "ipmi_errors_from": "0", "snmp_errors_from": "0", "ipmi_error": "", "snmp_error": "", "jmx_disable_until": "0", "jmx_available": "0", "jmx_errors_from": "0", "jmx_error": "", "name": "Linux", "flags": "0", "templateid": "10001", "description": "", "tls_connect": "1", "tls_accept": "1", "tls_issuer": "", "tls_subject": "", "tls_psk_identity": "", "tls_psk": "", "uuid": "282ffe33afc74cccaf1524d9aa9dc502" }, { "proxy_hostid": "0", "host": "Windows", "status": "3", "disable_until": "0", "error": "", "available": "0", "errors_from": "0", "lastaccess": "0", "ipmi_authtype": "0", "ipmi_privilege": "2", "ipmi_username": "", "ipmi_password": "", "ipmi_disable_until": "0", "ipmi_available": "0", "snmp_disable_until": "0", "snmp_available": "0", "maintenanceid": "0", "maintenance_status": "0", "maintenance_type": "0", "maintenance_from": "0", "ipmi_errors_from": "0", "snmp_errors_from": "0", "ipmi_error": "", "snmp_error": "", "jmx_disable_until": "0", "jmx_available": "0", "jmx_errors_from": "0", "jmx_error": "", "name": "Windows", "flags": "0", "templateid": "10081", "description": "", "tls_connect": "1", "tls_accept": "1", "tls_issuer": "", "tls_subject": "", "tls_psk_identity": "", "tls_psk": "", "uuid": "522d17e1834049be879287b7c0518e5d" } ], "id": 1 }テンプレート "Linux by Zabbix エージェント"が所属するテンプレートグループを取得します。
{ "jsonrpc": "2.0", "method": "template.get", "params": { "output": ["hostid"], "selectTemplateGroups": "extend", "filter": { "host": [ "Linux by Zabbix agent" ] } }, "id": 1 }Response:
{ "jsonrpc": "2.0", "result": [ { "templateid": "10001", "templategroups": [ { "groupid": "10", "name": "Templates/Operating systems", "uuid": "846977d1dfed4968bc5f8bdb363285bc" } ] } ], "id": 1 }"10001"(Linux by Zabbix エージェント) テンプレートがリンクされているホストを取得します。
{ "jsonrpc": "2.0", "method": "template.get", "params": { "output": "templateid", "templateids": "10001", "selectHosts": ["hostid", "name"] }, "id": 1 }Response:
{ "jsonrpc": "2.0", "result": [ { "templateid": "10001", "hosts": [ { "hostid": "10084", "name": "Zabbix server" }, { "hostid": "10603", "name": "Host 1" }, { "hostid": "10604", "name": "Host 2" } ] } ], "id": 1 }タグ"Host name"が"{HOST.NAME}"に等しいテンプレートを取得します。
Retrieve templates that have tag "Host name" equal to "{HOST.NAME}".
Request:
{ "jsonrpc": "2.0", "method": "template.get", "params": { "output": ["hostid"], "selectTags": "extend", "evaltype": 0, "tags": [ { "tag": "Host name", "value": "{HOST.NAME}", "operator": 1 } ] }, "auth": "038e1d7b1735c6a5436ee9eae095879e", "id": 1 }Response:
{ "jsonrpc": "2.0", "result": [ { "hostid": "10402", "tags": [ { "tag": "Host name", "value": "{HOST.NAME}" } ] } ], "id": 1 }CTemplate::get() in ui/include/classes/api/services/CTemplate.php.