2022 Zabbix中国峰会
2022 Zabbix中国峰会

2 模板

概述

模板的导出包含许多相关对象和对象关系。

模板导出包含:

  • 链接的主机组
  • 模板数据
  • 链接到其他模板
  • 连接到主机组
  • 直接链接的应用集
  • 直接链接的监控项
  • 直接链接触发器
  • 直接链接图形
  • 直接链接聚合图形
  • 直接链接发现规则与所有原型
  • 直接链接Web场景
  • 值映射

导出

导出模板,按以下步骤:

  • 转到: 配置模板
  • 选中需要导出模板的复选框
  • 在列表正文点击导出

所选模板将导出的本地XML文件默认名称为zabbix_export_templates.xml

导入

导入模板,按以下步骤:

  • 转到: 配置模板
  • 点击右边的Import
  • 选择需要导入的文件
  • 在导入规则中选中需要的选项
  • 点击导入

导入后在前端显示成功或失败的信息

导入规则:

规则 说
更新现有的 将使用从 入文件获取的数据更新现有元素。 否则不会更新。
创建新的 导入将 用导入文件中的数据添加新元素。 否则不会添加它们。
删除失败 导入将 除导入文件中不存在的现有元素。 否则不会删除它们。

导出格式

<?xml version="1.0" encoding="UTF-8"?>
       <zabbix_export>
           <version>3.4</version>
           <date>2016-12-28T09:18:27Z</date>
           <groups>
               <group>
                   <name>Templates</name>
               </group>
           </groups>
           <templates>
               <template>
                   <template>Template App MySQL</template>
                   <name>Template App MySQL</name>
                   <description/>
                   <groups>
                       <group>
                           <name>Templates</name>
                       </group>
                   </groups>
                   <applications>
                       <application>
                           <name>MySQL</name>
                       </application>
                   </applications>
                   <items>
                       <item>
                           <name>MySQL status</name>
                           <type>0</type>
                           <snmp_community/>
                           <snmp_oid/>
                           <key>mysql.ping</key>
                           <delay>60</delay>
                           <history>7</history>
                           <trends>365</trends>
                           <status>0</status>
                           <value_type>3</value_type>
                           <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/>
                           <formula>1</formula>
                           <delay_flex/>
                           <params/>
                           <ipmi_sensor/>
                           <authtype>0</authtype>
                           <username/>
                           <password/>
                           <publickey/>
                           <privatekey/>
                           <port/>
                           <description>It requires user parameter mysql.ping, which is defined in userparameter_mysql.conf.
       
       0 - MySQL server is down
       1 - MySQL server is up</description>
                           <inventory_link>0</inventory_link>
                           <applications>
                               <application>
                                   <name>MySQL</name>
                               </application>
                           </applications>
                           <valuemap>
                               <name>Service state</name>
                           </valuemap>
                           <logtimefmt/>
                           <preprocessing/>
                       </item>
                       <item>
                           <name>MySQL insert operations per second</name>
                           <type>0</type>
                           <snmp_community/>
                           <snmp_oid/>
                           <key>mysql.status[Com_insert]</key>
                           <delay>60</delay>
                           <history>7</history>
                           <trends>365</trends>
                           <status>0</status>
                           <value_type>0</value_type>
                           <allowed_hosts/>
                           <units>qps</units>
                           <snmpv3_contextname/>
                           <snmpv3_securityname/>
                           <snmpv3_securitylevel>0</snmpv3_securitylevel>
                           <snmpv3_authprotocol>0</snmpv3_authprotocol>
                           <snmpv3_authpassphrase/>
                           <snmpv3_privprotocol>0</snmpv3_privprotocol>
                           <snmpv3_privpassphrase/>
                           <formula>1</formula>
                           <delay_flex/>
                           <params/>
                           <ipmi_sensor/>
                           <authtype>0</authtype>
                           <username/>
                           <password/>
                           <publickey/>
                           <privatekey/>
                           <port/>
                           <description>It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description>
                           <inventory_link>0</inventory_link>
                           <applications>
                               <application>
                                   <name>MySQL</name>
                               </application>
                           </applications>
                           <valuemap/>
                           <logtimefmt/>
                           <preprocessing>
                               <step>
                                   <type>10</type>
                                   <params/>
                               </step>
                           </preprocessing>
                       </item>
                       <item>
                           <name>MySQL queries per second</name>
                           <type>0</type>
                           <snmp_community/>
                           <snmp_oid/>
                           <key>mysql.status[Questions]</key>
                           <delay>60</delay>
                           <history>7</history>
                           <trends>365</trends>
                           <status>0</status>
                           <value_type>0</value_type>
                           <allowed_hosts/>
                           <units>qps</units>
                           <snmpv3_contextname/>
                           <snmpv3_securityname/>
                           <snmpv3_securitylevel>0</snmpv3_securitylevel>
                           <snmpv3_authprotocol>0</snmpv3_authprotocol>
                           <snmpv3_authpassphrase/>
                           <snmpv3_privprotocol>0</snmpv3_privprotocol>
                           <snmpv3_privpassphrase/>
                           <formula>1</formula>
                           <delay_flex/>
                           <params/>
                           <ipmi_sensor/>
                           <authtype>0</authtype>
                           <username/>
                           <password/>
                           <publickey/>
                           <privatekey/>
                           <port/>
                           <description>It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description>
                           <inventory_link>0</inventory_link>
                           <applications>
                               <application>
                                   <name>MySQL</name>
                               </application>
                           </applications>
                           <valuemap/>
                           <logtimefmt/>
                           <preprocessing>
                               <step>
                                   <type>10</type>
                                   <params/>
                               </step>
                           </preprocessing>
                       </item>
                   </items>
                   <discovery_rules/>
                   <httptests/>
                   <macros/>
                   <templates/>
                   <screens>
                       <screen>
                           <name>MySQL performance</name>
                           <hsize>2</hsize>
                           <vsize>1</vsize>
                           <screen_items>
                               <screen_item>
                                   <resourcetype>0</resourcetype>
                                   <width>500</width>
                                   <height>200</height>
                                   <x>0</x>
                                   <y>0</y>
                                   <colspan>1</colspan>
                                   <rowspan>1</rowspan>
                                   <elements>0</elements>
                                   <valign>1</valign>
                                   <halign>0</halign>
                                   <style>0</style>
                                   <url/>
                                   <dynamic>0</dynamic>
                                   <sort_triggers>0</sort_triggers>
                                   <resource>
                                       <name>MySQL operations</name>
                                       <host>Template App MySQL</host>
                                   </resource>
                                   <max_columns>3</max_columns>
                                   <application/>
                               </screen_item>
                               <screen_item>
                                   <resourcetype>0</resourcetype>
                                   <width>500</width>
                                   <height>270</height>
                                   <x>1</x>
                                   <y>0</y>
                                   <colspan>1</colspan>
                                   <rowspan>1</rowspan>
                                   <elements>0</elements>
                                   <valign>1</valign>
                                   <halign>0</halign>
                                   <style>0</style>
                                   <url/>
                                   <dynamic>0</dynamic>
                                   <sort_triggers>0</sort_triggers>
                                   <resource>
                                       <name>MySQL bandwidth</name>
                                       <host>Template App MySQL</host>
                                   </resource>
                                   <max_columns>3</max_columns>
                                   <application/>
                               </screen_item>
                           </screen_items>
                       </screen>
                   </screens>
               </template>
           </templates>
           <triggers>
               <trigger>
                   <expression>{Template App MySQL:mysql.ping.last(0)}=0</expression>
                   <recovery_mode>0</recovery_mode>
                   <recovery_expression/>
                   <name>MySQL is down</name>
                   <correlation_mode>0</correlation_mode>
                   <correlation_tag/>
                   <url/>
                   <status>0</status>
                   <priority>2</priority>
                   <description/>
                   <type>0</type>
                   <manual_close>0</manual_close>
                   <dependencies/>
                   <tags/>
               </trigger>
           </triggers>
           <graphs>
               <graph>
                   <name>MySQL operations</name>
                   <width>900</width>
                   <height>200</height>
                   <yaxismin>0.0000</yaxismin>
                   <yaxismax>100.0000</yaxismax>
                   <show_work_period>1</show_work_period>
                   <show_triggers>1</show_triggers>
                   <type>0</type>
                   <show_legend>1</show_legend>
                   <show_3d>0</show_3d>
                   <percent_left>0.0000</percent_left>
                   <percent_right>0.0000</percent_right>
                   <ymin_type_1>0</ymin_type_1>
                   <ymax_type_1>0</ymax_type_1>
                   <ymin_item_1>0</ymin_item_1>
                   <ymax_item_1>0</ymax_item_1>
                   <graph_items>
                       <graph_item>
                           <sortorder>0</sortorder>
                           <drawtype>0</drawtype>
                           <color>C8C800</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App MySQL</host>
                               <key>mysql.status[Com_begin]</key>
                           </item>
                       </graph_item>
                       <graph_item>
                           <sortorder>1</sortorder>
                           <drawtype>0</drawtype>
                           <color>006400</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App MySQL</host>
                               <key>mysql.status[Com_commit]</key>
                           </item>
                       </graph_item>
                       <graph_item>
                           <sortorder>2</sortorder>
                           <drawtype>0</drawtype>
                           <color>C80000</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App MySQL</host>
                               <key>mysql.status[Com_delete]</key>
                           </item>
                       </graph_item>
                       <graph_item>
                           <sortorder>3</sortorder>
                           <drawtype>0</drawtype>
                           <color>0000EE</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App MySQL</host>
                               <key>mysql.status[Com_insert]</key>
                           </item>
                       </graph_item>
                       <graph_item>
                           <sortorder>4</sortorder>
                           <drawtype>0</drawtype>
                           <color>640000</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App MySQL</host>
                               <key>mysql.status[Com_rollback]</key>
                           </item>
                       </graph_item>
                       <graph_item>
                           <sortorder>5</sortorder>
                           <drawtype>0</drawtype>
                           <color>00C800</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App MySQL</host>
                               <key>mysql.status[Com_select]</key>
                           </item>
                       </graph_item>
                       <graph_item>
                           <sortorder>6</sortorder>
                           <drawtype>0</drawtype>
                           <color>C800C8</color>
                           <yaxisside>0</yaxisside>
                           <calc_fnc>2</calc_fnc>
                           <type>0</type>
                           <item>
                               <host>Template App MySQL</host>
                               <key>mysql.status[Com_update]</key>
                           </item>
                       </graph_item>
                   </graph_items>
               </graph>
           </graphs>
           <value_maps>
               <value_map>
                   <name>Service state</name>
                   <mappings>
                       <mapping>
                           <value>0</value>
                           <newvalue>Down</newvalue>
                       </mapping>
                       <mapping>
                           <value>1</value>
                           <newvalue>Up</newvalue>
                       </mapping>
                   </mappings>
               </value_map>
           </value_maps>
       </zabbix_export>

元素标签

元素标签值在下表中说明。

Templates 标签
元素 元 属性 类型 范围 说明
templates 模板根元素
template 单个模板
template string 唯一的模板名称。
name string 可见的模板名称。
description text 模板说明
groups 主机组根元素
group 单个主机组
name string 唯一的组名称
applications 模板应用集的根元素
application 单个模板应用集
name 应用集名称
macros 模板用户宏的根元素。
macro 单个模板用户宏
name 模板用户宏名称
value 模板用户宏值
templates 链接的模板的根元素
template 单个模板
name string 模板名称
Template item 标签
元素 元 属性 类型 范围 说明
items 监控项的根元素
item 单个监控项
name string 监控项名称
type integer 0 - Zabbix 客户端  监控1 - SNMPv1 客户端
2 - Zabbix采集器
3 - 简单检查
4 - SNMPv2 客户端
5 - Zabbix内部
6 - SNMPv3 客户端
7 - Zabbix客户端(主动式)
8 - Zabbix整合
9 - HTTP 测试(Web监控场步骤)
10 - 外部检查
11 - 数据库监控
12 - IPMI客户端
13 - SSH 客户端
14 - TELNET客户端
15 - 可计算的
16 - JMX agent代理程序
17 - SNMP trap
类型
snmp_community string 如果“类型”为1,4,SNMP团体名称
snmp_oid string SNMP 对象ID
key string 监控项的键
delay integer 监控项收集的常规频率(以秒为单位)
history integer 保存历史的天数。
trends integer 保持趋势的天数。
status integer 0 - 启用  监1 - 禁用 项状态
value_type integer 0 - 浮点数  接收1 - 字符
2 - 日志
3 - 数字(无正负)
4 - 文本
的类型
allowed_hosts string 如果'type'为2,允许发送数据的主机的IP地址(逗号分隔)列表。
units string 返回值单位(bps,B)。
snmpv3_contextname string SNMPv3上下文名称。
snmpv3_securityname string SNMPv3安全名称。
snmpv3_securitylevel integer 0 - noAuthNoPriv
1 - authNoPriv
2 - authPriv
SNMPv3 安装级别
snmpv3_authprotocol integer 0 - MD5
1 - SHA
SNMPv3 认证协议
snmpv3_authpassphrase string SNMPv3 认证密码
snmpv3_privprotocol integer 0 - DES
1 - AES
SNMPv3 隐私协议。
snmpv3_privpassphrase string SNMPv3 隐私密码。
formula string 如果“multiplier=1”,则计算接收值的乘数值
delay_flex string 监控项数据采集更新的频率。
params text 如果“type”为13,14,则“执行脚本”的名称
如果'type'为11,则"SQL query" 字段
如果'type'为15,则"Formula"字段
ipmi_sensor string 如果'type'为12,IPMI 传感器ID
authtype integer 0 - password
1 - key
'type'为13,验证类型
username string 'type' 为11,13,14,用户名
password string 'type' 为11,13,14,密码
publickey string 'type' 为 13,公钥文件的名称
privatekey string 'type' 为 13,私钥文件的名称
port string 监控项的自定义端口。
description text 监控项说明
inventory_link integer 0 - 没有链接  使用监数字 - “host_inventory”表中的字段数 项值填充此库存字段。
logtimefmt string 日志条目中的时间格式。 仅用于日志监控项。
interface_ref string 参考主机接口。
value map Value map.
name string 值映射监控项的名称
applications 应用集的根元素
application 单个应用集
name 应用集名称
preprocessing 监控项值预处理
step 单个监控项值预处理步骤
type integer 1 - 自定义乘数  监控项值2 - 右边修剪
3 - 左边修剪
4 - 两边修剪
5 - 正则表达式匹配
6 -布尔值转十进制
7 - 八进制转十进制
8 - 十六进制转十进制
9 - 计算为(接收值 - 先前值)
10 - 计算为(收到的值 - 上一个值)/(上次检查的时间)
处理步骤的类型。
params string 监控项值预处理步骤的参数。
模板低级发现规则标签
元素 元 属性 类型 范围 说明
discovery_rules 低级别发现规则的根元素
discovery_rule 单个低级别发现规则
对于大多数元素标签值,请参阅常规监控项的元素标签值。 下面仅描述特定于低级发现规则的标签。
lifetime string 0-3650 由LLD规则发现丢失资源的保留天数。
filter 单个过滤器
evaltype integer 0 - 与/或 逻辑  用于检1 - 与 逻辑
2 - 或 逻辑
3 - 自定义公式
低级发现规则过滤条件的逻辑。
formula string 过滤条件的自定义计算公式。
conditions 过滤条件的根元素
condition 单个过滤条件
macro string 低级发现的宏名称
value string 过滤器值: 正则表达式或全局正则表达式
operator integer .
formulaid character 过滤器条件ID. 用于定制计算公式
item_prototypes item_prototypes的根元素
item_prototype 单个item_prototype.
对于大多数元素标签值,请参阅常规监控项的元素标签值。 下面仅描述特定于item_prototypes的标签。
application_prototypes 应用集原型的根元素。
application_prototype 单个应用集原型
name 应用集原型名称
模板触发器标签
元素 元 属性 类型 范围 说明
triggers 触发器的根元素
trigger 单个触发器
expression string 触发器表达式
recovery_mode integer 0 - 表达式  生成1 - 恢复表达式
2 - 无
K事件的基础。
recovery_expression string 触发器恢复表达式。
name string 触发器名字
correlation_mode integer 0 - 无事件关联  关联模式1 - 通过标签的事件关联
correlation_tag string 用于事件相关的标签名称
url string 触发器URL.
status integer 0 - 启用  触1 - 禁用 器状态
priority integer 0 - 不分类  触发1 - 信息
2 - 警告
3 - 一般严重
4 - 严重
5 - 灾难
重性。
description text 触发器说明
type integer 0 - 单问题事件  事件生成1 - 多问题事件 型。
manual_close integer 0 - 不允许  手动1 - 允许 闭问题事件。
dependencies 依赖关系的根元素。
dependency 单个依赖关系
name string 依赖触发器名称。
expression string 依赖触发器表达式
recovery_expression string 依赖触发恢复表达式。
tags 事件标签的根元素
tag 单个事件标签
tag string 标签名称
value string 标签值
模板图形标签
元素 元 属性 类型 范围 说明
graphs 图形的根元素
graph 单个图形
name string 图形名称
width integer 图形宽度,以像素为单位。 用于预览和饼图/分裂式饼图。
height integer 图形高度,以像素为单位。 用于预览和饼图/分裂式饼图。
yaxismin double 如果“ymin_type_1”为1,Y轴的最小值。
yaxismax double 如果“ymax_type_1”为1,Y轴的最大值。
show_work_period integer 0 - 否
1 - 是
果“type”为0,1,则突出显示非工作时间。
show_triggers integer 0 - 否
1 - 是
果'type'为0,1,则显示简单的触发值作为一行。
type integer 0 - 正常  图1 - 层积的
2 - 饼图
3 - 分裂的
4 - 3D饼图
5 - 3D分裂式饼图
类型
show_legend integer 0 - 否
1 - 是
示图例
show_3d integer 0 - 2D
1 - 3D
如果'type'为2,3,启用3D风格
percent_left double 如果“type”为0,则显示左轴的百分位数线。
percent_right double 如果“type”为0,则显示右轴的百分位数线。
ymin_type_1 integer 0 - 可计算的  如果'1 - 固定的
2 - 选择监控项的最新值
ype'为0,1,Y轴的最小值。
ymax_type_1 integer 0 - 可计算的  如果'1 - 固定的
2 - 选择监控项的最新值
ype'为0,1,Y轴的最大值。
ymin_item_1 string 空或监控项详细信息 如果'ymin
type_1'为2,监控项详细信息
ymax_item_1 string 空或监控项详细信息 如果'ymax
type_1'为2,监控项详细信息
graph_items 图形监控项的根元素
graph_item 单个图形监控项
sortorder integer 绘制顺序。 较小的值首先绘制。 可用于绘制线条或区域后面(或前面)的另一个。
drawtype integer 0 - 线
1 - 填满的区域
2 - 粗线
3 - 点
4 - 虚线
果图形'type'为0,绘制风格
color string 元素颜色(6位,十六进制)
yaxisside integer 0 - 左轴  如1 - 右轴 图形'type'是0,1,元素所属的Y轴位置(左或右)
calc_fnc integer 1 - 最小  如2 - 平均
4 - 最大
7 - 所有(如果图形'type'为0,最小, 平均和最大)
9 - 最后 (如果图形'type'不为0,1)
一个监控项存在多个值,则绘制数据。
type integer 1 - 监控项的值成比例地表示在饼图  饼图/分解图的绘制类型。2 - 监控项的值代表整个饼图 (图形概括)
item 单个监控项
host string 监控项主机
key string 监控项键
模板Web场景标签
元素 元 属性 类型 范围 说明
httptests Web场景的根元素
httptest 单个Web场景
name string Web场景名称
delay integer 执行Web场景的频率,以秒为单位。
attempts integer 1-10 执行Web方案步骤的尝试次数。
agent string 客户代理。 Zabbix将假装成为所选的浏览器。 当网站为不同的浏览器返回不同的内容时,这很有用。
http_proxy string 指定要使用的HTTP代理, 使用格式: http://[username[:password]@]proxy.mycompany.com[:port]
variables text 在场景步骤中可以使用的场景级变量(宏)列表。
headers text 执行请求时将发送的HTTP头。
status integer 0 - 启用  W1 - 禁用 b场景状态
authentication integer 0 - 无
1 - 基本
2 - NTLM
证方式
http_user string 验证用户名
http_password string 用户名指定的验证密码
verify_peer integer 0 - 否
1 - 是
证Web服务器的SSL证书。
verify_host integer 0 - 否
1 - 是
证Web服务器证书的公用名称字段或主题备用名称字段是否匹配。
ssl_cert_file string 用于客户端身份验证的SSL证书文件的名称。
ssl_key_file string 用于客户端身份验证的SSL私钥文件的名称。
ssl_key_password string SSL私钥文件密码。
steps Web场景步骤的根元素
step 单个Web场景步骤
name string Web场景步骤名称
url string 监控的URL
posts text 'Post'变量列表。
variables text 应在此步骤之后应用级变量(宏)的列表。

如果变量值具有'regex:'前缀,则根据'regex:'前缀之后的正则表达式模式从该步骤返回的数据中提取其值
headers text 执行请求时将发送的HTTP头。
follow_redirects integer 0 - 否
1 - 是
循HTTP重定向
retrieve_mode integer 0 - 内容  H1 - 只有头 TP响应检索模式。
timeout integer 步骤执行的超时时间,以秒为单位
required string 必填字符串。 如果空,则忽略。
status_codes string 以逗号分隔的已接受的状态代码列表。如果空,则忽略。 例如: 200-201,210-299