From dd0a3b61c4705505e20680fa724a4a19928b8026 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 22 Apr 2016 18:42:58 +0200 Subject: [PATCH] feature #4296: Compress output of run_probes and uncompress it in oned to better deal with the UDP message size limit. --- src/common/NebulaUtil.cc | 20 ++++++++++++++++--- src/im/MonitorThread.cc | 12 +++++++++-- .../remotes/common.d/collectd-client.rb | 4 +++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/common/NebulaUtil.cc b/src/common/NebulaUtil.cc index 675cb40621..983a58c430 100644 --- a/src/common/NebulaUtil.cc +++ b/src/common/NebulaUtil.cc @@ -305,9 +305,9 @@ std::string one_util::trim(const std::string& str) std::string::const_iterator wlast(rwlast.base()); - std::string tstr(wfirst, wlast); + std::string tstr(wfirst, wlast); - return tstr; + return tstr; } /* -------------------------------------------------------------------------- */ @@ -449,12 +449,26 @@ std::string * one_util::zlib_decompress(const std::string& in, bool base64) zs.next_in = (unsigned char *) const_cast(in.c_str()); } + if ( zs.avail_in <= 2 ) //At least 2 byte header + { + inflateEnd(&zs); + + if ( base64 ) + { + delete in64; + } + + return 0; + } + do { zs.avail_out = ZBUFFER; zs.next_out = out; - if ( (rc = inflate(&zs, Z_FINISH)) == Z_STREAM_ERROR ) + rc = inflate(&zs, Z_FINISH); + + if ( rc != Z_STREAM_END && rc != Z_OK && rc != Z_BUF_ERROR ) { inflateEnd(&zs); diff --git a/src/im/MonitorThread.cc b/src/im/MonitorThread.cc index 0a560b0e3f..99ef9e42af 100644 --- a/src/im/MonitorThread.cc +++ b/src/im/MonitorThread.cc @@ -66,11 +66,19 @@ extern "C" void * do_message_thread(void *arg) void MonitorThread::do_message() { // ------------------------------------------------------------------------- - // Decode from base64 + // Decode from base64, check if it is compressed // ------------------------------------------------------------------------- string* hinfo = one_util::base64_decode(hinfo64); + string* zinfo = one_util::zlib_decompress(*hinfo, false); - Host* host = hpool->get(host_id,true); + if ( zinfo != 0 ) + { + delete hinfo; + + hinfo = zinfo; + } + + Host* host = hpool->get(host_id,true); if ( host == 0 ) { diff --git a/src/im_mad/remotes/common.d/collectd-client.rb b/src/im_mad/remotes/common.d/collectd-client.rb index 95807d0c55..3e687f1dc0 100644 --- a/src/im_mad/remotes/common.d/collectd-client.rb +++ b/src/im_mad/remotes/common.d/collectd-client.rb @@ -20,6 +20,7 @@ require 'socket' require 'base64' require 'resolv' require 'ipaddr' +require 'zlib' DIRNAME = File.dirname(__FILE__) @@ -68,7 +69,8 @@ class CollectdClient data = `#{@run_probes_cmd} 2>&1` code = $?.exitstatus == 0 - data64 = Base64::encode64(data).strip.delete("\n") + zdata = Zlib::Deflate.deflate(data, Zlib::BEST_COMPRESSION) + data64 = Base64::encode64(zdata).strip.delete("\n") [data64, code] end