Zabbix 监控 HP v1910-24G 交换机:community-templates SNMP 模板的监控项、触发器与图形全解析
Zabbix 监控 HP v1910-24G 交换机:community-templates SNMP 模板的监控项、触发器与图形全解析
本文以 Zabbix Community Templates 仓库中的 SNMP HP v1910-24G 模板为对象,系统梳理该模板如何通过 SNMP agent 采集 HP v1910-24G 接入交换机的端口流量、CRC 错误与接口状态,并剖析其背后的 ifTable OID 映射、预处理链与触发器表达式。读完本文,你将掌握该模板的全部 142 个监控项、85 个触发器与 28 个图形的设计逻辑,并能在 Zabbix 5.0/5.4/6.0 环境中直接导入使用或按需改造。
模板定位与仓库结构
该模板位于仓库的 Network_Devices/HP/template_zabbix_2.2_hp_v19xx-24g_snmp 目录下,面向 HP v1910-24G 千兆接入交换机。目录名中的 zabbix_2.2 暗示其源自 Zabbix 2.2 时代的模板,仓库则按主流版本提供了三套可导入的实体文件:
| 版本 | 配置格式 | 文件 |
|---|---|---|
| 5.0 | XML | template_zabbix_2.2_hp_v19xx-24g_snmp.xml |
| 5.4 | YAML | template_zabbix_2.2_hp_v19xx-24g_snmp.yaml |
| 6.0 | YAML | template_zabbix_2.2_hp_v19xx-24g_snmp.yaml |
6.0 版本的 YAML 头部标注 zabbix_export: version: '6.0'、导出日期 2021-11-25,模板名为 SNMP HP v1910-24G,归属模板组 Templates。各版本的 README.md 结构一致,明确声明:
- Macros used(使用的宏):无;
- Template links(模板链接):无;
- Discovery rules(自动发现规则):无。
也就是说,这是一个"全静态、逐端口显式建模"的模板:不依赖低层自动发现(LLD),所有端口(ifIndex 1–28)的监控项均在导入时一次性创建完毕。这种做法的好处是监控项数量完全可控、无需维护发现宏;代价是端口数量变化时需要人工增删监控项。
监控项体系:六大类共 142 个 item
从 README 的 "Items collected" 章节与 6.0 YAML 的 items 段可以确认,模板共定义 142 个监控项,全部采用 SNMP agent(SNMP_AGENT)类型,按功能划分为六类:
| 类别 | 监控项命名 | key | 数量 | 更新间隔 |
|---|---|---|---|---|
| 设备信息 | Model | .1.3.6.1.2.1.1.1.0 |
1 | 3600s |
| 运行时长 | Uptime | Uptime |
1 | 60s |
| 接收流量 | Bytes Rx port N | ifInOctets.N |
28 | 120s |
| 发送流量 | Bytes Tx port N | ifOutOctets.N |
28 | 120s |
| 接收错误 | InErrorsFa0/N | ifInErrors.N |
28 | 120s |
| 发送错误 | OutErrorsFa0/N | ifOutErrors.N |
28 | 120s |
| 接口状态 | Status port N | ifOperStatus.N |
28 | 120s |
其中端口序号 N 覆盖 1–28,对应设备 ifTable 中的 ifIndex 1–28;至于这 28 个 ifIndex 具体对应哪些物理端口(24 个千兆口与上行/扩展口的组合),取决于设备实际 ifTable 的布局,导入前建议先
snmpwalk核对。
监控项全清单
下表完整继承 README 中列出的全部监控项(更新间隔 120s,未单独标注者同此;Model 为 3600s,Uptime 为 60s):
| 名称 | key | 名称 | key | 名称 | key |
|---|---|---|---|---|---|
| Model | .1.3.6.1.2.1.1.1.0 | Uptime | Uptime | ||
| OutErrorsFa0/1 | ifOutErrors.1 | InErrorsFa0/1 | ifInErrors.1 | Status port 1 | ifOperStatus.1 |
| OutErrorsFa0/2 | ifOutErrors.2 | InErrorsFa0/2 | ifInErrors.2 | Status port 2 | ifOperStatus.2 |
| OutErrorsFa0/3 | ifOutErrors.3 | InErrorsFa0/3 | ifInErrors.3 | Status port 3 | ifOperStatus.3 |
| OutErrorsFa0/4 | ifOutErrors.4 | InErrorsFa0/4 | ifInErrors.4 | Status port 4 | ifOperStatus.4 |
| OutErrorsFa0/5 | ifOutErrors.5 | InErrorsFa0/5 | ifInErrors.5 | Status port 5 | ifOperStatus.5 |
| OutErrorsFa0/6 | ifOutErrors.6 | InErrorsFa0/6 | ifInErrors.6 | Status port 6 | ifOperStatus.6 |
| OutErrorsFa0/7 | ifOutErrors.7 | InErrorsFa0/7 | ifInErrors.7 | Status port 7 | ifOperStatus.7 |
| OutErrorsFa0/8 | ifOutErrors.8 | InErrorsFa0/8 | ifInErrors.8 | Status port 8 | ifOperStatus.8 |
| OutErrorsFa0/9 | ifOutErrors.9 | InErrorsFa0/9 | ifInErrors.9 | Status port 9 | ifOperStatus.9 |
| OutErrorsFa0/10 | ifOutErrors.10 | InErrorsFa0/10 | ifInErrors.10 | Status port 10 | ifOperStatus.10 |
| OutErrorsFa0/11 | ifOutErrors.11 | InErrorsFa0/11 | ifInErrors.11 | Status port 11 | ifOperStatus.11 |
| OutErrorsFa0/12 | ifOutErrors.12 | InErrorsFa0/12 | ifInErrors.12 | Status port 12 | ifOperStatus.12 |
| OutErrorsFa0/13 | ifOutErrors.13 | InErrorsFa0/13 | ifInErrors.13 | Status port 13 | ifOperStatus.13 |
| OutErrorsFa0/14 | ifOutErrors.14 | InErrorsFa0/14 | ifInErrors.14 | Status port 14 | ifOperStatus.14 |
| OutErrorsFa0/15 | ifOutErrors.15 | InErrorsFa0/15 | ifInErrors.15 | Status port 15 | ifOperStatus.15 |
| OutErrorsFa0/16 | ifOutErrors.16 | InErrorsFa0/16 | ifInErrors.16 | Status port 16 | ifOperStatus.16 |
| OutErrorsFa0/17 | ifOutErrors.17 | InErrorsFa0/17 | ifInErrors.17 | Status port 17 | ifOperStatus.17 |
| OutErrorsFa0/18 | ifOutErrors.18 | InErrorsFa0/18 | ifInErrors.18 | Status port 18 | ifOperStatus.18 |
| OutErrorsFa0/19 | ifOutErrors.19 | InErrorsFa0/19 | ifInErrors.19 | Status port 19 | ifOperStatus.19 |
| OutErrorsFa0/20 | ifOutErrors.20 | InErrorsFa0/20 | ifInErrors.20 | Status port 20 | ifOperStatus.20 |
| OutErrorsFa0/21 | ifOutErrors.21 | InErrorsFa0/21 | ifInErrors.21 | Status port 21 | ifOperStatus.21 |
| OutErrorsFa0/22 | ifOutErrors.22 | InErrorsFa0/22 | ifInErrors.22 | Status port 22 | ifOperStatus.22 |
| OutErrorsFa0/23 | ifOutErrors.23 | InErrorsFa0/23 | ifInErrors.23 | Status port 23 | ifOperStatus.23 |
| OutErrorsFa0/24 | ifOutErrors.24 | InErrorsFa0/24 | ifInErrors.24 | Status port 24 | ifOperStatus.24 |
| OutErrorsFa0/25 | ifOutErrors.25 | InErrorsFa0/25 | ifInErrors.25 | Status port 25 | ifOperStatus.25 |
| OutErrorsFa0/26 | ifOutErrors.26 | InErrorsFa0/26 | ifInErrors.26 | Status port 26 | ifOperStatus.26 |
| OutErrorsFa0/27 | ifOutErrors.27 | InErrorsFa0/27 | ifInErrors.27 | Status port 27 | ifOperStatus.27 |
| OutErrorsFa0/28 | ifOutErrors.28 | InErrorsFa0/28 | ifInErrors.28 | Status port 28 | ifOperStatus.28 |
| Bytes Rx port 1 | ifInOctets.1 | Bytes Tx port 1 | ifOutOctets.1 | ||
| Bytes Rx port 2 | ifInOctets.2 | Bytes Tx port 2 | ifOutOctets.2 | ||
| Bytes Rx port 3 | ifInOctets.3 | Bytes Tx port 3 | ifOutOctets.3 | ||
| Bytes Rx port 4 | ifInOctets.4 | Bytes Tx port 4 | ifOutOctets.4 | ||
| Bytes Rx port 5 | ifInOctets.5 | Bytes Tx port 5 | ifOutOctets.5 | ||
| Bytes Rx port 6 | ifInOctets.6 | Bytes Tx port 6 | ifOutOctets.6 | ||
| Bytes Rx port 7 | ifInOctets.7 | Bytes Tx port 7 | ifOutOctets.7 | ||
| Bytes Rx port 8 | ifInOctets.8 | Bytes Tx port 8 | ifOutOctets.8 | ||
| Bytes Rx port 9 | ifInOctets.9 | Bytes Tx port 9 | ifOutOctets.9 | ||
| Bytes Rx port 10 | ifInOctets.10 | Bytes Tx port 10 | ifOutOctets.10 | ||
| Bytes Rx port 11 | ifInOctets.11 | Bytes Tx port 11 | ifOutOctets.11 | ||
| Bytes Rx port 12 | ifInOctets.12 | Bytes Tx port 12 | ifOutOctets.12 | ||
| Bytes Rx port 13 | ifInOctets.13 | Bytes Tx port 13 | ifOutOctets.13 | ||
| Bytes Rx port 14 | ifInOctets.14 | Bytes Tx port 14 | ifOutOctets.14 | ||
| Bytes Rx port 15 | ifInOctets.15 | Bytes Tx port 15 | ifOutOctets.15 | ||
| Bytes Rx port 16 | ifInOctets.16 | Bytes Tx port 16 | ifOutOctets.16 | ||
| Bytes Rx port 17 | ifInOctets.17 | Bytes Tx port 17 | ifOutOctets.17 | ||
| Bytes Rx port 18 | ifInOctets.18 | Bytes Tx port 18 | ifOutOctets.18 | ||
| Bytes Rx port 19 | ifInOctets.19 | Bytes Tx port 19 | ifOutOctets.19 | ||
| Bytes Rx port 20 | ifInOctets.20 | Bytes Tx port 20 | ifOutOctets.20 | ||
| Bytes Rx port 21 | ifInOctets.21 | Bytes Tx port 21 | ifOutOctets.21 | ||
| Bytes Rx port 22 | ifInOctets.22 | Bytes Tx port 22 | ifOutOctets.22 | ||
| Bytes Rx port 23 | ifInOctets.23 | Bytes Tx port 23 | ifOutOctets.23 | ||
| Bytes Rx port 24 | ifInOctets.24 | Bytes Tx port 24 | ifOutOctets.24 | ||
| Bytes Rx port 25 | ifInOctets.25 | Bytes Tx port 25 | ifOutOctets.25 | ||
| Bytes Rx port 26 | ifInOctets.26 | Bytes Tx port 26 | ifOutOctets.26 | ||
| Bytes Rx port 27 | ifInOctets.27 | Bytes Tx port 27 | ifOutOctets.27 | ||
| Bytes Rx port 28 | ifInOctets.28 | Bytes Tx port 28 | ifOutOctets.28 |
核心 SNMP OID 映射与底层原理
模板的全部端口指标都来自标准 MIB-II 的 ifTable(RFC 1213 / IF-MIB),6.0 YAML 中每个 item 都显式写明了 snmp_oid:
| 监控项 | OID(.1.3.6.1.2.1.2.2.1 下) | 语义 | 取值特性 |
|---|---|---|---|
| Status port N | .8.N(ifOperStatus) |
接口当前运行状态 | 枚举:1=up,2=down,3=testing,… |
| Bytes Rx port N | .10.N(ifInOctets) |
接口累计收到的字节数 | 32 位计数器(Counter32) |
| Bytes Tx port N | .16.N(ifOutOctets) |
接口累计发送的字节数 | 32 位计数器(Counter32) |
| InErrorsFa0/N | .14.N(ifInErrors) |
接口接收方向错误包计数(含 CRC 错误) | 32 位计数器 |
| OutErrorsFa0/N | .20.N(ifOutErrors) |
接口发送方向错误包计数 | 32 位计数器 |
| Model | .1.3.6.1.2.1.1.1.0(sysDescr) |
设备型号/系统描述字符串 | TEXT,已挂接资产 MODEL 字段 |
| Uptime | .1.3.6.1.2.1.1.3.0(sysUpTime) |
系统运行时长(1/100 秒) | 需除以 100 换算为秒 |
端口与索引的对应关系:ifInOctets.N、ifOutOctets.N、ifInErrors.N、ifOutErrors.N、ifOperStatus.N 中的 N 即 ifIndex。由于 Zabbix 的 SNMP agent 类型 item 可以直接用可读 key(如 ifInOctets.1)配合 OID 轮询,模板在 YAML 中同时给出了 key 与 snmp_oid 两个字段,二者一一对应,这也是导入后 "Latest data" 页面里 key 与 OID 均可见的原因。
Model 与资产关联:Model 监控项设置了 value_type: TEXT、inventory_link: MODEL,意味着设备型号字符串会直接写入主机资产(Inventory)的 Model 字段,便于在资产列表里直接看到设备型号,而无需单独手工维护——这是从 6.0 YAML 第 18–31 行可以看到的实现细节。
数据预处理:把计数器变成实时速率(bps)
SNMP 计数器(Counter32)返回的是"累计字节数",直接展示没有意义。模板对 56 个流量监控项(Bytes Rx/Tx 各 28 个)配置了两步预处理链,6.0 YAML 中 Bytes Rx port 1 的定义如下:
- name: 'Bytes Rx port 1'
type: SNMP_AGENT
snmp_oid: 1.3.6.1.2.1.2.2.1.10.1
key: ifInOctets.1
delay: '120'
history: 7d
units: bps
preprocessing:
- type: CHANGE_PER_SECOND
parameters: ['']
- type: MULTIPLIER
parameters: ['8']
tags:
- tag: Application
value: 'Bytes Rx'
两步预处理的含义:
- CHANGE_PER_SECOND:对计数器求"每秒变化量",即
(本次值 - 上次值) / 时间差,把累计字节数换算为每秒字节数(B/s)。这一步是速率计算的根基。 - MULTIPLIER 8:将每秒字节数乘以 8,把 B/s 换算为 bit/s,与监控项单位
units: bps保持一致,最终图中直接显示 bps 速率的实时曲线。
同时,每个流量监控项还带有 tag: Application: Bytes Rx / Bytes Tx 标签(YAML 中即 tags 字段),在 Zabbix 6.0 的标签体系下可用于服务树、筛选与告警路由,等价于旧版本里的应用(Application)分组。
Uptime 的预处理略有不同:sysUpTime 的单位是百分之一秒(centiseconds),因此 Uptime 监控项只做一步 MULTIPLIER 0.01 预处理,将原始值换算为秒,配合 units: s 使用。
触发器逻辑:README 说"无触发器",实际配置含 85 个
一个值得注意的事实:三个版本的 README.md 在 "Triggers" 章节都写着 "There are no triggers in this template."(本模板无触发器),但对照同目录下真正的配置文件——6.0 YAML 与 5.0 XML——模板实际内嵌了 85 个触发器。这说明 README 为自动化生成的简化文档,未能完整反映配置实体;以 YAML/XML 为准,触发器分三类:
1. 端口 CRC 错误触发(56 个,HIGH 优先级)
每个 ifInErrors.N / ifOutErrors.N 监控项都带有一个 HIGH 优先级触发器,例如端口 1 的接收错误(对应 YAML 第 44–49 行):
表达式:(max(/SNMP HP v1910-24G/ifInErrors.1,#10)-min(/SNMP HP v1910-24G/ifInErrors.1,#10))>3
名称: CRC Errors Rx on port 1
优先级:HIGH
其设计思想是:ifInErrors 是累计错误计数器,直接用"最后一次值"无法感知错误是否在增长,因此取最近 10 次采样的 最大值与最小值之差(即 delta),若差值大于 3 个错误,说明该端口接收方向正持续产生错误包(典型如 CRC 错误、物理链路劣化),触发告警。发送方向(CRC Errors Tx on port N)采用完全相同的逻辑。56 个触发器的阈值统一为 >3、窗口统一为 #10(10 个采样点,配合 120s 更新间隔即约 20 分钟窗口)。
在 5.0 的 XML 版本中,同样的逻辑写作 {delta(#10)}>3,语义一致——这是 Zabbix 新旧触发器语法({delta(#10)} 与 max()-min())的差异,两个版本的判定结果等价。
2. 端口 down 触发(28 个,INFO 优先级,默认禁用)
每个 Status port N(ifOperStatus)监控项都带有一个"端口状态 down"触发器,例如:
表达式:last(/SNMP HP v1910-24G/ifOperStatus.1)=2
名称: Port 1 status down on {HOSTNAME}
优先级:INFO
ifOperStatus 为 2 即接口处于 down 状态。注意:这 28 个触发器默认是禁用(DISABLED)状态,且对应的 Status port N 监控项在 YAML 中同样标注 status: DISABLED。这是模板作者有意为之的默认策略——接入交换机上大量未接线端口本就处于 down 状态,若直接启用会刷屏告警。使用方若需要感知关键端口掉线,应在导入后自行启用对应监控项与触发器。5.0 XML 中该触发器写法为 {last(0)}=2,语义相同。
3. 设备重启触发(1 个,AVERAGE 优先级)
Uptime 监控项带有一个"设备刚重启"触发器:
表达式:last(/SNMP HP v1910-24G/Uptime)<600
名称: {HOSTNAME} has just been restarted
优先级:AVERAGE
当设备运行时长(已换算为秒)低于 600 秒(10 分钟)时触发,用于捕捉交换机意外重启事件——例如断电恢复、固件升级重启等。
三类触发器合计 28(CRC Rx)+ 28(CRC Tx)+ 28(Port down,禁用)+ 1(重启)= 85 个。
图形:每端口一张双线速率图
配置文件末尾的 graphs 段定义了 28 个图形(Port 1 stats ~ Port 28 stats),每个端口一张图,将 ifOutOctets.N(发送流量,颜色 000099 蓝色)与 ifInOctets.N(接收流量,颜色 990000 红色)绘制在同一坐标系内,ymin_type 固定为 FIXED(Y 轴从 0 开始),便于直观对比端口的上下行速率。由于图形引用的监控项已带 bps 单位与预处理链,图中直接呈现 bit/s 速率曲线。
版本差异与导入说明
三个版本在功能上等价,主要差异集中在导出格式与语法:
| 项目 | 5.0(XML) | 5.4 / 6.0(YAML) |
|---|---|---|
| 格式 | zabbix_export XML |
zabbix_export YAML |
| 应用分组 | <applications>(Bytes Rx、Bytes Tx、CRC Errors Rx、CRC Errors Tx、General、Oper Status) |
tags(Application: …) |
| 错误增量触发器 | {delta(#10)}>3 |
(max(...)-min(...))>3 |
| 端口 down 触发器 | {last(0)}=2 |
last(...)=2 |
| 预处理 | <preprocessing><step> 两段 |
preprocessing: 列表两段 |
导入方式(Zabbix 前端):Configuration → Templates → Import,选择与目标 Zabbix 大版本匹配的文件(5.0 用 XML,5.4/6.0 用 YAML),导入后模板名为 SNMP HP v1910-24G,位于 Templates 组。随后为 HP v1910-24G 主机配置 SNMP 接口(community 与宏按环境设置)并链接该模板即可开始采集。需要注意:模板本身不含任何宏(README 与配置中均无 macros 段),SNMP community 等参数需在主机层或全局宏层提供。
使用建议与注意事项
- 启用端口状态监控:默认
Status port N监控项及其 down 触发器均为禁用状态,对需要重点保障的链路(如上行口、服务器接入口)应逐个启用。 - CRC 阈值调优:错误增量阈值固定为
>3(10 采样点窗口),在错误本就较多的老旧线缆环境中可调大阈值或延长窗口(如#30)以减少误报;在关键链路上可调低。 - 端口数量扩展:模板为静态建模,若设备实际启用端口数超过 28,需在导入后复制对应监控项、触发器与图形并修改 ifIndex。
- README 与实体的差异:各版本 README 声明"无触发器、无发现规则",与配置实体中的 85 个触发器不符,阅读文档时应以 YAML / XML 配置为准。
综上,SNMP HP v1910-24G 模板以标准 ifTable OID 为核心,通过"计数器预处理为 bps 速率 + delta 增量错误检测 + 状态监控"的组合,为 HP v1910-24G 接入交换机提供了完整的端口级流量、链路质量与可用性监控能力;理解其静态建模风格与默认禁用策略,是正确使用和二次改造该模板的关键。