Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug: get event value with key #46

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

konoha279
Copy link

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