I am trying to create a (golang) struct for handling bosun alerts sent over http. It holds alert details, most importantly, about the eth0
IP address of the corresponding host.
/* 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"`
}
The corresponding template looks as follows:
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 = ``
}
However, I get this error:
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
I am using a []string for IpMac field as I cannot isolate the eth0 IP from it's ethernet address.
Any way to do this?
EDIT: This is the output I get:
"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"] }
This is the alert I have configured:
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
}
Are you sure that the host in question as an eth0 device (and bosun has indexed that metadata)? nil means it couldn't find the entry.
The following works for me:
template test {
subject = {{ .GetMeta "" "addresses" (printf "host=%s,iface=eth0" .Group.host) }}
}