2016-05-23 07:14:02 -05:00
|
|
|
package alerting
|
2016-06-14 09:56:14 -05:00
|
|
|
|
2016-07-23 04:50:48 -05:00
|
|
|
import (
|
2020-01-17 05:07:16 -06:00
|
|
|
"context"
|
2020-11-19 07:47:17 -06:00
|
|
|
"errors"
|
2016-09-26 03:51:45 -05:00
|
|
|
"fmt"
|
2020-01-17 05:07:16 -06:00
|
|
|
"time"
|
2016-07-23 04:50:48 -05:00
|
|
|
|
2016-07-30 06:36:21 -05:00
|
|
|
"github.com/grafana/grafana/pkg/components/imguploader"
|
2019-05-13 01:45:54 -05:00
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
2019-02-23 16:35:26 -06:00
|
|
|
"github.com/grafana/grafana/pkg/infra/metrics"
|
2019-05-14 01:15:05 -05:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2023-01-23 07:19:25 -06:00
|
|
|
alertmodels "github.com/grafana/grafana/pkg/services/alerting/models"
|
2022-02-03 06:26:05 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/notifications"
|
2022-08-10 04:56:48 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/org"
|
2018-05-24 08:26:27 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/rendering"
|
2018-09-25 05:17:04 -05:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2016-07-23 04:50:48 -05:00
|
|
|
)
|
|
|
|
|
2020-01-14 10:27:16 -06:00
|
|
|
// for stubbing in tests
|
2022-09-12 05:03:49 -05:00
|
|
|
//
|
|
|
|
//nolint:gocritic
|
2020-01-14 10:27:16 -06:00
|
|
|
var newImageUploaderProvider = func() (imguploader.ImageUploader, error) {
|
|
|
|
return imguploader.NewImageUploader()
|
|
|
|
}
|
|
|
|
|
2019-05-20 05:13:32 -05:00
|
|
|
// NotifierPlugin holds meta information about a notifier.
|
2017-01-06 05:04:25 -06:00
|
|
|
type NotifierPlugin struct {
|
2020-09-09 05:46:19 -05:00
|
|
|
Type string `json:"type"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Heading string `json:"heading"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Info string `json:"info"`
|
|
|
|
Factory NotifierFactory `json:"-"`
|
|
|
|
Options []NotifierOption `json:"options"`
|
2020-06-29 06:39:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// NotifierOption holds information about options specific for the NotifierPlugin.
|
|
|
|
type NotifierOption struct {
|
|
|
|
Element ElementType `json:"element"`
|
|
|
|
InputType InputType `json:"inputType"`
|
|
|
|
Label string `json:"label"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Placeholder string `json:"placeholder"`
|
|
|
|
PropertyName string `json:"propertyName"`
|
|
|
|
SelectOptions []SelectOption `json:"selectOptions"`
|
|
|
|
ShowWhen ShowWhen `json:"showWhen"`
|
|
|
|
Required bool `json:"required"`
|
|
|
|
ValidationRule string `json:"validationRule"`
|
2020-09-09 05:46:19 -05:00
|
|
|
Secure bool `json:"secure"`
|
2022-02-25 08:10:21 -06:00
|
|
|
DependsOn string `json:"dependsOn"`
|
2020-06-29 06:39:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// InputType is the type of input that can be rendered in the frontend.
|
|
|
|
type InputType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// InputTypeText will render a text field in the frontend
|
|
|
|
InputTypeText = "text"
|
2021-05-04 06:58:39 -05:00
|
|
|
// InputTypePassword will render a password field in the frontend
|
2020-06-29 06:39:12 -05:00
|
|
|
InputTypePassword = "password"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ElementType is the type of element that can be rendered in the frontend.
|
|
|
|
type ElementType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// ElementTypeInput will render an input
|
|
|
|
ElementTypeInput = "input"
|
|
|
|
// ElementTypeSelect will render a select
|
|
|
|
ElementTypeSelect = "select"
|
2020-09-09 05:46:19 -05:00
|
|
|
// ElementTypeCheckbox will render a checkbox
|
|
|
|
ElementTypeCheckbox = "checkbox"
|
2020-06-29 06:39:12 -05:00
|
|
|
// ElementTypeTextArea will render a textarea
|
|
|
|
ElementTypeTextArea = "textarea"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SelectOption is a simple type for Options that have dropdown options. Should be used when Element is ElementTypeSelect.
|
|
|
|
type SelectOption struct {
|
|
|
|
Value string `json:"value"`
|
|
|
|
Label string `json:"label"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ShowWhen holds information about when options are dependant on other options.
|
|
|
|
type ShowWhen struct {
|
|
|
|
Field string `json:"field"`
|
|
|
|
Is string `json:"is"`
|
2017-01-06 05:04:25 -06:00
|
|
|
}
|
|
|
|
|
2022-02-03 06:26:05 -06:00
|
|
|
func newNotificationService(renderService rendering.Service, sqlStore AlertStore, notificationSvc *notifications.NotificationService, decryptFn GetDecryptedValueFn) *notificationService {
|
2018-05-24 08:26:27 -05:00
|
|
|
return ¬ificationService{
|
2022-02-03 06:26:05 -06:00
|
|
|
log: log.New("alerting.notifier"),
|
|
|
|
renderService: renderService,
|
|
|
|
sqlStore: sqlStore,
|
|
|
|
notificationService: notificationSvc,
|
|
|
|
decryptFn: decryptFn,
|
2018-05-24 08:26:27 -05:00
|
|
|
}
|
2016-07-29 07:55:02 -05:00
|
|
|
}
|
|
|
|
|
2017-02-13 05:43:12 -06:00
|
|
|
type notificationService struct {
|
2022-02-03 06:26:05 -06:00
|
|
|
log log.Logger
|
|
|
|
renderService rendering.Service
|
|
|
|
sqlStore AlertStore
|
|
|
|
notificationService *notifications.NotificationService
|
|
|
|
decryptFn GetDecryptedValueFn
|
2016-10-11 03:13:19 -05:00
|
|
|
}
|
|
|
|
|
2020-01-17 05:07:16 -06:00
|
|
|
func (n *notificationService) SendIfNeeded(evalCtx *EvalContext) error {
|
|
|
|
notifierStates, err := n.getNeededNotifiers(evalCtx.Rule.OrgID, evalCtx.Rule.Notifications, evalCtx)
|
2016-07-25 06:52:17 -05:00
|
|
|
if err != nil {
|
2019-10-16 02:55:51 -05:00
|
|
|
n.log.Error("Failed to get alert notifiers", "error", err)
|
2016-10-03 02:38:03 -05:00
|
|
|
return err
|
2016-07-25 06:52:17 -05:00
|
|
|
}
|
2016-07-23 04:50:48 -05:00
|
|
|
|
2018-09-27 07:32:54 -05:00
|
|
|
if len(notifierStates) == 0 {
|
2016-10-03 02:38:03 -05:00
|
|
|
return nil
|
2016-07-31 02:31:32 -05:00
|
|
|
}
|
|
|
|
|
2018-09-27 07:32:54 -05:00
|
|
|
if notifierStates.ShouldUploadImage() {
|
2020-04-24 04:35:55 -05:00
|
|
|
// Create a copy of EvalContext and give it a new, shorter, timeout context to upload the image
|
|
|
|
uploadEvalCtx := *evalCtx
|
|
|
|
timeout := setting.AlertingNotificationTimeout / 2
|
|
|
|
var uploadCtxCancel func()
|
|
|
|
uploadEvalCtx.Ctx, uploadCtxCancel = context.WithTimeout(evalCtx.Ctx, timeout)
|
|
|
|
|
|
|
|
// Try to upload the image without consuming all the time allocated for EvalContext
|
|
|
|
if err = n.renderAndUploadImage(&uploadEvalCtx, timeout); err != nil {
|
|
|
|
n.log.Error("Failed to render and upload alert panel image.", "ruleId", uploadEvalCtx.Rule.ID, "error", err)
|
2017-02-13 05:43:12 -06:00
|
|
|
}
|
2020-04-24 04:35:55 -05:00
|
|
|
uploadCtxCancel()
|
|
|
|
evalCtx.ImageOnDiskPath = uploadEvalCtx.ImageOnDiskPath
|
|
|
|
evalCtx.ImagePublicURL = uploadEvalCtx.ImagePublicURL
|
2016-07-30 06:36:21 -05:00
|
|
|
}
|
|
|
|
|
2020-01-17 05:07:16 -06:00
|
|
|
return n.sendNotifications(evalCtx, notifierStates)
|
2018-09-27 07:32:54 -05:00
|
|
|
}
|
2018-09-27 04:33:13 -05:00
|
|
|
|
2018-10-02 07:03:30 -05:00
|
|
|
func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, notifierState *notifierState) error {
|
2018-10-02 07:04:50 -05:00
|
|
|
notifier := notifierState.notifier
|
2018-10-02 07:23:18 -05:00
|
|
|
|
2019-06-03 03:25:58 -05:00
|
|
|
n.log.Debug("Sending notification", "type", notifier.GetType(), "uid", notifier.GetNotifierUID(), "isDefault", notifier.GetIsDefault())
|
2019-07-16 09:58:46 -05:00
|
|
|
metrics.MAlertingNotificationSent.WithLabelValues(notifier.GetType()).Inc()
|
2018-09-28 04:14:36 -05:00
|
|
|
|
2021-01-19 15:02:44 -06:00
|
|
|
if err := evalContext.evaluateNotificationTemplateFields(); err != nil {
|
2023-09-04 11:46:34 -05:00
|
|
|
n.log.Error("Failed trying to evaluate notification template fields", "uid", notifier.GetNotifierUID(), "error", err)
|
2021-01-19 15:02:44 -06:00
|
|
|
}
|
2018-09-28 07:12:26 -05:00
|
|
|
|
2021-01-19 15:02:44 -06:00
|
|
|
if err := notifier.Notify(evalContext); err != nil {
|
2023-09-04 11:46:34 -05:00
|
|
|
n.log.Error("Failed to send notification", "uid", notifier.GetNotifierUID(), "error", err)
|
2019-07-24 04:43:24 -05:00
|
|
|
metrics.MAlertingNotificationFailed.WithLabelValues(notifier.GetType()).Inc()
|
2019-09-09 07:09:21 -05:00
|
|
|
return err
|
2018-09-28 04:14:36 -05:00
|
|
|
}
|
|
|
|
|
2018-09-28 07:12:26 -05:00
|
|
|
if evalContext.IsTestRun {
|
2018-09-28 04:14:36 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-01-23 07:19:25 -06:00
|
|
|
cmd := &alertmodels.SetAlertNotificationStateToCompleteCommand{
|
2023-02-03 08:46:55 -06:00
|
|
|
ID: notifierState.state.ID,
|
2018-10-02 06:57:41 -05:00
|
|
|
Version: notifierState.state.Version,
|
2018-09-28 07:12:26 -05:00
|
|
|
}
|
|
|
|
|
2022-02-03 06:26:05 -06:00
|
|
|
return n.sqlStore.SetAlertNotificationStateToCompleteCommand(evalContext.Ctx, cmd)
|
2018-09-27 07:32:54 -05:00
|
|
|
}
|
2018-06-29 09:16:09 -05:00
|
|
|
|
2018-10-02 07:03:30 -05:00
|
|
|
func (n *notificationService) sendNotification(evalContext *EvalContext, notifierState *notifierState) error {
|
2018-09-28 07:12:26 -05:00
|
|
|
if !evalContext.IsTestRun {
|
2023-01-23 07:19:25 -06:00
|
|
|
setPendingCmd := &alertmodels.SetAlertNotificationStateToPendingCommand{
|
2023-02-03 08:46:55 -06:00
|
|
|
ID: notifierState.state.ID,
|
2018-10-02 06:57:41 -05:00
|
|
|
Version: notifierState.state.Version,
|
2018-10-01 07:13:03 -05:00
|
|
|
AlertRuleStateUpdatedVersion: evalContext.Rule.StateChanges,
|
2018-09-28 07:12:26 -05:00
|
|
|
}
|
2018-06-29 09:16:09 -05:00
|
|
|
|
2022-02-03 06:26:05 -06:00
|
|
|
err := n.sqlStore.SetAlertNotificationStateToPendingCommand(evalContext.Ctx, setPendingCmd)
|
2018-09-28 07:12:26 -05:00
|
|
|
if err != nil {
|
2023-01-23 07:19:25 -06:00
|
|
|
if errors.Is(err, alertmodels.ErrAlertNotificationStateVersionConflict) {
|
2020-11-19 07:47:17 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-09-28 07:12:26 -05:00
|
|
|
return err
|
|
|
|
}
|
2018-10-02 06:57:41 -05:00
|
|
|
|
|
|
|
// We need to update state version to be able to log
|
|
|
|
// unexpected version conflicts when marking notifications as ok
|
|
|
|
notifierState.state.Version = setPendingCmd.ResultVersion
|
2018-09-27 07:32:54 -05:00
|
|
|
}
|
2018-09-26 10:26:02 -05:00
|
|
|
|
2018-09-27 07:32:54 -05:00
|
|
|
return n.sendAndMarkAsComplete(evalContext, notifierState)
|
|
|
|
}
|
2018-06-29 09:16:09 -05:00
|
|
|
|
2018-10-02 07:03:30 -05:00
|
|
|
func (n *notificationService) sendNotifications(evalContext *EvalContext, notifierStates notifierStateSlice) error {
|
2018-09-27 07:32:54 -05:00
|
|
|
for _, notifierState := range notifierStates {
|
|
|
|
err := n.sendNotification(evalContext, notifierState)
|
2018-06-29 09:16:09 -05:00
|
|
|
if err != nil {
|
2023-09-04 11:46:34 -05:00
|
|
|
n.log.Error("Failed to send notification", "uid", notifierState.notifier.GetNotifierUID(), "error", err)
|
2019-10-16 02:55:51 -05:00
|
|
|
if evalContext.IsTestRun {
|
|
|
|
return err
|
|
|
|
}
|
2018-06-29 09:16:09 -05:00
|
|
|
}
|
2016-07-23 04:50:48 -05:00
|
|
|
}
|
2018-06-29 09:16:09 -05:00
|
|
|
return nil
|
2016-07-23 04:50:48 -05:00
|
|
|
}
|
|
|
|
|
2020-01-17 05:07:16 -06:00
|
|
|
func (n *notificationService) renderAndUploadImage(evalCtx *EvalContext, timeout time.Duration) (err error) {
|
2020-01-14 10:27:16 -06:00
|
|
|
uploader, err := newImageUploaderProvider()
|
2016-09-29 07:31:19 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-07-30 06:36:21 -05:00
|
|
|
|
2018-05-24 08:26:27 -05:00
|
|
|
renderOpts := rendering.Opts{
|
2022-01-26 16:02:19 -06:00
|
|
|
TimeoutOpts: rendering.TimeoutOpts{
|
|
|
|
Timeout: timeout,
|
|
|
|
},
|
|
|
|
AuthOpts: rendering.AuthOpts{
|
|
|
|
OrgID: evalCtx.Rule.OrgID,
|
2022-08-10 04:56:48 -05:00
|
|
|
OrgRole: org.RoleAdmin,
|
2022-01-26 16:02:19 -06:00
|
|
|
},
|
2018-09-25 05:17:04 -05:00
|
|
|
Width: 1000,
|
|
|
|
Height: 500,
|
|
|
|
ConcurrentLimit: setting.AlertingRenderLimit,
|
2022-02-09 03:23:32 -06:00
|
|
|
Theme: models.ThemeDark,
|
2016-07-30 06:36:21 -05:00
|
|
|
}
|
|
|
|
|
2020-01-17 05:07:16 -06:00
|
|
|
ref, err := evalCtx.GetDashboardUID()
|
Outdent code after if block that ends with return (golint)
This commit fixes the following golint warnings:
pkg/bus/bus.go:64:9: if block ends with a return statement, so drop this else and outdent its block
pkg/bus/bus.go:84:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:137:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:177:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:183:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:199:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:208:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/components/dynmap/dynmap.go:236:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:242:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:257:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:263:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:278:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:284:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:299:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:331:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:350:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:356:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:366:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:390:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:396:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:405:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:427:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:433:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:442:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:459:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:465:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:474:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:491:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:497:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:506:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:523:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:529:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:538:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:555:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:561:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:570:12: if block ends with a return statement, so drop this else and outdent its block
pkg/login/ldap.go:55:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/login/ldap_test.go:372:10: if block ends with a return statement, so drop this else and outdent its block
pkg/middleware/middleware_test.go:213:12: if block ends with a return statement, so drop this else and outdent its block
pkg/plugins/dashboard_importer.go:153:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:39:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:121:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:210:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:235:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/eval_context.go:111:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:92:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:98:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:122:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:108:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:118:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:121:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifiers/telegram.go:94:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/annotation.go:34:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/annotation.go:99:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/dashboard_test.go:107:13: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/plugin_setting.go:78:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/preferences.go:91:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/user.go:50:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/migrator/migrator.go:106:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/migrator/postgres_dialect.go:48:10: if block ends with a return statement, so drop this else and outdent its block
pkg/tsdb/time_range.go:59:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/time_range.go:67:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/cloudwatch/metric_find_query.go:225:9: if block ends with a return statement, so drop this else and outdent its block
pkg/util/filepath.go:68:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
2018-04-27 15:42:49 -05:00
|
|
|
if err != nil {
|
2016-09-26 03:51:45 -05:00
|
|
|
return err
|
|
|
|
}
|
2018-05-24 08:26:27 -05:00
|
|
|
|
2023-01-16 09:33:55 -06:00
|
|
|
renderOpts.Path = fmt.Sprintf("d-solo/%s/%s?orgId=%d&panelId=%d", ref.UID, ref.Slug, evalCtx.Rule.OrgID, evalCtx.Rule.PanelID)
|
2016-09-26 03:51:45 -05:00
|
|
|
|
2020-01-17 05:07:16 -06:00
|
|
|
n.log.Debug("Rendering alert panel image", "ruleId", evalCtx.Rule.ID, "urlPath", renderOpts.Path)
|
|
|
|
start := time.Now()
|
2022-01-26 16:02:19 -06:00
|
|
|
result, err := n.renderService.Render(evalCtx.Ctx, renderOpts, nil)
|
Outdent code after if block that ends with return (golint)
This commit fixes the following golint warnings:
pkg/bus/bus.go:64:9: if block ends with a return statement, so drop this else and outdent its block
pkg/bus/bus.go:84:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:137:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:177:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:183:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:199:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:208:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/components/dynmap/dynmap.go:236:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:242:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:257:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:263:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:278:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:284:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:299:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:331:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:350:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:356:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:366:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:390:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:396:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:405:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:427:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:433:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:442:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:459:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:465:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:474:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:491:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:497:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:506:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:523:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:529:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:538:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:555:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:561:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:570:12: if block ends with a return statement, so drop this else and outdent its block
pkg/login/ldap.go:55:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/login/ldap_test.go:372:10: if block ends with a return statement, so drop this else and outdent its block
pkg/middleware/middleware_test.go:213:12: if block ends with a return statement, so drop this else and outdent its block
pkg/plugins/dashboard_importer.go:153:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:39:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:121:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:210:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:235:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/eval_context.go:111:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:92:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:98:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:122:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:108:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:118:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:121:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifiers/telegram.go:94:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/annotation.go:34:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/annotation.go:99:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/dashboard_test.go:107:13: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/plugin_setting.go:78:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/preferences.go:91:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/user.go:50:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/migrator/migrator.go:106:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/migrator/postgres_dialect.go:48:10: if block ends with a return statement, so drop this else and outdent its block
pkg/tsdb/time_range.go:59:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/time_range.go:67:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/cloudwatch/metric_find_query.go:225:9: if block ends with a return statement, so drop this else and outdent its block
pkg/util/filepath.go:68:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
2018-04-27 15:42:49 -05:00
|
|
|
if err != nil {
|
2016-07-30 06:36:21 -05:00
|
|
|
return err
|
|
|
|
}
|
2020-01-17 05:07:16 -06:00
|
|
|
took := time.Since(start)
|
2016-07-30 06:36:21 -05:00
|
|
|
|
2020-01-17 05:07:16 -06:00
|
|
|
n.log.Debug("Rendered alert panel image", "ruleId", evalCtx.Rule.ID, "path", result.FilePath, "took", took)
|
|
|
|
|
|
|
|
evalCtx.ImageOnDiskPath = result.FilePath
|
2020-04-24 04:35:55 -05:00
|
|
|
|
2020-01-17 05:07:16 -06:00
|
|
|
n.log.Debug("Uploading alert panel image to external image store", "ruleId", evalCtx.Rule.ID, "path", evalCtx.ImageOnDiskPath)
|
|
|
|
|
|
|
|
start = time.Now()
|
|
|
|
evalCtx.ImagePublicURL, err = uploader.Upload(evalCtx.Ctx, evalCtx.ImageOnDiskPath)
|
2016-07-30 06:36:21 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-01-17 05:07:16 -06:00
|
|
|
took = time.Since(start)
|
2016-07-30 06:36:21 -05:00
|
|
|
|
2020-01-17 05:07:16 -06:00
|
|
|
if evalCtx.ImagePublicURL != "" {
|
|
|
|
n.log.Debug("Uploaded alert panel image to external image store", "ruleId", evalCtx.Rule.ID, "url", evalCtx.ImagePublicURL, "took", took)
|
2018-06-29 02:58:58 -05:00
|
|
|
}
|
|
|
|
|
2016-07-30 06:36:21 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-20 05:13:32 -05:00
|
|
|
func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids []string, evalContext *EvalContext) (notifierStateSlice, error) {
|
2023-02-03 08:46:55 -06:00
|
|
|
query := &alertmodels.GetAlertNotificationsWithUidToSendQuery{OrgID: orgID, UIDs: notificationUids}
|
2016-07-23 04:50:48 -05:00
|
|
|
|
2023-02-02 02:41:05 -06:00
|
|
|
res, err := n.sqlStore.GetAlertNotificationsWithUidToSend(evalContext.Ctx, query)
|
|
|
|
if err != nil {
|
2016-07-25 06:52:17 -05:00
|
|
|
return nil, err
|
2016-07-23 04:50:48 -05:00
|
|
|
}
|
|
|
|
|
2018-10-02 07:03:30 -05:00
|
|
|
var result notifierStateSlice
|
2023-02-02 02:41:05 -06:00
|
|
|
for _, notification := range res {
|
2022-02-03 06:26:05 -06:00
|
|
|
not, err := InitNotifier(notification, n.decryptFn, n.notificationService)
|
Outdent code after if block that ends with return (golint)
This commit fixes the following golint warnings:
pkg/bus/bus.go:64:9: if block ends with a return statement, so drop this else and outdent its block
pkg/bus/bus.go:84:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:137:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:177:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:183:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:199:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:208:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/components/dynmap/dynmap.go:236:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:242:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:257:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:263:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:278:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:284:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:299:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:331:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:350:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:356:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:366:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:390:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:396:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:405:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:427:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:433:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:442:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:459:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:465:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:474:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:491:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:497:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:506:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:523:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:529:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:538:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:555:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:561:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:570:12: if block ends with a return statement, so drop this else and outdent its block
pkg/login/ldap.go:55:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/login/ldap_test.go:372:10: if block ends with a return statement, so drop this else and outdent its block
pkg/middleware/middleware_test.go:213:12: if block ends with a return statement, so drop this else and outdent its block
pkg/plugins/dashboard_importer.go:153:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:39:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:121:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:210:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:235:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/eval_context.go:111:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:92:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:98:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:122:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:108:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:118:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:121:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifiers/telegram.go:94:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/annotation.go:34:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/annotation.go:99:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/dashboard_test.go:107:13: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/plugin_setting.go:78:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/preferences.go:91:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/user.go:50:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/migrator/migrator.go:106:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/migrator/postgres_dialect.go:48:10: if block ends with a return statement, so drop this else and outdent its block
pkg/tsdb/time_range.go:59:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/time_range.go:67:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/cloudwatch/metric_find_query.go:225:9: if block ends with a return statement, so drop this else and outdent its block
pkg/util/filepath.go:68:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
2018-04-27 15:42:49 -05:00
|
|
|
if err != nil {
|
2023-02-03 08:46:55 -06:00
|
|
|
n.log.Error("Could not create notifier", "notifier", notification.UID, "error", err)
|
2018-09-27 07:32:54 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-01-23 07:19:25 -06:00
|
|
|
query := &alertmodels.GetOrCreateNotificationStateQuery{
|
2023-02-03 08:46:55 -06:00
|
|
|
NotifierID: notification.ID,
|
|
|
|
AlertID: evalContext.Rule.ID,
|
|
|
|
OrgID: evalContext.Rule.OrgID,
|
2018-09-27 07:32:54 -05:00
|
|
|
}
|
|
|
|
|
2023-02-02 02:41:05 -06:00
|
|
|
state, err := n.sqlStore.GetOrCreateAlertNotificationState(evalContext.Ctx, query)
|
2018-09-27 07:32:54 -05:00
|
|
|
if err != nil {
|
2023-02-03 08:46:55 -06:00
|
|
|
n.log.Error("Could not get notification state.", "notifier", notification.ID, "error", err)
|
2018-09-27 07:32:54 -05:00
|
|
|
continue
|
Outdent code after if block that ends with return (golint)
This commit fixes the following golint warnings:
pkg/bus/bus.go:64:9: if block ends with a return statement, so drop this else and outdent its block
pkg/bus/bus.go:84:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:137:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:177:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:183:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:199:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:208:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/components/dynmap/dynmap.go:236:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:242:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:257:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:263:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:278:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:284:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:299:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:331:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:350:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:356:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:366:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:390:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:396:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:405:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:427:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:433:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:442:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:459:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:465:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:474:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:491:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:497:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:506:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:523:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:529:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:538:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:555:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:561:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:570:12: if block ends with a return statement, so drop this else and outdent its block
pkg/login/ldap.go:55:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/login/ldap_test.go:372:10: if block ends with a return statement, so drop this else and outdent its block
pkg/middleware/middleware_test.go:213:12: if block ends with a return statement, so drop this else and outdent its block
pkg/plugins/dashboard_importer.go:153:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:39:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:121:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:210:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:235:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/eval_context.go:111:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:92:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:98:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:122:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:108:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:118:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:121:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifiers/telegram.go:94:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/annotation.go:34:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/annotation.go:99:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/dashboard_test.go:107:13: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/plugin_setting.go:78:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/preferences.go:91:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/user.go:50:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/migrator/migrator.go:106:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/migrator/postgres_dialect.go:48:10: if block ends with a return statement, so drop this else and outdent its block
pkg/tsdb/time_range.go:59:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/time_range.go:67:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/cloudwatch/metric_find_query.go:225:9: if block ends with a return statement, so drop this else and outdent its block
pkg/util/filepath.go:68:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
2018-04-27 15:42:49 -05:00
|
|
|
}
|
2018-06-05 05:07:02 -05:00
|
|
|
|
2023-02-02 02:41:05 -06:00
|
|
|
if not.ShouldNotify(evalContext.Ctx, evalContext, state) {
|
2018-10-02 07:03:30 -05:00
|
|
|
result = append(result, ¬ifierState{
|
2018-09-27 07:32:54 -05:00
|
|
|
notifier: not,
|
2023-02-02 02:41:05 -06:00
|
|
|
state: state,
|
2018-09-27 07:32:54 -05:00
|
|
|
})
|
2016-07-25 06:52:17 -05:00
|
|
|
}
|
2016-07-23 04:50:48 -05:00
|
|
|
}
|
|
|
|
|
2016-07-25 06:52:17 -05:00
|
|
|
return result, nil
|
2016-07-23 04:50:48 -05:00
|
|
|
}
|
|
|
|
|
2019-05-20 05:13:32 -05:00
|
|
|
// InitNotifier instantiate a new notifier based on the model.
|
2023-01-23 07:19:25 -06:00
|
|
|
func InitNotifier(model *alertmodels.AlertNotification, fn GetDecryptedValueFn, notificationService *notifications.NotificationService) (Notifier, error) {
|
2017-01-06 05:04:25 -06:00
|
|
|
notifierPlugin, found := notifierFactories[model.Type]
|
2016-07-27 05:09:55 -05:00
|
|
|
if !found {
|
2020-11-05 04:57:20 -06:00
|
|
|
return nil, fmt.Errorf("unsupported notification type %q", model.Type)
|
2016-07-23 04:50:48 -05:00
|
|
|
}
|
2016-07-26 05:29:52 -05:00
|
|
|
|
2022-02-03 06:26:05 -06:00
|
|
|
return notifierPlugin.Factory(model, fn, notificationService)
|
2016-07-23 04:50:48 -05:00
|
|
|
}
|
|
|
|
|
2021-10-07 09:33:50 -05:00
|
|
|
// GetDecryptedValueFn is a function that returns the decrypted value of
|
|
|
|
// the given key. If the key is not present, then it returns the fallback value.
|
|
|
|
type GetDecryptedValueFn func(ctx context.Context, sjd map[string][]byte, key string, fallback string, secret string) string
|
|
|
|
|
2019-05-20 05:13:32 -05:00
|
|
|
// NotifierFactory is a signature for creating notifiers.
|
2023-01-23 07:19:25 -06:00
|
|
|
type NotifierFactory func(*alertmodels.AlertNotification, GetDecryptedValueFn, notifications.Service) (Notifier, error)
|
2016-07-25 06:52:17 -05:00
|
|
|
|
2018-04-27 15:14:36 -05:00
|
|
|
var notifierFactories = make(map[string]*NotifierPlugin)
|
2017-01-06 05:04:25 -06:00
|
|
|
|
2021-04-22 09:00:21 -05:00
|
|
|
// RegisterNotifier registers a notifier.
|
2017-01-06 05:04:25 -06:00
|
|
|
func RegisterNotifier(plugin *NotifierPlugin) {
|
|
|
|
notifierFactories[plugin.Type] = plugin
|
|
|
|
}
|
|
|
|
|
2019-05-20 05:13:32 -05:00
|
|
|
// GetNotifiers returns a list of metadata about available notifiers.
|
2017-01-06 05:04:25 -06:00
|
|
|
func GetNotifiers() []*NotifierPlugin {
|
|
|
|
list := make([]*NotifierPlugin, 0)
|
|
|
|
|
|
|
|
for _, value := range notifierFactories {
|
|
|
|
list = append(list, value)
|
|
|
|
}
|
2016-07-23 04:50:48 -05:00
|
|
|
|
2017-01-06 05:04:25 -06:00
|
|
|
return list
|
2016-07-23 04:50:48 -05:00
|
|
|
}
|