array configuration.importcompare(object parameters)
此方法允许将导入文件与当前系统元素进行比较,并显示导入该文件后将发生的变更。
此方法对所有类型用户均可用。 调用该方法的权限可在用户角色设置中撤销。 更多信息请参阅User roles。
(object)
参数包含可导入的数据及数据处理规则。
参数 | 数据类型 | 描述 |
---|---|---|
format (required) |
string | 序列化string的格式。 可选值: yaml - YAML;xml - XML;json - JSON。 |
source (required) |
string | 包含配置数据的序列化string。 |
rules (required) |
object | 新objects与现有objects的导入规则。rules 参数详情见下表。 |
若未指定规则,则不会执行更新且结果为空。
仅对主机组和模板进行比对。 触发器与图形仅针对导入模板进行比对,其他内容均视为"新增"。
rules
object支持以下参数。
参数 | 数据类型 | 描述 |
---|---|---|
discoveryRules | object | LLD规则导入方式。 支持参数: createMissing - 设为true 时创建新LLD规则,默认:false ;updateExisting - 设为true 时更新现有LLD规则,默认:false ;deleteMissing - 设为true 时删除数据库中未导入的LLD规则,默认:false 。 |
graphs | object | 图形导入方式。 支持参数: createMissing - 设为true 时创建新图形,默认:false ;updateExisting - 设为true 时更新现有图形,默认:false ;deleteMissing - 设为true 时删除数据库中未导入的图形,默认:false 。 |
groups | object | 主机组导入方式。 支持参数: createMissing - 设为true 时创建新主机组,默认:false ;updateExisting - 设为true 时更新现有主机组,默认:false 。 |
hosts | object | 主机导入方式。 支持参数: createMissing - 设为true 时创建新主机,默认:false ;updateExisting - 设为true 时更新现有主机,默认:false 。此参数不影响输出结果,仅为保持与 configuration.import 的一致性而保留。 |
httptests | object | Web场景导入方式。 支持参数: createMissing - 设为true 时创建新Web场景,默认:false ;updateExisting - 设为true 时更新现有Web场景,默认:false ;deleteMissing - 设为true 时删除数据库中未导入的Web场景,默认:false 。 |
images | object | 图像导入方式。 支持参数: createMissing - 设为true 时创建新图像,默认:false ;updateExisting - 设为true 时更新现有图像,默认:false 。此参数不影响输出结果,仅为保持与 configuration.import 的一致性而保留。 |
items | object | 监控项导入方式。 支持参数: createMissing - 设为true 时创建新监控项,默认:false ;updateExisting - 设为true 时更新现有监控项,默认:false ;deleteMissing - 设为true 时删除数据库中未导入的监控项,默认:false 。 |
maps | object | 地图导入方式。 支持参数: createMissing - 设为true 时创建新地图,默认:false ;updateExisting - 设为true 时更新现有地图,默认:false 。此参数不影响输出结果,仅为保持与 configuration.import 的一致性而保留。 |
mediaTypes | object | 媒介类型导入方式。 支持参数: createMissing - 设为true 时创建新媒介类型,默认:false ;updateExisting - 设为true 时更新现有媒介类型,默认:false 。此参数不影响输出结果,仅为保持与 configuration.import 的一致性而保留。 |
templateLinkage | object | 模板链接导入方式。 支持参数: createMissing - 设为true 时链接导入数据中存在但未链接的模板,默认:false ;deleteMissing - 设为true 时解除未在导入数据中的模板链接(保留继承实体如监控项、触发器等),默认:false 。 |
templates | object | 模板导入方式。 支持参数: createMissing - 设为true 时创建新模板,默认:false ;updateExisting - 设为true 时更新现有模板,默认:false 。 |
templateDashboards | object | 模板仪表盘导入方式。 支持参数: createMissing - 设为true 时创建新模板仪表盘,默认:false ;updateExisting - 设为true 时更新现有模板仪表盘,默认:false ;deleteMissing - 设为true 时删除数据库中未导入的模板仪表盘,默认:false 。 |
triggers | object | 触发器导入方式。 支持参数: createMissing - 设为true 时创建新触发器,默认:false ;updateExisting - 设为true 时更新现有触发器,默认:false ;deleteMissing - 设为true 时删除数据库中未导入的触发器,默认:false 。 |
valueMaps | object | 主机或模板值映射导入方式。 支持参数: createMissing - 设为true 时创建新值映射,默认:false ;updateExisting - 设为true 时更新现有值映射,默认:false ;deleteMissing - 设为true 时删除数据库中未导入的值映射,默认:false 。 |
(array)
返回一个包含配置变更的array。
将XML string中包含的模板与当前系统元素进行比较, 并显示如果导入此模板将会发生哪些更改。
请求:
{
"jsonrpc": "2.0",
"method": "configuration.importcompare",
"params": {
"format": "xml",
"rules": {
"discoveryRules": {
"createMissing": true,
"updateExisting": true,
"deleteMissing": true
},
"graphs": {
"createMissing": true,
"updateExisting": true,
"deleteMissing": true
},
"groups": {
"createMissing": true,
"updateExisting": true
},
"httptests": {
"createMissing": true,
"updateExisting": true,
"deleteMissing": true
},
"items": {
"createMissing": true,
"updateExisting": true,
"deleteMissing": true
},
"templateLinkage": {
"createMissing": true,
"deleteMissing": true
},
"templates": {
"createMissing": true,
"updateExisting": true
},
"templateDashboards": {
"createMissing": true,
"updateExisting": true,
"deleteMissing": true
},
"triggers": {
"createMissing": true,
"updateExisting": true,
"deleteMissing": true
},
"valueMaps": {
"createMissing": true,
"updateExisting": true,
"deleteMissing": true
}
},
"source": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<zabbix_export><version>6.0</version><date>2023-01-01T12:30:00Z</date><groups><group><uuid>7df96b18c230490a9a0a9e2307226338</uuid><name>Templates</name></group></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><delay>3m</delay></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>648006da5971424ead0c47ddbbf1ea2e</uuid><name>CPU utilization</name><key>system.cpu.util</key><value_type>FLOAT</value_type><units>%</units><triggers><trigger><uuid>736225012c534ec480c2a66a91322ce0</uuid><expression>avg(/New template/system.cpu.util,3m)>70</expression><name>CPU utilization 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"
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": {
"templates": {
"updated": [
{
"before": {
"uuid": "5aef0444a82a4d8cb7a95dc4c0c85330",
"template": "New template",
"name": "New template"
},
"after": {
"uuid": "5aef0444a82a4d8cb7a95dc4c0c85330",
"template": "New template",
"name": "New template"
},
"items": {
"added": [
{
"after": {
"uuid": "648006da5971424ead0c47ddbbf1ea2e",
"name": "CPU utilization",
"key": "system.cpu.util",
"value_type": "FLOAT",
"units": "%"
},
"triggers": {
"added": [
{
"after": {
"uuid": "736225012c534ec480c2a66a91322ce0",
"expression": "avg(/New template/system.cpu.util,3m)>70",
"name": "CPU utilization too high on 'New host' for 3 minutes",
"priority": "WARNING"
}
}
]
}
}
],
"removed": [
{
"before": {
"uuid": "6805d4c39a624a8bab2cc8ab63df1ab3",
"name": "CPU load",
"key": "system.cpu.load",
"value_type": "FLOAT"
},
"triggers": {
"removed": [
{
"before": {
"uuid": "ab4c2526c2bc42e48a633082255ebcb3",
"expression": "avg(/New template/system.cpu.load,3m)>2",
"name": "CPU load too high on 'New host' for 3 minutes",
"priority": "WARNING"
}
}
]
}
}
],
"updated": [
{
"before": {
"uuid": "7f1e6f1e48aa4a128e5b6a958a5d11c3",
"name": "Zabbix agent ping",
"key": "agent.ping"
},
"after": {
"uuid": "7f1e6f1e48aa4a128e5b6a958a5d11c3",
"name": "Zabbix agent ping",
"key": "agent.ping",
"delay": "3m"
}
}
]
}
}
]
}
},
"id": 1
}
ui/include/classes/api/services/CConfiguration.php 中的 CConfiguration::importcompare() 方法