mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add new option to set where to open the message url
This commit is contained in:
parent
201dd6bf65
commit
b7787db34e
@ -2,6 +2,7 @@ package notifiers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
@ -15,12 +16,17 @@ const DingdingOptionsTemplate = `
|
|||||||
<h3 class="page-heading">DingDing settings</h3>
|
<h3 class="page-heading">DingDing settings</h3>
|
||||||
<div class="gf-form">
|
<div class="gf-form">
|
||||||
<span class="gf-form-label width-10">Url</span>
|
<span class="gf-form-label width-10">Url</span>
|
||||||
<input type="text" required class="gf-form-input max-width-26" ng-model="ctrl.model.settings.url" placeholder="https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx"></input>
|
<input type="text" required class="gf-form-input max-width-70" ng-model="ctrl.model.settings.url" placeholder="https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx"></input>
|
||||||
</div>
|
</div>
|
||||||
<div class="gf-form">
|
<div class="gf-form">
|
||||||
<span class="gf-form-label width-10">MessageType</span>
|
<span class="gf-form-label width-10">MessageType</span>
|
||||||
<select class="gf-form-input max-width-14" ng-model="ctrl.model.settings.msgType" ng-options="s for s in ['link','actionCard']" ng-init="ctrl.model.settings.msgType=ctrl.model.settings.msgType || '` + DefaultDingdingMsgType + `'"></select>
|
<select class="gf-form-input max-width-14" ng-model="ctrl.model.settings.msgType" ng-options="s for s in ['link','actionCard']" ng-init="ctrl.model.settings.msgType=ctrl.model.settings.msgType || '` + DefaultDingdingMsgType + `'"></select>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="gf-form">
|
||||||
|
<span class="gf-form-label width-10">OpenInBrowser</span>
|
||||||
|
<gf-form-switch class="gf-form" checked="ctrl.model.settings.openInBrowser"></gf-form-switch>
|
||||||
|
<info-popover mode="right-normal">Open the message url in browser instead of inside of Dingding</info-popover>
|
||||||
|
</div>
|
||||||
`
|
`
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -41,9 +47,11 @@ func NewDingDingNotifier(model *m.AlertNotification) (alerting.Notifier, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
msgType := model.Settings.Get("msgType").MustString(DefaultDingdingMsgType)
|
msgType := model.Settings.Get("msgType").MustString(DefaultDingdingMsgType)
|
||||||
|
openInBrowser := model.Settings.Get("openInBrowser").MustBool(true)
|
||||||
|
|
||||||
return &DingDingNotifier{
|
return &DingDingNotifier{
|
||||||
NotifierBase: NewNotifierBase(model),
|
NotifierBase: NewNotifierBase(model),
|
||||||
|
OpenInBrowser: openInBrowser,
|
||||||
MsgType: msgType,
|
MsgType: msgType,
|
||||||
Url: url,
|
Url: url,
|
||||||
log: log.New("alerting.notifier.dingding"),
|
log: log.New("alerting.notifier.dingding"),
|
||||||
@ -53,6 +61,7 @@ func NewDingDingNotifier(model *m.AlertNotification) (alerting.Notifier, error)
|
|||||||
type DingDingNotifier struct {
|
type DingDingNotifier struct {
|
||||||
NotifierBase
|
NotifierBase
|
||||||
MsgType string
|
MsgType string
|
||||||
|
OpenInBrowser bool //Set whether the message url will open outside of Dingding
|
||||||
Url string
|
Url string
|
||||||
log log.Logger
|
log log.Logger
|
||||||
}
|
}
|
||||||
@ -65,6 +74,18 @@ func (this *DingDingNotifier) Notify(evalContext *alerting.EvalContext) error {
|
|||||||
this.log.Error("Failed to get messageUrl", "error", err, "dingding", this.Name)
|
this.log.Error("Failed to get messageUrl", "error", err, "dingding", this.Name)
|
||||||
messageUrl = ""
|
messageUrl = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if this.OpenInBrowser {
|
||||||
|
q := url.Values{
|
||||||
|
"pc_slide": {"false"},
|
||||||
|
"url": {messageUrl},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use special link to auto open the message url outside of Dingding
|
||||||
|
// Refer: https://open-doc.dingtalk.com/docs/doc.htm?treeId=385&articleId=104972&docType=1#s9
|
||||||
|
messageUrl = "dingtalk://dingtalkclient/page/link?" + q.Encode()
|
||||||
|
}
|
||||||
|
|
||||||
this.log.Info("messageUrl:" + messageUrl)
|
this.log.Info("messageUrl:" + messageUrl)
|
||||||
|
|
||||||
message := evalContext.Rule.Message
|
message := evalContext.Rule.Message
|
||||||
|
Loading…
Reference in New Issue
Block a user