Skip to content

Commit

Permalink
Revert "Alerting: Add support for images in Line alerts (grafana#50703)…
Browse files Browse the repository at this point in the history
…" (grafana#52593)

This reverts commit 0af09b8.
  • Loading branch information
gotjosh authored Jul 21, 2022
1 parent 62a3f2e commit d762de7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 71 deletions.
37 changes: 10 additions & 27 deletions pkg/services/ngalert/notifier/channels/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
"github.com/grafana/grafana/pkg/services/notifications"
)

Expand All @@ -33,7 +32,7 @@ func LineFactory(fc FactoryConfig) (NotificationChannel, error) {
Cfg: *fc.Config,
}
}
return NewLineNotifier(cfg, fc.ImageStore, fc.NotificationService, fc.Template), nil
return NewLineNotifier(cfg, fc.NotificationService, fc.Template), nil
}

func NewLineConfig(config *NotificationChannelConfig, decryptFunc GetDecryptedValueFn) (*LineConfig, error) {
Expand All @@ -48,7 +47,7 @@ func NewLineConfig(config *NotificationChannelConfig, decryptFunc GetDecryptedVa
}

// NewLineNotifier is the constructor for the LINE notifier
func NewLineNotifier(config *LineConfig, images ImageStore, ns notifications.WebhookSender, t *template.Template) *LineNotifier {
func NewLineNotifier(config *LineConfig, ns notifications.WebhookSender, t *template.Template) *LineNotifier {
return &LineNotifier{
Base: NewBase(&models.AlertNotification{
Uid: config.UID,
Expand All @@ -57,23 +56,21 @@ func NewLineNotifier(config *LineConfig, images ImageStore, ns notifications.Web
DisableResolveMessage: config.DisableResolveMessage,
Settings: config.Settings,
}),
Token: config.Token,
log: log.New("alerting.notifier.line"),
images: images,
ns: ns,
tmpl: t,
Token: config.Token,
log: log.New("alerting.notifier.line"),
ns: ns,
tmpl: t,
}
}

// LineNotifier is responsible for sending
// alert notifications to LINE.
type LineNotifier struct {
*Base
Token string
log log.Logger
images ImageStore
ns notifications.WebhookSender
tmpl *template.Template
Token string
log log.Logger
ns notifications.WebhookSender
tmpl *template.Template
}

// Notify send an alert notification to LINE
Expand All @@ -98,20 +95,6 @@ func (ln *LineNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool, e
form := url.Values{}
form.Add("message", body)

_ = withStoredImages(ctx, ln.log, ln.images,
func(index int, image ngmodels.Image) error {
// If there is an image for this alert and the image has been uploaded
// to a public URL then add it to the request. We cannot add more than
// one image per request.
if image.URL != "" {
form.Add("imageThumbnail", image.URL)
form.Add("imageFullsize", image.URL)
return ErrImagesDone
}
return nil
},
as...)

cmd := &models.SendWebhookSync{
Url: LineNotifyURL,
HttpMethod: "POST",
Expand Down
46 changes: 2 additions & 44 deletions pkg/services/ngalert/notifier/channels/line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
func TestLineNotifier(t *testing.T) {
tmpl := templateForTests(t)

images := newFakeImageStore(2)

externalURL, err := url.Parse("http://localhost")
require.NoError(t, err)
tmpl.ExternalURL = externalURL
Expand All @@ -34,7 +32,7 @@ func TestLineNotifier(t *testing.T) {
expMsgError error
}{
{
name: "A single alert",
name: "One alert",
settings: `{"token": "sometoken"}`,
alerts: []*types.Alert{
{
Expand Down Expand Up @@ -72,46 +70,6 @@ func TestLineNotifier(t *testing.T) {
},
expMsg: "message=%5BFIRING%3A2%5D++%0Ahttp%3A%2Flocalhost%2Falerting%2Flist%0A%0A%2A%2AFiring%2A%2A%0A%0AValue%3A+%5Bno+value%5D%0ALabels%3A%0A+-+alertname+%3D+alert1%0A+-+lbl1+%3D+val1%0AAnnotations%3A%0A+-+ann1+%3D+annv1%0ASilence%3A+http%3A%2F%2Flocalhost%2Falerting%2Fsilence%2Fnew%3Falertmanager%3Dgrafana%26matcher%3Dalertname%253Dalert1%26matcher%3Dlbl1%253Dval1%0A%0AValue%3A+%5Bno+value%5D%0ALabels%3A%0A+-+alertname+%3D+alert1%0A+-+lbl1+%3D+val2%0AAnnotations%3A%0A+-+ann1+%3D+annv2%0ASilence%3A+http%3A%2F%2Flocalhost%2Falerting%2Fsilence%2Fnew%3Falertmanager%3Dgrafana%26matcher%3Dalertname%253Dalert1%26matcher%3Dlbl1%253Dval2%0A",
expMsgError: nil,
}, {
name: "A single alert with an image",
settings: `{"token": "sometoken"}`,
alerts: []*types.Alert{
{
Alert: model.Alert{
Labels: model.LabelSet{"alertname": "alert1", "lbl1": "val1"},
Annotations: model.LabelSet{"ann1": "annv1", "__dashboardUid__": "abcd", "__panelId__": "efgh", "__alertScreenshotToken__": "test-image-1"},
},
},
},
expHeaders: map[string]string{
"Authorization": "Bearer sometoken",
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
},
expMsg: "imageFullsize=https%3A%2F%2Fwww.example.com%2Ftest-image-1.jpg&imageThumbnail=https%3A%2F%2Fwww.example.com%2Ftest-image-1.jpg&message=%5BFIRING%3A1%5D++%28val1%29%0Ahttp%3A%2Flocalhost%2Falerting%2Flist%0A%0A%2A%2AFiring%2A%2A%0A%0AValue%3A+%5Bno+value%5D%0ALabels%3A%0A+-+alertname+%3D+alert1%0A+-+lbl1+%3D+val1%0AAnnotations%3A%0A+-+ann1+%3D+annv1%0ASilence%3A+http%3A%2F%2Flocalhost%2Falerting%2Fsilence%2Fnew%3Falertmanager%3Dgrafana%26matcher%3Dalertname%253Dalert1%26matcher%3Dlbl1%253Dval1%0ADashboard%3A+http%3A%2F%2Flocalhost%2Fd%2Fabcd%0APanel%3A+http%3A%2F%2Flocalhost%2Fd%2Fabcd%3FviewPanel%3Defgh%0A",
expMsgError: nil,
}, {
name: "Multiple alerts with an image",
settings: `{"token": "sometoken"}`,
alerts: []*types.Alert{
{
Alert: model.Alert{
Labels: model.LabelSet{"alertname": "alert1", "lbl1": "val1"},
Annotations: model.LabelSet{"ann1": "annv1", "__dashboardUid__": "abcd", "__panelId__": "efgh", "__alertScreenshotToken__": "test-image-1"},
},
},
{
Alert: model.Alert{
Labels: model.LabelSet{"alertname": "alert2", "lbl2": "val2"},
Annotations: model.LabelSet{"ann2": "annv2", "__dashboardUid__": "abcd", "__panelId__": "efgh", "__alertScreenshotToken__": "test-image-2"},
},
},
},
expHeaders: map[string]string{
"Authorization": "Bearer sometoken",
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
},
expMsg: "imageFullsize=https%3A%2F%2Fwww.example.com%2Ftest-image-1.jpg&imageThumbnail=https%3A%2F%2Fwww.example.com%2Ftest-image-1.jpg&message=%5BFIRING%3A2%5D++%0Ahttp%3A%2Flocalhost%2Falerting%2Flist%0A%0A%2A%2AFiring%2A%2A%0A%0AValue%3A+%5Bno+value%5D%0ALabels%3A%0A+-+alertname+%3D+alert1%0A+-+lbl1+%3D+val1%0AAnnotations%3A%0A+-+ann1+%3D+annv1%0ASilence%3A+http%3A%2F%2Flocalhost%2Falerting%2Fsilence%2Fnew%3Falertmanager%3Dgrafana%26matcher%3Dalertname%253Dalert1%26matcher%3Dlbl1%253Dval1%0ADashboard%3A+http%3A%2F%2Flocalhost%2Fd%2Fabcd%0APanel%3A+http%3A%2F%2Flocalhost%2Fd%2Fabcd%3FviewPanel%3Defgh%0A%0AValue%3A+%5Bno+value%5D%0ALabels%3A%0A+-+alertname+%3D+alert2%0A+-+lbl2+%3D+val2%0AAnnotations%3A%0A+-+ann2+%3D+annv2%0ASilence%3A+http%3A%2F%2Flocalhost%2Falerting%2Fsilence%2Fnew%3Falertmanager%3Dgrafana%26matcher%3Dalertname%253Dalert2%26matcher%3Dlbl2%253Dval2%0ADashboard%3A+http%3A%2F%2Flocalhost%2Fd%2Fabcd%0APanel%3A+http%3A%2F%2Flocalhost%2Fd%2Fabcd%3FviewPanel%3Defgh%0A",
expMsgError: nil,
}, {
name: "Token missing",
settings: `{}`,
Expand Down Expand Up @@ -145,7 +103,7 @@ func TestLineNotifier(t *testing.T) {

ctx := notify.WithGroupKey(context.Background(), "alertname")
ctx = notify.WithGroupLabels(ctx, model.LabelSet{"alertname": ""})
pn := NewLineNotifier(cfg, images, webhookSender, tmpl)
pn := NewLineNotifier(cfg, webhookSender, tmpl)
ok, err := pn.Notify(ctx, c.alerts...)
if c.expMsgError != nil {
require.False(t, ok)
Expand Down

0 comments on commit d762de7

Please sign in to comment.