mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Update receivers to use app version from factory config (#60585)
This commit is contained in:
parent
4df78cebc2
commit
a0bf62cc9e
@ -18,16 +18,16 @@ import (
|
|||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type DiscordNotifier struct {
|
type DiscordNotifier struct {
|
||||||
*channels.Base
|
*channels.Base
|
||||||
log channels.Logger
|
log channels.Logger
|
||||||
ns channels.WebhookSender
|
ns channels.WebhookSender
|
||||||
images channels.ImageStore
|
images channels.ImageStore
|
||||||
tmpl *template.Template
|
tmpl *template.Template
|
||||||
settings *discordSettings
|
settings *discordSettings
|
||||||
|
appVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
type discordSettings struct {
|
type discordSettings struct {
|
||||||
@ -83,12 +83,13 @@ func newDiscordNotifier(fc channels.FactoryConfig) (*DiscordNotifier, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &DiscordNotifier{
|
return &DiscordNotifier{
|
||||||
Base: channels.NewBase(fc.Config),
|
Base: channels.NewBase(fc.Config),
|
||||||
log: fc.Logger,
|
log: fc.Logger,
|
||||||
ns: fc.NotificationService,
|
ns: fc.NotificationService,
|
||||||
images: fc.ImageStore,
|
images: fc.ImageStore,
|
||||||
tmpl: fc.Template,
|
tmpl: fc.Template,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
appVersion: fc.GrafanaBuildVersion,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +122,7 @@ func (d DiscordNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
footer := map[string]interface{}{
|
footer := map[string]interface{}{
|
||||||
"text": "Grafana v" + setting.BuildVersion,
|
"text": "Grafana v" + d.appVersion,
|
||||||
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ package channels
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -11,8 +13,6 @@ import (
|
|||||||
"github.com/prometheus/alertmanager/types"
|
"github.com/prometheus/alertmanager/types"
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDiscordNotifier(t *testing.T) {
|
func TestDiscordNotifier(t *testing.T) {
|
||||||
@ -21,7 +21,7 @@ func TestDiscordNotifier(t *testing.T) {
|
|||||||
externalURL, err := url.Parse("http://localhost")
|
externalURL, err := url.Parse("http://localhost")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tmpl.ExternalURL = externalURL
|
tmpl.ExternalURL = externalURL
|
||||||
|
appVersion := fmt.Sprintf("%d.0.0", rand.Uint32())
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
settings string
|
settings string
|
||||||
@ -47,7 +47,7 @@ func TestDiscordNotifier(t *testing.T) {
|
|||||||
"color": 1.4037554e+07,
|
"color": 1.4037554e+07,
|
||||||
"footer": map[string]interface{}{
|
"footer": map[string]interface{}{
|
||||||
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
||||||
"text": "Grafana v" + setting.BuildVersion,
|
"text": "Grafana v" + appVersion,
|
||||||
},
|
},
|
||||||
"title": "[FIRING:1] (val1)",
|
"title": "[FIRING:1] (val1)",
|
||||||
"url": "http://localhost/alerting/list",
|
"url": "http://localhost/alerting/list",
|
||||||
@ -74,7 +74,7 @@ func TestDiscordNotifier(t *testing.T) {
|
|||||||
"color": 1.4037554e+07,
|
"color": 1.4037554e+07,
|
||||||
"footer": map[string]interface{}{
|
"footer": map[string]interface{}{
|
||||||
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
||||||
"text": "Grafana v" + setting.BuildVersion,
|
"text": "Grafana v" + appVersion,
|
||||||
},
|
},
|
||||||
"title": "Alerts firing: 1",
|
"title": "Alerts firing: 1",
|
||||||
"url": "http://localhost/alerting/list",
|
"url": "http://localhost/alerting/list",
|
||||||
@ -106,7 +106,7 @@ func TestDiscordNotifier(t *testing.T) {
|
|||||||
"color": 1.4037554e+07,
|
"color": 1.4037554e+07,
|
||||||
"footer": map[string]interface{}{
|
"footer": map[string]interface{}{
|
||||||
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
||||||
"text": "Grafana v" + setting.BuildVersion,
|
"text": "Grafana v" + appVersion,
|
||||||
},
|
},
|
||||||
"title": "[FIRING:1] (val1)",
|
"title": "[FIRING:1] (val1)",
|
||||||
"url": "http://localhost/alerting/list",
|
"url": "http://localhost/alerting/list",
|
||||||
@ -138,7 +138,7 @@ func TestDiscordNotifier(t *testing.T) {
|
|||||||
"color": 1.4037554e+07,
|
"color": 1.4037554e+07,
|
||||||
"footer": map[string]interface{}{
|
"footer": map[string]interface{}{
|
||||||
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
||||||
"text": "Grafana v" + setting.BuildVersion,
|
"text": "Grafana v" + appVersion,
|
||||||
},
|
},
|
||||||
"title": "[FIRING:1] (val1)",
|
"title": "[FIRING:1] (val1)",
|
||||||
"url": "http://localhost/alerting/list",
|
"url": "http://localhost/alerting/list",
|
||||||
@ -170,7 +170,7 @@ func TestDiscordNotifier(t *testing.T) {
|
|||||||
"color": 1.4037554e+07,
|
"color": 1.4037554e+07,
|
||||||
"footer": map[string]interface{}{
|
"footer": map[string]interface{}{
|
||||||
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
||||||
"text": "Grafana v" + setting.BuildVersion,
|
"text": "Grafana v" + appVersion,
|
||||||
},
|
},
|
||||||
"title": "[FIRING:1] (val1)",
|
"title": "[FIRING:1] (val1)",
|
||||||
"url": "http://localhost/alerting/list",
|
"url": "http://localhost/alerting/list",
|
||||||
@ -202,7 +202,7 @@ func TestDiscordNotifier(t *testing.T) {
|
|||||||
"color": 1.4037554e+07,
|
"color": 1.4037554e+07,
|
||||||
"footer": map[string]interface{}{
|
"footer": map[string]interface{}{
|
||||||
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
||||||
"text": "Grafana v" + setting.BuildVersion,
|
"text": "Grafana v" + appVersion,
|
||||||
},
|
},
|
||||||
"title": "[FIRING:1] (val1)",
|
"title": "[FIRING:1] (val1)",
|
||||||
"url": "http://localhost/alerting/list",
|
"url": "http://localhost/alerting/list",
|
||||||
@ -239,7 +239,7 @@ func TestDiscordNotifier(t *testing.T) {
|
|||||||
"color": 1.4037554e+07,
|
"color": 1.4037554e+07,
|
||||||
"footer": map[string]interface{}{
|
"footer": map[string]interface{}{
|
||||||
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
||||||
"text": "Grafana v" + setting.BuildVersion,
|
"text": "Grafana v" + appVersion,
|
||||||
},
|
},
|
||||||
"title": "[FIRING:2] ",
|
"title": "[FIRING:2] ",
|
||||||
"url": "http://localhost/alerting/list",
|
"url": "http://localhost/alerting/list",
|
||||||
@ -274,7 +274,7 @@ func TestDiscordNotifier(t *testing.T) {
|
|||||||
"color": 1.4037554e+07,
|
"color": 1.4037554e+07,
|
||||||
"footer": map[string]interface{}{
|
"footer": map[string]interface{}{
|
||||||
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
"icon_url": "https://grafana.com/static/assets/img/fav32.png",
|
||||||
"text": "Grafana v" + setting.BuildVersion,
|
"text": "Grafana v" + appVersion,
|
||||||
},
|
},
|
||||||
"title": "[FIRING:1] (val1)",
|
"title": "[FIRING:1] (val1)",
|
||||||
"url": "http://localhost/alerting/list",
|
"url": "http://localhost/alerting/list",
|
||||||
@ -301,6 +301,7 @@ func TestDiscordNotifier(t *testing.T) {
|
|||||||
NotificationService: webhookSender,
|
NotificationService: webhookSender,
|
||||||
Template: tmpl,
|
Template: tmpl,
|
||||||
Logger: &channels.FakeLogger{},
|
Logger: &channels.FakeLogger{},
|
||||||
|
GrafanaBuildVersion: appVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
dn, err := newDiscordNotifier(fc)
|
dn, err := newDiscordNotifier(fc)
|
||||||
|
@ -11,19 +11,18 @@ import (
|
|||||||
"github.com/grafana/alerting/alerting/notifier/channels"
|
"github.com/grafana/alerting/alerting/notifier/channels"
|
||||||
"github.com/prometheus/alertmanager/template"
|
"github.com/prometheus/alertmanager/template"
|
||||||
"github.com/prometheus/alertmanager/types"
|
"github.com/prometheus/alertmanager/types"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GoogleChatNotifier is responsible for sending
|
// GoogleChatNotifier is responsible for sending
|
||||||
// alert notifications to Google chat.
|
// alert notifications to Google chat.
|
||||||
type GoogleChatNotifier struct {
|
type GoogleChatNotifier struct {
|
||||||
*channels.Base
|
*channels.Base
|
||||||
log channels.Logger
|
log channels.Logger
|
||||||
ns channels.WebhookSender
|
ns channels.WebhookSender
|
||||||
images channels.ImageStore
|
images channels.ImageStore
|
||||||
tmpl *template.Template
|
tmpl *template.Template
|
||||||
settings *googleChatSettings
|
settings *googleChatSettings
|
||||||
|
appVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
type googleChatSettings struct {
|
type googleChatSettings struct {
|
||||||
@ -68,12 +67,13 @@ func newGoogleChatNotifier(fc channels.FactoryConfig) (*GoogleChatNotifier, erro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &GoogleChatNotifier{
|
return &GoogleChatNotifier{
|
||||||
Base: channels.NewBase(fc.Config),
|
Base: channels.NewBase(fc.Config),
|
||||||
log: fc.Logger,
|
log: fc.Logger,
|
||||||
ns: fc.NotificationService,
|
ns: fc.NotificationService,
|
||||||
images: fc.ImageStore,
|
images: fc.ImageStore,
|
||||||
tmpl: fc.Template,
|
tmpl: fc.Template,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
appVersion: fc.GrafanaBuildVersion,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ func (gcn *GoogleChatNotifier) Notify(ctx context.Context, as ...*types.Alert) (
|
|||||||
// Add text paragraph widget for the build version and timestamp.
|
// Add text paragraph widget for the build version and timestamp.
|
||||||
widgets = append(widgets, textParagraphWidget{
|
widgets = append(widgets, textParagraphWidget{
|
||||||
Text: text{
|
Text: text{
|
||||||
Text: "Grafana v" + setting.BuildVersion + " | " + (timeNow()).Format(time.RFC822),
|
Text: "Grafana v" + gcn.appVersion + " | " + (timeNow()).Format(time.RFC822),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ package channels
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -13,13 +15,12 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/grafana/alerting/alerting/notifier/channels"
|
"github.com/grafana/alerting/alerting/notifier/channels"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGoogleChatNotifier(t *testing.T) {
|
func TestGoogleChatNotifier(t *testing.T) {
|
||||||
constNow := time.Now()
|
constNow := time.Now()
|
||||||
defer mockTimeNow(constNow)()
|
defer mockTimeNow(constNow)()
|
||||||
|
appVersion := fmt.Sprintf("%d.0.0", rand.Uint32())
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
@ -75,7 +76,7 @@ func TestGoogleChatNotifier(t *testing.T) {
|
|||||||
textParagraphWidget{
|
textParagraphWidget{
|
||||||
Text: text{
|
Text: text{
|
||||||
// RFC822 only has the minute, hence it works in most cases.
|
// RFC822 only has the minute, hence it works in most cases.
|
||||||
Text: "Grafana v" + setting.BuildVersion + " | " + constNow.Format(time.RFC822),
|
Text: "Grafana v" + appVersion + " | " + constNow.Format(time.RFC822),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -134,7 +135,7 @@ func TestGoogleChatNotifier(t *testing.T) {
|
|||||||
},
|
},
|
||||||
textParagraphWidget{
|
textParagraphWidget{
|
||||||
Text: text{
|
Text: text{
|
||||||
Text: "Grafana v" + setting.BuildVersion + " | " + constNow.Format(time.RFC822),
|
Text: "Grafana v" + appVersion + " | " + constNow.Format(time.RFC822),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -194,7 +195,7 @@ func TestGoogleChatNotifier(t *testing.T) {
|
|||||||
textParagraphWidget{
|
textParagraphWidget{
|
||||||
Text: text{
|
Text: text{
|
||||||
// RFC822 only has the minute, hence it works in most cases.
|
// RFC822 only has the minute, hence it works in most cases.
|
||||||
Text: "Grafana v" + setting.BuildVersion + " | " + constNow.Format(time.RFC822),
|
Text: "Grafana v" + appVersion + " | " + constNow.Format(time.RFC822),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -249,7 +250,7 @@ func TestGoogleChatNotifier(t *testing.T) {
|
|||||||
textParagraphWidget{
|
textParagraphWidget{
|
||||||
Text: text{
|
Text: text{
|
||||||
// RFC822 only has the minute, hence it works in most cases.
|
// RFC822 only has the minute, hence it works in most cases.
|
||||||
Text: "Grafana v" + setting.BuildVersion + " | " + constNow.Format(time.RFC822),
|
Text: "Grafana v" + appVersion + " | " + constNow.Format(time.RFC822),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -304,7 +305,7 @@ func TestGoogleChatNotifier(t *testing.T) {
|
|||||||
textParagraphWidget{
|
textParagraphWidget{
|
||||||
Text: text{
|
Text: text{
|
||||||
// RFC822 only has the minute, hence it works in most cases.
|
// RFC822 only has the minute, hence it works in most cases.
|
||||||
Text: "Grafana v" + setting.BuildVersion + " | " + constNow.Format(time.RFC822),
|
Text: "Grafana v" + appVersion + " | " + constNow.Format(time.RFC822),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -354,7 +355,7 @@ func TestGoogleChatNotifier(t *testing.T) {
|
|||||||
textParagraphWidget{
|
textParagraphWidget{
|
||||||
Text: text{
|
Text: text{
|
||||||
// RFC822 only has the minute, hence it works in most cases.
|
// RFC822 only has the minute, hence it works in most cases.
|
||||||
Text: "Grafana v" + setting.BuildVersion + " | " + constNow.Format(time.RFC822),
|
Text: "Grafana v" + appVersion + " | " + constNow.Format(time.RFC822),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -399,7 +400,7 @@ func TestGoogleChatNotifier(t *testing.T) {
|
|||||||
textParagraphWidget{
|
textParagraphWidget{
|
||||||
Text: text{
|
Text: text{
|
||||||
// RFC822 only has the minute, hence it works in most cases.
|
// RFC822 only has the minute, hence it works in most cases.
|
||||||
Text: "Grafana v" + setting.BuildVersion + " | " + constNow.Format(time.RFC822),
|
Text: "Grafana v" + appVersion + " | " + constNow.Format(time.RFC822),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -443,7 +444,7 @@ func TestGoogleChatNotifier(t *testing.T) {
|
|||||||
textParagraphWidget{
|
textParagraphWidget{
|
||||||
Text: text{
|
Text: text{
|
||||||
// RFC822 only has the minute, hence it works in most cases.
|
// RFC822 only has the minute, hence it works in most cases.
|
||||||
Text: "Grafana v" + setting.BuildVersion + " | " + constNow.Format(time.RFC822),
|
Text: "Grafana v" + appVersion + " | " + constNow.Format(time.RFC822),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -476,6 +477,7 @@ func TestGoogleChatNotifier(t *testing.T) {
|
|||||||
NotificationService: webhookSender,
|
NotificationService: webhookSender,
|
||||||
Template: tmpl,
|
Template: tmpl,
|
||||||
Logger: &channels.FakeLogger{},
|
Logger: &channels.FakeLogger{},
|
||||||
|
GrafanaBuildVersion: appVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
pn, err := newGoogleChatNotifier(fc)
|
pn, err := newGoogleChatNotifier(fc)
|
||||||
|
@ -23,8 +23,6 @@ import (
|
|||||||
"github.com/prometheus/alertmanager/types"
|
"github.com/prometheus/alertmanager/types"
|
||||||
|
|
||||||
"github.com/grafana/alerting/alerting/notifier/channels"
|
"github.com/grafana/alerting/alerting/notifier/channels"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -68,6 +66,7 @@ type SlackNotifier struct {
|
|||||||
webhookSender channels.WebhookSender
|
webhookSender channels.WebhookSender
|
||||||
sendFn sendFunc
|
sendFn sendFunc
|
||||||
settings slackSettings
|
settings slackSettings
|
||||||
|
appVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
type slackSettings struct {
|
type slackSettings struct {
|
||||||
@ -164,6 +163,7 @@ func buildSlackNotifier(factoryConfig channels.FactoryConfig) (*SlackNotifier, e
|
|||||||
sendFn: sendSlackRequest,
|
sendFn: sendSlackRequest,
|
||||||
log: factoryConfig.Logger,
|
log: factoryConfig.Logger,
|
||||||
tmpl: factoryConfig.Template,
|
tmpl: factoryConfig.Template,
|
||||||
|
appVersion: factoryConfig.GrafanaBuildVersion,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,7 +374,7 @@ func (sn *SlackNotifier) createSlackMessage(ctx context.Context, alerts []*types
|
|||||||
Color: getAlertStatusColor(types.Alerts(alerts...).Status()),
|
Color: getAlertStatusColor(types.Alerts(alerts...).Status()),
|
||||||
Title: title,
|
Title: title,
|
||||||
Fallback: title,
|
Fallback: title,
|
||||||
Footer: "Grafana v" + setting.BuildVersion,
|
Footer: "Grafana v" + sn.appVersion,
|
||||||
FooterIcon: channels.FooterIconURL,
|
FooterIcon: channels.FooterIconURL,
|
||||||
Ts: time.Now().Unix(),
|
Ts: time.Now().Unix(),
|
||||||
TitleLink: ruleURL,
|
TitleLink: ruleURL,
|
||||||
|
@ -4,7 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math/rand"
|
||||||
"mime"
|
"mime"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -20,10 +22,10 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/grafana/alerting/alerting/notifier/channels"
|
"github.com/grafana/alerting/alerting/notifier/channels"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var appVersion = fmt.Sprintf("%d.0.0", rand.Uint32())
|
||||||
|
|
||||||
func TestSlackIncomingWebhook(t *testing.T) {
|
func TestSlackIncomingWebhook(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -55,7 +57,7 @@ func TestSlackIncomingWebhook(t *testing.T) {
|
|||||||
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\n",
|
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\n",
|
||||||
Fallback: "[FIRING:1] (val1)",
|
Fallback: "[FIRING:1] (val1)",
|
||||||
Fields: nil,
|
Fields: nil,
|
||||||
Footer: "Grafana v" + setting.BuildVersion,
|
Footer: "Grafana v" + appVersion,
|
||||||
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
||||||
Color: "#D63232",
|
Color: "#D63232",
|
||||||
},
|
},
|
||||||
@ -85,7 +87,7 @@ func TestSlackIncomingWebhook(t *testing.T) {
|
|||||||
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
|
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
|
||||||
Fallback: "[FIRING:1] (val1)",
|
Fallback: "[FIRING:1] (val1)",
|
||||||
Fields: nil,
|
Fields: nil,
|
||||||
Footer: "Grafana v" + setting.BuildVersion,
|
Footer: "Grafana v" + appVersion,
|
||||||
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
||||||
Color: "#D63232",
|
Color: "#D63232",
|
||||||
ImageURL: "https://www.example.com/test.png",
|
ImageURL: "https://www.example.com/test.png",
|
||||||
@ -116,7 +118,7 @@ func TestSlackIncomingWebhook(t *testing.T) {
|
|||||||
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
|
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
|
||||||
Fallback: "[FIRING:1] (val1)",
|
Fallback: "[FIRING:1] (val1)",
|
||||||
Fields: nil,
|
Fields: nil,
|
||||||
Footer: "Grafana v" + setting.BuildVersion,
|
Footer: "Grafana v" + appVersion,
|
||||||
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
||||||
Color: "#D63232",
|
Color: "#D63232",
|
||||||
},
|
},
|
||||||
@ -198,7 +200,7 @@ func TestSlackPostMessage(t *testing.T) {
|
|||||||
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
|
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
|
||||||
Fallback: "[FIRING:1] (val1)",
|
Fallback: "[FIRING:1] (val1)",
|
||||||
Fields: nil,
|
Fields: nil,
|
||||||
Footer: "Grafana v" + setting.BuildVersion,
|
Footer: "Grafana v" + appVersion,
|
||||||
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
||||||
Color: "#D63232",
|
Color: "#D63232",
|
||||||
},
|
},
|
||||||
@ -234,7 +236,7 @@ func TestSlackPostMessage(t *testing.T) {
|
|||||||
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val2\nAnnotations:\n - ann1 = annv2\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval2\n",
|
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val2\nAnnotations:\n - ann1 = annv2\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval2\n",
|
||||||
Fallback: "2 firing, 0 resolved",
|
Fallback: "2 firing, 0 resolved",
|
||||||
Fields: nil,
|
Fields: nil,
|
||||||
Footer: "Grafana v" + setting.BuildVersion,
|
Footer: "Grafana v" + appVersion,
|
||||||
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
||||||
Color: "#D63232",
|
Color: "#D63232",
|
||||||
},
|
},
|
||||||
@ -264,7 +266,7 @@ func TestSlackPostMessage(t *testing.T) {
|
|||||||
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
|
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
|
||||||
Fallback: "[FIRING:1] (val1)",
|
Fallback: "[FIRING:1] (val1)",
|
||||||
Fields: nil,
|
Fields: nil,
|
||||||
Footer: "Grafana v" + setting.BuildVersion,
|
Footer: "Grafana v" + appVersion,
|
||||||
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
||||||
Color: "#D63232",
|
Color: "#D63232",
|
||||||
},
|
},
|
||||||
@ -304,7 +306,7 @@ func TestSlackPostMessage(t *testing.T) {
|
|||||||
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\n",
|
Text: "**Firing**\n\nValue: [no value]\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matcher=alertname%3Dalert1&matcher=lbl1%3Dval1\n",
|
||||||
Fallback: "[FIRING:1] (val1)",
|
Fallback: "[FIRING:1] (val1)",
|
||||||
Fields: nil,
|
Fields: nil,
|
||||||
Footer: "Grafana v" + setting.BuildVersion,
|
Footer: "Grafana v" + appVersion,
|
||||||
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
FooterIcon: "https://grafana.com/static/assets/img/fav32.png",
|
||||||
Color: "#D63232",
|
Color: "#D63232",
|
||||||
},
|
},
|
||||||
@ -435,8 +437,9 @@ func setupSlackForTests(t *testing.T, settings string) (*SlackNotifier, *slackRe
|
|||||||
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
|
DecryptFunc: func(ctx context.Context, sjd map[string][]byte, key string, fallback string) string {
|
||||||
return fallback
|
return fallback
|
||||||
},
|
},
|
||||||
Template: tmpl,
|
Template: tmpl,
|
||||||
Logger: &channels.FakeLogger{},
|
Logger: &channels.FakeLogger{},
|
||||||
|
GrafanaBuildVersion: appVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
sn, err := buildSlackNotifier(c)
|
sn, err := buildSlackNotifier(c)
|
||||||
|
Loading…
Reference in New Issue
Block a user