Sha256: 528b0ca593771817cbc5574a7a51d6c980b064f146c3b1c8115bafa393da8939

Contents?: true

Size: 812 Bytes

Versions: 1

Compression:

Stored size: 812 Bytes

Contents

require "open3"

module Sensu
  module Push
    class Check
      attr_reader :name, :namespace, :output, :status

      def initialize(options={})
        @options = options
        @name = @options[:check_name]
        @namespace = @options.fetch(:namespace, "default")
      end

      def exec!
        stdin, stdout, stderr, wait = Open3.popen3(@options[:command])
        @output = "#{stdout.read}\n#{stderr.read}"
        @status = wait.value.exitstatus
        [@output, @status]
      end

      def to_hash
        {
          :metadata => {
            :name => @name,
            :namespace => @namespace
          },
          :command => @options[:command],
          :output => @output,
          :status => @status,
          :ttl => @options.fetch(:ttl, 0)
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sensu-push-0.3.0 lib/sensu/push/check.rb