sowawa / fluent-plugin-slack

132 stars 52 forks source link

Allow fetching key values from nested hash #46

Closed pbenefice closed 5 years ago

pbenefice commented 5 years ago

Hi @sonots,

I would like to be able to fetch keys from hash if there is any within the record. For example if using this kubernetes plugin, I'd like to be able to use the kubernetes_namespace within the message for example.

In order to do that, I considered that key which contain a "." could be interpreted as an attempt to access a nested hash. So if there is any dot, I extract the value of "the first key" (at the left of the first dot), extract the corresponding part of the record and call the same function with that piece of record and what remain of the key.

As an example, this record :

{"json":"message", "hash":{"random":"test", "sub-key":{"sub-sub_key":"Im a sub sub key"}  } }

With this config for the message :

<match tag.test>
  @type slack
  message %s
  message_keys hash.sub-key.sub-sub_key
</match>

Should return : Im a sub sub key

What do you think ?

Best regards

sonots commented 5 years ago

fluentd itself now supports nested key. we should use it. https://github.com/fluent/fluentd/issues/1578. Also, see https://github.com/sowawa/fluent-plugin-slack/issues/41

We can drop old version support.