Sha256: dc2815de446f3a57e4aeef8aae90ee989b63d6ef0033fb0d627a7b4308724fb7

Contents?: true

Size: 899 Bytes

Versions: 51

Compression:

Stored size: 899 Bytes

Contents

#encoding: utf-8

require 'open3'

module Riemann
  module Babbler
    module Plugins
      module Helpers

        # helper: stdout+stderr и exit status
        def shell(*cmd)
          exit_status=nil
          err        =nil
          out        =nil
          Timeout::timeout(plugin.timeout) {
            Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thread|
              err = stderr.gets(nil)
              out = stdout.gets(nil)
              [stdin, stdout, stderr].each { |stream| stream.send('close') }
              exit_status = wait_thread.value
            end
          }
          if exit_status.to_i > 0
            err = err.chomp if err
            raise 'Error while running shell: ' + err.to_s
          elsif out
            return out.strip
          else
            # exit status 0, no stdout
            ''
          end
        end

      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
riemann-babbler-2.8.5 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.8.4 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.8.3 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.8.2 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.8.1 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.8.0 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.6.0 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.5.9 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.5.8 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.5.7 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.5.6 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.5.5 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.5.4 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.5.3 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.5.2 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.5.1 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.5.0 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.1.5 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.1.4 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.1.3.2 lib/riemann/babbler/plugins/helpers/shell.rb