[comment]: # translation:outdated

[comment]: # ({2956300c-2956300c})
# configuration.importcompare

[comment]: # ({/2956300c-2956300c})

[comment]: # ({cd4d87f0-069ae59d})

### 描述

`array configuration.importcompare(object parameters)`


此方法允许将导入文件与当前系统元素进行比较并显示将更改的内容如果此文件被导入后。

::: noteclassic
该方法仅适用于任何类型的用户。
调用该方法的授权可以在用户角色设置中进行设置。 详情请参见[用户角色](/manual/web_interface/frontend_sections/administration/user_roles)
:::

[comment]: # ({/cd4d87f0-069ae59d})

[comment]: # ({09dbda4a-0ae26f0f})

### 参数

`(object)` 参数包含可能要导入的数据以及应如何处理数据的规则

|参数|[类型](/manual/api/reference_commentary#data_types)|说明|
|---------|---------------------------------------------------|-----------|
|**format**<br>(required)|string|序列化字符串的格式<br><br>可能的值：<br>`yaml` - YAML;<br>`xml` - XML;<br>`json` - JSON.|
|**source**<br>(required)|string|包含配置数据的序列化字符串|
|**rules**<br>(required)|object|新的或现有的对象的导入规则<br><br>`rules` 参数在下表中进行详细描述|

::: notetip
如果没有规则，配置将不被更新且结果为空。
::: 

::: notetip
仅对主机组和模板进行比较。触发器和图表将仅对导入的模板进行比较，任何其他的部分都将被视为“新的”。
:::

`rules`支持如下参数

|参数|[类型](/manual/api/reference_commentary#data_types)|说明|
|---------|---------------------------------------------------|-----------|
|discoveryRules|object|导入低级别自动发现(LLD)的规则<br><br>支持的参数:<br>`createMissing` - `(boolean)` 如果设置为`true`, 新的低级别自动发现(LLD)规则将被创建; 默认: `false`;<br>`updateExisting` - `(boolean)` 如果设置为`true`, 已有的低级别自动发现规则将被更新; 默认: `false`;<br>`deleteMissing` - `(boolean)` 如果设置为 `true`, 不在导入数据中的底层自动发现规则将会从数据库中被删除; 默认: `false`.|
|graphs|object|导入图表的规则<br><br>支持的参数:<br>`createMissing` - `(boolean)` 如果设置为`true`, 新的图表将会被创建; 默认: `false`;<br>`updateExisting` - `(boolean)` 如果设置为 `true`, 已有的图表将会被更新; 默认: `false`;<br>`deleteMissing` - `(boolean)` 如果设置为 `true`, 不在导入数据中的图表将会从数据库中被删除; 默认: `false`.|
|groups|object|导入主机组的规则<br><br>支持的参数:<br>`createMissing` - `(boolean)` 如果设置为 `true`, 新的主机组将会被创建; 默认: `false`;<br>`updateExisting` - `(boolean)` 如果设置为 `true`, 已有的主机组将会被更新; 默认: `false`.|
|hosts|object|导入主机的规则<br><br>支持的参数:<br>`createMissing` - `(boolean)` 如果设置为`true`, 新的主机将会被创建; 默认: `false`;<br>`updateExisting` - `(boolean)` 如果设置为`true`, 现有主机将被更新; 默认: `false`.<br><br>此参数对输出没有影响。它只允许与 `configuration.import`保持一致|
|httptests|object|导入web场景的规则<br><br>支持的参数:<br>`createMissing` - `(boolean)`如果设置为 `true`, 新的web监控场景将会被创建; 默认: `false`;<br>`updateExisting` - `(boolean)` 如果设置为 `true`, 现有的web监控场景将会被更新; 默认: `false`;<br>`deleteMissing` - `(boolean)` 如果设置为 `true`, 在导入数据中没有的web场景将会从数据库中彻底删除; 默认: `false`.|
|images|object|导入图片的规则<br><br>支持的参数:<br>`createMissing` - `(boolean)`如果设置为`true`, 新的图片将会被创建; 默认: `false`;<br>`updateExisting` - `(boolean)`如果设置为 `true`, 现有的图片将会被更新; 默认: `false`.<br><br>此参数对输出没有影响。它只允许与 `configuration.import`保持一致|
|items|object|导入监控项的规则<br><br>支持的参数:<br>`createMissing` - `(boolean)` 如果设置为 `true`, 新的监控项将会被创建; 默认: `false`;<br>`updateExisting` - `(boolean)` 如果设置为 `true`, 已有的监控项将会被更新; 默认: `false`;<br>`deleteMissing` - `(boolean)` 如果设置为 `true`, 不在导入数据中的监控项将会从数据库中被删除; 默认: `false`.|
|maps|object|导入拓扑图的规则<br><br>支持的参数:<br>`createMissing` - `(boolean)` 如果设置为 `true`, 新的拓扑图将会被创建; 默认: `false`;<br>`updateExisting` - `(boolean)` 如果设置为 `true`, 现有的拓扑图将被更新; 默认: `false`.<br><br>此参数对输出没有影响。它只允许与 `configuration.import`保持一致.|
|mediaTypes|object|导入媒介类型的规则<br><br>支持的参数:<br>`createMissing` - `(boolean)` 如果设置为 `true`, 新的媒介类型将被创建; 默认: `false`;<br>`updateExisting` - `(boolean)` 如果设置为 `true`, 现有的媒介类型将被更新; 默认: `false`.<br><br>此参数对输出没有影响。它只允许与 `configuration.import`保持一致.|
|templateLinkage|object|导入模板链接的规则<br><br>支持的参数:<br>`createMissing` - `(boolean)` 如果设置为 `true`, 新的模板和主机之间的链接将会被创建; 默认: `false`;<br>`deleteMissing` - `(boolean)` 如果设置为 `true`, 不在导入数据中的模板链接将会从数据库中被删除; 默认: `false`.|
|templates|object|导入模板的规则.<br><br>支持的参数:<br>`createMissing` - `(boolean)` 如果设置为 `true`, 新的模板将被创建; 默认: `false`;<br>`updateExisting` - `(boolean)` 如果设置为 `true`, 已有的模板将被更新; 默认: `false`.|
|templateDashboards|object|导入模板仪表板的规则<br><br>支持的参数:<br>`createMissing` - `(boolean)` 如果设置为 `true`, 新的模板仪表板将被创建; default: `false`;<br>`updateExisting` - `(boolean)` 如果设置为 `true`, 已有的模板仪表板将被更新; default: `false`;<br>`deleteMissing` - `(boolean)` 如果设置为 `true`, 不在导入数据中的模板仪表板将会从数据库中被删除; default: `false`.|
|triggers|object|导入触发器的规则<br><br>支持的参数:<br>`createMissing` - `(boolean)` 如果设置为 `true`, 新的触发器将被创建; 默认: `false`;<br>`updateExisting` - `(boolean)` 如果设置为 `true`, 已有的触发器将被更新; 默认: `false`;<br>`deleteMissing` - `(boolean)` 如果设置为 `true`, 不在导入数据中的触发器将会从数据库中被删除; 默认: `false`.|
|valueMaps|object|导入值映射的规则<br><br>支持的参数:<br>`createMissing` - `(boolean)` 如果设置为 `true`, 新的值映射将被创建; 默认: `false`;<br>`updateExisting` - `(boolean)`如果设置为 `true`, 已有的值映射将被更新; 默认: `false`;<br>`deleteMissing` - `(boolean)` 如果设置为 `true`, 不在导入数据中的值映射将会从数据库中被删除; 默认: `false`.|

[comment]: # ({/09dbda4a-0ae26f0f})

[comment]: # ({62203b3c-43693d8e})
### 返回值

`(array)` 以数组形式返回配置中的变更内容

[comment]: # ({/62203b3c-43693d8e})

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

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

[comment]: # ({80444c5f-d979e902})
#### 导入主机和监控项

导入YAML字符串中包含的模板和监控项。如果在YAML中缺失的监控项，它们将显示为已删除，其它内容将保持不变。

请求:

```json
{
    "jsonrpc": "2.0",
    "method": "configuration.import",
    "params": {
        "format": "xml",
        "rules": {
            "groups": {
                "createMissing": true,
                "updateExisting": true
            },
            "templates": {
                "createMissing": true,
                "updateExisting": true
            },
            "items": {
                "createMissing": true,
                "updateExisting": true,
                "deleteMissing": true
            },
            "triggers": {
                "createMissing": true,
                "updateExisting": true,
                "deleteMissing": true
            },
            "discoveryRules": {
                "createMissing": true,
                "updateExisting": true,
                "deleteMissing": true
            },
            "valueMaps": {
                "createMissing": true,
                "updateExisting": false
            }
        },
        "source": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><zabbix_export><version>5.4</version><date>2021-05-27T07:12:07Z</date><groups><group><uuid>6f6799aa69e844b4b3918f779f2abf08</uuid><name>Zabbix servers</name></group></groups><templates><template><uuid>e1bde9bf2f0544f5929f45b82502e744</uuid><template>Export template</template><name>Export template</name><groups><group><name>Zabbix servers</name></group></groups><items><item><uuid>3237bc89226e42ed8207574022470e83</uuid><name>Item</name><key>item.key</key><delay>30s</delay><valuemap><name>Host status</name></valuemap><triggers><trigger><uuid>bd1ed0089e4b4f35b762c9d6c599c348</uuid><expression>last(/Export template/item.key)=0</expression><name>Trigger</name></trigger></triggers></item></items><discovery_rules><discovery_rule><uuid>c91616bcf4a44f349539a1b40cb0979d</uuid><name>Discovery rule</name><key>rule.key</key><item_prototypes><item_prototype><uuid>7e164881825744248b3039af3435cf4b</uuid><name>Item prototype</name><key>prototype.key</key></item_prototype></item_prototypes></discovery_rule></discovery_rules><valuemaps><valuemap><uuid>7e666857c5df4af3a338349586f2afc3</uuid><name>Host status</name><mappings><mapping><value>0</value><newvalue>Up</newvalue></mapping><mapping><value>2</value><newvalue>Unreachable</newvalue></mapping></mappings></valuemap></valuemaps></template></templates></zabbix_export>"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应:

```json
{
   "jsonrpc":"2.0",
   "result":{
      "templates":{
         "updated":[
            {
               "before":{
                  "uuid":"e1bde9bf2f0544f5929f45b82502e744",
                  "template":"Export template",
                  "name":"Export template"
               },
               "after":{
                  "uuid":"e1bde9bf2f0544f5929f45b82502e744",
                  "template":"Export template",
                  "name":"Export template"
               },
               "items":{
                  "added":[
                     {
                        "after":{
                           "uuid":"3237bc89226e42ed8207574022470e83",
                           "name":"Item",
                           "key":"item.key",
                           "delay":"30s",
                           "valuemap":{
                              "name":"Host status"
                           }
                        },
                        "triggers":{
                           "added":[
                              {
                                 "after":{
                                    "uuid":"bd1ed0089e4b4f35b762c9d6c599c348",
                                    "expression":"last(/Export template/item.key)=0",
                                    "name":"Trigger"
                                 }
                              }
                           ]
                        }
                     }
                  ],
                  "removed":[
                     {
                        "before":{
                           "uuid":"bd3e7b28b3d544d6a83ed01ddaa65ab6",
                           "name":"Old Item",
                           "key":"ite_old.key",
                           "delay":"30s",
                           "valuemap":{
                              "name":"Host status"
                           }
                        }
                     }
                  ]
               },
               "discovery_rules":{
                  "updated":[
                     {
                        "before":{
                           "uuid":"c91616bcf4a44f349539a1b40cb0979d",
                           "name":"Discovery rule",
                           "key":"rule.key"
                        },
                        "after":{
                           "uuid":"c91616bcf4a44f349539a1b40cb0979d",
                           "name":"Discovery rule",
                           "key":"rule.key"
                        },
                        "item_prototypes":{
                           "updated":[
                              {
                                 "before":{
                                    "uuid":"7e164881825744248b3039af3435cf4b",
                                    "name":"Old item prototype",
                                    "key":"prototype_old.key"
                                 },
                                 "after":{
                                    "uuid":"7e164881825744248b3039af3435cf4b",
                                    "name":"Item prototype",
                                    "key":"prototype.key"
                                 }
                              }
                           ]
                        }
                     }
                  ]
               }
            }
         ]
      }
   },
   "id":1
}
```

[comment]: # ({/80444c5f-d979e902})

[comment]: # ({09510840-c9a0185c})
### 来源

CConfiguration::importcompare() in
*ui/include/classes/api/services/CConfiguration.php*.

[comment]: # ({/09510840-c9a0185c})
