I am struggling getting Logstash to insert new lines in JSON http output messages. Configuring Logstash to send out http messages (output-http plugin) works however, putting a new line into the mapping text will end up with the new line being escaped. I am unsure about how to get Logstash to leave the new line as it is.
http {
http_method => post
url => "http://..."
format => json
mapping => {
somefield => "Some text\nSome more text..."
}
}
Did you got any solution for this?
I know this is very old post, but i am also struggling from past few days and not getting any response from community
I added a filter rule which constructs the message:
mutate {
add_field => {"[@metadata][my_message]" => "Some\nMessage"}
}
# There does not seem to be a way to have new lines in Logstash variables
# therefore, we apply a hack here.
ruby {
code => "event['@metadata']['my_message'].gsub!('\n', 10.chr)"
}
As you can see I make use of a ruby filter to search for new line escape character sequences and replace that sequence with an actual newline character.
I can use this message in output rules:
http {
http_method => post
url => "https://..."
format => json
mapping => {
somefield => "%{[@metadata][my_message]}"
}
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.