Como expandir JSON no Fluentd?

Sep 29 2020

Existe uma maneira de filtrar a string JSON aninhada em campos separados no fluentd?

JSON atual:

 { 
   Value1: "something",
   Value2: "something",
   Message:{
             Value3: "Something",
             Value3: "Something"
          }
 }

O que eu quero (ou algo semelhante):

 { 
   Value1: "something",
   Value2: "something",
   Message.Value3: "Something",
   Message.Value3: "Something"
          
 }

O JSON não precisa ser nivelado como no exemplo acima, mas eu quero que os valores estejam em seus próprios campos separados (colunas) quando atingirem o elasticsearch. Em outras alas, quero dividir a única string longa de Message em vários campos contidos nela.

Respostas

1 MaxLobur Sep 29 2020 at 02:54

Experimente isto:

<source>
...
</source>

<filter myapp**>
  @type parser
  key_name Message

  format multi_format
  <pattern>
    format json # try parsing json in the first place
  </pattern>
  <pattern>
    format none # leave as is if this is not json (plaintext)
  </pattern>

  reserve_data true # keep the original Message field in case anything go wrong
</filter>

<match myapp**>
...
</match>

Analisador multiformato: https://github.com/repeatedly/fluent-plugin-multi-format-parser