fix a confusing debug message (#2386)

* fix a confusing debug message

* make CTIHelper simply log the error to avoid failing template rendering
This commit is contained in:
Thibault "bui" Koechlin 2023-07-28 09:52:21 +02:00 committed by GitHub
parent 5cb7013575
commit 718721b341
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
"github.com/crowdsecurity/crowdsec/pkg/models"
log "github.com/sirupsen/logrus"
)
var helpers = template.FuncMap{
@ -20,8 +21,14 @@ var helpers = template.FuncMap{
}
return metaValues
},
"CrowdsecCTI": exprhelpers.CrowdsecCTI,
"Hostname": os.Hostname,
"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 {

View file

@ -168,7 +168,7 @@ func (Profile *Runtime) EvaluateProfile(Alert *models.Alert) ([]*models.Decision
for eIdx, expression := range Profile.RuntimeFilters {
output, err := expr.Run(expression, map[string]interface{}{"Alert": Alert})
if err != nil {
Profile.Logger.Warningf("failed to run whitelist expr : %v", err)
Profile.Logger.Warningf("failed to run profile expr for %s : %v", Profile.Cfg.Name, err)
return nil, matched, errors.Wrapf(err, "while running expression %s", Profile.Cfg.Filters[eIdx])
}
switch out := output.(type) {