diff --git a/pkg/services/ngalert/api/api_alertmanager.go b/pkg/services/ngalert/api/api_alertmanager.go index a0972987b3b..2bdcefc62a1 100644 --- a/pkg/services/ngalert/api/api_alertmanager.go +++ b/pkg/services/ngalert/api/api_alertmanager.go @@ -192,11 +192,14 @@ func (srv AlertmanagerSrv) RoutePostAlertingConfig(c *models.ReqContext, body ap } } - currentConfig, err := notifier.Load([]byte(query.Result.AlertmanagerConfiguration)) - if err != nil { - return ErrResp(http.StatusInternalServerError, err, "failed to load lastest configuration") + currentReceiverMap := make(map[string]*apimodels.PostableGrafanaReceiver) + if query.Result != nil { + currentConfig, err := notifier.Load([]byte(query.Result.AlertmanagerConfiguration)) + if err != nil { + return ErrResp(http.StatusInternalServerError, err, "failed to load lastest configuration") + } + currentReceiverMap = currentConfig.GetGrafanaReceiverMap() } - currentReceiverMap := currentConfig.GetGrafanaReceiverMap() // Copy the previously known secure settings for i, r := range body.AlertmanagerConfig.Receivers { diff --git a/pkg/services/ngalert/models/alertmanager.go b/pkg/services/ngalert/models/alertmanager.go index 6861e84eeae..048b473aacf 100644 --- a/pkg/services/ngalert/models/alertmanager.go +++ b/pkg/services/ngalert/models/alertmanager.go @@ -1,7 +1,5 @@ package models -import "time" - const AlertConfigurationVersion = 1 // AlertConfiguration represents a single version of the Alerting Engine Configuration. @@ -10,7 +8,7 @@ type AlertConfiguration struct { AlertmanagerConfiguration string ConfigurationVersion string - CreatedAt time.Time `xorm:"created"` + CreatedAt int64 `xorm:"created"` Default bool } diff --git a/pkg/services/sqlstore/migrations/ualert/dash_alert.go b/pkg/services/sqlstore/migrations/ualert/dash_alert.go index c0d511f18b5..36158a1840a 100644 --- a/pkg/services/sqlstore/migrations/ualert/dash_alert.go +++ b/pkg/services/sqlstore/migrations/ualert/dash_alert.go @@ -2,6 +2,7 @@ package ualert import ( "encoding/json" + "fmt" "time" ) @@ -30,7 +31,7 @@ SELECT id, name, message, frequency, - for, + %s, state, settings FROM @@ -43,7 +44,7 @@ FROM // ParsedSettings property of the dash alert. func (m *migration) slurpDashAlerts() ([]dashAlert, error) { dashAlerts := []dashAlert{} - err := m.sess.SQL(slurpDashSQL).Find(&dashAlerts) + err := m.sess.SQL(fmt.Sprintf(slurpDashSQL, m.mg.Dialect.Quote("for"))).Find(&dashAlerts) if err != nil { return nil, err diff --git a/pkg/services/sqlstore/migrations/ualert/ualert.go b/pkg/services/sqlstore/migrations/ualert/ualert.go index 78800bbcac4..697b177ea0e 100644 --- a/pkg/services/sqlstore/migrations/ualert/ualert.go +++ b/pkg/services/sqlstore/migrations/ualert/ualert.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "os" - "time" pb "github.com/prometheus/alertmanager/silence/silencepb" "xorm.io/xorm" @@ -288,7 +287,7 @@ type AlertConfiguration struct { AlertmanagerConfiguration string ConfigurationVersion string - CreatedAt time.Time `xorm:"created"` + CreatedAt int64 `xorm:"created"` } type rmMigration struct {