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 (
|
2016-07-25 06:52:17 -05:00
|
|
|
"errors"
|
2016-09-26 03:51:45 -05:00
|
|
|
"fmt"
|
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
|
|
|
)
|
|
|
|
|
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 {
|
|
|
|
Type string `json:"type"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
OptionsTemplate string `json:"optionsTemplate"`
|
|
|
|
Factory NotifierFactory `json:"-"`
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-11-15 10:53:02 -06:00
|
|
|
func (n *notificationService) SendIfNeeded(context *EvalContext) error {
|
2019-06-03 03:25:58 -05:00
|
|
|
notifierStates, err := n.getNeededNotifiers(context.Rule.OrgID, context.Rule.Notifications, context)
|
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() {
|
2017-02-13 05:43:12 -06:00
|
|
|
if err = n.uploadImage(context); err != nil {
|
|
|
|
n.log.Error("Failed to upload alert panel image.", "error", err)
|
|
|
|
}
|
2016-07-30 06:36:21 -05:00
|
|
|
}
|
|
|
|
|
2018-09-27 07:32:54 -05:00
|
|
|
return n.sendNotifications(context, notifierStates)
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2017-02-13 05:43:12 -06:00
|
|
|
func (n *notificationService) uploadImage(context *EvalContext) (err error) {
|
2016-09-29 07:31:19 -05:00
|
|
|
uploader, err := imguploader.NewImageUploader()
|
|
|
|
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,
|
2019-04-30 05:05:38 -05:00
|
|
|
Timeout: setting.AlertingEvaluationTimeout,
|
2019-06-03 03:25:58 -05:00
|
|
|
OrgId: context.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
|
|
|
}
|
|
|
|
|
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
|
|
|
ref, err := context.GetDashboardUID()
|
|
|
|
if err != nil {
|
2016-09-26 03:51:45 -05:00
|
|
|
return err
|
|
|
|
}
|
2018-05-24 08:26:27 -05:00
|
|
|
|
2019-06-03 03:25:58 -05:00
|
|
|
renderOpts.Path = fmt.Sprintf("d-solo/%s/%s?orgId=%d&panelId=%d", ref.Uid, ref.Slug, context.Rule.OrgID, context.Rule.PanelID)
|
2016-09-26 03:51:45 -05:00
|
|
|
|
2018-05-24 08:26:27 -05:00
|
|
|
result, err := n.renderService.Render(context.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
|
|
|
|
}
|
|
|
|
|
2018-05-24 08:26:27 -05:00
|
|
|
context.ImageOnDiskPath = result.FilePath
|
2019-06-03 03:25:58 -05:00
|
|
|
context.ImagePublicURL, err = uploader.Upload(context.Ctx, context.ImageOnDiskPath)
|
2016-07-30 06:36:21 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-06-03 03:25:58 -05:00
|
|
|
if context.ImagePublicURL != "" {
|
|
|
|
n.log.Info("uploaded screenshot of alert to external image store", "url", context.ImagePublicURL)
|
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
|
|
|
}
|