Bosun从不发送未知通知

时间:2018-10-10 09:34:53

标签: alert bosun

未知通知确实困扰着我,官方文档似乎比已发布的bosun二进制更新,例如unknownPost是ilegal选项。

以下未知模板和通知无效。我可以在bosun UI中看到未知通知,但它不发送通知(http警报)。其他正常警报也可以正常工作。

template tmpl_unknown {
    body = 'x'
    subject = `{{$v := .Eval .Alert.Vars.val }}{"warn_undo": [{"app":"xxx","db_type":"NOSQL","db_cat":"aaaa","ip":"{{.Group.host}}","warn_level":1,"warn_type":"cpu","warn_detail":"cpu {{.Group.device}} total util is {{$v.Value | pct}} ","notifier": "xxxxxxxx","status":"undo","report_time":""}]}`

    # body = {{.Name}}: {{.Group | len}} unknown alerts
    # subject = `{"warn_undo": [{"app":"aaaa","db_type":"NOSQL","db_cat":"aaaa","ip":"x.x.x.x","warn_level":1,"warn_type":"alive","warn_detail":"Time: {{.Time}} xName: {{.Name}}  Alerts:{{range .Group}}{{.}},{{end}}","notifier": "xxxxxxxx","status":"undo","report_time":""}]}`

    unknown_alive = `
    {"warn_undo": [{"app":"aaaa","db_type":"NOSQL","db_cat":"aaaa","ip":"x.x.x.x","warn_level":1,"warn_type":"alive","warn_detail":"Time: {{.Time}} Name: {{.Name}}  Alerts:{{range .Group}}{{.}},{{end}}","notifier": "xxxxxxxx","status":"undo","report_time":""}]}`
}

unknownTemplate = tmpl_unknown


notification gcsx_unknown {
        post = ${sys.gcsAlert}
        contentType = application/json
        print = True
        timeout = 5m
        next = gcsx_unknown
        unknownBody = unknown_alive
        bodyTemplate = subject
        # unknownMinGroupSize = 5
        # unknownThreshold = 0
}

alert cpu_total_util_or_unknown {
        template = tmpl_unknown
        $val = avg(q("none:0all-last:cpu.pct_used{host=*,device=total}", "1m", ""))
        warn = $val > 60
        warnNotification = gcsx_unknown
        runEvery = 1
        unknown = 1m
}

我想提醒CPU使用情况。如果主机不见了,没有数据报告,我将收到未知警报。

Bosun版本:master分支的最新版本(2018.10.08)

1 个答案:

答案 0 :(得分:0)

在挖掘代码之后,我终于找到了问题,这很简单:

未知通知必须以critNotification的形式发送

cmd/bosun/sched/check.go:290

    incident.NeedAck = true
    switch event.Status {
    case models.StCritical, models.StUnknown:
        notify(a.CritNotification)
    case models.StWarning:
        notify(a.WarnNotification)
    }

warnwarnNotification更改为critcritNotification,便成功发送了通知。这应该记录在bosun.org中。

unknownPost是合法选项,就像unknownPostunknownGetunknownBodyunknownEmailSubject一样。但是应该在模板变量中定义它们,否则它将报告错误:

2018/10/11 16:19:36 fatal: main.go:130: couldn't read rules: conf: bosun_rule.conf:47:0: at <alert x...>: 
notification x uses template key unknown_post in unknown post url, but template cpu_util does not include it

正确的方法是:

template tmpl_unknown {
    unknown_alive = `
    {"warn_undo": [{"app":"xxx","db_type":"NOSQL","db_cat":"aaaa","ip":"x.x.x.x","warn_level":1,"warn_type":"alive","warn_detail":"Time: {{.Time}} Name: {{.Name}}  Alerts:{{range .Group}}{{.}},{{end}}","notifier": "xxx","status":"undo","report_time":""}]}`
    unknown_post = "//x.x.x.x:7777/alert"
    # unknown_post = {{ V "$gcsAlert" }}
}

notification gcsx_unknown {
        post = ${sys.gcsAlert}
        contentType = application/json
        print = True
        timeout = 5m
        next = gcsx_unknown
        unknownBody = unknown_alive
        unknownPost = unknown_post
}

您注意到,需要删除http网址前缀http: