boolean configuration.import(object parameters)
此方法允许从序列化的string导入配置数据。
此方法可供任何类型的用户使用。 调用该方法的权限可在用户角色设置中撤销。 更多信息请参阅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 时(boolean) ,将创建新LLD规则;默认:false ;updateExisting - 设为true 时(boolean) ,将更新现有LLD规则;默认:false ;deleteMissing - 设为true 时(boolean) ,将删除数据库中未包含在导入数据中的LLD规则;默认:false 。 |
graphs | object | 图形导入规则。 支持参数: createMissing - 设为true 时(boolean) ,将创建新图形;默认:false ;updateExisting - 设为true 时(boolean) ,将更新现有图形;默认:false ;deleteMissing - 设为true 时(boolean) ,将删除数据库中未包含在导入数据中的图形;默认:false 。 |
groups | object | 主机组导入规则。 支持参数: createMissing - 设为true 时(boolean) ,将创建新主机组;默认:false ;updateExisting - 设为true 时(boolean) ,将更新现有主机组;默认:false 。 |
hosts | object | 主机导入规则。 支持参数: createMissing - 设为true 时(boolean) ,将创建新主机;默认:false ;updateExisting - 设为true 时(boolean) ,将更新现有主机;默认:false 。 |
httptests | object | Web场景导入规则。 支持参数: createMissing - 设为true 时(boolean) ,将创建新Web场景;默认:false ;updateExisting - 设为true 时(boolean) ,将更新现有Web场景;默认:false ;deleteMissing - 设为true 时(boolean) ,将删除数据库中未包含在导入数据中的Web场景;默认:false 。 |
images | object | 图像导入规则。 支持参数: createMissing - 设为true 时(boolean) ,将创建新图像;默认:false ;updateExisting - 设为true 时(boolean) ,将更新现有图像;默认:false 。 |
items | object | 监控项导入规则。 支持参数: createMissing - 设为true 时(boolean) ,将创建新监控项;默认:false ;updateExisting - 设为true 时(boolean) ,将更新现有监控项;默认:false ;deleteMissing - 设为true 时(boolean) ,将删除数据库中未包含在导入数据中的监控项;默认:false 。 |
maps | object | 地图导入规则。 支持参数: createMissing - 设为true 时(boolean) ,将创建新地图;默认:false ;updateExisting - 设为true 时(boolean) ,将更新现有地图;默认:false 。 |
mediaTypes | object | 媒介类型导入规则。 支持参数: createMissing - 设为true 时(boolean) ,将创建新媒介类型;默认:false ;updateExisting - 设为true 时(boolean) ,将更新现有媒介类型;默认:false 。 |
templateLinkage | object | 模板链接导入规则。 支持参数: createMissing - 设为true 时(boolean) ,将链接导入数据中存在但未链接到当前主机或模板的模板;默认:false ;deleteMissing - 设为true 时(boolean) ,将解除当前主机或模板链接但未包含在导入数据中的模板链接(保留从解除链接模板继承的实体如监控项、触发器等);默认:false 。 |
templates | object | 模板导入规则。 支持参数: createMissing - 设为true 时(boolean) ,将创建新模板;默认:false ;updateExisting - 设为true 时(boolean) ,将更新现有模板;默认:false 。 |
templateDashboards | object | 模板仪表盘导入规则。 支持参数: createMissing - 设为true 时(boolean) ,将创建新模板仪表盘;默认:false ;updateExisting - 设为true 时(boolean) ,将更新现有模板仪表盘;默认:false ;deleteMissing - 设为true 时(boolean) ,将删除数据库中未包含在导入数据中的模板仪表盘;默认:false 。 |
triggers | object | 触发器导入规则。 支持参数: createMissing - 设为true 时(boolean) ,将创建新触发器;默认:false ;updateExisting - 设为true 时(boolean) ,将更新现有触发器;默认:false ;deleteMissing - 设为true 时(boolean) ,将删除数据库中未包含在导入数据中的触发器;默认:false 。 |
valueMaps | object | 主机或模板值映射导入规则。 支持参数: createMissing - 设为true 时(boolean) ,将创建新值映射;默认:false ;updateExisting - 设为true 时(boolean) ,将更新现有值映射;默认:false ;deleteMissing - 设为true 时(boolean) ,将删除数据库中未包含在导入数据中的值映射;默认:false 。 |
(boolean)
返回 true
表示导入成功。
导入包含在XML string中的模板配置。 如果XML string中缺少任何监控项或触发器,它们将从数据库中删除,其余内容将保持不变。
请求:
{
"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>6.0</version><date>2023-01-01T12:00: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></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"
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
位于 ui/include/classes/api/services/CConfiguration.php 中的 CConfiguration::import() 方法。