parent
fbff60eefb
commit
15892d6e57
|
@ -63,10 +63,11 @@ type AggrRule struct {
|
|||
Value string
|
||||
}
|
||||
|
||||
func (e *AlertCurEvent) ParseRuleNote() error {
|
||||
e.RuleNote = strings.TrimSpace(e.RuleNote)
|
||||
func (e *AlertCurEvent) ParseRule(field string) error {
|
||||
f := e.GetField(field)
|
||||
f = strings.TrimSpace(f)
|
||||
|
||||
if e.RuleNote == "" {
|
||||
if f == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -75,7 +76,7 @@ func (e *AlertCurEvent) ParseRuleNote() error {
|
|||
"{{$value := .TriggerValue}}",
|
||||
}
|
||||
|
||||
text := strings.Join(append(defs, e.RuleNote), "")
|
||||
text := strings.Join(append(defs, f), "")
|
||||
t, err := template.New(fmt.Sprint(e.RuleId)).Funcs(tplx.TemplateFuncMap).Parse(text)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -87,7 +88,13 @@ func (e *AlertCurEvent) ParseRuleNote() error {
|
|||
return err
|
||||
}
|
||||
|
||||
e.RuleNote = body.String()
|
||||
if field == "rule_name" {
|
||||
e.RuleName = body.String()
|
||||
}
|
||||
|
||||
if field == "rule_note" {
|
||||
e.RuleNote = body.String()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -133,6 +140,8 @@ func (e *AlertCurEvent) GetField(field string) string {
|
|||
return fmt.Sprint(e.RuleId)
|
||||
case "rule_name":
|
||||
return e.RuleName
|
||||
case "rule_note":
|
||||
return e.RuleNote
|
||||
case "severity":
|
||||
return fmt.Sprint(e.Severity)
|
||||
case "runbook_url":
|
||||
|
|
|
@ -45,7 +45,11 @@ func consume(events []interface{}, sema *semaphore.Semaphore) {
|
|||
func consumeOne(event *models.AlertCurEvent) {
|
||||
LogEvent(event, "consume")
|
||||
|
||||
if err := event.ParseRuleNote(); err != nil {
|
||||
if err := event.ParseRule("rule_name"); err != nil {
|
||||
event.RuleName = fmt.Sprintf("failed to parse rule name: %v", err)
|
||||
}
|
||||
|
||||
if err := event.ParseRule("rule_note"); err != nil {
|
||||
event.RuleNote = fmt.Sprintf("failed to parse rule note: %v", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,11 @@ func pushEventToQueue(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := event.ParseRuleNote(); err != nil {
|
||||
if err := event.ParseRule("rule_name"); err != nil {
|
||||
event.RuleName = fmt.Sprintf("failed to parse rule name: %v", err)
|
||||
}
|
||||
|
||||
if err := event.ParseRule("rule_note"); err != nil {
|
||||
event.RuleNote = fmt.Sprintf("failed to parse rule note: %v", err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue