Просмотр исходного кода

Merge branch 'utkarshcmu-slack_notifier'

bergquist 9 лет назад
Родитель
Сommit
39f9db8650

+ 10 - 0
pkg/services/alerting/notifiers/slack.go

@@ -22,9 +22,12 @@ func NewSlackNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
 		return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
 	}
 
+	recipient := model.Settings.Get("recipient").MustString()
+
 	return &SlackNotifier{
 		NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.Settings),
 		Url:          url,
+		Recipient:		recipient,
 		log:          log.New("alerting.notifier.slack"),
 	}, nil
 }
@@ -32,6 +35,7 @@ func NewSlackNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
 type SlackNotifier struct {
 	NotifierBase
 	Url string
+	Recipient string
 	log log.Logger
 }
 
@@ -85,6 +89,12 @@ func (this *SlackNotifier) Notify(evalContext *alerting.EvalContext) error {
 				"ts":          time.Now().Unix(),
 			},
 		},
+		"parse": "full", // to linkify urls, users and channels in alert message.
+	}
+
+	//recipient override
+	if this.Recipient != "" {
+		body["channel"] = this.Recipient
 	}
 
 	data, _ := json.Marshal(&body)

+ 12 - 1
public/app/features/alerting/partials/notification_edit.html

@@ -59,10 +59,21 @@
 
     <div class="gf-form-group" ng-if="ctrl.model.type === 'slack'">
       <h3 class="page-heading">Slack settings</h3>
-      <div class="gf-form">
+      <div class="gf-form max-width-30">
         <span class="gf-form-label width-6">Url</span>
         <input type="text" required class="gf-form-input max-width-30" ng-model="ctrl.model.settings.url" placeholder="Slack incoming webhook url"></input>
       </div>
+      <div class="gf-form max-width-30">
+        <span class="gf-form-label width-6">Recipient</span>
+        <input type="text"
+          class="gf-form-input max-width-30"
+          ng-model="ctrl.model.settings.recipient"
+          data-placement="right">
+        </input>
+        <info-popover mode="right-absolute">
+          Override default channel or user, use #channel-name or &lt;@username&gt;&lt;/@username&gt;
+        </info-popover>
+      </div>
     </div>
 
     <div class="gf-form-group section" ng-if="ctrl.model.type === 'email'">