警报值替换为prometheus模板字典中的字符串
我对普罗米修斯的APC UPS进行了SNMP监控 我有这样的戒备规则:警报值替换为prometheus模板字典中的字符串,prometheus,Prometheus,我对普罗米修斯的APC UPS进行了SNMP监控 我有这样的戒备规则: - alert: 'APC status' expr: apc_snmp_power_status{job="apc_snmp"} != 2 #snmp upsBasicOutputStatus, UID 1.3.6.1.4.1.318.1.1.1.4.1.1.0 for: 3m labels: severity: 'warning' annotations:
- alert: 'APC status'
expr: apc_snmp_power_status{job="apc_snmp"} != 2
#snmp upsBasicOutputStatus, UID 1.3.6.1.4.1.318.1.1.1.4.1.1.0
for: 3m
labels:
severity: 'warning'
annotations:
title: 'APC {{ $labels.apcname }} status error.'
description: 'APC UPS management card {{ $labels.instance }} reports that UPS {{ $labels.apcname }} is not in Online status. (status {{ $value }}).
1: unknown \
2: onLine \
3: onBattery \
4: onSmartBoost \
5: timedSleeping \
6: softwareBypass \
7: off \
8: rebooting \
... '
是否可以在这里实现任何模板,用字典中对应的字符串替换$value
我想收到通知的形式
'APC UPS管理卡1.2.3.4报告UPS myAPC处于电池状态。(状态3)。经过几个小时的挖掘,它似乎起了作用:
- alert: 'APC status'
expr: apc_snmp_power_status{job="apc_snmp"} != 2
#snmp upsBasicOutputStatus, UID 1.3.6.1.4.1.318.1.1.1.4.1.1.0
for: 30s
labels:
severity: 'warning'
annotations:
title: 'APC {{ $labels.apcname }} status error.'
description: 'APC UPS management card {{ $labels.instance }} reports that UPS {{ $labels.apcname }} is in
{{ if eq ($value | humanize) "1" }} unknown
{{ else if eq ($value | humanize) "2" }} onLine
{{ else if eq ($value | humanize) "3" }} onBattery
{{ else if eq ($value | humanize) "4" }} onSmartBoost
{{ else if eq ($value | humanize) "5" }} timedSleeping
{{ else if eq ($value | humanize) "6" }} softwareBypass
{{ else if eq ($value | humanize) "7" }} off
{{ else if eq ($value | humanize) "8" }} rebooting {{ end }} status. (status {{ $value }})'
问题是比较float64类型和int,我通过“人性化”函数和int的引号解决了这个问题。
我不知道GoLang,也许有另一个更简单的解决方案