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

json adapter #65

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

json adapter #65

wants to merge 1 commit into from

Conversation

progrium
Copy link
Contributor

This is a generic JSON adapter that can be used with Logstash, but doesn't need to be. Its fields can be configured with environment variables, with minimal default fields enabled, and a few useful premade fields that can be enabled.

"JSON_DOCKER_HOSTNAME": "{{.Container.Config.Hostname}}",
"JSON_DOCKER_IMAGE": "{{.Container.Config.Image}}",
"JSON_DOCKER_ID": "{{.Container.ID}}",
"JSON_DOCKER_NAME": "{{.ContainerName}}",
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing ".", should be "{{.Container.Name}}".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NoumanSaleem
Copy link

@progrium any update on this?

@tumd
Copy link

tumd commented Jun 30, 2015

I would really love to see this feature merged.
Would do it myself, but not sure how to resolve the conflicts.

@geoffreytran
Copy link

Another +1 on getting this merged.

@dkiser
Copy link

dkiser commented Jan 22, 2016

@progrium Any way we can get map types properly converted to json before this PR is merged? I tried running this branch on a dev box to see what {{.Container.Config.Labels}} would look like, but it doesn't appear the types map properly reads maps to end up being json marshalled correctly.

example json pretty print of a syslog message with json adapter and labels field

{
  "docker": {
    "hostname": "6965fdb0f180",
    "image": "centos:centos7",
    "labels": "map[name:CentOS Base Image vendor:CentOS build-date:2015-12-23 license:GPLv2]"
  },
  "message": "test",
  "time": "1453494436"
}

Ran with following env vars

JSON_FIELDS="time:uint,message,docker.hostname,docker.image,docker.labels"
JSON_DOCKER_LABELS="{{.Container.Config.Labels}}"

Thoughts?

@progrium
Copy link
Contributor Author

That looks like an easy fix. Also I'm surprised this was never merged. Maybe it would be a good idea to merge this and then talk about fixing that as a separate issue that others might be able to help with?

@dkiser
Copy link

dkiser commented Jan 22, 2016

@progrium either way is fine.

Any ideas how the marshalling would be fixed? Looking at golang json docs seems like it would be marshalled correctly by default for known types. Is the use of the template render causing this? Haven't looked too deeply at it plus I'm a go beginner.

@progrium
Copy link
Contributor Author

Yeah I'm assuming it's some oversight where I assume some variable is going to be a string. I haven't looked at the code in a while. I'm just, you know, swamped. Also still looking for another maintainer for this project.

@progrium
Copy link
Contributor Author

Ugh, and it needs to be rebased now too. Maybe neeeext week? :\

@dkiser
Copy link

dkiser commented Jan 22, 2016

Hehe No rush on my part. I can always build and use locally with the changes 8-).

@dkiser
Copy link

dkiser commented Jan 23, 2016

@progrium one thing I noticed was this code is using the stock udp transport. I had a specific need to send JSON over a valid syslog message. So i'll possibly fork and re-use some of this json code by adding a new MODE to the syslog adaptor configured by environment variables. The idea would be to send JSON payload in the "message" portion of a syslog message where this payload is configured via environment variables as you've already started on this branch.

High level goal is JSON payload + syslog (udp or tcp).

@progrium
Copy link
Contributor Author

No reason adapters can't use each other. If there was a way to refactor this so that syslog could be configured to use it (and all its JSON configuration) in its messages that would be rad. Try and explore that in your fork and if you come up with anything let us know!

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

Successfully merging this pull request may close these issues.

None yet

7 participants