2016-09-06 27 views
1

我想创建一个(golang)结构来处理通过http发送的博迅警报。它拥有警报详细信息,最重要的是,其中包含相应主机的IP地址eth0Bosun - 获取主机的IP地址使用.GetMeta

/* 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 
} 

回答

2

你肯定有问题的主机作为eth0设备(和bosun已经索引了这些元数据)?零表示无法找到条目。

对我来说,以下工作:

template test { 
    subject = {{ .GetMeta "" "addresses" (printf "host=%s,iface=eth0" .Group.host) }} 
} 
+0

它确实有eth0的,我已经检查了。你发布的片段也适用。但是当我像我一样尝试使用它时,它就会失败。任何指针为什么。 – krish7919

+0

什么Bosun版本? –

+0

./bosun --version bosun版本0.5.0-dev(00772aee8c27482893f885bbdbb10e26f75d7fd0)内置2016-06-22T00:47:49Z – krish7919