template.get

説明

integer/array template.get(object parameters)

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

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

パラメータ

(object) 目的の出力を定義するパラメータです。

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

Parameter Type Description
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 - (デフォルト) Contains;
1 - Equals;
2 - Does not contain;
3 - Does not equal;
4 - Exists;
5 - Does not exist.
selectTags query テンプレートタグを tags プロパティで返します。
selectHosts query テンプレートにリンクされているホストを hosts プロパティで返します。

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

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

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

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 これらのパラメータはリファレンスコメントで説明されています。
editable boolean
excludeSearch boolean
filter object
limit integer
output query
preservekeys boolean
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean
selectGroups
(deprecated)
query このパラメータは非推奨です。代わりに selectTemplateGroups を使用してください。
テンプレートが属するテンプレートグループを groups プロパティで返します。

戻り値

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

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

名前でテンプレートを取得

"Linux" および "Windows" という名前の2つのテンプレートに関するすべてのデータを取得します。

リクエスト:

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

レスポンス:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "proxyid": "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"
        },
        {
            "proxyid": "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}" と等しいテンプレートを取得します。

リクエスト:

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