mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
Alerting: Remove reference to global models package in channels package (#60358)
* remove intermediate struct to create Base struct * fix alertmanager
This commit is contained in:
parent
342b0f3668
commit
0e7c95a4d2
@ -13,7 +13,6 @@ import (
|
||||
"github.com/prometheus/common/model"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
// GetDecryptedValueFn is a function that returns the decrypted value of
|
||||
@ -70,12 +69,7 @@ func AlertmanagerFactory(fc FactoryConfig) (NotificationChannel, error) {
|
||||
// NewAlertmanagerNotifier returns a new Alertmanager notifier.
|
||||
func NewAlertmanagerNotifier(config *AlertmanagerConfig, images ImageStore, _ *template.Template, fn GetDecryptedValueFn) *AlertmanagerNotifier {
|
||||
return &AlertmanagerNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: config.UID,
|
||||
Name: config.Name,
|
||||
DisableResolveMessage: config.DisableResolveMessage,
|
||||
Settings: config.Settings,
|
||||
}),
|
||||
Base: NewBase(config.NotificationChannelConfig),
|
||||
images: images,
|
||||
urls: config.URLs,
|
||||
basicAuthUser: config.BasicAuthUser,
|
||||
|
@ -1,32 +1,22 @@
|
||||
package channels
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
// Base is the base implementation of a notifier. It contains the common fields across all notifier types.
|
||||
type Base struct {
|
||||
Name string
|
||||
Type string
|
||||
UID string
|
||||
IsDefault bool
|
||||
DisableResolveMessage bool
|
||||
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func (n *Base) GetDisableResolveMessage() bool {
|
||||
return n.DisableResolveMessage
|
||||
}
|
||||
|
||||
func NewBase(model *models.AlertNotification) *Base {
|
||||
func NewBase(cfg *NotificationChannelConfig) *Base {
|
||||
return &Base{
|
||||
UID: model.Uid,
|
||||
Name: model.Name,
|
||||
IsDefault: model.IsDefault,
|
||||
Type: model.Type,
|
||||
DisableResolveMessage: model.DisableResolveMessage,
|
||||
log: log.New("alerting.notifier." + model.Name),
|
||||
UID: cfg.UID,
|
||||
Name: cfg.Name,
|
||||
Type: cfg.Type,
|
||||
DisableResolveMessage: cfg.DisableResolveMessage,
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"github.com/prometheus/alertmanager/types"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
const defaultDingdingMsgType = "link"
|
||||
@ -54,13 +53,7 @@ func newDingDingNotifier(fc FactoryConfig) (*DingDingNotifier, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &DingDingNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: fc.Config.UID,
|
||||
Name: fc.Config.Name,
|
||||
Type: fc.Config.Type,
|
||||
DisableResolveMessage: fc.Config.DisableResolveMessage,
|
||||
Settings: fc.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(fc.Config),
|
||||
log: log.New("alerting.notifier.dingding"),
|
||||
ns: fc.NotificationService,
|
||||
tmpl: fc.Template,
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
@ -67,14 +66,7 @@ func newDiscordNotifier(fc FactoryConfig) (*DiscordNotifier, error) {
|
||||
}
|
||||
|
||||
return &DiscordNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: fc.Config.UID,
|
||||
Name: fc.Config.Name,
|
||||
Type: fc.Config.Type,
|
||||
DisableResolveMessage: fc.Config.DisableResolveMessage,
|
||||
Settings: fc.Config.Settings,
|
||||
SecureSettings: fc.Config.SecureSettings,
|
||||
}),
|
||||
Base: NewBase(fc.Config),
|
||||
log: log.New("alerting.notifier.discord"),
|
||||
ns: fc.NotificationService,
|
||||
images: fc.ImageStore,
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"github.com/prometheus/alertmanager/types"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
@ -69,13 +68,7 @@ func NewEmailConfig(config *NotificationChannelConfig) (*EmailConfig, error) {
|
||||
// for the EmailNotifier.
|
||||
func NewEmailNotifier(config *EmailConfig, ns EmailSender, images ImageStore, t *template.Template) *EmailNotifier {
|
||||
return &EmailNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: config.UID,
|
||||
Name: config.Name,
|
||||
Type: config.Type,
|
||||
DisableResolveMessage: config.DisableResolveMessage,
|
||||
Settings: config.Settings,
|
||||
}),
|
||||
Base: NewBase(config.NotificationChannelConfig),
|
||||
Addresses: config.Addresses,
|
||||
SingleEmail: config.SingleEmail,
|
||||
Message: config.Message,
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"github.com/prometheus/alertmanager/types"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
@ -57,13 +56,7 @@ func newGoogleChatNotifier(fc FactoryConfig) (*GoogleChatNotifier, error) {
|
||||
}
|
||||
|
||||
return &GoogleChatNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: fc.Config.UID,
|
||||
Name: fc.Config.Name,
|
||||
Type: fc.Config.Type,
|
||||
DisableResolveMessage: fc.Config.DisableResolveMessage,
|
||||
Settings: fc.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(fc.Config),
|
||||
log: log.New("alerting.notifier.googlechat"),
|
||||
ns: fc.NotificationService,
|
||||
images: fc.ImageStore,
|
||||
|
@ -58,13 +58,7 @@ func newKafkaNotifier(fc FactoryConfig) (*KafkaNotifier, error) {
|
||||
details := fc.Config.Settings.Get("details").MustString(DefaultMessageEmbed)
|
||||
|
||||
return &KafkaNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: fc.Config.UID,
|
||||
Name: fc.Config.Name,
|
||||
Type: fc.Config.Type,
|
||||
DisableResolveMessage: fc.Config.DisableResolveMessage,
|
||||
Settings: fc.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(fc.Config),
|
||||
log: log.New("alerting.notifier.kafka"),
|
||||
images: fc.ImageStore,
|
||||
ns: fc.NotificationService,
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"github.com/prometheus/alertmanager/types"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -55,13 +54,7 @@ func newLineNotifier(fc FactoryConfig) (*LineNotifier, error) {
|
||||
description := fc.Config.Settings.Get("description").MustString(DefaultMessageEmbed)
|
||||
|
||||
return &LineNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: fc.Config.UID,
|
||||
Name: fc.Config.Name,
|
||||
Type: fc.Config.Type,
|
||||
DisableResolveMessage: fc.Config.DisableResolveMessage,
|
||||
Settings: fc.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(fc.Config),
|
||||
log: log.New("alerting.notifier.line"),
|
||||
ns: fc.NotificationService,
|
||||
tmpl: fc.Template,
|
||||
|
@ -16,7 +16,6 @@ import (
|
||||
ptr "github.com/xorcare/pointer"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -125,13 +124,7 @@ func NewOpsgenieNotifier(fc FactoryConfig) (*OpsgenieNotifier, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &OpsgenieNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: fc.Config.UID,
|
||||
Name: fc.Config.Name,
|
||||
Type: fc.Config.Type,
|
||||
DisableResolveMessage: fc.Config.DisableResolveMessage,
|
||||
Settings: fc.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(fc.Config),
|
||||
tmpl: fc.Template,
|
||||
log: log.New("alerting.notifier.opsgenie"),
|
||||
ns: fc.NotificationService,
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"github.com/prometheus/common/model"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -130,13 +129,7 @@ func newPagerdutyNotifier(fc FactoryConfig) (*PagerdutyNotifier, error) {
|
||||
}
|
||||
|
||||
return &PagerdutyNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: fc.Config.UID,
|
||||
Name: fc.Config.Name,
|
||||
Type: fc.Config.Type,
|
||||
DisableResolveMessage: fc.Config.DisableResolveMessage,
|
||||
Settings: fc.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(fc.Config),
|
||||
tmpl: fc.Template,
|
||||
log: log.New("alerting.notifier." + fc.Config.Name),
|
||||
ns: fc.NotificationService,
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
"github.com/prometheus/common/model"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -147,14 +146,7 @@ func NewPushoverNotifier(fc FactoryConfig) (*PushoverNotifier, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &PushoverNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: fc.Config.UID,
|
||||
Name: fc.Config.Name,
|
||||
Type: fc.Config.Type,
|
||||
DisableResolveMessage: fc.Config.DisableResolveMessage,
|
||||
Settings: fc.Config.Settings,
|
||||
SecureSettings: fc.Config.SecureSettings,
|
||||
}),
|
||||
Base: NewBase(fc.Config),
|
||||
tmpl: fc.Template,
|
||||
log: log.New("alerting.notifier.pushover"),
|
||||
images: fc.ImageStore,
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"github.com/prometheus/common/model"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
type SensuGoNotifier struct {
|
||||
@ -71,14 +70,7 @@ func NewSensuGoNotifier(fc FactoryConfig) (*SensuGoNotifier, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &SensuGoNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: fc.Config.UID,
|
||||
Name: fc.Config.Name,
|
||||
Type: fc.Config.Type,
|
||||
DisableResolveMessage: fc.Config.DisableResolveMessage,
|
||||
Settings: fc.Config.Settings,
|
||||
SecureSettings: fc.Config.SecureSettings,
|
||||
}),
|
||||
Base: NewBase(fc.Config),
|
||||
log: log.New("alerting.notifier.sensugo"),
|
||||
images: fc.ImageStore,
|
||||
ns: fc.NotificationService,
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
"github.com/prometheus/alertmanager/types"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
@ -156,13 +155,7 @@ func buildSlackNotifier(factoryConfig FactoryConfig) (*SlackNotifier, error) {
|
||||
settings.Title = DefaultMessageTitleEmbed
|
||||
}
|
||||
return &SlackNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: factoryConfig.Config.UID,
|
||||
Name: factoryConfig.Config.Name,
|
||||
Type: factoryConfig.Config.Type,
|
||||
DisableResolveMessage: factoryConfig.Config.DisableResolveMessage,
|
||||
Settings: factoryConfig.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(factoryConfig.Config),
|
||||
settings: settings,
|
||||
|
||||
images: factoryConfig.ImageStore,
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"github.com/prometheus/common/model"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -263,13 +262,7 @@ func NewTeamsNotifier(fc FactoryConfig) (*TeamsNotifier, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &TeamsNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: fc.Config.UID,
|
||||
Name: fc.Config.Name,
|
||||
Type: fc.Config.Type,
|
||||
DisableResolveMessage: fc.Config.DisableResolveMessage,
|
||||
Settings: fc.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(fc.Config),
|
||||
log: log.New("alerting.notifier.teams"),
|
||||
ns: fc.NotificationService,
|
||||
images: fc.ImageStore,
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
"github.com/prometheus/alertmanager/types"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -101,13 +100,7 @@ func NewTelegramNotifier(fc FactoryConfig) (*TelegramNotifier, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &TelegramNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: fc.Config.UID,
|
||||
Name: fc.Config.Name,
|
||||
Type: fc.Config.Type,
|
||||
DisableResolveMessage: fc.Config.DisableResolveMessage,
|
||||
Settings: fc.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(fc.Config),
|
||||
tmpl: fc.Template,
|
||||
log: log.New("alerting.notifier.telegram"),
|
||||
images: fc.ImageStore,
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"github.com/prometheus/common/model"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -95,13 +94,7 @@ func NewThreemaNotifier(fc FactoryConfig) (*ThreemaNotifier, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &ThreemaNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: fc.Config.UID,
|
||||
Name: fc.Config.Name,
|
||||
Type: fc.Config.Type,
|
||||
DisableResolveMessage: fc.Config.DisableResolveMessage,
|
||||
Settings: fc.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(fc.Config),
|
||||
log: log.New("alerting.notifier.threema"),
|
||||
images: fc.ImageStore,
|
||||
ns: fc.NotificationService,
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"github.com/prometheus/common/model"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
@ -76,13 +75,7 @@ func NewVictoropsNotifier(fc FactoryConfig) (*VictoropsNotifier, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &VictoropsNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: fc.Config.UID,
|
||||
Name: fc.Config.Name,
|
||||
Type: fc.Config.Type,
|
||||
DisableResolveMessage: fc.Config.DisableResolveMessage,
|
||||
Settings: fc.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(fc.Config),
|
||||
log: log.New("alerting.notifier.victorops"),
|
||||
images: fc.ImageStore,
|
||||
ns: fc.NotificationService,
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"github.com/prometheus/alertmanager/types"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
const webexAPIURL = "https://webexapis.com/v1/messages"
|
||||
@ -84,13 +83,7 @@ func buildWebexNotifier(factoryConfig FactoryConfig) (*WebexNotifier, error) {
|
||||
logger := log.New("alerting.notifier.webex")
|
||||
|
||||
return &WebexNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: factoryConfig.Config.UID,
|
||||
Name: factoryConfig.Config.Name,
|
||||
Type: factoryConfig.Config.Type,
|
||||
DisableResolveMessage: factoryConfig.Config.DisableResolveMessage,
|
||||
Settings: factoryConfig.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(factoryConfig.Config),
|
||||
orgID: factoryConfig.Config.OrgID,
|
||||
log: logger,
|
||||
ns: factoryConfig.NotificationService,
|
||||
|
@ -116,13 +116,7 @@ func buildWebhookNotifier(factoryConfig FactoryConfig) (*WebhookNotifier, error)
|
||||
return nil, err
|
||||
}
|
||||
return &WebhookNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: factoryConfig.Config.UID,
|
||||
Name: factoryConfig.Config.Name,
|
||||
Type: factoryConfig.Config.Type,
|
||||
DisableResolveMessage: factoryConfig.Config.DisableResolveMessage,
|
||||
Settings: factoryConfig.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(factoryConfig.Config),
|
||||
orgID: factoryConfig.Config.OrgID,
|
||||
log: log.New("alerting.notifier.webhook"),
|
||||
ns: factoryConfig.NotificationService,
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"golang.org/x/sync/singleflight"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
var weComEndpoint = "https://qyapi.weixin.qq.com"
|
||||
@ -110,13 +109,7 @@ func buildWecomNotifier(factoryConfig FactoryConfig) (*WeComNotifier, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &WeComNotifier{
|
||||
Base: NewBase(&models.AlertNotification{
|
||||
Uid: factoryConfig.Config.UID,
|
||||
Name: factoryConfig.Config.Name,
|
||||
Type: factoryConfig.Config.Type,
|
||||
DisableResolveMessage: factoryConfig.Config.DisableResolveMessage,
|
||||
Settings: factoryConfig.Config.Settings,
|
||||
}),
|
||||
Base: NewBase(factoryConfig.Config),
|
||||
tmpl: factoryConfig.Template,
|
||||
log: log.New("alerting.notifier.wecom"),
|
||||
ns: factoryConfig.NotificationService,
|
||||
|
Loading…
Reference in New Issue
Block a user