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

[Not needed?] Add ability to disable sending notifications #9

Draft
wants to merge 1 commit into
base: soracom_main
Choose a base branch
from
Draft
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: 9 additions & 4 deletions pkg/services/alerting/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"os"
"time"

"github.com/grafana/grafana/pkg/components/imguploader"
Expand Down Expand Up @@ -142,10 +143,14 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
n.log.Error("failed trying to evaluate notification template fields", "uid", notifier.GetNotifierUID(), "error", err)
}

if err := notifier.Notify(evalContext); err != nil {
n.log.Error("failed to send notification", "uid", notifier.GetNotifierUID(), "error", err)
metrics.MAlertingNotificationFailed.WithLabelValues(notifier.GetType()).Inc()
return err
if os.Getenv("LAGOON_SEND_NOTIFICATIONS") == "true" {
if err := notifier.Notify(evalContext); err != nil {
n.log.Error("failed to send notification", "uid", notifier.GetNotifierUID(), "error", err)
metrics.MAlertingNotificationFailed.WithLabelValues(notifier.GetType()).Inc()
return err
}
} else {
n.log.Info("NOT sending notification", "notification_type", notifier.GetType())
}

if evalContext.IsTestRun {
Expand Down
7 changes: 7 additions & 0 deletions pkg/services/ngalert/schedule/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/url"
"os"
"sync"
"time"

Expand Down Expand Up @@ -533,6 +534,12 @@ func (sch *schedule) ruleRoutine(grafanaCtx context.Context, key ngmodels.AlertR
evalTotalFailures := sch.metrics.EvalFailures.WithLabelValues(orgID)

notify := func(alerts definitions.PostableAlerts, logger log.Logger) {
if os.Getenv("LAGOON_SEND_NOTIFICATIONS") != "true" {
if len(alerts.PostableAlerts) > 0 {
logger.Info("DISABLED_NOTIFICATIONS", "alerts", alerts)
}
return
}
if len(alerts.PostableAlerts) == 0 {
logger.Debug("no alerts to put in the notifier or to send to external Alertmanager(s)")
return
Expand Down