fluent-plugin-record-modifier icon indicating copy to clipboard operation
fluent-plugin-record-modifier copied to clipboard

Whitelist nested json

Open adolia opened this issue 7 years ago • 3 comments

Hi!

Is there any way to whitelist nested keys from a json string? Currently whitelisting top level keys works great but I can not find a way to whitelist nested keys.

Thanks in advance

adolia avatar Jul 17 '17 07:07 adolia

Currently, no way. Writing such routine in ${...} is one way like this: https://groups.google.com/d/msg/fluentd/uh0Vb_sOFz4/WSZRHGXcAgAJ

repeatedly avatar Jul 18 '17 12:07 repeatedly

Another way is adding whitelist_for like parameter to specify field for whitelist_keys

repeatedly avatar Jul 18 '17 18:07 repeatedly

I found a solution for myself in this form:

    <filter k8s.events>
      @type record_modifier
      @id filter_events
      <record>
        object.count                    ${record["object"]["count"]}
        object.firstTimestamp           ${record["object"]["firstTimestamp"]}
        object.involvedObject.kind      ${record["object"]["involvedObject"]["kind"]}
        object.involvedObject.name      ${record["object"]["involvedObject"]["name"]}
        object.involvedObject.namespace ${record["object"]["involvedObject"]["namespace"]}
        object.lastTimestamp            ${record["object"]["lastTimestamp"]}
        object.message                  ${record["object"]["message"]}
        object.reason                   ${record["object"]["reason"]}
        object.source.component         ${record["object"]["source"]["component"]}
        object.source.host              ${record["object"]["source"]["host"]}
        object.type                     ${record["object"]["type"]}
      </record>
      whitelist_keys ""
      # The commented block below does not work!
      #whitelist_keys [
      #        "$.object.count", 
      #        "$.object.firstTimestamp", 
      #        "$.object.involvedObject.kind", 
      #        "$.object.involvedObject.name", 
      #        "$.object.involvedObject.namespace", 
      #        "$.object.lastTimestamp", 
      #        "$.object.message", 
      #        "$.object.reason", 
      #        "$.object.source.component", 
      #        "$.object.source.host", 
      #        "$.object.type"
      #        ]
    </filter>

Since now records from the block record are automatically added to whitelist_keys, you do not need to re-specify them.

Hope this helps someone

jc36 avatar May 15 '20 07:05 jc36