2016-09-06 108 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