Sha256: ab94497ade9a6ca9da4b6ced0a50a6959f63ae2b1541c775ee8048f493e16bec

Contents?: true

Size: 968 Bytes

Versions: 1

Compression:

Stored size: 968 Bytes

Contents

require "open3"

module Sensu
  module Run
    class Check
      attr_reader :output, :status

      def initialize(options={})
        @options = options
      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 event
        {
          :entity => {
            :metadata => {
              :name => @options[:entity_name],
              :namespace => @options.fetch(:namespace, "default")
            },
            :entity_class => "proxy"
          },
          :check => {
            :metadata => {
              :name => @options[:check_name],
              :namespace => @options.fetch(:namespace, "default")
            },
            :command => @options[:command],
            :output => @output,
            :status => @status
          }
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sensu-run-0.1.0 lib/sensu/run/check.rb