Use ctx.States() for alert cards in HTML report
Build alert cards from rule states when available; fall back to raw-data analysis (resolve failures, CNAME violations, unreachable targets) when states are absent.
This commit is contained in:
parent
a1e33e90f7
commit
0a41c706aa
1 changed files with 72 additions and 45 deletions
|
|
@ -256,6 +256,32 @@ func (p *srvProvider) GetHTMLReport(ctx sdk.ReportContext) (string, error) {
|
||||||
rd.Records = append(rd.Records, rec)
|
rd.Records = append(rd.Records, rec)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build alerts from rule states when available; fall back to raw-data
|
||||||
|
// analysis when the host hasn't threaded rule output through yet.
|
||||||
|
states := ctx.States()
|
||||||
|
if len(states) > 0 {
|
||||||
|
for _, st := range states {
|
||||||
|
sev := ""
|
||||||
|
switch st.Status {
|
||||||
|
case sdk.StatusCrit, sdk.StatusError:
|
||||||
|
sev = "crit"
|
||||||
|
case sdk.StatusWarn:
|
||||||
|
sev = "warn"
|
||||||
|
case sdk.StatusInfo:
|
||||||
|
sev = "info"
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
alert := reportAlert{
|
||||||
|
Severity: sev,
|
||||||
|
Title: st.Message,
|
||||||
|
}
|
||||||
|
if fix, ok := st.Meta["fix"].(string); ok && fix != "" {
|
||||||
|
alert.Body = template.HTML(template.HTMLEscapeString(fix))
|
||||||
|
}
|
||||||
|
rd.Alerts = append(rd.Alerts, alert)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if len(resolveFails) > 0 {
|
if len(resolveFails) > 0 {
|
||||||
rd.Alerts = append(rd.Alerts, reportAlert{
|
rd.Alerts = append(rd.Alerts, reportAlert{
|
||||||
Severity: "crit",
|
Severity: "crit",
|
||||||
|
|
@ -303,6 +329,7 @@ func (p *srvProvider) GetHTMLReport(ctx sdk.ReportContext) (string, error) {
|
||||||
"If you expected clients to reach this service, replace the null target with a real hostname."),
|
"If you expected clients to reach this service, replace the null target with a real hostname."),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var buf strings.Builder
|
var buf strings.Builder
|
||||||
if err := htmlTpl.Execute(&buf, rd); err != nil {
|
if err := htmlTpl.Execute(&buf, rd); err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue