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