Sha256: 6209d85938ae84af58afa4fe60e367185b42e9f5d6c1a708f1fa95c0ea993616

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 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_shell = ( plugin.interval * 2 ).to_f/3
      Timeout::timeout(timeout_shell) {
        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.strip
      else
        # статус 0, вывода stdout нет
        ''
      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

2 entries across 2 versions & 1 rubygems

Version Path
riemann-babbler-0.9.7 lib/riemann/babbler/plugin_helpers.rb
riemann-babbler-0.9.6 lib/riemann/babbler/plugin_helpers.rb