monitoringartist / zabbix-template-converter

:triangular_ruler: Zabbix template XML/JSON/YAML converter
GNU General Public License v2.0
18 stars 12 forks source link

4.0 support #1

Open mjtrangoni opened 5 years ago

mjtrangoni commented 5 years ago

Hi @jangaraj,

I was testing your project, and there is a parsing issue with the trends storage period values.

See,

$ zabbix-template-converter -in zbx_export_templates.xml -out zbx_export_templates.yaml
Input XML file unmarshal error: strconv.ParseInt: parsing "365d": invalid syntax
$ grep -ri "365d" zbx_export_templates.xml | uniq -c
     34                     <trends>365d</trends>

Zabbix Version: 4.0.5

Or you can also write down in the README.md that the project only support Zabbix 4.4 upwards, which I realize after reading the code.

jangaraj commented 5 years ago

Trends fixed in https://github.com/monitoringartist/go-zabbix/commit/7f87a630fad1c7dcdaeea069e6be72a12b626169 - please test again.

Yes, 4.4 is supported at the moment, because template model was created from 4.4 template. In theory branch and template model for 4.0 can be created in https://github.com/monitoringartist/go-zabbix/ and then just version detection must be implemented here. Will you be able to create 4.0 model?

Fixed more string items. Tested on official templates:

[templates]# find . -type f -name *.xml -exec zabbix-template-converter -in {} -out output.yaml \;
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.2, only 4.4 is supported
Unsupported Zabbix template version 4.2, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.2, only 4.4 is supported
Unsupported Zabbix template version 4.2, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.0, only 4.4 is supported
Unsupported Zabbix template version 4.2, only 4.4 is supported
Unsupported Zabbix template version 4.2, only 4.4 is supported
Unsupported Zabbix template version 3.4, only 4.4 is supported
Unsupported Zabbix template version 3.4, only 4.4 is supported
Unsupported Zabbix template version 3.4, only 4.4 is supported
mjtrangoni commented 5 years ago

@jangaraj Are you planning to build the support for versions 4.0 and/or 4.2? I have an idea for checking this, and it is converting from XML to YAML in some CI, and then from YAML to XML back, and checking both XML files for compatibility. Do you agree?

I can take a look at weekend, and start contributing. Thanks!

jangaraj commented 5 years ago

Yes. It will nice to have support for 4.0, because it is LTS release. 4.2 has reached end of full support - but probably it uses the same template model as 4.0.

Zabbix XML ->YAML -> XML conversion doesn't produce input XML, because golang xml lib encodes some characters differently (see https://github.com/golang/go/issues/12400), .e.g.

<key>net.tcp.service.perf[http,"{HOST.CONN}","{$APACHE.STATUS.PORT}"]</key>

vs

<key>net.tcp.service.perf[http,&#34;{HOST.CONN}&#34;,&#34;{$APACHE.STATUS.PORT}&#34;]</key>
jangaraj commented 5 years ago

Support for 4.0 has been added + I'm trying to match Zabbix XML style, so output XML can be used for verification (see readme). It is still not perfect, because some fields, which are not used very often may be missing missing in the model + self-closing tags can be a problem. Example diff - original xml vs xml produced by zabbix-template-converter: image

mjtrangoni commented 5 years ago

Hi @jangaraj,

I have some other fields from 4.0 which goes missing on the conversion,

<status>0</status>
<snmp_community/>
<snmp_oid/>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
 <username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<inventory_link>0</inventory_link>
<logtimefmt/>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
< allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>

Application prototypes are also missing,

                            <application_prototypes>
                                <application_prototype>
                                    <name>APP NAME</name>
                                </application_prototype>
                            </application_prototypes>

And I also see an extra generated "retrieve mode" on the output side, which I am not sure It should or not be there, or is it sorted out.

<retrieve_mode>0</retrieve_mode>
jangaraj commented 5 years ago

Please compare v44 (it is better model, but it's still not completed) with v40 - https://github.com/monitoringartist/go-zabbix/compare/v40...v44?expand=1 and create PR please.