2022 Zabbix中国峰会
2022 Zabbix中国峰会

创建

Description 说明

object template.create(object/array templates)

This method allows to create new templates. 此方法允许创建新模板。

Parameters 参数

(object/array) Templates to create. 创建模板。

Additionally to the standard template properties, the method accepts the following parameters. 除了标准模板属性之外,该方法接受以下属性。

Parameter 参数 T pe 类型 Des ription 说明
groups
(required 必须)
object/array 对象/数组 Hos
groups to add the template to. 模板添加到主机组。
The host groups must have the groupid property defined. 主机组必须定义groupid属性。
templates object/array 对象/数组 Tem lates to be linked to the template. 被链接到模板的模板。

The templates must have the templateid property defined. 模板必须定义templateid属性。
macros object/array 对象/数组 Use macros to be created for the template. 为模板创建的用户宏。
hosts object/array 对象/数组 Hos s to link the template to. 链接到模板的主机。

The hosts must have the hostid property defined. 主机必须定义hostid属性。

Return values 返回值

(object) Returns an object containing the IDs of the created templates under the templateids property. The order of the returned IDs matches the order of the passed templates. (object)返回一个对象,包含templateids属性中创建的模板ID,返回ID的顺序与传递模板的顺序一致。

Examples 范例

Creating a template 创建模板

Create a template and link it to two hosts. 创建一个模板并将其链接到两台主机上。

Request 请求:

{
           "jsonrpc": "2.0",
           "method": "template.create",
           "params": {
               "host": "Linux template",
               "groups": {
                   "groupid": 1
               },
               "hosts": [
                   {
                       "hostid": "10084"
                   },
                   {
                       "hostid": "10090"
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response 响应:

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

Source 源码

CTemplate::create() in frontends/php/include/classes/api/services/CTemplate.php. CTemplate::create()方法可在frontends/php/include/classes/api/services/CTemplate.php中参考。