Avenash
Avenash

Reputation: 85

Fluentd - Add new attributes in JSON data

Using Fluentd I am sending logs to Splunk and ES in JSON format, as given below:

{
    "object1": {
            "obj1_key1": "value_xyz"
     }
     "object2": {
            "obj2_key1": "value_abc"
     }
}

Before sending logs to server, I want to add few fields as metadata in Object1 and Object2, like.

{
    "object1": {
            "obj1_key1": "value_xyz"
            "metadata": "constant_value"
     }
     "object2": {
            "obj2_key1": "value_abc"
            "metadata": "constant_value"
     }
}

I know using fluentd "record_transformer" plugin we can add new fields but the question is how to add fields inside objects or nested objects?

Upvotes: 1

Views: 4729

Answers (1)

okkez
okkez

Reputation: 455

You can use built-in filter record_transformer plugin like the followings:

<source>
  @type dummy
  tag dummy
  dummy [
    {"message": "dummy", "json": {"log": "log"}}
  ]
</source>

<filter dummy>
  @type record_transformer
  enable_ruby true
  <record>
    json ${record["json"].merge({key: "key", value: "value"})}
  </record>
</filter>

<match dummy>
  @type stdout
</match>

Upvotes: 6

Related Questions