You are viewing documentation for the development version, it may be incomplete.
Join our translation project and help translate Zabbix documentation into your native language.

template.get

説明

integer/array template.get(object parameters)

このメソッドは、指定されたパラメータに従ってテンプレートを取得することができます。

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

パラメーター

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

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

パラメーター 説明
templateids ID/array 指定したテンプレートIDを持つテンプレートのみを返します。
groupids ID/array 指定したテンプレートグループに属するテンプレートのみを返します。
parentTemplateids ID/array 指定したテンプレートにリンクされているテンプレートのみを返します。
hostids ID/array 指定したホスト/テンプレートにリンクされているテンプレートのみを返します。
graphids ID/array 指定したグラフを含むテンプレートのみを返します。
itemids ID/array 指定したアイテムを含むテンプレートのみを返します。
triggerids ID/array 指定したトリガーを含むテンプレートのみを返します。
with_items flag アイテムを持つテンプレートのみを返します。
with_triggers flag トリガーを持つテンプレートのみを返します。
with_graphs flag グラフを持つテンプレートのみを返します。
with_httptests flag Webシナリオを持つテンプレートのみを返します。
evaltype integer タグの評価方法

指定可能な値:
0 - (デフォルト) And/Or;
2 - Or.
tags object/array 指定したタグを持つテンプレートのみを返します。
フォーマット: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...]
空の配列はすべてのテンプレートを返します。

指定可能なoperator値:
0 - (デフォルト) 含む;
1 - 等しい;
2 - 含まない;
3 - 等しくない;
4 - 存在する;
5 - 存在しない。
selectTags query tagsプロパティでテンプレートタグを返します。
selectDiscoveryRules query テンプレートLLDルールを持つdiscoveryRulesプロパティを返します。countをサポートします。
selectHosts query hostsプロパティでテンプレートにリンクされているホストを返します。

countをサポートします。
selectTemplateGroups query templategroupsプロパティでテンプレートが属するテンプレートグループを返します。
selectTemplates query templatesプロパティで指定したテンプレートがリンクされているテンプレートを返します。

countをサポートします。
selectParentTemplates query parentTemplatesプロパティで指定したテンプレートにリンクされているテンプレートを返します。

countをサポートします。
selectHttpTests query httpTestsプロパティでテンプレートからWebシナリオを返します。

countをサポートします。
selectItems query itemsプロパティでテンプレートからアイテムを返します。

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でソート;
selectDiscoveryRules - nameでソート;
selectTriggers - descriptionでソート;
selectGraphs - nameでソート;
selectDashboards - nameでソート。
sortfield string/array 指定したプロパティで結果をソートします。

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

countをサポートします。

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

戻り値

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

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

テンプレート名によるテンプレートの取得

"Linux"と"Windows"という2つのテンプレートのすべてのデータを取得します。

リクエスト:

{
           "jsonrpc": "2.0",
           "method": "template.get",
           "params": {
               "output": "extend",
               "filter": {
                   "host": [
                       "Linux by Zabbix agent",
                       "Windows by Zabbix agent"
                   ]
               }
           },
           "id": 1
       }

レスポンス:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "proxyid": "0",
                   "host": "Linux by Zabbix agent",
                   "status": "3",
                   "ipmi_authtype": "-1",
                   "ipmi_privilege": "2",
                   "ipmi_username": "",
                   "ipmi_password": "",
                   "maintenanceid": "0",
                   "maintenance_status": "0",
                   "maintenance_type": "0",
                   "maintenance_from": "0",
                   "name": "Linux by Zabbix agent",
                   "flags": "0",
                   "templateid": "10001",
                   "description": "This is an official Linux template. It requires Zabbix agent 8.0 or newer.\r\n\r\nNotes on filesystem (FS) discovery:\r\n- The ext4/3/2 filesystem reserves space for privileged usage, typically set at 5% by default.\r\n- BTRFS allocates a default of 10% of the volume for its own needs.\r\n- To mitigate potential disasters, FS usage triggers are based on the maximum available space.\r\n  - Utilization formula: 'pused = 100 - 100 * (available / total - free + available)'\r\n- The FS utilization chart, derived from graph prototypes, reflects FS reserved space as the difference between used and available space from the total volume.\r\n\r\nYou can discuss this template or leave feedback on our forum https://www.zabbix.com/forum/zabbix-suggestions-and-feedback/387225-discussion-thread-for-official-zabbix-template-for-linux\r\n\r\nGenerated by official Zabbix template tool \"Templator\"",
                   "tls_connect": "1",
                   "tls_accept": "1",
                   "tls_issuer": "",
                   "tls_subject": "",
                   "tls_psk_identity": "",
                   "tls_psk": "",
                   "custom_interfaces": "0",
                   "uuid": "f8f7908280354f2abeed07dc788c3747",
                   "vendor_name": "Zabbix",
                   "vendor_version": "8.0-2",
                   "proxy_groupid": "0",
                   "monitored_by": "0",
                   "wizard_ready": "1",
                   "readme": "## Overview\r\n\r\nThis is an official Linux template. It requires Zabbix agent 8.0 or newer.\r\n\r\n#### Notes on filesystem (FS) discovery:\r\n- The ext4/3/2 FS reserves space for privileged usage, typically set at 5% by default.\r\n- BTRFS allocates a default of 10% of the volume for its own needs.\r\n- To mitigate potential disasters, FS usage triggers are based on the maximum available space.\r\n  - Utilization formula: `pused = 100 - 100 * (available / total - free + available)`\r\n- The FS utilization chart, derived from graph prototypes, reflects FS reserved space as the difference between used and available space from the total volume."
               },
               {
                   "proxyid": "0",
                   "host": "Windows by Zabbix agent",
                   "status": "3",
                   "ipmi_authtype": "-1",
                   "ipmi_privilege": "2",
                   "ipmi_username": "",
                   "ipmi_password": "",
                   "maintenanceid": "0",
                   "maintenance_status": "0",
                   "maintenance_type": "0",
                   "maintenance_from": "0",
                   "name": "Windows by Zabbix agent",
                   "flags": "0",
                   "templateid": "10081",
                   "description": "This is an official Windows template. It requires Zabbix agent 8.0 or newer.\r\n\r\nYou can discuss this template or leave feedback on our forum https://www.zabbix.com/forum/zabbix-suggestions-and-feedback/387224-discussion-thread-for-official-zabbix-template-for-windows\r\n\r\nGenerated by official Zabbix template tool \"Templator\"",
                   "tls_connect": "1",
                   "tls_accept": "1",
                   "tls_issuer": "",
                   "tls_subject": "",
                   "tls_psk_identity": "",
                   "tls_psk": "",
                   "custom_interfaces": "0",
                   "uuid": "13b06904a6bf41cbb795e3193d896340",
                   "vendor_name": "Zabbix",
                   "vendor_version": "8.0-2",
                   "proxy_groupid": "0",
                   "monitored_by": "0",
                   "wizard_ready": "1",
                   "readme": "## Overview\r\n\r\nThis is an official Windows template. It requires Zabbix agent 8.0 or newer."
               }
           ],
           "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}" と等しいテンプレートを取得します。

リクエスト:

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

レスポンス:

{
           "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.