1

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
}
krish7919
  • 892
  • 2
  • 13
  • 30

1 Answers1

2

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) }}
}
Kyle Brandt
  • 26,938
  • 37
  • 124
  • 165
  • It does have eth0, I have checked that. The snippet you posted works too. But when I try to use it as I do, it fails. Any pointers why. – krish7919 Sep 06 '16 at 16:14
  • What Bosun version? – Kyle Brandt Sep 06 '16 at 16:15
  • ./bosun --version bosun version 0.5.0-dev (00772aee8c27482893f885bbdbb10e26f75d7fd0) built 2016-06-22T00:47:49Z – krish7919 Sep 06 '16 at 16:16
  • Not sure ... What you provided would error for me because of `Group` and not `.Group`. Is the snippet different from what you are running. Maybe yo ucan post more/ I'm not sure I understand how the Go struct fits in, is that something you are using in a different process? – Kyle Brandt Sep 06 '16 at 16:25
  • I also don't understand where the `ifName` in the error comes from since the alert that goes with the template is not shown. – Kyle Brandt Sep 06 '16 at 16:27
  • I updated the question. Had missed the '.' while formatting the question here. – krish7919 Sep 06 '16 at 16:29
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/122768/discussion-between-krish7919-and-kyle-brandt). – krish7919 Sep 06 '16 at 16:33
  • Might also see if host api sees it: `curl bosun/api/host | jq '."ny-bosun01" | ."Interfaces"'` , replacing ny-bosun01 with your host 147210308125790 ( odd hostname by the way :P ) – Kyle Brandt Sep 06 '16 at 16:33
  • Thanks, Kyle. The hostname is a timestamp. :) The problem seems to be translating the [IP, Mac] to the golang json struct. I think the bug is on that side. Is there a way to just extract the IP from the host? – krish7919 Sep 06 '16 at 16:35
  • the ifName comes from because I measure the container.net.bytes of an interface. Will edit the question and post the alert. – krish7919 Sep 06 '16 at 16:40
  • alright, I could reproduce this issue and know the root cause. basically when I restart bosun container, scollector does not populate the metadata for a node again. I have opened another one here: http://stackoverflow.com/questions/39362190/scollector-send-metadata-for-a-node-if-bosun-restarts – krish7919 Sep 07 '16 at 06:00