我正在尝试创建一个(golang)结构来处理通过http发送的bosun警报。它包含有关相应主机的eth0 IP地址的警报详细信息(最重要的是)。
/* This struct is defined as per the notification defined in bosun config */
type BosunAlert struct {
AckUrl string `json:"ack"`
AlertName string `json:"alert_name"`
LastStatus string `json:"last_status"`
IpMac []string `json:"ip,omitempty"`
}对应的模板如下:
template template.bosun_listener {
subject = `{
"ack":"{{.Ack}}",
"alert_name":"{{.Alert.Name}}",
"last_status":"{{.Last.Status}}",
"ip":{{ .GetMeta "" "addresses" (printf "host=%s,iface=eth0" .Group.host) }}
}`
body = ``
}然而,我得到了这个错误:
info: check.go:305: alert.network{host=147210308125790,ifName=server-1609}:
template: template.bosun_listener:6:12: executing "template.bosun_listener" at
<.GetMeta>: error calling GetMeta: redigo: nil returned我对IpMac字段使用[]字符串,因为我无法将eth0 IP从其以太网地址中分离出来。
有办法做到这一点吗?
编辑:这是我得到的输出:
"ack":"http://localhost:8070/action?
key=alert.network%7Bhost%3D147210308125790%2CifName%3server-1609%7D&type=ack",
"alert_name":"alert.network", "last_status":"critical", "ip":
["172.31.40.31/20","fe80::61:adff:feb1:1f5b/64"] }这是我配置的警报:
alert alert.network {
runEvery = 5
$ip = ""
template = template.bosun_listener
$usage = avg(q("avg:rate:container.net.bytes{host=*,ifName=server*}", "5m", ""))
crit = $usage > 100
critNotification = notification.test
}发布于 2016-09-07 00:09:00
您确定有问题的主机是eth0设备(并且bosun已经为该元数据建立了索引)吗?nil表示找不到该条目。
下面的方法对我很有效:
template test {
subject = {{ .GetMeta "" "addresses" (printf "host=%s,iface=eth0" .Group.host) }}
}https://stackoverflow.com/questions/39352921
复制相似问题