簡體   English   中英

Bosun從不發送未知通知

[英]bosun never send unknown notifications

未知通知確實困擾着我,官方文檔似乎比發布的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)

在研究了代碼之后,我終於找到了問題,這很簡單:

未知通知必須作為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更改為crit並將critNotification和通知成功發送。 這應該記錄在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 url前綴http:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM