mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix notification channel migration and handle case when Alertmanager default configuration is absent (#35086)
* Fix dashboard alert and nootifier migration for MySQL * Fix POSTing Alertmanager configuration if no current configuration exists in case the default configuration has not be stored yet or has failed to get stored * Change CreatedAt field type
This commit is contained in:
parent
c13f247a94
commit
15c55b0115
@ -192,11 +192,14 @@ func (srv AlertmanagerSrv) RoutePostAlertingConfig(c *models.ReqContext, body ap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentConfig, err := notifier.Load([]byte(query.Result.AlertmanagerConfiguration))
|
currentReceiverMap := make(map[string]*apimodels.PostableGrafanaReceiver)
|
||||||
if err != nil {
|
if query.Result != nil {
|
||||||
return ErrResp(http.StatusInternalServerError, err, "failed to load lastest configuration")
|
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
|
// Copy the previously known secure settings
|
||||||
for i, r := range body.AlertmanagerConfig.Receivers {
|
for i, r := range body.AlertmanagerConfig.Receivers {
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
const AlertConfigurationVersion = 1
|
const AlertConfigurationVersion = 1
|
||||||
|
|
||||||
// AlertConfiguration represents a single version of the Alerting Engine Configuration.
|
// AlertConfiguration represents a single version of the Alerting Engine Configuration.
|
||||||
@ -10,7 +8,7 @@ type AlertConfiguration struct {
|
|||||||
|
|
||||||
AlertmanagerConfiguration string
|
AlertmanagerConfiguration string
|
||||||
ConfigurationVersion string
|
ConfigurationVersion string
|
||||||
CreatedAt time.Time `xorm:"created"`
|
CreatedAt int64 `xorm:"created"`
|
||||||
Default bool
|
Default bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package ualert
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ SELECT id,
|
|||||||
name,
|
name,
|
||||||
message,
|
message,
|
||||||
frequency,
|
frequency,
|
||||||
for,
|
%s,
|
||||||
state,
|
state,
|
||||||
settings
|
settings
|
||||||
FROM
|
FROM
|
||||||
@ -43,7 +44,7 @@ FROM
|
|||||||
// ParsedSettings property of the dash alert.
|
// ParsedSettings property of the dash alert.
|
||||||
func (m *migration) slurpDashAlerts() ([]dashAlert, error) {
|
func (m *migration) slurpDashAlerts() ([]dashAlert, error) {
|
||||||
dashAlerts := []dashAlert{}
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
pb "github.com/prometheus/alertmanager/silence/silencepb"
|
pb "github.com/prometheus/alertmanager/silence/silencepb"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
@ -288,7 +287,7 @@ type AlertConfiguration struct {
|
|||||||
|
|
||||||
AlertmanagerConfiguration string
|
AlertmanagerConfiguration string
|
||||||
ConfigurationVersion string
|
ConfigurationVersion string
|
||||||
CreatedAt time.Time `xorm:"created"`
|
CreatedAt int64 `xorm:"created"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type rmMigration struct {
|
type rmMigration struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user