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

Support bracketed target field name #33

Open
nickcarenza opened this issue Aug 2, 2016 · 2 comments
Open

Support bracketed target field name #33

nickcarenza opened this issue Aug 2, 2016 · 2 comments

Comments

@nickcarenza
Copy link

nickcarenza commented Aug 2, 2016

The argument for defining the target isn't like other logstash plugins (logstash-filter-geoip). It seems to require that I supply the field without surrounding brackets. If i use brackets, it silently adds the fields to the root of the event. Strangely however, if i target a nested field like [one][two] with the brackets, it does write the fields to that location. It is not obvious to me how this line allows that since the resulting normalized_target seems like it would be [[one][two]]. Maybe that is a valid target or I am misunderstanding what that line does.

Here is the config I expect to work but causes the filter to write fields to root:

    useragent {
      source => "[device][user_agent]"
      target => "[device]"
    }

Here is the config where I specify a deep path and the fields are successfully written to it as expected:

    useragent {
      source => "[device][user_agent]"
      target => "[device][test]"
    }

And here is the config I ended up using for this filter which works as intended but unlike other plugins in how target is specified:

    useragent {
      source => "[device][user_agent]"
      target => "device"
    }

This is with version 2.0.8 but the line of the code that seems to matter looks the same on master.

@jordansissel
Copy link
Contributor

Based on my interpretation of the code, the problem is that this normalized_target is not aware that field references can be nested. It looks like the regexp would accept foo and [foo] but would bug out when given nested [foo][bar] producing [[foo][bar]] as a field reference.

@nickcarenza
Copy link
Author

The else case though sets normalized_target to "", which defaults to document root.

irb(main):001:0> target = "[test]"
=> "[test]"
irb(main):002:0> normalized_target = (target && target !~ /^\[[^\[\]]+\]$/) ? "[#{target}]" : ""
=> ""
irb(main):003:0> target = "[one][two]"
=> "[one][two]"
irb(main):004:0> normalized_target = (target && target !~ /^\[[^\[\]]+\]$/) ? "[#{target}]" : ""
=> "[[one][two]]"
irb(main):005:0> target = "test"
=> "test"
irb(main):006:0> normalized_target = (target && target !~ /^\[[^\[\]]+\]$/) ? "[#{target}]" : ""
=> "[test]"

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

No branches or pull requests

2 participants