2016-09-06 1 views
1

http를 통해 전송 된 bosun 경고를 처리하기위한 (golang) 구조체를 만들려고합니다. 가장 중요한 것은 해당 호스트의 eth0 IP 주소에 대한 경보 세부 정보입니다. 다음과 같이Bosun - .GetMeta를 사용하여 호스트의 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 
} 

답변

2

는 당신 확인한다는 eth0를 장치로 문제의 호스트 (및 bosun이 해당 메타 데이터를 색인에 추가 했습니까?) nil은 항목을 찾을 수 없음을 의미합니다. 나를 위해

다음 작품 :

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

그것은 eth0를 가지고 않습니다, 나는 그것을 확인했다. 당신이 게시 한 스 니펫도 작동합니다. 그러나 내가 그것을 사용하려고 할 때, 그것은 실패합니다. 왜 어떤 포인터. – krish7919

+0

어떤 보순 버전입니까? –

+0

./bosun --version bosun 버전 0.5.0-dev (00772aee8c27482893f885bbdbb10e26f75d7fd0) 빌드 됨 2016-06-22T00 : 47 : 49Z – krish7919