浏览代码

tech: avoid alias for importing models in alerting (#17041)

ref #14679
Carl Bergquist 6 年之前
父节点
当前提交
13f137a17d
共有 47 个文件被更改,包括 261 次插入259 次删除
  1. 4 4
      pkg/services/alerting/commands.go
  2. 3 3
      pkg/services/alerting/conditions/query.go
  3. 4 4
      pkg/services/alerting/conditions/query_test.go
  4. 22 22
      pkg/services/alerting/eval_context.go
  5. 18 18
      pkg/services/alerting/extractor.go
  6. 18 18
      pkg/services/alerting/extractor_test.go
  7. 9 10
      pkg/services/alerting/notifier.go
  8. 8 8
      pkg/services/alerting/notifiers/alertmanager.go
  9. 15 14
      pkg/services/alerting/notifiers/alertmanager_test.go
  10. 3 3
      pkg/services/alerting/notifiers/dingding.go
  11. 3 3
      pkg/services/alerting/notifiers/dingding_test.go
  12. 4 4
      pkg/services/alerting/notifiers/discord.go
  13. 3 3
      pkg/services/alerting/notifiers/discord_test.go
  14. 5 4
      pkg/services/alerting/notifiers/email.go
  15. 4 4
      pkg/services/alerting/notifiers/email_test.go
  16. 3 3
      pkg/services/alerting/notifiers/googlechat.go
  17. 3 3
      pkg/services/alerting/notifiers/googlechat_test.go
  18. 4 4
      pkg/services/alerting/notifiers/hipchat_test.go
  19. 3 3
      pkg/services/alerting/notifiers/kafka.go
  20. 3 3
      pkg/services/alerting/notifiers/kafka_test.go
  21. 4 4
      pkg/services/alerting/notifiers/line.go
  22. 3 3
      pkg/services/alerting/notifiers/line_test.go
  23. 6 6
      pkg/services/alerting/notifiers/opsgenie.go
  24. 3 3
      pkg/services/alerting/notifiers/opsgenie_test.go
  25. 5 5
      pkg/services/alerting/notifiers/pagerduty.go
  26. 4 4
      pkg/services/alerting/notifiers/pagerduty_test.go
  27. 4 4
      pkg/services/alerting/notifiers/pushover.go
  28. 7 6
      pkg/services/alerting/notifiers/pushover_test.go
  29. 3 3
      pkg/services/alerting/notifiers/sensu.go
  30. 3 3
      pkg/services/alerting/notifiers/sensu_test.go
  31. 5 5
      pkg/services/alerting/notifiers/slack.go
  32. 4 4
      pkg/services/alerting/notifiers/slack_test.go
  33. 4 4
      pkg/services/alerting/notifiers/teams.go
  34. 4 4
      pkg/services/alerting/notifiers/teams_test.go
  35. 8 8
      pkg/services/alerting/notifiers/telegram.go
  36. 7 7
      pkg/services/alerting/notifiers/telegram_test.go
  37. 6 6
      pkg/services/alerting/notifiers/threema.go
  38. 6 6
      pkg/services/alerting/notifiers/threema_test.go
  39. 3 3
      pkg/services/alerting/notifiers/victorops_test.go
  40. 3 3
      pkg/services/alerting/notifiers/webhook.go
  41. 3 3
      pkg/services/alerting/notifiers/webhook_test.go
  42. 2 3
      pkg/services/alerting/reader.go
  43. 5 4
      pkg/services/alerting/result_handler.go
  44. 7 7
      pkg/services/alerting/rule.go
  45. 6 6
      pkg/services/alerting/rule_test.go
  46. 4 4
      pkg/services/alerting/test_notification.go
  47. 3 3
      pkg/services/alerting/test_rule.go

+ 4 - 4
pkg/services/alerting/commands.go

@@ -2,7 +2,7 @@ package alerting
 
 
 import (
 import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 )
 )
 
 
 func init() {
 func init() {
@@ -10,14 +10,14 @@ func init() {
 	bus.AddHandler("alerting", validateDashboardAlerts)
 	bus.AddHandler("alerting", validateDashboardAlerts)
 }
 }
 
 
-func validateDashboardAlerts(cmd *m.ValidateDashboardAlertsCommand) error {
+func validateDashboardAlerts(cmd *models.ValidateDashboardAlertsCommand) error {
 	extractor := NewDashAlertExtractor(cmd.Dashboard, cmd.OrgId, cmd.User)
 	extractor := NewDashAlertExtractor(cmd.Dashboard, cmd.OrgId, cmd.User)
 
 
 	return extractor.ValidateAlerts()
 	return extractor.ValidateAlerts()
 }
 }
 
 
-func updateDashboardAlerts(cmd *m.UpdateDashboardAlertsCommand) error {
-	saveAlerts := m.SaveAlertsCommand{
+func updateDashboardAlerts(cmd *models.UpdateDashboardAlertsCommand) error {
+	saveAlerts := models.SaveAlertsCommand{
 		OrgId:       cmd.OrgId,
 		OrgId:       cmd.OrgId,
 		UserId:      cmd.User.UserId,
 		UserId:      cmd.User.UserId,
 		DashboardId: cmd.Dashboard.Id,
 		DashboardId: cmd.Dashboard.Id,

+ 3 - 3
pkg/services/alerting/conditions/query.go

@@ -10,7 +10,7 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/null"
 	"github.com/grafana/grafana/pkg/components/null"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/tsdb"
 	"github.com/grafana/grafana/pkg/tsdb"
 )
 )
@@ -100,7 +100,7 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext) (*alerting.Conditio
 }
 }
 
 
 func (c *QueryCondition) executeQuery(context *alerting.EvalContext, timeRange *tsdb.TimeRange) (tsdb.TimeSeriesSlice, error) {
 func (c *QueryCondition) executeQuery(context *alerting.EvalContext, timeRange *tsdb.TimeRange) (tsdb.TimeSeriesSlice, error) {
-	getDsInfo := &m.GetDataSourceByIdQuery{
+	getDsInfo := &models.GetDataSourceByIdQuery{
 		Id:    c.Query.DatasourceId,
 		Id:    c.Query.DatasourceId,
 		OrgId: context.Rule.OrgId,
 		OrgId: context.Rule.OrgId,
 	}
 	}
@@ -139,7 +139,7 @@ func (c *QueryCondition) executeQuery(context *alerting.EvalContext, timeRange *
 	return result, nil
 	return result, nil
 }
 }
 
 
-func (c *QueryCondition) getRequestForAlertRule(datasource *m.DataSource, timeRange *tsdb.TimeRange) *tsdb.TsdbQuery {
+func (c *QueryCondition) getRequestForAlertRule(datasource *models.DataSource, timeRange *tsdb.TimeRange) *tsdb.TsdbQuery {
 	req := &tsdb.TsdbQuery{
 	req := &tsdb.TsdbQuery{
 		TimeRange: timeRange,
 		TimeRange: timeRange,
 		Queries: []*tsdb.Query{
 		Queries: []*tsdb.Query{

+ 4 - 4
pkg/services/alerting/conditions/query_test.go

@@ -7,7 +7,7 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/null"
 	"github.com/grafana/grafana/pkg/components/null"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/tsdb"
 	"github.com/grafana/grafana/pkg/tsdb"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
@@ -168,7 +168,7 @@ func (ctx *queryConditionTestContext) exec() (*alerting.ConditionResult, error)
 
 
 	ctx.condition = condition
 	ctx.condition = condition
 
 
-	condition.HandleRequest = func(context context.Context, dsInfo *m.DataSource, req *tsdb.TsdbQuery) (*tsdb.Response, error) {
+	condition.HandleRequest = func(context context.Context, dsInfo *models.DataSource, req *tsdb.TsdbQuery) (*tsdb.Response, error) {
 		return &tsdb.Response{
 		return &tsdb.Response{
 			Results: map[string]*tsdb.QueryResult{
 			Results: map[string]*tsdb.QueryResult{
 				"A": {Series: ctx.series},
 				"A": {Series: ctx.series},
@@ -182,8 +182,8 @@ func (ctx *queryConditionTestContext) exec() (*alerting.ConditionResult, error)
 func queryConditionScenario(desc string, fn queryConditionScenarioFunc) {
 func queryConditionScenario(desc string, fn queryConditionScenarioFunc) {
 	Convey(desc, func() {
 	Convey(desc, func() {
 
 
-		bus.AddHandler("test", func(query *m.GetDataSourceByIdQuery) error {
-			query.Result = &m.DataSource{Id: 1, Type: "graphite"}
+		bus.AddHandler("test", func(query *models.GetDataSourceByIdQuery) error {
+			query.Result = &models.DataSource{Id: 1, Type: "graphite"}
 			return nil
 			return nil
 		})
 		})
 
 

+ 22 - 22
pkg/services/alerting/eval_context.go

@@ -7,7 +7,7 @@ import (
 
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
 )
 )
 
 
@@ -23,12 +23,12 @@ type EvalContext struct {
 	Rule           *Rule
 	Rule           *Rule
 	log            log.Logger
 	log            log.Logger
 
 
-	dashboardRef *m.DashboardRef
+	dashboardRef *models.DashboardRef
 
 
 	ImagePublicUrl  string
 	ImagePublicUrl  string
 	ImageOnDiskPath string
 	ImageOnDiskPath string
 	NoDataFound     bool
 	NoDataFound     bool
-	PrevAlertState  m.AlertStateType
+	PrevAlertState  models.AlertStateType
 
 
 	Ctx context.Context
 	Ctx context.Context
 }
 }
@@ -53,22 +53,22 @@ type StateDescription struct {
 
 
 func (c *EvalContext) GetStateModel() *StateDescription {
 func (c *EvalContext) GetStateModel() *StateDescription {
 	switch c.Rule.State {
 	switch c.Rule.State {
-	case m.AlertStateOK:
+	case models.AlertStateOK:
 		return &StateDescription{
 		return &StateDescription{
 			Color: "#36a64f",
 			Color: "#36a64f",
 			Text:  "OK",
 			Text:  "OK",
 		}
 		}
-	case m.AlertStateNoData:
+	case models.AlertStateNoData:
 		return &StateDescription{
 		return &StateDescription{
 			Color: "#888888",
 			Color: "#888888",
 			Text:  "No Data",
 			Text:  "No Data",
 		}
 		}
-	case m.AlertStateAlerting:
+	case models.AlertStateAlerting:
 		return &StateDescription{
 		return &StateDescription{
 			Color: "#D63232",
 			Color: "#D63232",
 			Text:  "Alerting",
 			Text:  "Alerting",
 		}
 		}
-	case m.AlertStateUnknown:
+	case models.AlertStateUnknown:
 		return &StateDescription{
 		return &StateDescription{
 			Color: "#888888",
 			Color: "#888888",
 			Text:  "Unknown",
 			Text:  "Unknown",
@@ -90,12 +90,12 @@ func (c *EvalContext) GetNotificationTitle() string {
 	return "[" + c.GetStateModel().Text + "] " + c.Rule.Name
 	return "[" + c.GetStateModel().Text + "] " + c.Rule.Name
 }
 }
 
 
-func (c *EvalContext) GetDashboardUID() (*m.DashboardRef, error) {
+func (c *EvalContext) GetDashboardUID() (*models.DashboardRef, error) {
 	if c.dashboardRef != nil {
 	if c.dashboardRef != nil {
 		return c.dashboardRef, nil
 		return c.dashboardRef, nil
 	}
 	}
 
 
-	uidQuery := &m.GetDashboardRefByIdQuery{Id: c.Rule.DashboardId}
+	uidQuery := &models.GetDashboardRefByIdQuery{Id: c.Rule.DashboardId}
 	if err := bus.Dispatch(uidQuery); err != nil {
 	if err := bus.Dispatch(uidQuery); err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -115,29 +115,29 @@ func (c *EvalContext) GetRuleUrl() (string, error) {
 	if err != nil {
 	if err != nil {
 		return "", err
 		return "", err
 	}
 	}
-	return fmt.Sprintf(urlFormat, m.GetFullDashboardUrl(ref.Uid, ref.Slug), c.Rule.PanelId, c.Rule.OrgId), nil
+	return fmt.Sprintf(urlFormat, models.GetFullDashboardUrl(ref.Uid, ref.Slug), c.Rule.PanelId, c.Rule.OrgId), nil
 }
 }
 
 
 // GetNewState returns the new state from the alert rule evaluation
 // GetNewState returns the new state from the alert rule evaluation
-func (c *EvalContext) GetNewState() m.AlertStateType {
+func (c *EvalContext) GetNewState() models.AlertStateType {
 	ns := getNewStateInternal(c)
 	ns := getNewStateInternal(c)
-	if ns != m.AlertStateAlerting || c.Rule.For == 0 {
+	if ns != models.AlertStateAlerting || c.Rule.For == 0 {
 		return ns
 		return ns
 	}
 	}
 
 
 	since := time.Since(c.Rule.LastStateChange)
 	since := time.Since(c.Rule.LastStateChange)
-	if c.PrevAlertState == m.AlertStatePending && since > c.Rule.For {
-		return m.AlertStateAlerting
+	if c.PrevAlertState == models.AlertStatePending && since > c.Rule.For {
+		return models.AlertStateAlerting
 	}
 	}
 
 
-	if c.PrevAlertState == m.AlertStateAlerting {
-		return m.AlertStateAlerting
+	if c.PrevAlertState == models.AlertStateAlerting {
+		return models.AlertStateAlerting
 	}
 	}
 
 
-	return m.AlertStatePending
+	return models.AlertStatePending
 }
 }
 
 
-func getNewStateInternal(c *EvalContext) m.AlertStateType {
+func getNewStateInternal(c *EvalContext) models.AlertStateType {
 	if c.Error != nil {
 	if c.Error != nil {
 		c.log.Error("Alert Rule Result Error",
 		c.log.Error("Alert Rule Result Error",
 			"ruleId", c.Rule.Id,
 			"ruleId", c.Rule.Id,
@@ -145,14 +145,14 @@ func getNewStateInternal(c *EvalContext) m.AlertStateType {
 			"error", c.Error,
 			"error", c.Error,
 			"changing state to", c.Rule.ExecutionErrorState.ToAlertState())
 			"changing state to", c.Rule.ExecutionErrorState.ToAlertState())
 
 
-		if c.Rule.ExecutionErrorState == m.ExecutionErrorKeepState {
+		if c.Rule.ExecutionErrorState == models.ExecutionErrorKeepState {
 			return c.PrevAlertState
 			return c.PrevAlertState
 		}
 		}
 		return c.Rule.ExecutionErrorState.ToAlertState()
 		return c.Rule.ExecutionErrorState.ToAlertState()
 	}
 	}
 
 
 	if c.Firing {
 	if c.Firing {
-		return m.AlertStateAlerting
+		return models.AlertStateAlerting
 	}
 	}
 
 
 	if c.NoDataFound {
 	if c.NoDataFound {
@@ -161,11 +161,11 @@ func getNewStateInternal(c *EvalContext) m.AlertStateType {
 			"name", c.Rule.Name,
 			"name", c.Rule.Name,
 			"changing state to", c.Rule.NoDataState.ToAlertState())
 			"changing state to", c.Rule.NoDataState.ToAlertState())
 
 
-		if c.Rule.NoDataState == m.NoDataKeepState {
+		if c.Rule.NoDataState == models.NoDataKeepState {
 			return c.PrevAlertState
 			return c.PrevAlertState
 		}
 		}
 		return c.Rule.NoDataState.ToAlertState()
 		return c.Rule.NoDataState.ToAlertState()
 	}
 	}
 
 
-	return m.AlertStateOK
+	return models.AlertStateOK
 }
 }

+ 18 - 18
pkg/services/alerting/extractor.go

@@ -8,19 +8,19 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 )
 )
 
 
 // DashAlertExtractor extracts alerts from the dashboard json
 // DashAlertExtractor extracts alerts from the dashboard json
 type DashAlertExtractor struct {
 type DashAlertExtractor struct {
-	User  *m.SignedInUser
-	Dash  *m.Dashboard
+	User  *models.SignedInUser
+	Dash  *models.Dashboard
 	OrgID int64
 	OrgID int64
 	log   log.Logger
 	log   log.Logger
 }
 }
 
 
 // NewDashAlertExtractor returns a new DashAlertExtractor
 // NewDashAlertExtractor returns a new DashAlertExtractor
-func NewDashAlertExtractor(dash *m.Dashboard, orgID int64, user *m.SignedInUser) *DashAlertExtractor {
+func NewDashAlertExtractor(dash *models.Dashboard, orgID int64, user *models.SignedInUser) *DashAlertExtractor {
 	return &DashAlertExtractor{
 	return &DashAlertExtractor{
 		User:  user,
 		User:  user,
 		Dash:  dash,
 		Dash:  dash,
@@ -29,9 +29,9 @@ func NewDashAlertExtractor(dash *m.Dashboard, orgID int64, user *m.SignedInUser)
 	}
 	}
 }
 }
 
 
-func (e *DashAlertExtractor) lookupDatasourceID(dsName string) (*m.DataSource, error) {
+func (e *DashAlertExtractor) lookupDatasourceID(dsName string) (*models.DataSource, error) {
 	if dsName == "" {
 	if dsName == "" {
-		query := &m.GetDataSourcesQuery{OrgId: e.OrgID}
+		query := &models.GetDataSourcesQuery{OrgId: e.OrgID}
 		if err := bus.Dispatch(query); err != nil {
 		if err := bus.Dispatch(query); err != nil {
 			return nil, err
 			return nil, err
 		}
 		}
@@ -42,7 +42,7 @@ func (e *DashAlertExtractor) lookupDatasourceID(dsName string) (*m.DataSource, e
 			}
 			}
 		}
 		}
 	} else {
 	} else {
-		query := &m.GetDataSourceByNameQuery{Name: dsName, OrgId: e.OrgID}
+		query := &models.GetDataSourceByNameQuery{Name: dsName, OrgId: e.OrgID}
 		if err := bus.Dispatch(query); err != nil {
 		if err := bus.Dispatch(query); err != nil {
 			return nil, err
 			return nil, err
 		}
 		}
@@ -73,8 +73,8 @@ func copyJSON(in *simplejson.Json) (*simplejson.Json, error) {
 	return simplejson.NewJson(rawJSON)
 	return simplejson.NewJson(rawJSON)
 }
 }
 
 
-func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json, validateAlertFunc func(*m.Alert) bool) ([]*m.Alert, error) {
-	alerts := make([]*m.Alert, 0)
+func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json, validateAlertFunc func(*models.Alert) bool) ([]*models.Alert, error) {
+	alerts := make([]*models.Alert, 0)
 
 
 	for _, panelObj := range jsonWithPanels.Get("panels").MustArray() {
 	for _, panelObj := range jsonWithPanels.Get("panels").MustArray() {
 		panel := simplejson.NewFromAny(panelObj)
 		panel := simplejson.NewFromAny(panelObj)
@@ -124,7 +124,7 @@ func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json,
 			}
 			}
 		}
 		}
 
 
-		alert := &m.Alert{
+		alert := &models.Alert{
 			DashboardId: e.Dash.Id,
 			DashboardId: e.Dash.Id,
 			OrgId:       e.OrgID,
 			OrgId:       e.OrgID,
 			PanelId:     panelID,
 			PanelId:     panelID,
@@ -161,9 +161,9 @@ func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json,
 				return nil, ValidationError{Reason: fmt.Sprintf("Data source used by alert rule not found, alertName=%v, datasource=%s", alert.Name, dsName)}
 				return nil, ValidationError{Reason: fmt.Sprintf("Data source used by alert rule not found, alertName=%v, datasource=%s", alert.Name, dsName)}
 			}
 			}
 
 
-			dsFilterQuery := m.DatasourcesPermissionFilterQuery{
+			dsFilterQuery := models.DatasourcesPermissionFilterQuery{
 				User:        e.User,
 				User:        e.User,
-				Datasources: []*m.DataSource{datasource},
+				Datasources: []*models.DataSource{datasource},
 			}
 			}
 
 
 			if err := bus.Dispatch(&dsFilterQuery); err != nil {
 			if err := bus.Dispatch(&dsFilterQuery); err != nil {
@@ -172,7 +172,7 @@ func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json,
 				}
 				}
 			} else {
 			} else {
 				if len(dsFilterQuery.Result) == 0 {
 				if len(dsFilterQuery.Result) == 0 {
-					return nil, m.ErrDataSourceAccessDenied
+					return nil, models.ErrDataSourceAccessDenied
 				}
 				}
 			}
 			}
 
 
@@ -203,22 +203,22 @@ func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json,
 	return alerts, nil
 	return alerts, nil
 }
 }
 
 
-func validateAlertRule(alert *m.Alert) bool {
+func validateAlertRule(alert *models.Alert) bool {
 	return alert.ValidToSave()
 	return alert.ValidToSave()
 }
 }
 
 
 // GetAlerts extracts alerts from the dashboard json and does full validation on the alert json data
 // GetAlerts extracts alerts from the dashboard json and does full validation on the alert json data
-func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error) {
+func (e *DashAlertExtractor) GetAlerts() ([]*models.Alert, error) {
 	return e.extractAlerts(validateAlertRule)
 	return e.extractAlerts(validateAlertRule)
 }
 }
 
 
-func (e *DashAlertExtractor) extractAlerts(validateFunc func(alert *m.Alert) bool) ([]*m.Alert, error) {
+func (e *DashAlertExtractor) extractAlerts(validateFunc func(alert *models.Alert) bool) ([]*models.Alert, error) {
 	dashboardJSON, err := copyJSON(e.Dash.Data)
 	dashboardJSON, err := copyJSON(e.Dash.Data)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	alerts := make([]*m.Alert, 0)
+	alerts := make([]*models.Alert, 0)
 
 
 	// We extract alerts from rows to be backwards compatible
 	// We extract alerts from rows to be backwards compatible
 	// with the old dashboard json model.
 	// with the old dashboard json model.
@@ -249,6 +249,6 @@ func (e *DashAlertExtractor) extractAlerts(validateFunc func(alert *m.Alert) boo
 // ValidateAlerts validates alerts in the dashboard json but does not require a valid dashboard id
 // ValidateAlerts validates alerts in the dashboard json but does not require a valid dashboard id
 // in the first validation pass
 // in the first validation pass
 func (e *DashAlertExtractor) ValidateAlerts() error {
 func (e *DashAlertExtractor) ValidateAlerts() error {
-	_, err := e.extractAlerts(func(alert *m.Alert) bool { return alert.OrgId != 0 && alert.PanelId != 0 })
+	_, err := e.extractAlerts(func(alert *models.Alert) bool { return alert.OrgId != 0 && alert.PanelId != 0 })
 	return err
 	return err
 }
 }

+ 18 - 18
pkg/services/alerting/extractor_test.go

@@ -7,7 +7,7 @@ import (
 
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/sqlstore"
 	"github.com/grafana/grafana/pkg/services/sqlstore"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
@@ -21,17 +21,17 @@ func TestAlertRuleExtraction(t *testing.T) {
 		})
 		})
 
 
 		// mock data
 		// mock data
-		defaultDs := &m.DataSource{Id: 12, OrgId: 1, Name: "I am default", IsDefault: true}
-		graphite2Ds := &m.DataSource{Id: 15, OrgId: 1, Name: "graphite2"}
-		influxDBDs := &m.DataSource{Id: 16, OrgId: 1, Name: "InfluxDB"}
-		prom := &m.DataSource{Id: 17, OrgId: 1, Name: "Prometheus"}
+		defaultDs := &models.DataSource{Id: 12, OrgId: 1, Name: "I am default", IsDefault: true}
+		graphite2Ds := &models.DataSource{Id: 15, OrgId: 1, Name: "graphite2"}
+		influxDBDs := &models.DataSource{Id: 16, OrgId: 1, Name: "InfluxDB"}
+		prom := &models.DataSource{Id: 17, OrgId: 1, Name: "Prometheus"}
 
 
-		bus.AddHandler("test", func(query *m.GetDataSourcesQuery) error {
-			query.Result = []*m.DataSource{defaultDs, graphite2Ds}
+		bus.AddHandler("test", func(query *models.GetDataSourcesQuery) error {
+			query.Result = []*models.DataSource{defaultDs, graphite2Ds}
 			return nil
 			return nil
 		})
 		})
 
 
-		bus.AddHandler("test", func(query *m.GetDataSourceByNameQuery) error {
+		bus.AddHandler("test", func(query *models.GetDataSourceByNameQuery) error {
 			if query.Name == defaultDs.Name {
 			if query.Name == defaultDs.Name {
 				query.Result = defaultDs
 				query.Result = defaultDs
 			}
 			}
@@ -55,7 +55,7 @@ func TestAlertRuleExtraction(t *testing.T) {
 			dashJson, err := simplejson.NewJson(json)
 			dashJson, err := simplejson.NewJson(json)
 			So(err, ShouldBeNil)
 			So(err, ShouldBeNil)
 
 
-			dash := m.NewDashboardFromJson(dashJson)
+			dash := models.NewDashboardFromJson(dashJson)
 
 
 			getTarget := func(j *simplejson.Json) string {
 			getTarget := func(j *simplejson.Json) string {
 				rowObj := j.Get("rows").MustArray()[0]
 				rowObj := j.Get("rows").MustArray()[0]
@@ -84,7 +84,7 @@ func TestAlertRuleExtraction(t *testing.T) {
 			dashJson, err := simplejson.NewJson(json)
 			dashJson, err := simplejson.NewJson(json)
 			So(err, ShouldBeNil)
 			So(err, ShouldBeNil)
 
 
-			dash := m.NewDashboardFromJson(dashJson)
+			dash := models.NewDashboardFromJson(dashJson)
 			extractor := NewDashAlertExtractor(dash, 1, nil)
 			extractor := NewDashAlertExtractor(dash, 1, nil)
 
 
 			alerts, err := extractor.GetAlerts()
 			alerts, err := extractor.GetAlerts()
@@ -152,7 +152,7 @@ func TestAlertRuleExtraction(t *testing.T) {
 
 
 			dashJson, err := simplejson.NewJson(panelWithoutId)
 			dashJson, err := simplejson.NewJson(panelWithoutId)
 			So(err, ShouldBeNil)
 			So(err, ShouldBeNil)
-			dash := m.NewDashboardFromJson(dashJson)
+			dash := models.NewDashboardFromJson(dashJson)
 			extractor := NewDashAlertExtractor(dash, 1, nil)
 			extractor := NewDashAlertExtractor(dash, 1, nil)
 
 
 			_, err = extractor.GetAlerts()
 			_, err = extractor.GetAlerts()
@@ -168,7 +168,7 @@ func TestAlertRuleExtraction(t *testing.T) {
 
 
 			dashJson, err := simplejson.NewJson(panelWithIdZero)
 			dashJson, err := simplejson.NewJson(panelWithIdZero)
 			So(err, ShouldBeNil)
 			So(err, ShouldBeNil)
-			dash := m.NewDashboardFromJson(dashJson)
+			dash := models.NewDashboardFromJson(dashJson)
 			extractor := NewDashAlertExtractor(dash, 1, nil)
 			extractor := NewDashAlertExtractor(dash, 1, nil)
 
 
 			_, err = extractor.GetAlerts()
 			_, err = extractor.GetAlerts()
@@ -184,7 +184,7 @@ func TestAlertRuleExtraction(t *testing.T) {
 
 
 			dashJson, err := simplejson.NewJson(json)
 			dashJson, err := simplejson.NewJson(json)
 			So(err, ShouldBeNil)
 			So(err, ShouldBeNil)
-			dash := m.NewDashboardFromJson(dashJson)
+			dash := models.NewDashboardFromJson(dashJson)
 			extractor := NewDashAlertExtractor(dash, 1, nil)
 			extractor := NewDashAlertExtractor(dash, 1, nil)
 
 
 			alerts, err := extractor.GetAlerts()
 			alerts, err := extractor.GetAlerts()
@@ -200,10 +200,10 @@ func TestAlertRuleExtraction(t *testing.T) {
 
 
 		Convey("Alert notifications are in DB", func() {
 		Convey("Alert notifications are in DB", func() {
 			sqlstore.InitTestDB(t)
 			sqlstore.InitTestDB(t)
-			firstNotification := m.CreateAlertNotificationCommand{Uid: "notifier1", OrgId: 1, Name: "1"}
+			firstNotification := models.CreateAlertNotificationCommand{Uid: "notifier1", OrgId: 1, Name: "1"}
 			err = sqlstore.CreateAlertNotificationCommand(&firstNotification)
 			err = sqlstore.CreateAlertNotificationCommand(&firstNotification)
 			So(err, ShouldBeNil)
 			So(err, ShouldBeNil)
-			secondNotification := m.CreateAlertNotificationCommand{Uid: "notifier2", OrgId: 1, Name: "2"}
+			secondNotification := models.CreateAlertNotificationCommand{Uid: "notifier2", OrgId: 1, Name: "2"}
 			err = sqlstore.CreateAlertNotificationCommand(&secondNotification)
 			err = sqlstore.CreateAlertNotificationCommand(&secondNotification)
 			So(err, ShouldBeNil)
 			So(err, ShouldBeNil)
 
 
@@ -213,7 +213,7 @@ func TestAlertRuleExtraction(t *testing.T) {
 
 
 				dashJson, err := simplejson.NewJson(json)
 				dashJson, err := simplejson.NewJson(json)
 				So(err, ShouldBeNil)
 				So(err, ShouldBeNil)
-				dash := m.NewDashboardFromJson(dashJson)
+				dash := models.NewDashboardFromJson(dashJson)
 				extractor := NewDashAlertExtractor(dash, 1, nil)
 				extractor := NewDashAlertExtractor(dash, 1, nil)
 
 
 				alerts, err := extractor.GetAlerts()
 				alerts, err := extractor.GetAlerts()
@@ -243,7 +243,7 @@ func TestAlertRuleExtraction(t *testing.T) {
 				dashJson, err := simplejson.NewJson(json)
 				dashJson, err := simplejson.NewJson(json)
 				So(err, ShouldBeNil)
 				So(err, ShouldBeNil)
 
 
-				dash := m.NewDashboardFromJson(dashJson)
+				dash := models.NewDashboardFromJson(dashJson)
 				extractor := NewDashAlertExtractor(dash, 1, nil)
 				extractor := NewDashAlertExtractor(dash, 1, nil)
 
 
 				alerts, err := extractor.GetAlerts()
 				alerts, err := extractor.GetAlerts()
@@ -263,7 +263,7 @@ func TestAlertRuleExtraction(t *testing.T) {
 
 
 				dashJSON, err := simplejson.NewJson(json)
 				dashJSON, err := simplejson.NewJson(json)
 				So(err, ShouldBeNil)
 				So(err, ShouldBeNil)
-				dash := m.NewDashboardFromJson(dashJSON)
+				dash := models.NewDashboardFromJson(dashJSON)
 				extractor := NewDashAlertExtractor(dash, 1, nil)
 				extractor := NewDashAlertExtractor(dash, 1, nil)
 
 
 				err = extractor.ValidateAlerts()
 				err = extractor.ValidateAlerts()

+ 9 - 10
pkg/services/alerting/notifier.go

@@ -8,10 +8,9 @@ import (
 	"github.com/grafana/grafana/pkg/components/imguploader"
 	"github.com/grafana/grafana/pkg/components/imguploader"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/metrics"
 	"github.com/grafana/grafana/pkg/infra/metrics"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/rendering"
 	"github.com/grafana/grafana/pkg/services/rendering"
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
-
-	m "github.com/grafana/grafana/pkg/models"
 )
 )
 
 
 type NotifierPlugin struct {
 type NotifierPlugin struct {
@@ -73,7 +72,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
 		return nil
 		return nil
 	}
 	}
 
 
-	cmd := &m.SetAlertNotificationStateToCompleteCommand{
+	cmd := &models.SetAlertNotificationStateToCompleteCommand{
 		Id:      notifierState.state.Id,
 		Id:      notifierState.state.Id,
 		Version: notifierState.state.Version,
 		Version: notifierState.state.Version,
 	}
 	}
@@ -83,14 +82,14 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
 
 
 func (n *notificationService) sendNotification(evalContext *EvalContext, notifierState *notifierState) error {
 func (n *notificationService) sendNotification(evalContext *EvalContext, notifierState *notifierState) error {
 	if !evalContext.IsTestRun {
 	if !evalContext.IsTestRun {
-		setPendingCmd := &m.SetAlertNotificationStateToPendingCommand{
+		setPendingCmd := &models.SetAlertNotificationStateToPendingCommand{
 			Id:                           notifierState.state.Id,
 			Id:                           notifierState.state.Id,
 			Version:                      notifierState.state.Version,
 			Version:                      notifierState.state.Version,
 			AlertRuleStateUpdatedVersion: evalContext.Rule.StateChanges,
 			AlertRuleStateUpdatedVersion: evalContext.Rule.StateChanges,
 		}
 		}
 
 
 		err := bus.DispatchCtx(evalContext.Ctx, setPendingCmd)
 		err := bus.DispatchCtx(evalContext.Ctx, setPendingCmd)
-		if err == m.ErrAlertNotificationStateVersionConflict {
+		if err == models.ErrAlertNotificationStateVersionConflict {
 			return nil
 			return nil
 		}
 		}
 
 
@@ -128,7 +127,7 @@ func (n *notificationService) uploadImage(context *EvalContext) (err error) {
 		Height:          500,
 		Height:          500,
 		Timeout:         setting.AlertingEvaluationTimeout,
 		Timeout:         setting.AlertingEvaluationTimeout,
 		OrgId:           context.Rule.OrgId,
 		OrgId:           context.Rule.OrgId,
-		OrgRole:         m.ROLE_ADMIN,
+		OrgRole:         models.ROLE_ADMIN,
 		ConcurrentLimit: setting.AlertingRenderLimit,
 		ConcurrentLimit: setting.AlertingRenderLimit,
 	}
 	}
 
 
@@ -158,7 +157,7 @@ func (n *notificationService) uploadImage(context *EvalContext) (err error) {
 }
 }
 
 
 func (n *notificationService) getNeededNotifiers(orgId int64, notificationUids []string, evalContext *EvalContext) (notifierStateSlice, error) {
 func (n *notificationService) getNeededNotifiers(orgId int64, notificationUids []string, evalContext *EvalContext) (notifierStateSlice, error) {
-	query := &m.GetAlertNotificationsWithUidToSendQuery{OrgId: orgId, Uids: notificationUids}
+	query := &models.GetAlertNotificationsWithUidToSendQuery{OrgId: orgId, Uids: notificationUids}
 
 
 	if err := bus.Dispatch(query); err != nil {
 	if err := bus.Dispatch(query); err != nil {
 		return nil, err
 		return nil, err
@@ -172,7 +171,7 @@ func (n *notificationService) getNeededNotifiers(orgId int64, notificationUids [
 			continue
 			continue
 		}
 		}
 
 
-		query := &m.GetOrCreateNotificationStateQuery{
+		query := &models.GetOrCreateNotificationStateQuery{
 			NotifierId: notification.Id,
 			NotifierId: notification.Id,
 			AlertId:    evalContext.Rule.Id,
 			AlertId:    evalContext.Rule.Id,
 			OrgId:      evalContext.Rule.OrgId,
 			OrgId:      evalContext.Rule.OrgId,
@@ -196,7 +195,7 @@ func (n *notificationService) getNeededNotifiers(orgId int64, notificationUids [
 }
 }
 
 
 // InitNotifier instantiate a new notifier based on the model
 // InitNotifier instantiate a new notifier based on the model
-func InitNotifier(model *m.AlertNotification) (Notifier, error) {
+func InitNotifier(model *models.AlertNotification) (Notifier, error) {
 	notifierPlugin, found := notifierFactories[model.Type]
 	notifierPlugin, found := notifierFactories[model.Type]
 	if !found {
 	if !found {
 		return nil, errors.New("Unsupported notification type")
 		return nil, errors.New("Unsupported notification type")
@@ -205,7 +204,7 @@ func InitNotifier(model *m.AlertNotification) (Notifier, error) {
 	return notifierPlugin.Factory(model)
 	return notifierPlugin.Factory(model)
 }
 }
 
 
-type NotifierFactory func(notification *m.AlertNotification) (Notifier, error)
+type NotifierFactory func(notification *models.AlertNotification) (Notifier, error)
 
 
 var notifierFactories = make(map[string]*NotifierPlugin)
 var notifierFactories = make(map[string]*NotifierPlugin)
 
 

+ 8 - 8
pkg/services/alerting/notifiers/alertmanager.go

@@ -7,7 +7,7 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
 )
 
 
@@ -27,7 +27,7 @@ func init() {
 	})
 	})
 }
 }
 
 
-func NewAlertmanagerNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewAlertmanagerNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	url := model.Settings.Get("url").MustString()
 	url := model.Settings.Get("url").MustString()
 	if url == "" {
 	if url == "" {
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
@@ -46,24 +46,24 @@ type AlertmanagerNotifier struct {
 	log log.Logger
 	log log.Logger
 }
 }
 
 
-func (this *AlertmanagerNotifier) ShouldNotify(ctx context.Context, evalContext *alerting.EvalContext, notificationState *m.AlertNotificationState) bool {
+func (this *AlertmanagerNotifier) ShouldNotify(ctx context.Context, evalContext *alerting.EvalContext, notificationState *models.AlertNotificationState) bool {
 	this.log.Debug("Should notify", "ruleId", evalContext.Rule.Id, "state", evalContext.Rule.State, "previousState", evalContext.PrevAlertState)
 	this.log.Debug("Should notify", "ruleId", evalContext.Rule.Id, "state", evalContext.Rule.State, "previousState", evalContext.PrevAlertState)
 
 
 	// Do not notify when we become OK for the first time.
 	// Do not notify when we become OK for the first time.
-	if (evalContext.PrevAlertState == m.AlertStatePending) && (evalContext.Rule.State == m.AlertStateOK) {
+	if (evalContext.PrevAlertState == models.AlertStatePending) && (evalContext.Rule.State == models.AlertStateOK) {
 		return false
 		return false
 	}
 	}
 	// Notify on Alerting -> OK to resolve before alertmanager timeout.
 	// Notify on Alerting -> OK to resolve before alertmanager timeout.
-	if (evalContext.PrevAlertState == m.AlertStateAlerting) && (evalContext.Rule.State == m.AlertStateOK) {
+	if (evalContext.PrevAlertState == models.AlertStateAlerting) && (evalContext.Rule.State == models.AlertStateOK) {
 		return true
 		return true
 	}
 	}
-	return evalContext.Rule.State == m.AlertStateAlerting
+	return evalContext.Rule.State == models.AlertStateAlerting
 }
 }
 
 
 func (this *AlertmanagerNotifier) createAlert(evalContext *alerting.EvalContext, match *alerting.EvalMatch, ruleUrl string) *simplejson.Json {
 func (this *AlertmanagerNotifier) createAlert(evalContext *alerting.EvalContext, match *alerting.EvalMatch, ruleUrl string) *simplejson.Json {
 	alertJSON := simplejson.New()
 	alertJSON := simplejson.New()
 	alertJSON.Set("startsAt", evalContext.StartTime.UTC().Format(time.RFC3339))
 	alertJSON.Set("startsAt", evalContext.StartTime.UTC().Format(time.RFC3339))
-	if evalContext.Rule.State == m.AlertStateOK {
+	if evalContext.Rule.State == models.AlertStateOK {
 		alertJSON.Set("endsAt", time.Now().UTC().Format(time.RFC3339))
 		alertJSON.Set("endsAt", time.Now().UTC().Format(time.RFC3339))
 	}
 	}
 	alertJSON.Set("generatorURL", ruleUrl)
 	alertJSON.Set("generatorURL", ruleUrl)
@@ -128,7 +128,7 @@ func (this *AlertmanagerNotifier) Notify(evalContext *alerting.EvalContext) erro
 	bodyJSON := simplejson.NewFromAny(alerts)
 	bodyJSON := simplejson.NewFromAny(alerts)
 	body, _ := bodyJSON.MarshalJSON()
 	body, _ := bodyJSON.MarshalJSON()
 
 
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:        this.Url + "/api/v1/alerts",
 		Url:        this.Url + "/api/v1/alerts",
 		HttpMethod: "POST",
 		HttpMethod: "POST",
 		Body:       string(body),
 		Body:       string(body),

+ 15 - 14
pkg/services/alerting/notifiers/alertmanager_test.go

@@ -6,36 +6,37 @@ import (
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
+
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
 func TestWhenAlertManagerShouldNotify(t *testing.T) {
 func TestWhenAlertManagerShouldNotify(t *testing.T) {
 	tcs := []struct {
 	tcs := []struct {
-		prevState m.AlertStateType
-		newState  m.AlertStateType
+		prevState models.AlertStateType
+		newState  models.AlertStateType
 
 
 		expect bool
 		expect bool
 	}{
 	}{
 		{
 		{
-			prevState: m.AlertStatePending,
-			newState:  m.AlertStateOK,
+			prevState: models.AlertStatePending,
+			newState:  models.AlertStateOK,
 			expect:    false,
 			expect:    false,
 		},
 		},
 		{
 		{
-			prevState: m.AlertStateAlerting,
-			newState:  m.AlertStateOK,
+			prevState: models.AlertStateAlerting,
+			newState:  models.AlertStateOK,
 			expect:    true,
 			expect:    true,
 		},
 		},
 		{
 		{
-			prevState: m.AlertStateOK,
-			newState:  m.AlertStatePending,
+			prevState: models.AlertStateOK,
+			newState:  models.AlertStatePending,
 			expect:    false,
 			expect:    false,
 		},
 		},
 		{
 		{
-			prevState: m.AlertStateUnknown,
-			newState:  m.AlertStatePending,
+			prevState: models.AlertStateUnknown,
+			newState:  models.AlertStatePending,
 			expect:    false,
 			expect:    false,
 		},
 		},
 	}
 	}
@@ -48,7 +49,7 @@ func TestWhenAlertManagerShouldNotify(t *testing.T) {
 
 
 		evalContext.Rule.State = tc.newState
 		evalContext.Rule.State = tc.newState
 
 
-		res := am.ShouldNotify(context.TODO(), evalContext, &m.AlertNotificationState{})
+		res := am.ShouldNotify(context.TODO(), evalContext, &models.AlertNotificationState{})
 		if res != tc.expect {
 		if res != tc.expect {
 			t.Errorf("got %v expected %v", res, tc.expect)
 			t.Errorf("got %v expected %v", res, tc.expect)
 		}
 		}
@@ -63,7 +64,7 @@ func TestAlertmanagerNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "alertmanager",
 					Name:     "alertmanager",
 					Type:     "alertmanager",
 					Type:     "alertmanager",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -77,7 +78,7 @@ func TestAlertmanagerNotifier(t *testing.T) {
 				json := `{ "url": "http://127.0.0.1:9093/" }`
 				json := `{ "url": "http://127.0.0.1:9093/" }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "alertmanager",
 					Name:     "alertmanager",
 					Type:     "alertmanager",
 					Type:     "alertmanager",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 3 - 3
pkg/services/alerting/notifiers/dingding.go

@@ -8,7 +8,7 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
 )
 
 
@@ -36,7 +36,7 @@ func init() {
 
 
 }
 }
 
 
-func NewDingDingNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewDingDingNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	url := model.Settings.Get("url").MustString()
 	url := model.Settings.Get("url").MustString()
 	if url == "" {
 	if url == "" {
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
@@ -129,7 +129,7 @@ func (this *DingDingNotifier) Notify(evalContext *alerting.EvalContext) error {
 		return err
 		return err
 	}
 	}
 
 
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:  this.Url,
 		Url:  this.Url,
 		Body: string(body),
 		Body: string(body),
 	}
 	}

+ 3 - 3
pkg/services/alerting/notifiers/dingding_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -14,7 +14,7 @@ func TestDingDingNotifier(t *testing.T) {
 			json := `{ }`
 			json := `{ }`
 
 
 			settingsJSON, _ := simplejson.NewJson([]byte(json))
 			settingsJSON, _ := simplejson.NewJson([]byte(json))
-			model := &m.AlertNotification{
+			model := &models.AlertNotification{
 				Name:     "dingding_testing",
 				Name:     "dingding_testing",
 				Type:     "dingding",
 				Type:     "dingding",
 				Settings: settingsJSON,
 				Settings: settingsJSON,
@@ -28,7 +28,7 @@ func TestDingDingNotifier(t *testing.T) {
 			json := `{ "url": "https://www.google.com" }`
 			json := `{ "url": "https://www.google.com" }`
 
 
 			settingsJSON, _ := simplejson.NewJson([]byte(json))
 			settingsJSON, _ := simplejson.NewJson([]byte(json))
-			model := &m.AlertNotification{
+			model := &models.AlertNotification{
 				Name:     "dingding_testing",
 				Name:     "dingding_testing",
 				Type:     "dingding",
 				Type:     "dingding",
 				Settings: settingsJSON,
 				Settings: settingsJSON,

+ 4 - 4
pkg/services/alerting/notifiers/discord.go

@@ -11,7 +11,7 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
 )
 )
@@ -32,7 +32,7 @@ func init() {
 	})
 	})
 }
 }
 
 
-func NewDiscordNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewDiscordNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	url := model.Settings.Get("url").MustString()
 	url := model.Settings.Get("url").MustString()
 	if url == "" {
 	if url == "" {
 		return nil, alerting.ValidationError{Reason: "Could not find webhook url property in settings"}
 		return nil, alerting.ValidationError{Reason: "Could not find webhook url property in settings"}
@@ -111,7 +111,7 @@ func (this *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
 
 
 	json, _ := bodyJSON.MarshalJSON()
 	json, _ := bodyJSON.MarshalJSON()
 
 
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:         this.WebhookURL,
 		Url:         this.WebhookURL,
 		HttpMethod:  "POST",
 		HttpMethod:  "POST",
 		ContentType: "application/json",
 		ContentType: "application/json",
@@ -135,7 +135,7 @@ func (this *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
 	return nil
 	return nil
 }
 }
 
 
-func (this *DiscordNotifier) embedImage(cmd *m.SendWebhookSync, imagePath string, existingJSONBody []byte) error {
+func (this *DiscordNotifier) embedImage(cmd *models.SendWebhookSync, imagePath string, existingJSONBody []byte) error {
 	f, err := os.Open(imagePath)
 	f, err := os.Open(imagePath)
 	defer f.Close()
 	defer f.Close()
 	if err != nil {
 	if err != nil {

+ 3 - 3
pkg/services/alerting/notifiers/discord_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -16,7 +16,7 @@ func TestDiscordNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "discord_testing",
 					Name:     "discord_testing",
 					Type:     "discord",
 					Type:     "discord",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -33,7 +33,7 @@ func TestDiscordNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "discord_testing",
 					Name:     "discord_testing",
 					Type:     "discord",
 					Type:     "discord",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 5 - 4
pkg/services/alerting/notifiers/email.go

@@ -6,7 +6,8 @@ import (
 
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
+
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
 )
 )
@@ -35,7 +36,7 @@ type EmailNotifier struct {
 	log       log.Logger
 	log       log.Logger
 }
 }
 
 
-func NewEmailNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewEmailNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	addressesString := model.Settings.Get("addresses").MustString()
 	addressesString := model.Settings.Get("addresses").MustString()
 
 
 	if addressesString == "" {
 	if addressesString == "" {
@@ -72,8 +73,8 @@ func (this *EmailNotifier) Notify(evalContext *alerting.EvalContext) error {
 		error = evalContext.Error.Error()
 		error = evalContext.Error.Error()
 	}
 	}
 
 
-	cmd := &m.SendEmailCommandSync{
-		SendEmailCommand: m.SendEmailCommand{
+	cmd := &models.SendEmailCommandSync{
+		SendEmailCommand: models.SendEmailCommand{
 			Subject: evalContext.GetNotificationTitle(),
 			Subject: evalContext.GetNotificationTitle(),
 			Data: map[string]interface{}{
 			Data: map[string]interface{}{
 				"Title":         evalContext.GetNotificationTitle(),
 				"Title":         evalContext.GetNotificationTitle(),

+ 4 - 4
pkg/services/alerting/notifiers/email_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -16,7 +16,7 @@ func TestEmailNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "email",
 					Type:     "email",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -33,7 +33,7 @@ func TestEmailNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "email",
 					Type:     "email",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -57,7 +57,7 @@ func TestEmailNotifier(t *testing.T) {
 				settingsJSON, err := simplejson.NewJson([]byte(json))
 				settingsJSON, err := simplejson.NewJson([]byte(json))
 				So(err, ShouldBeNil)
 				So(err, ShouldBeNil)
 
 
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "email",
 					Type:     "email",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 3 - 3
pkg/services/alerting/notifiers/googlechat.go

@@ -7,7 +7,7 @@ import (
 
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
 )
 )
@@ -29,7 +29,7 @@ func init() {
 	})
 	})
 }
 }
 
 
-func NewGoogleChatNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewGoogleChatNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	url := model.Settings.Get("url").MustString()
 	url := model.Settings.Get("url").MustString()
 	if url == "" {
 	if url == "" {
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
@@ -199,7 +199,7 @@ func (this *GoogleChatNotifier) Notify(evalContext *alerting.EvalContext) error
 	}
 	}
 	body, _ := json.Marshal(res1D)
 	body, _ := json.Marshal(res1D)
 
 
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:        this.Url,
 		Url:        this.Url,
 		HttpMethod: "POST",
 		HttpMethod: "POST",
 		HttpHeader: headers,
 		HttpHeader: headers,

+ 3 - 3
pkg/services/alerting/notifiers/googlechat_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -16,7 +16,7 @@ func TestGoogleChatNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "googlechat",
 					Type:     "googlechat",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -33,7 +33,7 @@ func TestGoogleChatNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "googlechat",
 					Type:     "googlechat",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 4 - 4
pkg/services/alerting/notifiers/hipchat_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -16,7 +16,7 @@ func TestHipChatNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "hipchat",
 					Type:     "hipchat",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -33,7 +33,7 @@ func TestHipChatNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "hipchat",
 					Type:     "hipchat",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -59,7 +59,7 @@ func TestHipChatNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "hipchat",
 					Type:     "hipchat",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 3 - 3
pkg/services/alerting/notifiers/kafka.go

@@ -8,7 +8,7 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
 )
 
 
@@ -32,7 +32,7 @@ func init() {
 	})
 	})
 }
 }
 
 
-func NewKafkaNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewKafkaNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	endpoint := model.Settings.Get("kafkaRestProxy").MustString()
 	endpoint := model.Settings.Get("kafkaRestProxy").MustString()
 	if endpoint == "" {
 	if endpoint == "" {
 		return nil, alerting.ValidationError{Reason: "Could not find kafka rest proxy endpoint property in settings"}
 		return nil, alerting.ValidationError{Reason: "Could not find kafka rest proxy endpoint property in settings"}
@@ -101,7 +101,7 @@ func (this *KafkaNotifier) Notify(evalContext *alerting.EvalContext) error {
 
 
 	topicUrl := this.Endpoint + "/topics/" + this.Topic
 	topicUrl := this.Endpoint + "/topics/" + this.Topic
 
 
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:        topicUrl,
 		Url:        topicUrl,
 		Body:       string(body),
 		Body:       string(body),
 		HttpMethod: "POST",
 		HttpMethod: "POST",

+ 3 - 3
pkg/services/alerting/notifiers/kafka_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -16,7 +16,7 @@ func TestKafkaNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "kafka_testing",
 					Name:     "kafka_testing",
 					Type:     "kafka",
 					Type:     "kafka",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -34,7 +34,7 @@ func TestKafkaNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "kafka_testing",
 					Name:     "kafka_testing",
 					Type:     "kafka",
 					Type:     "kafka",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 4 - 4
pkg/services/alerting/notifiers/line.go

@@ -6,7 +6,7 @@ import (
 
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
 )
 
 
@@ -32,7 +32,7 @@ const (
 	lineNotifyUrl string = "https://notify-api.line.me/api/notify"
 	lineNotifyUrl string = "https://notify-api.line.me/api/notify"
 )
 )
 
 
-func NewLINENotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewLINENotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	token := model.Settings.Get("token").MustString()
 	token := model.Settings.Get("token").MustString()
 	if token == "" {
 	if token == "" {
 		return nil, alerting.ValidationError{Reason: "Could not find token in settings"}
 		return nil, alerting.ValidationError{Reason: "Could not find token in settings"}
@@ -56,7 +56,7 @@ func (this *LineNotifier) Notify(evalContext *alerting.EvalContext) error {
 
 
 	var err error
 	var err error
 	switch evalContext.Rule.State {
 	switch evalContext.Rule.State {
-	case m.AlertStateAlerting:
+	case models.AlertStateAlerting:
 		err = this.createAlert(evalContext)
 		err = this.createAlert(evalContext)
 	}
 	}
 	return err
 	return err
@@ -79,7 +79,7 @@ func (this *LineNotifier) createAlert(evalContext *alerting.EvalContext) error {
 		form.Add("imageFullsize", evalContext.ImagePublicUrl)
 		form.Add("imageFullsize", evalContext.ImagePublicUrl)
 	}
 	}
 
 
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:        lineNotifyUrl,
 		Url:        lineNotifyUrl,
 		HttpMethod: "POST",
 		HttpMethod: "POST",
 		HttpHeader: map[string]string{
 		HttpHeader: map[string]string{

+ 3 - 3
pkg/services/alerting/notifiers/line_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -14,7 +14,7 @@ func TestLineNotifier(t *testing.T) {
 			json := `{ }`
 			json := `{ }`
 
 
 			settingsJSON, _ := simplejson.NewJson([]byte(json))
 			settingsJSON, _ := simplejson.NewJson([]byte(json))
-			model := &m.AlertNotification{
+			model := &models.AlertNotification{
 				Name:     "line_testing",
 				Name:     "line_testing",
 				Type:     "line",
 				Type:     "line",
 				Settings: settingsJSON,
 				Settings: settingsJSON,
@@ -30,7 +30,7 @@ func TestLineNotifier(t *testing.T) {
   "token": "abcdefgh0123456789"
   "token": "abcdefgh0123456789"
 			}`
 			}`
 			settingsJSON, _ := simplejson.NewJson([]byte(json))
 			settingsJSON, _ := simplejson.NewJson([]byte(json))
-			model := &m.AlertNotification{
+			model := &models.AlertNotification{
 				Name:     "line_testing",
 				Name:     "line_testing",
 				Type:     "line",
 				Type:     "line",
 				Settings: settingsJSON,
 				Settings: settingsJSON,

+ 6 - 6
pkg/services/alerting/notifiers/opsgenie.go

@@ -7,7 +7,7 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
 )
 
 
@@ -44,7 +44,7 @@ var (
 	opsgenieAlertURL = "https://api.opsgenie.com/v2/alerts"
 	opsgenieAlertURL = "https://api.opsgenie.com/v2/alerts"
 )
 )
 
 
-func NewOpsGenieNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewOpsGenieNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	autoClose := model.Settings.Get("autoClose").MustBool(true)
 	autoClose := model.Settings.Get("autoClose").MustBool(true)
 	apiKey := model.Settings.Get("apiKey").MustString()
 	apiKey := model.Settings.Get("apiKey").MustString()
 	apiUrl := model.Settings.Get("apiUrl").MustString()
 	apiUrl := model.Settings.Get("apiUrl").MustString()
@@ -76,11 +76,11 @@ func (this *OpsGenieNotifier) Notify(evalContext *alerting.EvalContext) error {
 
 
 	var err error
 	var err error
 	switch evalContext.Rule.State {
 	switch evalContext.Rule.State {
-	case m.AlertStateOK:
+	case models.AlertStateOK:
 		if this.AutoClose {
 		if this.AutoClose {
 			err = this.closeAlert(evalContext)
 			err = this.closeAlert(evalContext)
 		}
 		}
-	case m.AlertStateAlerting:
+	case models.AlertStateAlerting:
 		err = this.createAlert(evalContext)
 		err = this.createAlert(evalContext)
 	}
 	}
 	return err
 	return err
@@ -115,7 +115,7 @@ func (this *OpsGenieNotifier) createAlert(evalContext *alerting.EvalContext) err
 	bodyJSON.Set("details", details)
 	bodyJSON.Set("details", details)
 	body, _ := bodyJSON.MarshalJSON()
 	body, _ := bodyJSON.MarshalJSON()
 
 
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:        this.ApiUrl,
 		Url:        this.ApiUrl,
 		Body:       string(body),
 		Body:       string(body),
 		HttpMethod: "POST",
 		HttpMethod: "POST",
@@ -139,7 +139,7 @@ func (this *OpsGenieNotifier) closeAlert(evalContext *alerting.EvalContext) erro
 	bodyJSON.Set("source", "Grafana")
 	bodyJSON.Set("source", "Grafana")
 	body, _ := bodyJSON.MarshalJSON()
 	body, _ := bodyJSON.MarshalJSON()
 
 
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:        fmt.Sprintf("%s/alertId-%d/close?identifierType=alias", this.ApiUrl, evalContext.Rule.Id),
 		Url:        fmt.Sprintf("%s/alertId-%d/close?identifierType=alias", this.ApiUrl, evalContext.Rule.Id),
 		Body:       string(body),
 		Body:       string(body),
 		HttpMethod: "POST",
 		HttpMethod: "POST",

+ 3 - 3
pkg/services/alerting/notifiers/opsgenie_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -16,7 +16,7 @@ func TestOpsGenieNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "opsgenie_testing",
 					Name:     "opsgenie_testing",
 					Type:     "opsgenie",
 					Type:     "opsgenie",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -33,7 +33,7 @@ func TestOpsGenieNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "opsgenie_testing",
 					Name:     "opsgenie_testing",
 					Type:     "opsgenie",
 					Type:     "opsgenie",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 5 - 5
pkg/services/alerting/notifiers/pagerduty.go

@@ -10,7 +10,7 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
 )
 
 
@@ -43,7 +43,7 @@ var (
 	pagerdutyEventApiUrl = "https://events.pagerduty.com/v2/enqueue"
 	pagerdutyEventApiUrl = "https://events.pagerduty.com/v2/enqueue"
 )
 )
 
 
-func NewPagerdutyNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewPagerdutyNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	autoResolve := model.Settings.Get("autoResolve").MustBool(false)
 	autoResolve := model.Settings.Get("autoResolve").MustBool(false)
 	key := model.Settings.Get("integrationKey").MustString()
 	key := model.Settings.Get("integrationKey").MustString()
 	if key == "" {
 	if key == "" {
@@ -67,13 +67,13 @@ type PagerdutyNotifier struct {
 
 
 func (this *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error {
 func (this *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error {
 
 
-	if evalContext.Rule.State == m.AlertStateOK && !this.AutoResolve {
+	if evalContext.Rule.State == models.AlertStateOK && !this.AutoResolve {
 		this.log.Info("Not sending a trigger to Pagerduty", "state", evalContext.Rule.State, "auto resolve", this.AutoResolve)
 		this.log.Info("Not sending a trigger to Pagerduty", "state", evalContext.Rule.State, "auto resolve", this.AutoResolve)
 		return nil
 		return nil
 	}
 	}
 
 
 	eventType := "trigger"
 	eventType := "trigger"
-	if evalContext.Rule.State == m.AlertStateOK {
+	if evalContext.Rule.State == models.AlertStateOK {
 		eventType = "resolve"
 		eventType = "resolve"
 	}
 	}
 	customData := triggMetrString
 	customData := triggMetrString
@@ -122,7 +122,7 @@ func (this *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error {
 
 
 	body, _ := bodyJSON.MarshalJSON()
 	body, _ := bodyJSON.MarshalJSON()
 
 
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:        pagerdutyEventApiUrl,
 		Url:        pagerdutyEventApiUrl,
 		Body:       string(body),
 		Body:       string(body),
 		HttpMethod: "POST",
 		HttpMethod: "POST",

+ 4 - 4
pkg/services/alerting/notifiers/pagerduty_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -15,7 +15,7 @@ func TestPagerdutyNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "pageduty_testing",
 					Name:     "pageduty_testing",
 					Type:     "pagerduty",
 					Type:     "pagerduty",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -29,7 +29,7 @@ func TestPagerdutyNotifier(t *testing.T) {
 				json := `{ "integrationKey": "abcdefgh0123456789" }`
 				json := `{ "integrationKey": "abcdefgh0123456789" }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "pagerduty_testing",
 					Name:     "pagerduty_testing",
 					Type:     "pagerduty",
 					Type:     "pagerduty",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -53,7 +53,7 @@ func TestPagerdutyNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "pagerduty_testing",
 					Name:     "pagerduty_testing",
 					Type:     "pagerduty",
 					Type:     "pagerduty",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 4 - 4
pkg/services/alerting/notifiers/pushover.go

@@ -10,7 +10,7 @@ import (
 
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
 )
 
 
@@ -95,7 +95,7 @@ func init() {
 	})
 	})
 }
 }
 
 
-func NewPushoverNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewPushoverNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	userKey := model.Settings.Get("userKey").MustString()
 	userKey := model.Settings.Get("userKey").MustString()
 	apiToken := model.Settings.Get("apiToken").MustString()
 	apiToken := model.Settings.Get("apiToken").MustString()
 	device := model.Settings.Get("device").MustString()
 	device := model.Settings.Get("device").MustString()
@@ -169,7 +169,7 @@ func (this *PushoverNotifier) Notify(evalContext *alerting.EvalContext) error {
 		return err
 		return err
 	}
 	}
 
 
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:        PUSHOVER_ENDPOINT,
 		Url:        PUSHOVER_ENDPOINT,
 		HttpMethod: "POST",
 		HttpMethod: "POST",
 		HttpHeader: headers,
 		HttpHeader: headers,
@@ -248,7 +248,7 @@ func (this *PushoverNotifier) genPushoverBody(evalContext *alerting.EvalContext,
 
 
 	// Add sound
 	// Add sound
 	sound := this.AlertingSound
 	sound := this.AlertingSound
-	if evalContext.Rule.State == m.AlertStateOK {
+	if evalContext.Rule.State == models.AlertStateOK {
 		sound = this.OkSound
 		sound = this.OkSound
 	}
 	}
 	if sound != "default" {
 	if sound != "default" {

+ 7 - 6
pkg/services/alerting/notifiers/pushover_test.go

@@ -2,12 +2,13 @@ package notifiers
 
 
 import (
 import (
 	"context"
 	"context"
-	"github.com/grafana/grafana/pkg/services/alerting"
 	"strings"
 	"strings"
 	"testing"
 	"testing"
 
 
+	"github.com/grafana/grafana/pkg/services/alerting"
+
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -19,7 +20,7 @@ func TestPushoverNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "Pushover",
 					Name:     "Pushover",
 					Type:     "pushover",
 					Type:     "pushover",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -40,7 +41,7 @@ func TestPushoverNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "Pushover",
 					Name:     "Pushover",
 					Type:     "pushover",
 					Type:     "pushover",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -73,7 +74,7 @@ func TestGenPushoverBody(t *testing.T) {
 			Convey("When alert is firing - should use siren sound", func() {
 			Convey("When alert is firing - should use siren sound", func() {
 				evalContext := alerting.NewEvalContext(context.Background(),
 				evalContext := alerting.NewEvalContext(context.Background(),
 					&alerting.Rule{
 					&alerting.Rule{
-						State: m.AlertStateAlerting,
+						State: models.AlertStateAlerting,
 					})
 					})
 				_, pushoverBody, err := notifier.genPushoverBody(evalContext, "", "")
 				_, pushoverBody, err := notifier.genPushoverBody(evalContext, "", "")
 
 
@@ -84,7 +85,7 @@ func TestGenPushoverBody(t *testing.T) {
 			Convey("When alert is ok - should use success sound", func() {
 			Convey("When alert is ok - should use success sound", func() {
 				evalContext := alerting.NewEvalContext(context.Background(),
 				evalContext := alerting.NewEvalContext(context.Background(),
 					&alerting.Rule{
 					&alerting.Rule{
-						State: m.AlertStateOK,
+						State: models.AlertStateOK,
 					})
 					})
 				_, pushoverBody, err := notifier.genPushoverBody(evalContext, "", "")
 				_, pushoverBody, err := notifier.genPushoverBody(evalContext, "", "")
 
 

+ 3 - 3
pkg/services/alerting/notifiers/sensu.go

@@ -7,7 +7,7 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
 )
 
 
@@ -44,7 +44,7 @@ func init() {
 
 
 }
 }
 
 
-func NewSensuNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewSensuNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	url := model.Settings.Get("url").MustString()
 	url := model.Settings.Get("url").MustString()
 	if url == "" {
 	if url == "" {
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
@@ -117,7 +117,7 @@ func (this *SensuNotifier) Notify(evalContext *alerting.EvalContext) error {
 
 
 	body, _ := bodyJSON.MarshalJSON()
 	body, _ := bodyJSON.MarshalJSON()
 
 
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:        this.Url,
 		Url:        this.Url,
 		User:       this.User,
 		User:       this.User,
 		Password:   this.Password,
 		Password:   this.Password,

+ 3 - 3
pkg/services/alerting/notifiers/sensu_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -16,7 +16,7 @@ func TestSensuNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "sensu",
 					Name:     "sensu",
 					Type:     "sensu",
 					Type:     "sensu",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -35,7 +35,7 @@ func TestSensuNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "sensu",
 					Name:     "sensu",
 					Type:     "sensu",
 					Type:     "sensu",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 5 - 5
pkg/services/alerting/notifiers/slack.go

@@ -11,7 +11,7 @@ import (
 
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
 )
 )
@@ -99,7 +99,7 @@ func init() {
 
 
 }
 }
 
 
-func NewSlackNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewSlackNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	url := model.Settings.Get("url").MustString()
 	url := model.Settings.Get("url").MustString()
 	if url == "" {
 	if url == "" {
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
@@ -171,7 +171,7 @@ func (this *SlackNotifier) Notify(evalContext *alerting.EvalContext) error {
 	}
 	}
 
 
 	message := this.Mention
 	message := this.Mention
-	if evalContext.Rule.State != m.AlertStateOK { //don't add message when going back to alert state ok.
+	if evalContext.Rule.State != models.AlertStateOK { //don't add message when going back to alert state ok.
 		message += " " + evalContext.Rule.Message
 		message += " " + evalContext.Rule.Message
 	}
 	}
 	image_url := ""
 	image_url := ""
@@ -212,7 +212,7 @@ func (this *SlackNotifier) Notify(evalContext *alerting.EvalContext) error {
 		body["icon_url"] = this.IconUrl
 		body["icon_url"] = this.IconUrl
 	}
 	}
 	data, _ := json.Marshal(&body)
 	data, _ := json.Marshal(&body)
-	cmd := &m.SendWebhookSync{Url: this.Url, Body: string(data)}
+	cmd := &models.SendWebhookSync{Url: this.Url, Body: string(data)}
 	if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
 	if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
 		this.log.Error("Failed to send slack notification", "error", err, "webhook", this.Name)
 		this.log.Error("Failed to send slack notification", "error", err, "webhook", this.Name)
 		return err
 		return err
@@ -235,7 +235,7 @@ func SlackFileUpload(evalContext *alerting.EvalContext, log log.Logger, url stri
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-	cmd := &m.SendWebhookSync{Url: url, Body: uploadBody.String(), HttpHeader: headers, HttpMethod: "POST"}
+	cmd := &models.SendWebhookSync{Url: url, Body: uploadBody.String(), HttpHeader: headers, HttpMethod: "POST"}
 	if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
 	if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
 		log.Error("Failed to upload slack image", "error", err, "webhook", "file.upload")
 		log.Error("Failed to upload slack image", "error", err, "webhook", "file.upload")
 		return err
 		return err

+ 4 - 4
pkg/services/alerting/notifiers/slack_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -16,7 +16,7 @@ func TestSlackNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "slack",
 					Type:     "slack",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -33,7 +33,7 @@ func TestSlackNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "slack",
 					Type:     "slack",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -67,7 +67,7 @@ func TestSlackNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "slack",
 					Type:     "slack",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 4 - 4
pkg/services/alerting/notifiers/teams.go

@@ -5,7 +5,7 @@ import (
 
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
 )
 
 
@@ -26,7 +26,7 @@ func init() {
 
 
 }
 }
 
 
-func NewTeamsNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewTeamsNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	url := model.Settings.Get("url").MustString()
 	url := model.Settings.Get("url").MustString()
 	if url == "" {
 	if url == "" {
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
@@ -74,7 +74,7 @@ func (this *TeamsNotifier) Notify(evalContext *alerting.EvalContext) error {
 	}
 	}
 
 
 	message := ""
 	message := ""
-	if evalContext.Rule.State != m.AlertStateOK { //don't add message when going back to alert state ok.
+	if evalContext.Rule.State != models.AlertStateOK { //don't add message when going back to alert state ok.
 		message = evalContext.Rule.Message
 		message = evalContext.Rule.Message
 	}
 	}
 
 
@@ -126,7 +126,7 @@ func (this *TeamsNotifier) Notify(evalContext *alerting.EvalContext) error {
 	}
 	}
 
 
 	data, _ := json.Marshal(&body)
 	data, _ := json.Marshal(&body)
-	cmd := &m.SendWebhookSync{Url: this.Url, Body: string(data)}
+	cmd := &models.SendWebhookSync{Url: this.Url, Body: string(data)}
 
 
 	if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
 	if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
 		this.log.Error("Failed to send teams notification", "error", err, "webhook", this.Name)
 		this.log.Error("Failed to send teams notification", "error", err, "webhook", this.Name)

+ 4 - 4
pkg/services/alerting/notifiers/teams_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -16,7 +16,7 @@ func TestTeamsNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "teams",
 					Type:     "teams",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -33,7 +33,7 @@ func TestTeamsNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "teams",
 					Type:     "teams",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -55,7 +55,7 @@ func TestTeamsNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "teams",
 					Type:     "teams",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 8 - 8
pkg/services/alerting/notifiers/telegram.go

@@ -9,7 +9,7 @@ import (
 
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
 )
 
 
@@ -60,7 +60,7 @@ type TelegramNotifier struct {
 	log         log.Logger
 	log         log.Logger
 }
 }
 
 
-func NewTelegramNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewTelegramNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	if model.Settings == nil {
 	if model.Settings == nil {
 		return nil, alerting.ValidationError{Reason: "No Settings Supplied"}
 		return nil, alerting.ValidationError{Reason: "No Settings Supplied"}
 	}
 	}
@@ -86,7 +86,7 @@ func NewTelegramNotifier(model *m.AlertNotification) (alerting.Notifier, error)
 	}, nil
 	}, nil
 }
 }
 
 
-func (this *TelegramNotifier) buildMessage(evalContext *alerting.EvalContext, sendImageInline bool) *m.SendWebhookSync {
+func (this *TelegramNotifier) buildMessage(evalContext *alerting.EvalContext, sendImageInline bool) *models.SendWebhookSync {
 	if sendImageInline {
 	if sendImageInline {
 		cmd, err := this.buildMessageInlineImage(evalContext)
 		cmd, err := this.buildMessageInlineImage(evalContext)
 		if err == nil {
 		if err == nil {
@@ -98,7 +98,7 @@ func (this *TelegramNotifier) buildMessage(evalContext *alerting.EvalContext, se
 	return this.buildMessageLinkedImage(evalContext)
 	return this.buildMessageLinkedImage(evalContext)
 }
 }
 
 
-func (this *TelegramNotifier) buildMessageLinkedImage(evalContext *alerting.EvalContext) *m.SendWebhookSync {
+func (this *TelegramNotifier) buildMessageLinkedImage(evalContext *alerting.EvalContext) *models.SendWebhookSync {
 	message := fmt.Sprintf("<b>%s</b>\nState: %s\nMessage: %s\n", evalContext.GetNotificationTitle(), evalContext.Rule.Name, evalContext.Rule.Message)
 	message := fmt.Sprintf("<b>%s</b>\nState: %s\nMessage: %s\n", evalContext.GetNotificationTitle(), evalContext.Rule.Name, evalContext.Rule.Message)
 
 
 	ruleUrl, err := evalContext.GetRuleUrl()
 	ruleUrl, err := evalContext.GetRuleUrl()
@@ -122,7 +122,7 @@ func (this *TelegramNotifier) buildMessageLinkedImage(evalContext *alerting.Eval
 	return cmd
 	return cmd
 }
 }
 
 
-func (this *TelegramNotifier) buildMessageInlineImage(evalContext *alerting.EvalContext) (*m.SendWebhookSync, error) {
+func (this *TelegramNotifier) buildMessageInlineImage(evalContext *alerting.EvalContext) (*models.SendWebhookSync, error) {
 	var imageFile *os.File
 	var imageFile *os.File
 	var err error
 	var err error
 
 
@@ -153,7 +153,7 @@ func (this *TelegramNotifier) buildMessageInlineImage(evalContext *alerting.Eval
 	return cmd, nil
 	return cmd, nil
 }
 }
 
 
-func (this *TelegramNotifier) generateTelegramCmd(message string, messageField string, apiAction string, extraConf func(writer *multipart.Writer)) *m.SendWebhookSync {
+func (this *TelegramNotifier) generateTelegramCmd(message string, messageField string, apiAction string, extraConf func(writer *multipart.Writer)) *models.SendWebhookSync {
 	var body bytes.Buffer
 	var body bytes.Buffer
 	w := multipart.NewWriter(&body)
 	w := multipart.NewWriter(&body)
 
 
@@ -170,7 +170,7 @@ func (this *TelegramNotifier) generateTelegramCmd(message string, messageField s
 	this.log.Info("Sending telegram notification", "chat_id", this.ChatID, "bot_token", this.BotToken, "apiAction", apiAction)
 	this.log.Info("Sending telegram notification", "chat_id", this.ChatID, "bot_token", this.BotToken, "apiAction", apiAction)
 	url := fmt.Sprintf(telegramApiUrl, this.BotToken, apiAction)
 	url := fmt.Sprintf(telegramApiUrl, this.BotToken, apiAction)
 
 
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:        url,
 		Url:        url,
 		Body:       body.String(),
 		Body:       body.String(),
 		HttpMethod: "POST",
 		HttpMethod: "POST",
@@ -227,7 +227,7 @@ func appendIfPossible(message string, extra string, sizeLimit int) string {
 }
 }
 
 
 func (this *TelegramNotifier) Notify(evalContext *alerting.EvalContext) error {
 func (this *TelegramNotifier) Notify(evalContext *alerting.EvalContext) error {
-	var cmd *m.SendWebhookSync
+	var cmd *models.SendWebhookSync
 	if evalContext.ImagePublicUrl == "" && this.UploadImage {
 	if evalContext.ImagePublicUrl == "" && this.UploadImage {
 		cmd = this.buildMessage(evalContext, true)
 		cmd = this.buildMessage(evalContext, true)
 	} else {
 	} else {

+ 7 - 7
pkg/services/alerting/notifiers/telegram_test.go

@@ -5,7 +5,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
@@ -18,7 +18,7 @@ func TestTelegramNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "telegram_testing",
 					Name:     "telegram_testing",
 					Type:     "telegram",
 					Type:     "telegram",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -36,7 +36,7 @@ func TestTelegramNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "telegram_testing",
 					Name:     "telegram_testing",
 					Type:     "telegram",
 					Type:     "telegram",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -57,7 +57,7 @@ func TestTelegramNotifier(t *testing.T) {
 					&alerting.Rule{
 					&alerting.Rule{
 						Name:    "This is an alarm",
 						Name:    "This is an alarm",
 						Message: "Some kind of message.",
 						Message: "Some kind of message.",
-						State:   m.AlertStateOK,
+						State:   models.AlertStateOK,
 					})
 					})
 
 
 				caption := generateImageCaption(evalContext, "http://grafa.url/abcdef", "")
 				caption := generateImageCaption(evalContext, "http://grafa.url/abcdef", "")
@@ -74,7 +74,7 @@ func TestTelegramNotifier(t *testing.T) {
 						&alerting.Rule{
 						&alerting.Rule{
 							Name:    "This is an alarm",
 							Name:    "This is an alarm",
 							Message: "Some kind of message.",
 							Message: "Some kind of message.",
-							State:   m.AlertStateOK,
+							State:   models.AlertStateOK,
 						})
 						})
 
 
 					caption := generateImageCaption(evalContext,
 					caption := generateImageCaption(evalContext,
@@ -92,7 +92,7 @@ func TestTelegramNotifier(t *testing.T) {
 						&alerting.Rule{
 						&alerting.Rule{
 							Name:    "This is an alarm",
 							Name:    "This is an alarm",
 							Message: "Some kind of message that is too long for appending to our pretty little message, this line is actually exactly 197 chars long and I will get there in the end I promise I will. Yes siree that's it. But suddenly Telegram increased the length so now we need some lorem ipsum to fix this test. Here we go: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus consectetur molestie cursus. Donec suscipit egestas nisi. Proin ut efficitur ex. Mauris mi augue, volutpat a nisi vel, euismod dictum arcu. Sed quis tempor eros, sed malesuada dolor. Ut orci augue, viverra sit amet blandit quis, faucibus sit amet ex. Duis condimentum efficitur lectus, id dignissim quam tempor id. Morbi sollicitudin rhoncus diam, id tincidunt lectus scelerisque vitae. Etiam imperdiet semper sem, vel eleifend ligula mollis eget. Etiam ultrices fringilla lacus, sit amet pharetra ex blandit quis. Suspendisse in egestas neque, et posuere lectus. Vestibulum eu ex dui. Sed molestie nulla a lobortis scelerisque. Nulla ipsum ex, iaculis vitae vehicula sit amet, fermentum eu eros.",
 							Message: "Some kind of message that is too long for appending to our pretty little message, this line is actually exactly 197 chars long and I will get there in the end I promise I will. Yes siree that's it. But suddenly Telegram increased the length so now we need some lorem ipsum to fix this test. Here we go: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus consectetur molestie cursus. Donec suscipit egestas nisi. Proin ut efficitur ex. Mauris mi augue, volutpat a nisi vel, euismod dictum arcu. Sed quis tempor eros, sed malesuada dolor. Ut orci augue, viverra sit amet blandit quis, faucibus sit amet ex. Duis condimentum efficitur lectus, id dignissim quam tempor id. Morbi sollicitudin rhoncus diam, id tincidunt lectus scelerisque vitae. Etiam imperdiet semper sem, vel eleifend ligula mollis eget. Etiam ultrices fringilla lacus, sit amet pharetra ex blandit quis. Suspendisse in egestas neque, et posuere lectus. Vestibulum eu ex dui. Sed molestie nulla a lobortis scelerisque. Nulla ipsum ex, iaculis vitae vehicula sit amet, fermentum eu eros.",
-							State:   m.AlertStateOK,
+							State:   models.AlertStateOK,
 						})
 						})
 
 
 					caption := generateImageCaption(evalContext,
 					caption := generateImageCaption(evalContext,
@@ -109,7 +109,7 @@ func TestTelegramNotifier(t *testing.T) {
 						&alerting.Rule{
 						&alerting.Rule{
 							Name:    "This is an alarm",
 							Name:    "This is an alarm",
 							Message: "Some kind of message that is too long for appending to our pretty little message, this line is actually exactly 197 chars long and I will get there in the end I promise I will. Yes siree that's it. But suddenly Telegram increased the length so now we need some lorem ipsum to fix this test. Here we go: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus consectetur molestie cursus. Donec suscipit egestas nisi. Proin ut efficitur ex. Mauris mi augue, volutpat a nisi vel, euismod dictum arcu. Sed quis tempor eros, sed malesuada dolor. Ut orci augue, viverra sit amet blandit quis, faucibus sit amet ex. Duis condimentum efficitur lectus, id dignissim quam tempor id. Morbi sollicitudin rhoncus diam, id tincidunt lectus scelerisque vitae. Etiam imperdiet semper sem, vel eleifend ligula mollis eget. Etiam ultrices fringilla lacus, sit amet pharetra ex blandit quis. Suspendisse in egestas neque, et posuere lectus. Vestibulum eu ex dui. Sed molestie nulla a lobortis sceleri",
 							Message: "Some kind of message that is too long for appending to our pretty little message, this line is actually exactly 197 chars long and I will get there in the end I promise I will. Yes siree that's it. But suddenly Telegram increased the length so now we need some lorem ipsum to fix this test. Here we go: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus consectetur molestie cursus. Donec suscipit egestas nisi. Proin ut efficitur ex. Mauris mi augue, volutpat a nisi vel, euismod dictum arcu. Sed quis tempor eros, sed malesuada dolor. Ut orci augue, viverra sit amet blandit quis, faucibus sit amet ex. Duis condimentum efficitur lectus, id dignissim quam tempor id. Morbi sollicitudin rhoncus diam, id tincidunt lectus scelerisque vitae. Etiam imperdiet semper sem, vel eleifend ligula mollis eget. Etiam ultrices fringilla lacus, sit amet pharetra ex blandit quis. Suspendisse in egestas neque, et posuere lectus. Vestibulum eu ex dui. Sed molestie nulla a lobortis sceleri",
-							State:   m.AlertStateOK,
+							State:   models.AlertStateOK,
 						})
 						})
 
 
 					caption := generateImageCaption(evalContext,
 					caption := generateImageCaption(evalContext,

+ 6 - 6
pkg/services/alerting/notifiers/threema.go

@@ -7,7 +7,7 @@ import (
 
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
 )
 
 
@@ -76,7 +76,7 @@ type ThreemaNotifier struct {
 	log         log.Logger
 	log         log.Logger
 }
 }
 
 
-func NewThreemaNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewThreemaNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	if model.Settings == nil {
 	if model.Settings == nil {
 		return nil, alerting.ValidationError{Reason: "No Settings Supplied"}
 		return nil, alerting.ValidationError{Reason: "No Settings Supplied"}
 	}
 	}
@@ -127,11 +127,11 @@ func (notifier *ThreemaNotifier) Notify(evalContext *alerting.EvalContext) error
 	// Determine emoji
 	// Determine emoji
 	stateEmoji := ""
 	stateEmoji := ""
 	switch evalContext.Rule.State {
 	switch evalContext.Rule.State {
-	case m.AlertStateOK:
+	case models.AlertStateOK:
 		stateEmoji = "\u2705 " // White Heavy Check Mark
 		stateEmoji = "\u2705 " // White Heavy Check Mark
-	case m.AlertStateNoData:
+	case models.AlertStateNoData:
 		stateEmoji = "\u2753 " // Black Question Mark Ornament
 		stateEmoji = "\u2753 " // Black Question Mark Ornament
-	case m.AlertStateAlerting:
+	case models.AlertStateAlerting:
 		stateEmoji = "\u26A0 " // Warning sign
 		stateEmoji = "\u26A0 " // Warning sign
 	}
 	}
 
 
@@ -154,7 +154,7 @@ func (notifier *ThreemaNotifier) Notify(evalContext *alerting.EvalContext) error
 	headers := map[string]string{
 	headers := map[string]string{
 		"Content-Type": "application/x-www-form-urlencoded",
 		"Content-Type": "application/x-www-form-urlencoded",
 	}
 	}
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:        url,
 		Url:        url,
 		Body:       body,
 		Body:       body,
 		HttpMethod: "POST",
 		HttpMethod: "POST",

+ 6 - 6
pkg/services/alerting/notifiers/threema_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
@@ -17,7 +17,7 @@ func TestThreemaNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "threema_testing",
 					Name:     "threema_testing",
 					Type:     "threema",
 					Type:     "threema",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -36,7 +36,7 @@ func TestThreemaNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "threema_testing",
 					Name:     "threema_testing",
 					Type:     "threema",
 					Type:     "threema",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -63,7 +63,7 @@ func TestThreemaNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "threema_testing",
 					Name:     "threema_testing",
 					Type:     "threema",
 					Type:     "threema",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -83,7 +83,7 @@ func TestThreemaNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "threema_testing",
 					Name:     "threema_testing",
 					Type:     "threema",
 					Type:     "threema",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -103,7 +103,7 @@ func TestThreemaNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "threema_testing",
 					Name:     "threema_testing",
 					Type:     "threema",
 					Type:     "threema",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 3 - 3
pkg/services/alerting/notifiers/victorops_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -16,7 +16,7 @@ func TestVictoropsNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "victorops_testing",
 					Name:     "victorops_testing",
 					Type:     "victorops",
 					Type:     "victorops",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -33,7 +33,7 @@ func TestVictoropsNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "victorops_testing",
 					Name:     "victorops_testing",
 					Type:     "victorops",
 					Type:     "victorops",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 3 - 3
pkg/services/alerting/notifiers/webhook.go

@@ -4,7 +4,7 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/alerting"
 	"github.com/grafana/grafana/pkg/services/alerting"
 )
 )
 
 
@@ -40,7 +40,7 @@ func init() {
 
 
 }
 }
 
 
-func NewWebHookNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
+func NewWebHookNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
 	url := model.Settings.Get("url").MustString()
 	url := model.Settings.Get("url").MustString()
 	if url == "" {
 	if url == "" {
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
@@ -90,7 +90,7 @@ func (this *WebhookNotifier) Notify(evalContext *alerting.EvalContext) error {
 
 
 	body, _ := bodyJSON.MarshalJSON()
 	body, _ := bodyJSON.MarshalJSON()
 
 
-	cmd := &m.SendWebhookSync{
+	cmd := &models.SendWebhookSync{
 		Url:        this.Url,
 		Url:        this.Url,
 		User:       this.User,
 		User:       this.User,
 		Password:   this.Password,
 		Password:   this.Password,

+ 3 - 3
pkg/services/alerting/notifiers/webhook_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
 
 
@@ -16,7 +16,7 @@ func TestWebhookNotifier(t *testing.T) {
 				json := `{ }`
 				json := `{ }`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "webhook",
 					Type:     "webhook",
 					Settings: settingsJSON,
 					Settings: settingsJSON,
@@ -33,7 +33,7 @@ func TestWebhookNotifier(t *testing.T) {
 				}`
 				}`
 
 
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
 				settingsJSON, _ := simplejson.NewJson([]byte(json))
-				model := &m.AlertNotification{
+				model := &models.AlertNotification{
 					Name:     "ops",
 					Name:     "ops",
 					Type:     "webhook",
 					Type:     "webhook",
 					Settings: settingsJSON,
 					Settings: settingsJSON,

+ 2 - 3
pkg/services/alerting/reader.go

@@ -7,7 +7,7 @@ import (
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/metrics"
 	"github.com/grafana/grafana/pkg/infra/metrics"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 )
 )
 
 
 type RuleReader interface {
 type RuleReader interface {
@@ -16,7 +16,6 @@ type RuleReader interface {
 
 
 type DefaultRuleReader struct {
 type DefaultRuleReader struct {
 	sync.RWMutex
 	sync.RWMutex
-	//serverID       string
 	serverPosition int
 	serverPosition int
 	clusterSize    int
 	clusterSize    int
 	log            log.Logger
 	log            log.Logger
@@ -40,7 +39,7 @@ func (arr *DefaultRuleReader) initReader() {
 }
 }
 
 
 func (arr *DefaultRuleReader) Fetch() []*Rule {
 func (arr *DefaultRuleReader) Fetch() []*Rule {
-	cmd := &m.GetAllAlertsQuery{}
+	cmd := &models.GetAllAlertsQuery{}
 
 
 	if err := bus.Dispatch(cmd); err != nil {
 	if err := bus.Dispatch(cmd); err != nil {
 		arr.log.Error("Could not load alerts", "error", err)
 		arr.log.Error("Could not load alerts", "error", err)

+ 5 - 4
pkg/services/alerting/result_handler.go

@@ -7,7 +7,8 @@ import (
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/metrics"
 	"github.com/grafana/grafana/pkg/infra/metrics"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
+
 	"github.com/grafana/grafana/pkg/services/annotations"
 	"github.com/grafana/grafana/pkg/services/annotations"
 	"github.com/grafana/grafana/pkg/services/rendering"
 	"github.com/grafana/grafana/pkg/services/rendering"
 )
 )
@@ -47,7 +48,7 @@ func (handler *DefaultResultHandler) Handle(evalContext *EvalContext) error {
 	if evalContext.ShouldUpdateAlertState() {
 	if evalContext.ShouldUpdateAlertState() {
 		handler.log.Info("New state change", "alertId", evalContext.Rule.Id, "newState", evalContext.Rule.State, "prev state", evalContext.PrevAlertState)
 		handler.log.Info("New state change", "alertId", evalContext.Rule.Id, "newState", evalContext.Rule.State, "prev state", evalContext.PrevAlertState)
 
 
-		cmd := &m.SetAlertStateCommand{
+		cmd := &models.SetAlertStateCommand{
 			AlertId:  evalContext.Rule.Id,
 			AlertId:  evalContext.Rule.Id,
 			OrgId:    evalContext.Rule.OrgId,
 			OrgId:    evalContext.Rule.OrgId,
 			State:    evalContext.Rule.State,
 			State:    evalContext.Rule.State,
@@ -56,12 +57,12 @@ func (handler *DefaultResultHandler) Handle(evalContext *EvalContext) error {
 		}
 		}
 
 
 		if err := bus.Dispatch(cmd); err != nil {
 		if err := bus.Dispatch(cmd); err != nil {
-			if err == m.ErrCannotChangeStateOnPausedAlert {
+			if err == models.ErrCannotChangeStateOnPausedAlert {
 				handler.log.Error("Cannot change state on alert that's paused", "error", err)
 				handler.log.Error("Cannot change state on alert that's paused", "error", err)
 				return err
 				return err
 			}
 			}
 
 
-			if err == m.ErrRequiresNewState {
+			if err == models.ErrRequiresNewState {
 				handler.log.Info("Alert already updated")
 				handler.log.Info("Alert already updated")
 				return nil
 				return nil
 			}
 			}

+ 7 - 7
pkg/services/alerting/rule.go

@@ -8,7 +8,7 @@ import (
 	"time"
 	"time"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 )
 )
 
 
 var (
 var (
@@ -26,9 +26,9 @@ type Rule struct {
 	Message             string
 	Message             string
 	LastStateChange     time.Time
 	LastStateChange     time.Time
 	For                 time.Duration
 	For                 time.Duration
-	NoDataState         m.NoDataOption
-	ExecutionErrorState m.ExecutionErrorOption
-	State               m.AlertStateType
+	NoDataState         models.NoDataOption
+	ExecutionErrorState models.ExecutionErrorOption
+	State               models.AlertStateType
 	Conditions          []Condition
 	Conditions          []Condition
 	Notifications       []string
 	Notifications       []string
 
 
@@ -103,7 +103,7 @@ func getTimeDurationStringToSeconds(str string) (int64, error) {
 	return int64(value * multiplier), nil
 	return int64(value * multiplier), nil
 }
 }
 
 
-func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) {
+func NewRuleFromDBAlert(ruleDef *models.Alert) (*Rule, error) {
 	model := &Rule{}
 	model := &Rule{}
 	model.Id = ruleDef.Id
 	model.Id = ruleDef.Id
 	model.OrgId = ruleDef.OrgId
 	model.OrgId = ruleDef.OrgId
@@ -114,8 +114,8 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) {
 	model.State = ruleDef.State
 	model.State = ruleDef.State
 	model.LastStateChange = ruleDef.NewStateDate
 	model.LastStateChange = ruleDef.NewStateDate
 	model.For = ruleDef.For
 	model.For = ruleDef.For
-	model.NoDataState = m.NoDataOption(ruleDef.Settings.Get("noDataState").MustString("no_data"))
-	model.ExecutionErrorState = m.ExecutionErrorOption(ruleDef.Settings.Get("executionErrorState").MustString("alerting"))
+	model.NoDataState = models.NoDataOption(ruleDef.Settings.Get("noDataState").MustString("no_data"))
+	model.ExecutionErrorState = models.ExecutionErrorOption(ruleDef.Settings.Get("executionErrorState").MustString("alerting"))
 	model.StateChanges = ruleDef.StateChanges
 	model.StateChanges = ruleDef.StateChanges
 
 
 	model.Frequency = ruleDef.Frequency
 	model.Frequency = ruleDef.Frequency

+ 6 - 6
pkg/services/alerting/rule_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/services/sqlstore"
 	"github.com/grafana/grafana/pkg/services/sqlstore"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
 )
 )
@@ -60,10 +60,10 @@ func TestAlertRuleModel(t *testing.T) {
 		})
 		})
 
 
 		Convey("can construct alert rule model", func() {
 		Convey("can construct alert rule model", func() {
-			firstNotification := m.CreateAlertNotificationCommand{OrgId: 1, Name: "1"}
+			firstNotification := models.CreateAlertNotificationCommand{OrgId: 1, Name: "1"}
 			err := sqlstore.CreateAlertNotificationCommand(&firstNotification)
 			err := sqlstore.CreateAlertNotificationCommand(&firstNotification)
 			So(err, ShouldBeNil)
 			So(err, ShouldBeNil)
-			secondNotification := m.CreateAlertNotificationCommand{Uid: "notifier2", OrgId: 1, Name: "2"}
+			secondNotification := models.CreateAlertNotificationCommand{Uid: "notifier2", OrgId: 1, Name: "2"}
 			err = sqlstore.CreateAlertNotificationCommand(&secondNotification)
 			err = sqlstore.CreateAlertNotificationCommand(&secondNotification)
 			So(err, ShouldBeNil)
 			So(err, ShouldBeNil)
 
 
@@ -92,7 +92,7 @@ func TestAlertRuleModel(t *testing.T) {
 				alertJSON, jsonErr := simplejson.NewJson([]byte(json))
 				alertJSON, jsonErr := simplejson.NewJson([]byte(json))
 				So(jsonErr, ShouldBeNil)
 				So(jsonErr, ShouldBeNil)
 
 
-				alert := &m.Alert{
+				alert := &models.Alert{
 					Id:          1,
 					Id:          1,
 					OrgId:       1,
 					OrgId:       1,
 					DashboardId: 1,
 					DashboardId: 1,
@@ -129,7 +129,7 @@ func TestAlertRuleModel(t *testing.T) {
 			alertJSON, jsonErr := simplejson.NewJson([]byte(json))
 			alertJSON, jsonErr := simplejson.NewJson([]byte(json))
 			So(jsonErr, ShouldBeNil)
 			So(jsonErr, ShouldBeNil)
 
 
-			alert := &m.Alert{
+			alert := &models.Alert{
 				Id:          1,
 				Id:          1,
 				OrgId:       1,
 				OrgId:       1,
 				DashboardId: 1,
 				DashboardId: 1,
@@ -167,7 +167,7 @@ func TestAlertRuleModel(t *testing.T) {
 			alertJSON, jsonErr := simplejson.NewJson([]byte(json))
 			alertJSON, jsonErr := simplejson.NewJson([]byte(json))
 			So(jsonErr, ShouldBeNil)
 			So(jsonErr, ShouldBeNil)
 
 
-			alert := &m.Alert{
+			alert := &models.Alert{
 				Id:          1,
 				Id:          1,
 				OrgId:       1,
 				OrgId:       1,
 				DashboardId: 1,
 				DashboardId: 1,

+ 4 - 4
pkg/services/alerting/test_notification.go

@@ -8,11 +8,11 @@ import (
 	"github.com/grafana/grafana/pkg/components/null"
 	"github.com/grafana/grafana/pkg/components/null"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/infra/log"
 	"github.com/grafana/grafana/pkg/infra/log"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 )
 )
 
 
 type NotificationTestCommand struct {
 type NotificationTestCommand struct {
-	State    m.AlertStateType
+	State    models.AlertStateType
 	Name     string
 	Name     string
 	Type     string
 	Type     string
 	Settings *simplejson.Json
 	Settings *simplejson.Json
@@ -29,7 +29,7 @@ func init() {
 func handleNotificationTestCommand(cmd *NotificationTestCommand) error {
 func handleNotificationTestCommand(cmd *NotificationTestCommand) error {
 	notifier := NewNotificationService(nil).(*notificationService)
 	notifier := NewNotificationService(nil).(*notificationService)
 
 
-	model := &m.AlertNotification{
+	model := &models.AlertNotification{
 		Name:     cmd.Name,
 		Name:     cmd.Name,
 		Type:     cmd.Type,
 		Type:     cmd.Type,
 		Settings: cmd.Settings,
 		Settings: cmd.Settings,
@@ -51,7 +51,7 @@ func createTestEvalContext(cmd *NotificationTestCommand) *EvalContext {
 		PanelId:     1,
 		PanelId:     1,
 		Name:        "Test notification",
 		Name:        "Test notification",
 		Message:     "Someone is testing the alert notification within grafana.",
 		Message:     "Someone is testing the alert notification within grafana.",
-		State:       m.AlertStateAlerting,
+		State:       models.AlertStateAlerting,
 	}
 	}
 
 
 	ctx := NewEvalContext(context.Background(), testRule)
 	ctx := NewEvalContext(context.Background(), testRule)

+ 3 - 3
pkg/services/alerting/test_rule.go

@@ -6,14 +6,14 @@ import (
 
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
-	m "github.com/grafana/grafana/pkg/models"
+	"github.com/grafana/grafana/pkg/models"
 )
 )
 
 
 type AlertTestCommand struct {
 type AlertTestCommand struct {
 	Dashboard *simplejson.Json
 	Dashboard *simplejson.Json
 	PanelId   int64
 	PanelId   int64
 	OrgId     int64
 	OrgId     int64
-	User      *m.SignedInUser
+	User      *models.SignedInUser
 
 
 	Result *EvalContext
 	Result *EvalContext
 }
 }
@@ -24,7 +24,7 @@ func init() {
 
 
 func handleAlertTestCommand(cmd *AlertTestCommand) error {
 func handleAlertTestCommand(cmd *AlertTestCommand) error {
 
 
-	dash := m.NewDashboardFromJson(cmd.Dashboard)
+	dash := models.NewDashboardFromJson(cmd.Dashboard)
 
 
 	extractor := NewDashAlertExtractor(dash, cmd.OrgId, cmd.User)
 	extractor := NewDashAlertExtractor(dash, cmd.OrgId, cmd.User)
 	alerts, err := extractor.GetAlerts()
 	alerts, err := extractor.GetAlerts()