doupu7651 2016-09-06 15:38
浏览 27
已采纳

Bosun-使用.GetMeta获取主机的IP地址

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
}
  • 写回答

1条回答 默认 最新

  • dongyi6269 2016-09-06 16:08
    关注

    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) }}
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看