Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/bosun: stopping notifications that should no longer fire #1716

Merged
merged 3 commits into from
May 6, 2016
Merged
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
13 changes: 12 additions & 1 deletion cmd/bosun/sched/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func (s *Schedule) sendNotifications(silenced SilenceTester) {
for n, states := range s.pendingNotifications {
for _, st := range states {
ak := st.AlertKey
alert := s.Conf.Alerts[ak.Name()]
if alert == nil {
continue
}
silenced := silenced(ak) != nil
if st.CurrentStatus == models.StUnknown {
if silenced {
Expand All @@ -121,7 +125,14 @@ func (s *Schedule) sendNotifications(silenced SilenceTester) {
}
s.pendingUnknowns[n] = append(s.pendingUnknowns[n], st)
} else if silenced {
slog.Infoln("silencing", ak)
slog.Infof("silencing %s", ak)
continue
} else if !alert.Log && (!st.Open || !st.NeedAck) {
slog.Errorf("Cannot notify acked or closed alert %s. Clearing.", ak)
if err := s.DataAccess.Notifications().ClearNotifications(ak); err != nil {
slog.Error(err)
}
continue
} else {
s.notify(st, n)
}
Expand Down
20 changes: 11 additions & 9 deletions cmd/bosun/sched/sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,20 @@ func (s *Schedule) ActionByIncidentId(user, message string, t models.ActionType,
return s.action(user, message, t, st)
}

func (s *Schedule) action(user, message string, t models.ActionType, st *models.IncidentState) (models.AlertKey, error) {
func (s *Schedule) action(user, message string, t models.ActionType, st *models.IncidentState) (ak models.AlertKey, e error) {
if err := collect.Add("actions", opentsdb.TagSet{"user": user, "alert": st.AlertKey.Name(), "type": t.String()}, 1); err != nil {
slog.Errorln(err)
}
defer func() {
if e == nil {
if err := collect.Add("actions", opentsdb.TagSet{"user": user, "alert": st.AlertKey.Name(), "type": t.String()}, 1); err != nil {
slog.Errorln(err)
}
if err := s.DataAccess.Notifications().ClearNotifications(st.AlertKey); err != nil {
e = err
}
}
}()
isUnknown := st.LastAbnormalStatus == models.StUnknown
timestamp := utcNow()
switch t {
Expand All @@ -612,9 +622,6 @@ func (s *Schedule) action(user, message string, t models.ActionType, st *models.
return "", fmt.Errorf("cannot acknowledge closed alert")
}
st.NeedAck = false
if err := s.DataAccess.Notifications().ClearNotifications(st.AlertKey); err != nil {
return "", err
}
case models.ActionClose:
if st.IsActive() {
return "", fmt.Errorf("cannot close active alert")
Expand All @@ -633,11 +640,6 @@ func (s *Schedule) action(user, message string, t models.ActionType, st *models.
default:
return "", fmt.Errorf("unknown action type: %v", t)
}
// Would like to also track the alert group, but I believe this is impossible because any character
// that could be used as a delimiter could also be a valid tag key or tag value character
if err := collect.Add("actions", opentsdb.TagSet{"user": user, "alert": st.AlertKey.Name(), "type": t.String()}, 1); err != nil {
slog.Errorln(err)
}
st.Actions = append(st.Actions, models.Action{
Message: message,
Time: timestamp,
Expand Down