2022-12-06 12:47:29 +00:00
|
|
|
package csplugin
|
|
|
|
|
|
|
|
import (
|
2023-09-04 08:49:39 +00:00
|
|
|
"html"
|
2023-05-11 12:25:04 +00:00
|
|
|
"os"
|
2022-12-06 12:47:29 +00:00
|
|
|
"text/template"
|
|
|
|
|
2023-01-19 07:45:50 +00:00
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
|
2022-12-06 12:47:29 +00:00
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
2023-07-28 07:52:21 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2022-12-06 12:47:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
},
|
2023-07-28 07:52:21 +00:00
|
|
|
"CrowdsecCTI": func(x string) any {
|
|
|
|
ret, err := exprhelpers.CrowdsecCTI(x)
|
|
|
|
if err != nil {
|
|
|
|
log.Warningf("error while calling CrowdsecCTI : %s", err)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
},
|
2023-09-04 08:49:39 +00:00
|
|
|
"Hostname": os.Hostname,
|
|
|
|
"HTMLEscape": html.EscapeString,
|
2022-12-06 12:47:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func funcMap() template.FuncMap {
|
|
|
|
return helpers
|
|
|
|
}
|