template.update

説明

object template.update(object/array templates)

このメソッドは、既存のテンプレートを更新するためのものです。

このメソッドは管理者およびスーパ管理者ユーザータイプでのみ利用可能です。メソッドの呼び出し権限はユーザーロール設定で取り消すことができます。詳細はユーザーロールを参照してください。

パラメータ

(object/array) 更新するテンプレートのプロパティ。

各テンプレートにはtemplateidプロパティを定義する必要があり、他のプロパティはオプションです。指定されたプロパティのみが更新され、他は変更されません。

標準のテンプレートプロパティに加えて、このメソッドは以下のパラメータを受け付けます。

パラメータ 説明
groups object/array テンプレートが属する現在のテンプレートグループを置き換えるテンプレートグループ

テンプレートグループにはgroupidプロパティのみを定義する必要があります。
tags object/array 現在のテンプレートタグを置き換えるテンプレートタグ
macros object/array 指定したテンプレートの現在のユーザーマクロを置き換えるユーザーマクロ
templates object/array 現在リンクされているテンプレートを置き換えるテンプレート。渡されていないテンプレートはアンリンクのみされます。

テンプレートにはtemplateidプロパティのみを定義する必要があります。
templates_clear object/array 指定したテンプレートからアンリンクしてクリアするテンプレート

テンプレートにはtemplateidプロパティのみを定義する必要があります。

戻り値

(object) templateids プロパティの下で更新されたテンプレートの ID を含むオブジェクトを返します。

標準テンプレートプロパティの変更

テンプレートの技術名を「Linux by Zabbix agent Custom」、表示名を「My template」、テンプレートの説明を更新します。

リクエスト:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "host": "Linux by Zabbix agent Custom",
        "name": "My template",
        "description": "This is a custom Linux template."
    },
    "id": 1
}

レスポンス:

{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "10086"
        ]
    },
    "id": 1
}

テンプレートグループの更新

指定したテンプレートのすべてのテンプレートグループを別のものに置き換えます。

リクエスト:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "groups": [
            {
                "groupid": "24"
            } 
        ]
    },
    "id": 1
}

レスポンス:

{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "10086"
        ]
    },
    "id": 1
}

複数のテンプレートグループの更新

複数のテンプレートのすべてのテンプレートグループを異なるものに置き換えます。

リクエスト:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": [
        {
            "templateid": "10086",
            "groups": [
                {
                    "groupid": "24"
                }
            ]
        },
        {
            "templateid": "10087",
            "groups": [
                {
                    "groupid": "1"
                },
                {
                    "groupid": "12"
                }
            ]
        },
        {
            "templateid": "10088",
            "groups": [
                {
                    "groupid": "1"
                },
                {
                    "groupid": "12"
                }
            ]
        }
    ],
    "id": 1
}

レスポンス:

{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "10086",
            "10087",
            "10088"
        ]
    },
    "id": 1
}

テンプレートタグの更新

すべてのテンプレートタグを別のものに置き換えます。

リクエスト:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "tags": [
            {
                "tag": "host-name",
                "value": "{HOST.NAME}"
            }
        ]
    },
    "id": 1
}

レスポンス:

{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "10086"
        ]
    },
    "id": 1
}

テンプレートマクロの更新

すべてのテンプレートマクロを別のものに置き換えます。

リクエスト:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "macros": [
            {
                "macro": "{$MY_MACRO}",
                "value": "new_value"
            }
        ]
    },
    "id": 1
}

レスポンス:

{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "10086"
        ]
    },
    "id": 1
}

複数のテンプレートマクロの更新

複数のテンプレートで、すべてのユーザーマクロを指定したユーザーマクロに置き換えます。

リクエスト:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": [
            {
                "templateid": "10087",
                "macros": [
                    {
                        "macro": "{$AGENT.TIMEOUT}",
                        "value": "5m",
                        "description": "Timeout after which agent is considered unavailable. Works only for agents reachable from Zabbix server/proxy (passive mode)."
                    }
                ]
            },
            {
                "templateid": "10088",
                "macros": [
                    {
                        "macro": "{$AGENT.TIMEOUT}",
                        "value": "5m",
                        "description": "Timeout after which agent is considered unavailable. Works only for agents reachable from Zabbix server/proxy (passive mode)."
                    }
                ]
            }
        ],
    "id": 1
}

レスポンス:

{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "10087",
            "10088"
        ]
    },
    "id": 1
}

テンプレートのリンクテンプレートの更新

指定したテンプレートからすべてのテンプレートのリンクを解除し(クリアせず)、別のテンプレートをリンクします。

リクエスト:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "templates": [
            {
                "templateid": "10001"
            }
        ]
    },
    "id": 1
}

レスポンス:

{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "10086"
        ]
    },
    "id": 1
}

複数のテンプレートからリンクされたテンプレートをクリアする

指定したテンプレートから特定のリンクされたテンプレートのリンクを解除し、クリアします。

リクエスト:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": [
        {
            "templateid": "10087",
            "templates_clear": [
                {
                    "templateid": "10001"
                }
            ]
        },
        {
            "templateid": "10088",
            "templates_clear": [
                {
                    "templateid": "10001"
                }
            ]
        }
    ],
    "id": 1
}

レスポンス:

{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "10087",
            "10088"
        ]
    },
    "id": 1
}

ソース

CTemplate::update() in ui/include/classes/api/services/CTemplate.php.