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"
|
2016-07-25 06:52:17 -05: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
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
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"
|
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
|
2020-07-16 07:39:01 -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-06-29 06:39:12 -05:00
|
|
|
Type string `json:"type"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Heading string `json:"heading"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Info string `json:"info"`
|
|
|
|
OptionsTemplate string `json:"optionsTemplate"`
|
|
|
|
Factory NotifierFactory `json:"-"`
|
|
|
|
Options []NotifierOption `json:"options"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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"
|
|
|
|
// InputTypePassword will render a text field in the frontend
|
|
|
|
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"
|
|
|
|
// ElementTypeSwitch will render a switch
|
|
|
|
ElementTypeSwitch = "switch"
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2019-05-20 05:13:32 -05:00
|
|
|
func newNotificationService(renderService rendering.Service) *notificationService {
|
2018-05-24 08:26:27 -05:00
|
|
|
return ¬ificationService{
|
|
|
|
log: log.New("alerting.notifier"),
|
|
|
|
renderService: renderService,
|
|
|
|
}
|
2016-07-29 07:55:02 -05:00
|
|
|
}
|
|
|
|
|
2017-02-13 05:43:12 -06:00
|
|
|
type notificationService struct {
|
2018-05-24 08:26:27 -05:00
|
|
|
log log.Logger
|
|
|
|
renderService rendering.Service
|
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
|
|
|
|
2018-10-02 07:04:50 -05:00
|
|
|
err := notifier.Notify(evalContext)
|
2018-09-28 07:12:26 -05:00
|
|
|
|
|
|
|
if err != nil {
|
2019-06-03 03:25:58 -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
|
|
|
|
}
|
|
|
|
|
2019-05-14 01:15:05 -05:00
|
|
|
cmd := &models.SetAlertNotificationStateToCompleteCommand{
|
2018-10-02 07:53:39 -05: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
|
|
|
}
|
|
|
|
|
2018-10-02 07:23:18 -05:00
|
|
|
return bus.DispatchCtx(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 {
|
2019-05-14 01:15:05 -05:00
|
|
|
setPendingCmd := &models.SetAlertNotificationStateToPendingCommand{
|
2018-10-02 07:53:39 -05: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
|
|
|
|
2018-09-28 07:12:26 -05:00
|
|
|
err := bus.DispatchCtx(evalContext.Ctx, setPendingCmd)
|
2019-05-14 01:15:05 -05:00
|
|
|
if err == models.ErrAlertNotificationStateVersionConflict {
|
2018-09-28 07:12:26 -05:00
|
|
|
return nil
|
|
|
|
}
|
2018-08-20 09:27:13 -05:00
|
|
|
|
2018-09-28 07:12:26 -05:00
|
|
|
if err != nil {
|
|
|
|
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 {
|
2019-06-03 03:25:58 -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{
|
2018-09-25 05:17:04 -05:00
|
|
|
Width: 1000,
|
|
|
|
Height: 500,
|
2020-01-17 05:07:16 -06:00
|
|
|
Timeout: timeout,
|
|
|
|
OrgId: evalCtx.Rule.OrgID,
|
2019-05-14 01:15:05 -05:00
|
|
|
OrgRole: models.ROLE_ADMIN,
|
2018-09-25 05:17:04 -05:00
|
|
|
ConcurrentLimit: setting.AlertingRenderLimit,
|
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
|
|
|
|
2020-01-17 05:07:16 -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()
|
|
|
|
result, err := n.renderService.Render(evalCtx.Ctx, renderOpts)
|
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) {
|
|
|
|
query := &models.GetAlertNotificationsWithUidToSendQuery{OrgId: orgID, Uids: notificationUids}
|
2016-07-23 04:50:48 -05:00
|
|
|
|
|
|
|
if err := bus.Dispatch(query); 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
|
2016-07-25 06:52:17 -05:00
|
|
|
for _, notification := range query.Result {
|
2018-12-19 06:38:49 -06:00
|
|
|
not, err := InitNotifier(notification)
|
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 {
|
2018-12-14 03:53:50 -06:00
|
|
|
n.log.Error("Could not create notifier", "notifier", notification.Uid, "error", err)
|
2018-09-27 07:32:54 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-05-14 01:15:05 -05:00
|
|
|
query := &models.GetOrCreateNotificationStateQuery{
|
2018-09-27 07:32:54 -05:00
|
|
|
NotifierId: notification.Id,
|
2019-06-03 03:25:58 -05:00
|
|
|
AlertId: evalContext.Rule.ID,
|
|
|
|
OrgId: evalContext.Rule.OrgID,
|
2018-09-27 07:32:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
err = bus.DispatchCtx(evalContext.Ctx, query)
|
|
|
|
if err != nil {
|
2018-10-02 04:19:09 -05: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
|
|
|
|
2018-09-27 07:32:54 -05:00
|
|
|
if not.ShouldNotify(evalContext.Ctx, evalContext, query.Result) {
|
2018-10-02 07:03:30 -05:00
|
|
|
result = append(result, ¬ifierState{
|
2018-09-27 07:32:54 -05:00
|
|
|
notifier: not,
|
|
|
|
state: query.Result,
|
|
|
|
})
|
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.
|
2019-05-14 01:15:05 -05:00
|
|
|
func InitNotifier(model *models.AlertNotification) (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 {
|
|
|
|
return nil, errors.New("Unsupported notification type")
|
2016-07-23 04:50:48 -05:00
|
|
|
}
|
2016-07-26 05:29:52 -05:00
|
|
|
|
2017-01-06 05:04:25 -06:00
|
|
|
return notifierPlugin.Factory(model)
|
2016-07-23 04:50:48 -05:00
|
|
|
}
|
|
|
|
|
2019-05-20 05:13:32 -05:00
|
|
|
// NotifierFactory is a signature for creating notifiers.
|
2019-05-14 01:15:05 -05:00
|
|
|
type NotifierFactory func(notification *models.AlertNotification) (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
|
|
|
|
2018-12-19 06:38:49 -06:00
|
|
|
// RegisterNotifier register an 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
|
|
|
}
|