alerting: images in alert notifications is now optional

its now possible to turn of image uploading in alert notifications
for those who operate on very sensitive data.

closes #7419
This commit is contained in:
bergquist
2017-02-13 12:43:12 +01:00
parent f14e25612e
commit bd010289b2
7 changed files with 70 additions and 56 deletions

View File

@@ -21,37 +21,25 @@ type NotifierPlugin struct {
Factory NotifierFactory `json:"-"`
}
type RootNotifier struct {
type NotificationService interface {
Send(context *EvalContext) error
}
func NewNotificationService() NotificationService {
return newNotificationService()
}
type notificationService struct {
log log.Logger
}
func NewRootNotifier() *RootNotifier {
return &RootNotifier{
func newNotificationService() *notificationService {
return &notificationService{
log: log.New("alerting.notifier"),
}
}
func (n *RootNotifier) GetType() string {
return "root"
}
func (n *RootNotifier) NeedsImage() bool {
return false
}
func (n *RootNotifier) PassesFilter(rule *Rule) bool {
return false
}
func (n *RootNotifier) GetNotifierId() int64 {
return 0
}
func (n *RootNotifier) GetIsDefault() bool {
return false
}
func (n *RootNotifier) Notify(context *EvalContext) error {
func (n *notificationService) Send(context *EvalContext) error {
notifiers, err := n.getNotifiers(context.Rule.OrgId, context.Rule.Notifications, context)
if err != nil {
return err
@@ -63,14 +51,16 @@ func (n *RootNotifier) Notify(context *EvalContext) error {
return nil
}
if err = n.uploadImage(context); err != nil {
n.log.Error("Failed to upload alert panel image.", "error", err)
if notifiers.ShouldUploadImage() {
if err = n.uploadImage(context); err != nil {
n.log.Error("Failed to upload alert panel image.", "error", err)
}
}
return n.sendNotifications(context, notifiers)
}
func (n *RootNotifier) sendNotifications(context *EvalContext, notifiers []Notifier) error {
func (n *notificationService) sendNotifications(context *EvalContext, notifiers []Notifier) error {
g, _ := errgroup.WithContext(context.Ctx)
for _, notifier := range notifiers {
@@ -82,7 +72,7 @@ func (n *RootNotifier) sendNotifications(context *EvalContext, notifiers []Notif
return g.Wait()
}
func (n *RootNotifier) uploadImage(context *EvalContext) (err error) {
func (n *notificationService) uploadImage(context *EvalContext) (err error) {
uploader, err := imguploader.NewImageUploader()
if err != nil {
return err
@@ -116,7 +106,7 @@ func (n *RootNotifier) uploadImage(context *EvalContext) (err error) {
return nil
}
func (n *RootNotifier) getNotifiers(orgId int64, notificationIds []int64, context *EvalContext) ([]Notifier, error) {
func (n *notificationService) getNotifiers(orgId int64, notificationIds []int64, context *EvalContext) (NotifierSlice, error) {
query := &m.GetAlertNotificationsToSendQuery{OrgId: orgId, Ids: notificationIds}
if err := bus.Dispatch(query); err != nil {
@@ -137,7 +127,7 @@ func (n *RootNotifier) getNotifiers(orgId int64, notificationIds []int64, contex
return result, nil
}
func (n *RootNotifier) createNotifierFor(model *m.AlertNotification) (Notifier, error) {
func (n *notificationService) createNotifierFor(model *m.AlertNotification) (Notifier, error) {
notifierPlugin, found := notifierFactories[model.Type]
if !found {
return nil, errors.New("Unsupported notification type")