通过导入/导出zabbix配置文件,我们可以将自己写好的模板等配置在网络上分享,我们也可以导入网络上分享的配置文件,配置文件有两种格式,分为为xml与json,通过zabbix管理界面可以导出xml,通过zabbix api可以导出json与xml格式配置。

可导出的项目

  • host groups (只能通过zabbix api导出)

  • templates (包含所有预其直接关联的items, triggers, graphs, screens, discovery rules和link的template)

  • hosts (包含所有与它直接相关的items, triggers, graphs, discovery rules 和link的template)

  • network maps (包含所有相关图片; map export/import 从Zabbix 1.8.2开始被支持)

  • p_w_picpaths

  • screens

导出详细说明

  • 导出为单个文件

  • Host and template从模板中link过来的实体 (items, triggers, graphs, discovery rules)不会导出,通过low-level创建的实体不会导出。但是导入之后,会重新创建link的实体。

  • 与low-level实体相关联的实体不会被导出,例如触发器。

  • web items相关的Triggers and graphs不支持导出

导入详细说明

  • 导入过程中遇到任何问题,都会停止导入

  • 支持导入xml与json格式文件,并且文件名后缀必须为.xml或者.json

XML文件基本格式

<?xml version="1.0" encoding="UTF-8"?><zabbix_export>    
    <version>2.0</version>    
    <date>2015-02-09T05:58:54Z</date>    
</zabbix_export>

xml默认头

<?xml version="1.0" encoding="UTF-8"?>

zabbix xml root元素

<zabbix_export>

导出版本

<version>2.0</version>

导出日期

<date>2015-02-09T05:58:54Z</date>

导出模板

configuration>>templates>>勾选需要导出的模板>>左下角下拉列表选择”Export selected”,点击Go,保存xml即可。

如下是我的一个测试模板内容

<?xml version="1.0" encoding="UTF-8"?><zabbix_export>    
    <version>2.0</version>    
    <date>2015-02-09T07:34:25Z</date>    
    <groups>    
        <group>    
            <name>Templates</name>    
        </group>    
    </groups>    
    <templates>    
        <template>    
            <template>A_Template_For_Discovery</template>    
            <name>A_Template_For_Discovery</name>    
            <groups>    
                <group>    
                    <name>Templates</name>    
                </group>    
            </groups>    
            <applications>    
                <application>    
                    <name>Network</name>    
                </application>    
            </applications>    
            <items/>    
            <discovery_rules>    
                <discovery_rule>    
                    <name>PING</name>    
                    <type>0</type>    
                    <snmp_community/>    
                    <snmp_oid/>    
                    <key>net.if.icmpping</key>    
                    <delay>30</delay>    
                    <status>0</status>    
                    <allowed_hosts/>    
                    <snmpv3_contextname/>    
                    <snmpv3_securityname/>    
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>    
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>    
                    <snmpv3_authpassphrase/>    
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>    
                    <snmpv3_privpassphrase/>    
                    <delay_flex/>    
                    <params/>    
                    <ipmi_sensor/>    
                    <authtype>0</authtype>    
                    <username/>    
                    <password/>    
                    <publickey/>    
                    <privatekey/>    
                    <port/>    
                    <filter>{#LOC}:^cn|^jp</filter>    
                    <lifetime>30</lifetime>    
                    <description/>    
                    <item_prototypes>    
                        <item_prototype>    
                            <name>PING IP $1</name>    
                            <type>3</type>    
                            <snmp_community/>    
                            <multiplier>1</multiplier>    
                            <snmp_oid/>    
                            <key>icmpping[{#IPADD},4,,,]</key>    
                            <delay>30</delay>    
                            <history>90</history>    
                            <trends>365</trends>    
                            <status>0</status>    
                            <value_type>3</value_type>    
                            <allowed_hosts/>    
                            <units/>    
                            <delta>0</delta>    
                            <snmpv3_contextname/>    
                            <snmpv3_securityname/>    
                            <snmpv3_securitylevel>0</snmpv3_securitylevel>    
                            <snmpv3_authprotocol>0</snmpv3_authprotocol>    
                            <snmpv3_authpassphrase/>    
                            <snmpv3_privprotocol>0</snmpv3_privprotocol>    
                            <snmpv3_privpassphrase/>    
                            <formula>1000</formula>    
                            <delay_flex/>    
                            <params/>    
                            <ipmi_sensor/>    
                            <data_type>0</data_type>    
                            <authtype>0</authtype>    
                            <username/>    
                            <password/>    
                            <publickey/>    
                            <privatekey/>    
                            <port/>    
                            <description/>    
                            <inventory_link>0</inventory_link>    
                            <applications>    
                                <application>    
                                    <name>Network</name>    
                                </application>    
                            </applications>    
                            <valuemap/>    
                        </item_prototype>    
                    </item_prototypes>    
                    <trigger_prototypes/>    
                    <graph_prototypes/>    
                    <host_prototypes/>    
                </discovery_rule>    
            </discovery_rules>    
            <macros/>    
            <templates>    
                <template>    
                    <name>Template OS Linux</name>    
                </template>    
            </templates>    
            <screens/>    
        </template>    
    </templates>    
</zabbix_export>

与模板相关的数据都在xml里,它link的模板”Template OS Linux”并未导出。而是通过如下元素将他关联起来,下回导入还会link一次。

通过此方式,大家可以互相共享配置文件,提高效率。