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

ecs: add args_count field #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Vladimir-A
Copy link

Added implementation of the args_count field for process and pprocess.
ecs_mapping

Signed-off-by: Anikeev Vladimir <[email protected]>
@Vladimir-A
Copy link
Author

@araujof, is there a chance that this request will be merged?

@araujof
Copy link
Member

araujof commented Jul 12, 2024

Hi @Vladimir-A -- sorry for my delayed response. I was on leave and just catching up on things.

I will review the PR. Thanks for your contribution!

@araujof araujof added the enhancement New feature or request label Jul 12, 2024
@araujof araujof self-requested a review July 12, 2024 14:42
Copy link
Member

@araujof araujof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you refactor the code to use the shlex package to split the command options into tokens that can then be used to count the command line arguments. Once the initial split is done, we can use some simple heuristics to parse the slice into groups of keyword and positional arguments, and then get a final count on those groups. We should create a helper function for this.

@terylpt any additional thoughts?

@@ -470,23 +470,33 @@ func encodeUser(rec *flatrecord.Record) JSONData {
// encodeProcess creates an ECS process field including the nested parent process.
func encodeProcess(rec *flatrecord.Record) JSONData {
exe := flatrecord.Mapper.MapStr(flatrecord.SF_PROC_EXE)(rec)
args_count := 0
if flatrecord.Mapper.MapStr(flatrecord.SF_PROC_ARGS)(rec) != "" {
args_count = len(strings.Split(flatrecord.Mapper.MapStr(flatrecord.SF_PROC_ARGS)(rec), " "))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This simple splitting strategy may lead to false positives. A more accurate counter should consider quotes, positional and keyword arguments. My suggestion is to use shlex: https://pkg.go.dev/github.com/google/shlex

A perfect solution might not be simple, but we can probably use shlex to handle most cases.

}
pexe := flatrecord.Mapper.MapStr(flatrecord.SF_PPROC_EXE)(rec)
pargs_count := 0
if flatrecord.Mapper.MapStr(flatrecord.SF_PPROC_ARGS)(rec) != "" {
pargs_count = len(strings.Split(flatrecord.Mapper.MapStr(flatrecord.SF_PPROC_ARGS)(rec), " "))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same comment applies here. We need a better strategy to parse/split the command options string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants