MCPcopy
hub / github.com/crowdsecurity/crowdsec / GetDecisionsSinceCount

Function GetDecisionsSinceCount

pkg/exprhelpers/helpers.go:770–795  ·  view source on GitHub ↗

func GetDecisionsSinceCount(value string, since string) int {

(params ...any)

Source from the content-addressed store, hash-verified

768
769// func GetDecisionsSinceCount(value string, since string) int {
770func GetDecisionsSinceCount(params ...any) (any, error) {
771 value := params[0].(string)
772 since := params[1].(string)
773
774 if dbClient == nil {
775 log.Error("No database config to call GetDecisionsSinceCount()")
776 return 0, nil
777 }
778
779 sinceDuration, err := cstime.ParseDurationWithDays(since)
780 if err != nil {
781 log.Errorf("Failed to parse since parameter '%s' : %s", since, err)
782 return 0, nil
783 }
784
785 ctx := context.TODO()
786 sinceTime := time.Now().UTC().Add(-sinceDuration)
787
788 count, err := dbClient.CountDecisionsByValue(ctx, value, &sinceTime, false)
789 if err != nil {
790 log.Errorf("Failed to get decisions count from value '%s'", value)
791 return 0, nil //nolint:nilerr // This helper did not return an error before the move to expr.Function, we keep this behavior for backward compatibility
792 }
793
794 return count, nil
795}
796
797func GetActiveDecisionsCount(params ...any) (any, error) {
798 value := params[0].(string)

Callers

nothing calls this directly

Calls 3

CountDecisionsByValueMethod · 0.80
ErrorMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…