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

logparser support mixed parser decoding #2756

Closed
ghost opened this issue May 3, 2017 · 5 comments
Closed

logparser support mixed parser decoding #2756

ghost opened this issue May 3, 2017 · 5 comments
Labels
area/tail feature request Requests for new plugin and for new features to existing plugins
Milestone

Comments

@ghost
Copy link

ghost commented May 3, 2017

We are trying to solve a very specific problem, but this may be generally useful.

logparser should support decoding JSON from the body of a log message.

There are two ways this can occur, one is that the JSON is in a syslog style "field", for example:
<38>2013-07-22T13:45:54 localhost prg00000[1234]: {"MESSAGE": "foo", "PROGRAM": "bar"}

The other is that the entire log is just one JSON item per line. In both cases, what we would want here is that selected JSON fields [including possibly dicts in dicts and so on] are mapped to tags or metrics in telegraf (if they exist in that row).

The only sane way that I can think of to handle #1 is a regular expression to tell the plugin what to attempt to JSON decode. #2 is obviously trivial to deal with, although less common (it happens to be what we are dealing with though).

If we submitted a patch to achieve this, would that work? Is there another approach that i'm missing?

@danielnelson
Copy link
Contributor

For the line separated JSON, you might be able to use the tail plugin which uses the normal parsers. For the first one, I think an option to strip a prefix could be useful, whatever remains would be passed to the parsers.

Long term, tail and logparser should probably be merged and grok be made into one of the parsers. There are some unfortunate ways the config is processed that make this difficult but perhaps we can solve them with the work to move to a plugin based configuration.

@ghost
Copy link
Author

ghost commented May 7, 2017

We ended up writing a custom plugin to solve our problem before it gets to a log file, which is probably the right way to handle this - but long term I can see a lot of uses for more generic log parsing. Your suggestion makes total sense to me.

I'm not sure if there is already an issue to do what you propose -feel free to close this if its not helpful or rename it!

@danielnelson
Copy link
Contributor

I think what we need here is basically grok to process the line, and then hand the output over to one of the parsers. Perhaps grok could specify a parser as a conversion? I think the syslog case could be pretty common and we likely need the timestamp out of it.

@danielnelson danielnelson changed the title logparser support JSON decoding logparser support mixed parser decoding May 8, 2017
@danielnelson danielnelson added this to the Future Milestone milestone May 8, 2017
@danielnelson danielnelson removed this from the Future Milestone milestone Jun 14, 2017
@danielnelson
Copy link
Contributor

The solution we are planning for this issue is to create a parser processor (#4428). The initial parse would use tail+grok or the syslog input, placing the JSON data into a field. Then the parser processor could use the json parser to pull out the individual fields.

@danielnelson danielnelson added this to the 1.8.0 milestone Aug 27, 2018
@danielnelson
Copy link
Contributor

In 1.8 this can be accomplished using syslog -> parser processor(json) or from a logfile using tail(grok) -> parser processor(json).

@danielnelson danielnelson added the feature request Requests for new plugin and for new features to existing plugins label Aug 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/tail feature request Requests for new plugin and for new features to existing plugins
Projects
None yet
Development

No branches or pull requests

1 participant