Logstash un-gzip array log configuration











up vote
0
down vote

favorite












everyone!
I have logstash config, which forwards logs from RabbitMQ to elasticSearch. Something like this:



input {
rabbitmq {
...
}
}

filter {
if [type] == "rabbitmq" {
json {
source => "message"
target => "message"
}
}
}

output {
elasticsearch {
hosts => ["${ES_HOST}"]
user => "${ES_USERNAME}"
password => "${ES_PASSWORD}"
sniffing => false
index => "kit_events-%{[message][elasticsearch][index]}"
}
}


And we were forced to compress logs on a fly, because they are spending too much traffic.
Logs were moved into array and gzipped.
What is the correct way of configuring un-gzipping and splitting array back into objects?



I did some research and found out that there is gzip_lines plugin and something on Ruby(?) to parse array, but I failed to implement it. Did anyone make something like this before?



UPD:



Added this filter



filter {

if [type] == "kitlog-rabbitmq" {
ruby {
init => "
require 'zlib'
require 'stringio'
"
code => "
body = event.get('[http][response][body]').to_s
sio = StringIO.new(body)
gz = Zlib::GzipReader.new(sio)
result = gz.read.to_s
event.set('[http][response][body]', result)
"
}
}
}


And now catching an error



ERROR][logstash.filters.ruby    ] Ruby exception occurred: not in gzip format
[DEBUG][logstash.pipeline ] output received {"event"=>{"@timestamp"=>2018-11-30T09:16:19.127Z, "tags"=>["_rubyexception"], "@version"=>"1", "message"=>"x^\x8B\xAEV*\xCE\xCE\xCC\xC9)V\xB2R\x88V\xD26T07\xB7\xB0\xB4\xB44000W\x8A\xD5QPJ\xCE\xCF+IL.\u0001\xCA*)\u0001\xB9\xA9\xB9\x89\x999 N\x96C\x96^r~.X,\xA5\u0014(R\xADT\x9A\u000E6#\xA0\xB2$#?\u000F\xAC\xB9\u0000\"\xE2\u001C\xAC\u0014[\v\xE4\xE6%概\xF4z\u0001\xE9b%\xA0\xC8\xC0\xD9\u001D\v\u0000\u0003\x9ADk", "type"=>"kitlog-rabbitmq"}}


Was trying different gzipping methods, but result is still the same. Also tried changing input codecs (plain - utf-8, plain - binary)










share|improve this question




























    up vote
    0
    down vote

    favorite












    everyone!
    I have logstash config, which forwards logs from RabbitMQ to elasticSearch. Something like this:



    input {
    rabbitmq {
    ...
    }
    }

    filter {
    if [type] == "rabbitmq" {
    json {
    source => "message"
    target => "message"
    }
    }
    }

    output {
    elasticsearch {
    hosts => ["${ES_HOST}"]
    user => "${ES_USERNAME}"
    password => "${ES_PASSWORD}"
    sniffing => false
    index => "kit_events-%{[message][elasticsearch][index]}"
    }
    }


    And we were forced to compress logs on a fly, because they are spending too much traffic.
    Logs were moved into array and gzipped.
    What is the correct way of configuring un-gzipping and splitting array back into objects?



    I did some research and found out that there is gzip_lines plugin and something on Ruby(?) to parse array, but I failed to implement it. Did anyone make something like this before?



    UPD:



    Added this filter



    filter {

    if [type] == "kitlog-rabbitmq" {
    ruby {
    init => "
    require 'zlib'
    require 'stringio'
    "
    code => "
    body = event.get('[http][response][body]').to_s
    sio = StringIO.new(body)
    gz = Zlib::GzipReader.new(sio)
    result = gz.read.to_s
    event.set('[http][response][body]', result)
    "
    }
    }
    }


    And now catching an error



    ERROR][logstash.filters.ruby    ] Ruby exception occurred: not in gzip format
    [DEBUG][logstash.pipeline ] output received {"event"=>{"@timestamp"=>2018-11-30T09:16:19.127Z, "tags"=>["_rubyexception"], "@version"=>"1", "message"=>"x^\x8B\xAEV*\xCE\xCE\xCC\xC9)V\xB2R\x88V\xD26T07\xB7\xB0\xB4\xB44000W\x8A\xD5QPJ\xCE\xCF+IL.\u0001\xCA*)\u0001\xB9\xA9\xB9\x89\x999 N\x96C\x96^r~.X,\xA5\u0014(R\xADT\x9A\u000E6#\xA0\xB2$#?\u000F\xAC\xB9\u0000\"\xE2\u001C\xAC\u0014[\v\xE4\xE6%概\xF4z\u0001\xE9b%\xA0\xC8\xC0\xD9\u001D\v\u0000\u0003\x9ADk", "type"=>"kitlog-rabbitmq"}}


    Was trying different gzipping methods, but result is still the same. Also tried changing input codecs (plain - utf-8, plain - binary)










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      everyone!
      I have logstash config, which forwards logs from RabbitMQ to elasticSearch. Something like this:



      input {
      rabbitmq {
      ...
      }
      }

      filter {
      if [type] == "rabbitmq" {
      json {
      source => "message"
      target => "message"
      }
      }
      }

      output {
      elasticsearch {
      hosts => ["${ES_HOST}"]
      user => "${ES_USERNAME}"
      password => "${ES_PASSWORD}"
      sniffing => false
      index => "kit_events-%{[message][elasticsearch][index]}"
      }
      }


      And we were forced to compress logs on a fly, because they are spending too much traffic.
      Logs were moved into array and gzipped.
      What is the correct way of configuring un-gzipping and splitting array back into objects?



      I did some research and found out that there is gzip_lines plugin and something on Ruby(?) to parse array, but I failed to implement it. Did anyone make something like this before?



      UPD:



      Added this filter



      filter {

      if [type] == "kitlog-rabbitmq" {
      ruby {
      init => "
      require 'zlib'
      require 'stringio'
      "
      code => "
      body = event.get('[http][response][body]').to_s
      sio = StringIO.new(body)
      gz = Zlib::GzipReader.new(sio)
      result = gz.read.to_s
      event.set('[http][response][body]', result)
      "
      }
      }
      }


      And now catching an error



      ERROR][logstash.filters.ruby    ] Ruby exception occurred: not in gzip format
      [DEBUG][logstash.pipeline ] output received {"event"=>{"@timestamp"=>2018-11-30T09:16:19.127Z, "tags"=>["_rubyexception"], "@version"=>"1", "message"=>"x^\x8B\xAEV*\xCE\xCE\xCC\xC9)V\xB2R\x88V\xD26T07\xB7\xB0\xB4\xB44000W\x8A\xD5QPJ\xCE\xCF+IL.\u0001\xCA*)\u0001\xB9\xA9\xB9\x89\x999 N\x96C\x96^r~.X,\xA5\u0014(R\xADT\x9A\u000E6#\xA0\xB2$#?\u000F\xAC\xB9\u0000\"\xE2\u001C\xAC\u0014[\v\xE4\xE6%概\xF4z\u0001\xE9b%\xA0\xC8\xC0\xD9\u001D\v\u0000\u0003\x9ADk", "type"=>"kitlog-rabbitmq"}}


      Was trying different gzipping methods, but result is still the same. Also tried changing input codecs (plain - utf-8, plain - binary)










      share|improve this question















      everyone!
      I have logstash config, which forwards logs from RabbitMQ to elasticSearch. Something like this:



      input {
      rabbitmq {
      ...
      }
      }

      filter {
      if [type] == "rabbitmq" {
      json {
      source => "message"
      target => "message"
      }
      }
      }

      output {
      elasticsearch {
      hosts => ["${ES_HOST}"]
      user => "${ES_USERNAME}"
      password => "${ES_PASSWORD}"
      sniffing => false
      index => "kit_events-%{[message][elasticsearch][index]}"
      }
      }


      And we were forced to compress logs on a fly, because they are spending too much traffic.
      Logs were moved into array and gzipped.
      What is the correct way of configuring un-gzipping and splitting array back into objects?



      I did some research and found out that there is gzip_lines plugin and something on Ruby(?) to parse array, but I failed to implement it. Did anyone make something like this before?



      UPD:



      Added this filter



      filter {

      if [type] == "kitlog-rabbitmq" {
      ruby {
      init => "
      require 'zlib'
      require 'stringio'
      "
      code => "
      body = event.get('[http][response][body]').to_s
      sio = StringIO.new(body)
      gz = Zlib::GzipReader.new(sio)
      result = gz.read.to_s
      event.set('[http][response][body]', result)
      "
      }
      }
      }


      And now catching an error



      ERROR][logstash.filters.ruby    ] Ruby exception occurred: not in gzip format
      [DEBUG][logstash.pipeline ] output received {"event"=>{"@timestamp"=>2018-11-30T09:16:19.127Z, "tags"=>["_rubyexception"], "@version"=>"1", "message"=>"x^\x8B\xAEV*\xCE\xCE\xCC\xC9)V\xB2R\x88V\xD26T07\xB7\xB0\xB4\xB44000W\x8A\xD5QPJ\xCE\xCF+IL.\u0001\xCA*)\u0001\xB9\xA9\xB9\x89\x999 N\x96C\x96^r~.X,\xA5\u0014(R\xADT\x9A\u000E6#\xA0\xB2$#?\u000F\xAC\xB9\u0000\"\xE2\u001C\xAC\u0014[\v\xE4\xE6%概\xF4z\u0001\xE9b%\xA0\xC8\xC0\xD9\u001D\v\u0000\u0003\x9ADk", "type"=>"kitlog-rabbitmq"}}


      Was trying different gzipping methods, but result is still the same. Also tried changing input codecs (plain - utf-8, plain - binary)







      elasticsearch logstash logstash-configuration






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 30 at 10:41

























      asked Nov 22 at 16:17









      ikebastuz

      475




      475
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          So the content in rabbitmq is gzipped?



          In the best of all possible worlds, logstash would see the content-encoding header and unzip it for you, but the plugin doesn't seem to do anything with that knowledge. You might request the feature.



          The plugin does let you access the header, so you could do the gzip yourself. Something like this:



          filter {
          if [@metadata][rabbitmq_properties][content-encoding] == "gzip" {
          ruby {
          ...
          }
          }
          }


          Examples of unzipping a string with ruby exist elsewhere. Hopefully the 'zip' gem is available in logstash.






          share|improve this answer





















          • Thank you, I will give it a try!
            – ikebastuz
            Nov 28 at 10:06











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434887%2flogstash-un-gzip-array-log-configuration%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          So the content in rabbitmq is gzipped?



          In the best of all possible worlds, logstash would see the content-encoding header and unzip it for you, but the plugin doesn't seem to do anything with that knowledge. You might request the feature.



          The plugin does let you access the header, so you could do the gzip yourself. Something like this:



          filter {
          if [@metadata][rabbitmq_properties][content-encoding] == "gzip" {
          ruby {
          ...
          }
          }
          }


          Examples of unzipping a string with ruby exist elsewhere. Hopefully the 'zip' gem is available in logstash.






          share|improve this answer





















          • Thank you, I will give it a try!
            – ikebastuz
            Nov 28 at 10:06















          up vote
          1
          down vote



          accepted










          So the content in rabbitmq is gzipped?



          In the best of all possible worlds, logstash would see the content-encoding header and unzip it for you, but the plugin doesn't seem to do anything with that knowledge. You might request the feature.



          The plugin does let you access the header, so you could do the gzip yourself. Something like this:



          filter {
          if [@metadata][rabbitmq_properties][content-encoding] == "gzip" {
          ruby {
          ...
          }
          }
          }


          Examples of unzipping a string with ruby exist elsewhere. Hopefully the 'zip' gem is available in logstash.






          share|improve this answer





















          • Thank you, I will give it a try!
            – ikebastuz
            Nov 28 at 10:06













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          So the content in rabbitmq is gzipped?



          In the best of all possible worlds, logstash would see the content-encoding header and unzip it for you, but the plugin doesn't seem to do anything with that knowledge. You might request the feature.



          The plugin does let you access the header, so you could do the gzip yourself. Something like this:



          filter {
          if [@metadata][rabbitmq_properties][content-encoding] == "gzip" {
          ruby {
          ...
          }
          }
          }


          Examples of unzipping a string with ruby exist elsewhere. Hopefully the 'zip' gem is available in logstash.






          share|improve this answer












          So the content in rabbitmq is gzipped?



          In the best of all possible worlds, logstash would see the content-encoding header and unzip it for you, but the plugin doesn't seem to do anything with that knowledge. You might request the feature.



          The plugin does let you access the header, so you could do the gzip yourself. Something like this:



          filter {
          if [@metadata][rabbitmq_properties][content-encoding] == "gzip" {
          ruby {
          ...
          }
          }
          }


          Examples of unzipping a string with ruby exist elsewhere. Hopefully the 'zip' gem is available in logstash.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 27 at 19:37









          Alain Collins

          13.4k12147




          13.4k12147












          • Thank you, I will give it a try!
            – ikebastuz
            Nov 28 at 10:06


















          • Thank you, I will give it a try!
            – ikebastuz
            Nov 28 at 10:06
















          Thank you, I will give it a try!
          – ikebastuz
          Nov 28 at 10:06




          Thank you, I will give it a try!
          – ikebastuz
          Nov 28 at 10:06


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434887%2flogstash-un-gzip-array-log-configuration%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          Alexandru Averescu

          Trompette piccolo