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.1.3.1 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.1.3 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.1.2 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.1.1 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.1.0 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.9 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.8 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.7 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.6.1 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.6 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.5 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.4 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.3.2 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.3.1 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.3 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.2 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.1 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.0 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.0pre15 lib/riemann/babbler/plugins/helpers/shell.rb
riemann-babbler-2.0.0pre13 lib/riemann/babbler/plugins/helpers/shell.rb