Skip to content

fix bug: get event value with key#46

Open
konoha279 wants to merge 14 commits into
bradleyjkemp:mainfrom
konoha279:main
Open

fix bug: get event value with key#46
konoha279 wants to merge 14 commits into
bradleyjkemp:mainfrom
konoha279:main

Conversation

@konoha279
Copy link
Copy Markdown

In function eventValue in evaluator/evaluate.go, if type event is interface{}, function can't return true value. Example:

- Event:
{
    "log": {
      "source": {
        "name": "aws",
        "product": "cloudtrail",
        "vendor": "aws"
      }
    }
}

- Key: "log.source.name"
- Reality return value of function: null
- True return value: "aws"

To fix this bug, need to flatten event to be able to get value by key string. Example:

- Event:
{
    "log": {
      "source": {
        "name": "aws",
        "product": "cloudtrail",
        "vendor": "aws"
      }
    }
}
- Flatten event:
{
  "log.source.name": "aws",
  "log.source.product": "cloudtrail",
  "log.source.vendor": "aws"
}

And of course we also need to unify the output of the eventValue function as an array by using toGenericSlice, to avoid the case where the return value of the eventValue function is an array. Example:

- Event:
{
  "log": [
    {
      "key": 1,
      "value": "a",
    },
    {
      "key": 2,
      "value": "b",
    }
  ],
  "temp": "abc"
}
- Flatten event:
{
  "log.key": [1, 2],
  "log.value": ["a", "b"]
}

With "[]interface{}{eventValue(event, field)}" :
- Key: "log.key"
- Value: error

- Key: "temp"
- Value: ["temp"]

With "toGenericSlice(eventValue(event, field))" :
- Key: "log.key"
- Value: [1,2]

- Key: "temp"
- Value: ["temp"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant