批量更新

描述

object template.massupdate(object parameters)

该方法允许同时替换或移除相关对象,并更新多个模板的属性。

这个方法只有 管理员超级管理员 两个用户类型可用。可以在用户角色设置中取消调用该方法的权限。查看 [用户角色(/manual/web_interface/frontend_sections/users/user_roles) 获取更多信息。

参数

(object) 参数包含要更新的模板的ID以及要替换的对象。

这个方法接受下列参数。

参数 类型 描述
templates object/array 要更新的模版

模版必须有已定义的 templateid 属性。

参数行为:
- 必需
groups object/array 要替换模版所属的当前模版组的模版组。

模版组必须有已经定义的 groupid 属性。
macros object/array 要替换给定模版上所有当前用户宏的用户宏用户宏
templates_clear object/array 要从给定模版中取消链接并清除的模版

模版必须有已定义的 templateid 属性。
templates_link object/array 要替换当前链接的模版

模版必须有已定义的 templateid 属性。

返回值

(object) 返回一个对象,该对象包含templateids属性下已更新模板的ID。

示例

取消模板的链接

从给定的模板中取消链接并清除模板 "10091"。

请求:

{
    "jsonrpc": "2.0",
    "method": "template.massupdate",
    "params": {
        "templates": [
            {
                "templateid": "10085"
            },
            {
                "templateid": "10086"
            }
        ],
        "templates_clear": [
            {
                "templateid": "10091"
            }
        ]
    },
    "id": 1
}

响应:

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

替换用户宏

在多个模板上用给定的用户宏替换所有用户宏。

请求:

{
    "jsonrpc": "2.0",
    "method": "template.massupdate",
    "params": {
        "templates": [
            {
                "templateid": "10074"
            },
            {
                "templateid": "10075"
            },
            {
                "templateid": "10076"
            },
            {
                "templateid": "10077"
            }
        ],
        "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": [
            "10074",
            "10075",
            "10076",
            "10077"
        ]
    },
    "id": 1
}

参阅

来源

CTemplate::massUpdate() 在 ui/include/classes/api/services/CTemplate.php.