github.com/crowdsecurity/crowdsec@v1.6.1/pkg/csplugin/helpers.go (about) 1 package csplugin 2 3 import ( 4 "html" 5 "os" 6 "text/template" 7 8 "github.com/crowdsecurity/crowdsec/pkg/exprhelpers" 9 "github.com/crowdsecurity/crowdsec/pkg/models" 10 log "github.com/sirupsen/logrus" 11 ) 12 13 var helpers = template.FuncMap{ 14 "GetMeta": func(a *models.Alert, metaName string) []string { 15 var metaValues []string 16 for _, evt := range a.Events { 17 for _, meta := range evt.Meta { 18 if meta.Key == metaName { 19 metaValues = append(metaValues, meta.Value) 20 } 21 } 22 } 23 return metaValues 24 }, 25 "CrowdsecCTI": func(x string) any { 26 ret, err := exprhelpers.CrowdsecCTI(x) 27 if err != nil { 28 log.Warningf("error while calling CrowdsecCTI : %s", err) 29 } 30 return ret 31 }, 32 "Hostname": os.Hostname, 33 "HTMLEscape": html.EscapeString, 34 } 35 36 func funcMap() template.FuncMap { 37 return helpers 38 }