* fix a confusing debug message * make CTIHelper simply log the error to avoid failing template rendering
37 lines
754 B
Go
37 lines
754 B
Go
package csplugin
|
|
|
|
import (
|
|
"os"
|
|
"text/template"
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
|
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var helpers = template.FuncMap{
|
|
"GetMeta": func(a *models.Alert, metaName string) []string {
|
|
var metaValues []string
|
|
for _, evt := range a.Events {
|
|
for _, meta := range evt.Meta {
|
|
if meta.Key == metaName {
|
|
metaValues = append(metaValues, meta.Value)
|
|
}
|
|
}
|
|
}
|
|
return metaValues
|
|
},
|
|
"CrowdsecCTI": func(x string) any {
|
|
ret, err := exprhelpers.CrowdsecCTI(x)
|
|
if err != nil {
|
|
log.Warningf("error while calling CrowdsecCTI : %s", err)
|
|
}
|
|
return ret
|
|
},
|
|
"Hostname": os.Hostname,
|
|
}
|
|
|
|
func funcMap() template.FuncMap {
|
|
return helpers
|
|
}
|