MCPcopy Create free account
hub / github.com/cortexproject/cortex / SendAlerts

Function SendAlerts

pkg/ruler/ruler.go:510–533  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

508//
509// Copied from Prometheus's main.go.
510func 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 := &notifier.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
535func ruleGroupDisabled(ruleGroup *rulespb.RuleGroupDesc, disabledRuleGroupsForUser validation.DisabledRuleGroups) bool {
536 for _, disabledRuleGroupForUser := range disabledRuleGroupsForUser {

Callers 2

TestSendAlertsFunction · 0.85

Calls 1

SendMethod · 0.65

Tested by 1

TestSendAlertsFunction · 0.68