I am trying to compare two of xml files and update only for a certain key as a new file. The issue occurs when i export a zabbix template and try to import on the other environment, status should be left as destination one. Assume that i have two xml files,
source.xml
<zabbix_export>
<version>5.0</version>
<groups>
<group>
<name>zabbix</name>
</group>
</groups>
<templates>
<template>
<template>testtemp</template>
<name>testtemp</name>
<groups>
<group>
<name>zabbix</name>
</group>
</groups>
<items>
<item>
<name>test1</name>
<key>kernel.maxproc</key>
<triggers>
<trigger>
<expression>{last()}=0</expression>
<name>testtrig1</name>
</trigger>
<trigger>
<expression>{last()}=100</expression>
<name>testtrig2</name>
</trigger>
</triggers>
</item>
</items>
</template>
</templates>
</zabbix_export>
destination.xml
<version>5.0</version>
<groups>
<group>
<name> zabbix </name>
</group>
</groups>
<templates>
<template>
<template>testtemp</template>
<name>testtemp</name>
<groups>
<group>
<name>zabbix</name>
</group>
</groups>
<items>
<item>
<name>test1</name>
<key>kernel.maxproc</key>
<triggers>
<trigger>
<expression>{last()}=0</expression>
<name>testtrig1</name>
<status>DISABLED</status>
</trigger>
</triggers>
</item>
</items>
</template>
</templates>
</zabbix_export>
So my goal would be to create a new file and put the key/value "DISABLED" as following.
final.xml
<zabbix_export>
<version>5.0</version>
<groups>
<group>
<name>zabbix</name>
</group>
</groups>
<templates>
<template>
<template>testtemp</template>
<name>testtemp</name>
<groups>
<group>
<name>zabbix</name>
</group>
</groups>
<items>
<item>
<name>test1</name>
<key>kernel.maxproc</key>
<triggers>
<trigger>
<expression>{last()}=0</expression>
<name>testtrig1</name>
<status>DISABLED</status>
</trigger>
<trigger>
<expression>{last()}=100</expression>
<name>testtrig2</name>
</trigger>
</triggers>
</item>
</items>
</template>
</templates>
</zabbix_export>
I've found one of the closest way to achieve this behave on the post Updating two xml file using xmlstarlet but still needs a small touch. So seems better to use 'xmlstarlet' since i need to run this babe in Debian natively.
It would be great at least give a clue how to use it in that way.
Thanks in advance,