40 Star 146 Fork 3

Gitee 极速下载/grafana

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/grafana/grafana
克隆/下载
test_notification.go 1.84 KB
一键复制 编辑 原始数据 按行查看 历史
package alerting
import (
"context"
"fmt"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/null"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/log"
m "github.com/grafana/grafana/pkg/models"
)
type NotificationTestCommand struct {
State m.AlertStateType
Name string
Type string
Settings *simplejson.Json
}
func init() {
bus.AddHandler("alerting", handleNotificationTestCommand)
}
func handleNotificationTestCommand(cmd *NotificationTestCommand) error {
notifier := NewNotificationService(nil).(*notificationService)
model := &m.AlertNotification{
Name: cmd.Name,
Type: cmd.Type,
Settings: cmd.Settings,
}
notifiers, err := notifier.createNotifierFor(model)
if err != nil {
log.Error2("Failed to create notifier", "error", err.Error())
return err
}
return notifier.sendNotifications(createTestEvalContext(cmd), []Notifier{notifiers})
}
func createTestEvalContext(cmd *NotificationTestCommand) *EvalContext {
testRule := &Rule{
DashboardId: 1,
PanelId: 1,
Name: "Test notification",
Message: "Someone is testing the alert notification within grafana.",
State: m.AlertStateAlerting,
}
ctx := NewEvalContext(context.Background(), testRule)
if cmd.Settings.Get("uploadImage").MustBool(true) {
ctx.ImagePublicUrl = "http://grafana.org/assets/img/blog/mixed_styles.png"
}
ctx.IsTestRun = true
ctx.Firing = true
ctx.Error = fmt.Errorf("This is only a test")
ctx.EvalMatches = evalMatchesBasedOnState()
return ctx
}
func evalMatchesBasedOnState() []*EvalMatch {
matches := make([]*EvalMatch, 0)
matches = append(matches, &EvalMatch{
Metric: "High value",
Value: null.FloatFrom(100),
})
matches = append(matches, &EvalMatch{
Metric: "Higher Value",
Value: null.FloatFrom(200),
})
return matches
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/grafana.git
git@gitee.com:mirrors/grafana.git
mirrors
grafana
grafana
v5.3.0-beta1

搜索帮助