Using JSON with LogStash

后端 未结 3 1396
名媛妹妹
名媛妹妹 2020-12-05 02:26

I\'m going out of my mind here. I have an app that writes logs to a file. Each log entry is a JSON object. An example of my .json file looks like the following:



        
3条回答
  •  既然无缘
    2020-12-05 03:00

    By default tcp put everything to message field if json codec not specified.

    An workaround to _jsonparsefailure of the message field after we specify the json codec also can be rectified by doing the following:

    input {
      tcp {
        port => '9563'
      }
    }
    filter{
      json{
        source => "message"
        target => "myroot"
      }
      json{
        source => "myroot"
      }
    
    }
    output {
        elasticsearch {
          hosts => [ "localhost:9200" ]
        }
    }
    

    It will parse message field to proper json string to field myroot and then myroot is parsed to yield the json.

    We can remove the redundant field like message as

    filter {
      json {
        source => "message"
        remove_field => ["message"]
      }
    }
    

提交回复
热议问题