Search code examples
pythonfluentd

Fluentd - send json using python


I have a Fluentd server, which is configured to accept json data through TCP and on match to output it to std. The configuration is:

<source>
 @type tcp
 tag json_logs
 port 12312
 format json
 bind 0.0.0.0
</source>

<match **>
@type stdout
</match>

When trying to send a message by using netcat everything works fine - the message is received and it gets displayed in the output. The issue that I'm facing is trying to send messages through python - the message seems to be received fine(I'm checking using tcpdump to see what the server receives), but in the output nothing gets displayed, not even some kind of error. One additional detail is that if I try to send a bad formatted json from python, a message gets displayed to the output - a "pattern not matched" message.

The code that I'm using to send the messages:

from pyfluent.client import FluentSender
logdata = '{ "prop1": "val1", "prop2": "val2" }'
fluent = FluentSender("host", 12312, "json_logs")
fluent.send(logdata)


Solution

  • Found the issue - the Fluentd server only accepted data received with 'ASCII' encoding.