Hello all,
I am working on something I have never worked on before and I really do not know where to go from here and I am hoping someone might have some direction for me to attempt trying to get this parsed to Elasticsearch properly.
The application team sending logs to kafka topics with base64 encoded. Now i want to decode that base64 encoded logs through logstash pipeline. Could you please guide me on this?
Hi Badger,
Thanks for replying!
I have tried below ruby filter
ruby { code => 'event.set("decoded", Base64.decode64(event.get("payload")).force_encoding("UTF-8"))' }
But i am getting below error.
[ERROR] 2023-12-21 00:30:03.194 [[pecspayload]>worker1] ruby - Ruby exception occurred: undefined method unpack1' for nil:NilClass {:class=>"NoMethodError", :backtrace=>["/usr/share/logstash/vendor/jruby/lib/ruby/stdlib/base64.rb:59:in decode64'", "(ruby filter code):2:in block in filter_method'", "/usr/share/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-filter-ruby-3.1.8/lib/logstash/filters/ruby.rb:96:in inline_script'", "/usr/share/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-filter-ruby-3.1.8/lib/logstash/filters/ruby.rb:89:in filter'", "/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb:159:in do_filter'", "/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb:178:in block inmulti_filter'", "org/jruby/RubyArray.java:1865:in each'", "/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb:175:in multi_filter'", "org/logstash/config/ir/compiler/AbstractFilterDelegatorExt.java:133:in multi_filter'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:304:in `block in start_workers'"]}
I think that means event.get("payload") returned nil, i.e, the field does not exists. Perhaps should use event.get("message"), or whatever field is Base64 encoded.
Hi Badger,
Thanks for answering!
I have checked with application team they are doing GZIP and encoding with uTF-8.
Now how can i read logs through logstash.
The ruby code snippet works it's just your data that is not encoded in full ascii readble.
Have you tried to decode it any other way is it readable ?
Base64 encoding is made to ship data with ASCII charcaters, if you try to decode it then render the binary back to ascii you might have some surprises.....
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.