[英]bosun never send unknown notifications
Unknown notfication is really struggling me and the official docs seems newer than released bosun binary, like unknownPost
is ilegal option. 未知通知确实困扰着我,官方文档似乎比发布的bosun二进制更新,例如unknownPost
是ilegal选项。
The following unknown template and notification do not work. 以下未知模板和通知无效。 I can see unknown notfications in bosun UI, but it doesn't send notification(http alert). 我可以在bosun UI中看到未知通知,但它不发送通知(http警报)。 Other normal alerts work fine. 其他正常警报可以正常工作。
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
}
I want to alert cpu usage. 我想提醒CPU使用情况。 If host is gone, no data reported and I will got an unknown alert. 如果主机不见了,没有数据报告,我将收到未知警报。
Bosun version: the newest compiled from master branch(2018.10.08) Bosun版本:master分支的最新版本(2018.10.08)
After digging the code, I found the issue finally and it's simply: 在研究了代码之后,我终于找到了问题,这很简单:
unknown notification must be sent as critNotification
未知通知必须作为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)
}
Change warn
, warnNotification
to crit
and critNotification
and notfication is sent successfully. 将warn
, warnNotification
更改为crit
并将critNotification
和通知成功发送。 This should be documented in bosun.org. 这应该记录在bosun.org中。
unknownPost
is a legal option, just like unknownPost
, unknownGet
, unknownBody
, unknownEmailSubject
. unknownPost
是一个合法选项,就像unknownPost
, unknownGet
, unknownBody
, unknownEmailSubject
。 But they should be defined in template variables, or it will report error: 但是它们应该在模板变量中定义,否则将报告错误:
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
The right way is: 正确的方法是:
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
}
As you note that the http url prefix http:
need to be removed. 如您所见,需要删除http url前缀http:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.