SendAlerts implements a rules.NotifyFunc for a Notifier. It filters any non-firing alerts from the input. Copied from Prometheus's main.go.
(n sender, externalURL string)
| 508 | // |
| 509 | // Copied from Prometheus's main.go. |
| 510 | func SendAlerts(n sender, externalURL string) promRules.NotifyFunc { |
| 511 | return func(ctx context.Context, expr string, alerts ...*promRules.Alert) { |
| 512 | var res []*notifier.Alert |
| 513 | |
| 514 | for _, alert := range alerts { |
| 515 | a := ¬ifier.Alert{ |
| 516 | StartsAt: alert.FiredAt, |
| 517 | Labels: alert.Labels, |
| 518 | Annotations: alert.Annotations, |
| 519 | GeneratorURL: externalURL + strutil.TableLinkForExpression(expr), |
| 520 | } |
| 521 | if !alert.ResolvedAt.IsZero() { |
| 522 | a.EndsAt = alert.ResolvedAt |
| 523 | } else { |
| 524 | a.EndsAt = alert.ValidUntil |
| 525 | } |
| 526 | res = append(res, a) |
| 527 | } |
| 528 | |
| 529 | if len(alerts) > 0 { |
| 530 | n.Send(res...) |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | func ruleGroupDisabled(ruleGroup *rulespb.RuleGroupDesc, disabledRuleGroupsForUser validation.DisabledRuleGroups) bool { |
| 536 | for _, disabledRuleGroupForUser := range disabledRuleGroupsForUser { |