helpers.go 798 B

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