这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions cmd/bosun/conf/unknownNotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ import (
"bosun.org/slog"
)

type UnknownNotificationIncidentState struct {
*models.IncidentState
AlertVars Vars
}

type unknownContext struct {
Time time.Time
Name string
Group models.AlertKeys
States *models.IncidentState
States *UnknownNotificationIncidentState
makeLink func(string, *url.Values) string
}

Expand Down Expand Up @@ -53,12 +58,16 @@ func init() {
unknownDefaults.body = template.Must(template.New("body").Parse(body))
}

func (n *Notification) PrepareUnknown(t *Template, c SystemConfProvider, name string, aks []models.AlertKey, states *models.IncidentState) *PreparedNotifications {
func (n *Notification) PrepareUnknown(t *Template, c SystemConfProvider, name string, aks []models.AlertKey, states *models.IncidentState, rcp RuleConfProvider) *PreparedNotifications {
unknownStates := &UnknownNotificationIncidentState{
IncidentState: states,
AlertVars: rcp.GetAlert(states.Alert).Vars,
}
ctx := &unknownContext{
Time: time.Now().UTC(),
Name: name,
Group: aks,
States: states,
States: unknownStates,
makeLink: c.MakeLink,
}
pn := &PreparedNotifications{}
Expand Down Expand Up @@ -112,8 +121,8 @@ func (n *Notification) PrepareUnknown(t *Template, c SystemConfProvider, name st
return pn
}

func (n *Notification) NotifyUnknown(t *Template, c SystemConfProvider, name string, aks []models.AlertKey, states *models.IncidentState) {
go n.PrepareUnknown(t, c, name, aks, states).Send(c)
func (n *Notification) NotifyUnknown(t *Template, c SystemConfProvider, name string, aks []models.AlertKey, states *models.IncidentState, rcp RuleConfProvider) {
go n.PrepareUnknown(t, c, name, aks, states, rcp).Send(c)
}

var unknownMultiDefaults defaultTemplates
Expand All @@ -122,7 +131,7 @@ type unknownMultiContext struct {
Time time.Time
Threshold int
Groups map[string]models.AlertKeys
States []*models.IncidentState
States []*UnknownNotificationIncidentState
}

func init() {
Expand All @@ -147,12 +156,18 @@ func init() {
unknownMultiDefaults.body = template.Must(template.New("body").Parse(body))
}

func (n *Notification) PrepareMultipleUnknowns(t *Template, c SystemConfProvider, groups map[string]models.AlertKeys, states []*models.IncidentState) *PreparedNotifications {
func (n *Notification) PrepareMultipleUnknowns(t *Template, c SystemConfProvider, groups map[string]models.AlertKeys, states []*models.IncidentState, rcp RuleConfProvider) *PreparedNotifications {
var unknownStates []*UnknownNotificationIncidentState
for _, state := range states {
us := UnknownNotificationIncidentState{IncidentState: state, AlertVars: rcp.GetAlert(state.Alert).Vars}
unknownStates = append(unknownStates, &us)
}

ctx := &unknownMultiContext{
Time: time.Now().UTC(),
Threshold: c.GetUnknownThreshold(),
Groups: groups,
States: states,
States: unknownStates,
}
pn := &PreparedNotifications{}
buf := &bytes.Buffer{}
Expand Down Expand Up @@ -193,8 +208,8 @@ func (n *Notification) PrepareMultipleUnknowns(t *Template, c SystemConfProvider
return pn
}

func (n *Notification) NotifyMultipleUnknowns(t *Template, c SystemConfProvider, groups map[string]models.AlertKeys, states []*models.IncidentState) {
n.PrepareMultipleUnknowns(t, c, groups, states).Send(c)
func (n *Notification) NotifyMultipleUnknowns(t *Template, c SystemConfProvider, groups map[string]models.AlertKeys, states []*models.IncidentState, rcp RuleConfProvider) {
n.PrepareMultipleUnknowns(t, c, groups, states, rcp).Send(c)
}

// code common to PrepareAction / PrepareUnknown / PrepareMultipleUnknowns
Expand Down
6 changes: 3 additions & 3 deletions cmd/bosun/sched/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,19 @@ func (s *Schedule) sendUnknownNotifications() {
if c >= threshold && threshold > 0 {
if !hitThreshold && len(groupSets) == c {
// If the threshold is hit but only 1 email remains, just send the normal unknown
n.NotifyUnknown(gk.template, s.SystemConf, name, group, ustates[ak])
n.NotifyUnknown(gk.template, s.SystemConf, name, group, ustates[ak], s.RuleConf)
break
}
hitThreshold = true
overThresholdSets[name] = group
multiUstates = append(multiUstates, ustates[ak])
} else {
n.NotifyUnknown(gk.template, s.SystemConf, name, group, ustates[ak])
n.NotifyUnknown(gk.template, s.SystemConf, name, group, ustates[ak], s.RuleConf)
}
}
}
if len(overThresholdSets) > 0 {
n.NotifyMultipleUnknowns(gk.template, s.SystemConf, overThresholdSets, multiUstates)
n.NotifyMultipleUnknowns(gk.template, s.SystemConf, overThresholdSets, multiUstates, s.RuleConf)
}
}
s.pendingUnknowns = make(map[notificationGroupKey][]*models.IncidentState)
Expand Down