[comment]: # translation:outdated

[comment]: # ({1359fe15-1359fe15})
# 导入

[comment]: # ({/1359fe15-1359fe15})

[comment]: # ({347dffb3-fe885a4a})
### 描述

`boolean configuration.import(object parameters)`

该方法允许从序列化字符串导入配置数据。

::: noteclassic
此方法适用于任何类型的用户。
可以在用户角色设置中撤销调用此方法的权限。
更多信息请参见[用户角色](/manual/web_interface/frontend_sections/users/user_roles)。
:::

[comment]: # ({/347dffb3-fe885a4a})

[comment]: # ({98a53f81-147fd272})
### 参数

`(object)` 包含要导入的数据以及如何处理这些数据的参数的对象。

|参数|[类型](/manual/api/reference_commentary#数据类型)|描述|
|--|--|------|
|format|string|序列化字符串的格式。<br><br>可能的值：<br>`yaml` - YAML；<br>`xml` - XML；<br>`json` - JSON。<br><br>[参数行为](/manual/api/reference_commentary#参数行为)：<br>- *必填*|
|source|string|包含配置数据的序列化字符串。<br><br>[参数行为](/manual/api/reference_commentary#参数行为)：<br>- *必填*|
|rules|object|关于如何导入新对象和现有对象的规则。<br><br>`rules`参数在下面的表中进行了详细描述。<br><br>[参数行为](/manual/api/reference_commentary#参数行为)：<br>- *必填*|

::: notetip
如果没有给出规则，则不会更新配置。
:::

`rules`对象支持以下参数。

|参数|[类型](/manual/api/reference_commentary#数据类型)|描述|
|--|--|------|
|discoveryRules|object|关于如何导入LLD规则的规则。<br><br>支持的参数：<br>`createMissing` - `(布尔型)` 如果设置为`true`，则会创建新的LLD规则；默认值：`false`；<br>`updateExisting` - `(布尔型)` 如果设置为`true`，则会更新现有的LLD规则；默认值：`false`；<br>`deleteMissing` - `(布尔型)` 如果设置为`true`，则会从数据库中删除导入数据中不存在的LLD规则；默认值：`false`。|
|host_groups|object|关于如何导入主机组的规则。<br><br>支持的参数：<br>`createMissing` - `(布尔型)` 如果设置为`true`，则会创建新的主机组；默认值：`false`；<br>`updateExisting` - `(布尔型)` 如果设置为`true`，则会更新现有的主机组；默认值：`false`。|
|template_groups|object|关于如何导入模板组的规则。<br><br>支持的参数：<br>`createMissing` - `(布尔型)` 如果设置为`true`，则会创建新的模板组；默认值：`false`；<br>`updateExisting` - `(布尔型)` 如果设置为`true`，则会更新现有的模板组；默认值：`false`。|
|hosts|object|关于如何导入主机的规则。<br><br>支持的参数：<br>`createMissing` - `(布尔型)` 如果设置为`true`，则会创建新的主机；默认值：`false`；<br>`updateExisting` - `(布尔型)` 如果设置为`true`，则会更新现有的主机；默认值：`false`。|
|httptests|object|关于如何导入Web场景的规则。<br><br>支持的参数：<br>`createMissing` - `(布尔型)` 如果设置为`true`，则会创建新的Web场景；默认值：`false`；<br>`updateExisting` - `(布尔型)` 如果设置为`true`，则会更新现有的Web场景；默认值：`false`；<br>`deleteMissing` - `(布尔型)` 如果设置为`true`，则会从数据库中删除导入数据中不存在的Web场景；默认值：`false`。|
|templates|object|关于如何导入模板的规则。<br><br>支持的参数：<br>`createMissing` - `(布尔型)` 如果设置为`true`，则会创建新的模板；默认值：`false`；<br>`updateExisting` - `(布尔型)` 如果设置为`true`，则会更新现有的模板；默认值：`false`。|
|templateDashboards|object|关于如何导入模板仪表盘的规则。<br><br>支持的参数：<br>`createMissing` - `(布尔型)` 如果设置为`true`，则会创建新的模板仪表盘；默认值：`false`；<br>`updateExisting` - `(布尔型)` 如果设置为`true`，则会更新现有的模板仪表盘；默认值：`false`；<br>`deleteMissing` - `(布尔型)` 如果设置为`true`，则会从数据库中删除导入数据中不存在的模板仪表盘；默认值：`false`。|
|triggers|object|关于如何导入触发器的规则。<br><br>支持的参数：<br>`createMissing` - `(布尔型)` 如果设置为`true`，则会创建新的触发器；默认值：`false`；<br>`updateExisting` - `(布尔型)` 如果设置为`true`，则会更新现有的触发器；默认值：`false`；<br>`deleteMissing` - `(布尔型)` 如果设置为`true`，则会从数据库中删除导入数据中不存在的触发器；默认值：`false`。|

[comment]: # ({/98a53f81-147fd272})

[comment]: # ({08d02880-08d02880})
### 返回值

`(boolean)` 如果导入成功，则返回`true`。

[comment]: # ({/08d02880-08d02880})

[comment]: # ({b41637d2-b41637d2})
### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({fa65170d-0801380e})
#### 导入模板

导入包含在XML字符串中的模板配置。
如果XML字符串中的任何项或触发器缺失，它们将从数据库中删除，而其他所有内容将保持不变。

[请求](/manual/api#执行请求)：

```json
{
    "jsonrpc": "2.0",
    "method": "configuration.import",
    "params": {
        "format": "xml",
        "rules": {
            "templates": {
                "createMissing": true,
                "updateExisting": true
            },
            "items": {
                "createMissing": true,
                "updateExisting": true,
                "deleteMissing": true
            },
            "triggers": {
                "createMissing": true,
                "updateExisting": true,
                "deleteMissing": true
            },
            "valueMaps": {
                "createMissing": true,
                "updateExisting": false
            }
        },
        "source": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<zabbix_export><version>7.0</version><template_groups><template_group><uuid>7df96b18c230490a9a0a9e2307226338</uuid><name>Templates</name></template_group></template_groups><templates><template><uuid>5aef0444a82a4d8cb7a95dc4c0c85330</uuid><template>New template</template><name>New template</name><groups><group><name>Templates</name></group></groups><items><item><uuid>7f1e6f1e48aa4a128e5b6a958a5d11c3</uuid><name>Zabbix agent ping</name><key>agent.ping</key></item><item><uuid>77ba228662be4570830aa3c503fcdc03</uuid><name>Apache server uptime</name><type>DEPENDENT</type><key>apache.server.uptime</key><delay>0</delay><trends>0</trends><value_type>TEXT</value_type><preprocessing><step><type>REGEX</type><parameters><parameter><dt>Server uptime: (.*)<\/dt></parameter><parameter>\\1</parameter></parameters></step></preprocessing><master_item><key>web.page.get[127.0.0.1/server-status]</key></master_item></item><item><uuid>6805d4c39a624a8bab2cc8ab63df1ab3</uuid><name>CPU load</name><key>system.cpu.load</key><value_type>FLOAT</value_type><triggers><trigger><uuid>ab4c2526c2bc42e48a633082255ebcb3</uuid><expression>avg(/New template/system.cpu.load,3m)>2</expression><name>CPU load too high on 'New host' for 3 minutes</name><priority>WARNING</priority></trigger></triggers></item><item><uuid>590efe5731254f089265c76ff9320726</uuid><name>Apache server status</name><key>web.page.get[127.0.0.1/server-status]</key><trends>0</trends><value_type>TEXT</value_type></item></items><valuemaps><valuemap><uuid>8fd5814c45d44a00a15ac6eaae1f3946</uuid><name>Zabbix agent ping</name><mappings><mapping><value>1</value><newvalue>Available</newvalue></mapping><mapping><value>0</value><newvalue>Not available</newvalue></mapping></mappings></valuemap></valuemaps></template></templates></zabbix_export>\n"
    },
    "id": 1
}
```

响应:

```json
{
    "jsonrpc": "2.0",
    "result": true,
    "id": 1
}
```

[comment]: # ({/fa65170d-0801380e})

[comment]: # ({b6dce61f-c5744b74})
### 源码位置

CConfiguration::import() 在 *ui/include/classes/api/services/CConfiguration.php* 文件中。

[comment]: # ({/b6dce61f-c5744b74})
