Sha256: 0dbad75c22f58903767c6c89f5e7ba1bc6e48ae5205dc0054eec1e5026444658

Contents?: true

Size: 1.13 KB

Versions: 11

Compression:

Stored size: 1.13 KB

Contents

#encoding: utf-8

module Riemann
  class Babbler

    def helper_error(msg = "Unknown helper error")
      report({
        :service => plugin.service,
        :state => 'critical',
        :description => msg
      })      
    end

    # хэлпер для парса stdout+stderr и exit status
    def shell(*cmd)
      exit_status=nil
      err=nil
      out=nil
      begin
      Timeout::timeout(5) {
        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
      }
      rescue => e
        helper_error "#{e.class} #{e}\n#{e.backtrace.join "\n"}"
      end
      if exit_status.to_i > 0
        err = err.chomp if err
        helper_error(err)
      elsif out
        return out.chomp
      else
        # статус 0, вывода stdout нет
        return ""
      end
    end

    # http rest 
    def rest_get(url)
      begin
        RestClient.get url
      rescue
        helper_error("Get from url: #{url}")
      end
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
riemann-babbler-0.6.0 lib/riemann/babbler/plugin_helpers.rb
riemann-babbler-0.5.9 lib/riemann/babbler/plugin_helpers.rb
riemann-babbler-0.5.8 lib/riemann/babbler/plugin_helpers.rb
riemann-babbler-0.5.7 lib/riemann/babbler/plugin_helpers.rb
riemann-babbler-0.5.6 lib/riemann/babbler/plugin_helpers.rb
riemann-babbler-0.5.5 lib/riemann/babbler/plugin_helpers.rb
riemann-babbler-0.5.4 lib/riemann/babbler/plugin_helpers.rb
riemann-babbler-0.5.3 lib/riemann/babbler/plugin_helpers.rb
riemann-babbler-0.5.2 lib/riemann/babbler/plugin_helpers.rb
riemann-babbler-0.5.1 lib/riemann/babbler/plugin_helpers.rb
riemann-babbler-0.5.0 lib/riemann/babbler/plugin_helpers.rb