fix event push api (#1057)
This commit is contained in:
parent
b6436b09ce
commit
65439df7fb
|
@ -2,6 +2,7 @@ package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/didi/nightingale/v5/src/models"
|
"github.com/didi/nightingale/v5/src/models"
|
||||||
"github.com/didi/nightingale/v5/src/server/config"
|
"github.com/didi/nightingale/v5/src/server/config"
|
||||||
|
@ -14,14 +15,46 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func pushEventToQueue(c *gin.Context) {
|
func pushEventToQueue(c *gin.Context) {
|
||||||
var event models.AlertCurEvent
|
var event *models.AlertCurEvent
|
||||||
ginx.BindJSON(c, &event)
|
ginx.BindJSON(c, &event)
|
||||||
if event.RuleId == 0 {
|
if event.RuleId == 0 {
|
||||||
ginx.Bomb(200, "event is illegal")
|
ginx.Bomb(200, "event is illegal")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event.TagsMap = make(map[string]string)
|
||||||
|
for i := 0; i < len(event.TagsJSON); i++ {
|
||||||
|
pair := strings.TrimSpace(event.TagsJSON[i])
|
||||||
|
if pair == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
arr := strings.Split(pair, "=")
|
||||||
|
if len(arr) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
event.TagsMap[arr[0]] = arr[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := event.ParseRuleNote(); err != nil {
|
||||||
|
event.RuleNote = fmt.Sprintf("failed to parse rule note: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果 rule_note 中有 ; 前缀,则使用 rule_note 替换 tags 中的内容
|
||||||
|
if strings.HasPrefix(event.RuleNote, ";") {
|
||||||
|
event.RuleNote = strings.TrimPrefix(event.RuleNote, ";")
|
||||||
|
event.Tags = strings.ReplaceAll(event.RuleNote, " ", ",,")
|
||||||
|
event.TagsJSON = strings.Split(event.Tags, ",,")
|
||||||
|
} else {
|
||||||
|
event.Tags = strings.Join(event.TagsJSON, ",,")
|
||||||
|
}
|
||||||
|
|
||||||
|
event.Callbacks = strings.Join(event.CallbacksJSON, " ")
|
||||||
|
event.NotifyChannels = strings.Join(event.NotifyChannelsJSON, " ")
|
||||||
|
event.NotifyGroups = strings.Join(event.NotifyGroupsJSON, " ")
|
||||||
|
|
||||||
promstat.CounterAlertsTotal.WithLabelValues(config.C.ClusterName).Inc()
|
promstat.CounterAlertsTotal.WithLabelValues(config.C.ClusterName).Inc()
|
||||||
engine.LogEvent(&event, "http_push_queue")
|
engine.LogEvent(event, "http_push_queue")
|
||||||
if !engine.EventQueue.PushFront(event) {
|
if !engine.EventQueue.PushFront(event) {
|
||||||
msg := fmt.Sprintf("event:%+v push_queue err: queue is full", event)
|
msg := fmt.Sprintf("event:%+v push_queue err: queue is full", event)
|
||||||
ginx.Bomb(200, msg)
|
ginx.Bomb(200, msg)
|
||||||
|
|
Loading…
Reference in New Issue