Skip to content

Instantly share code, notes, and snippets.

@decklin
Created December 9, 2011 19:03
Show Gist options
  • Save decklin/1452832 to your computer and use it in GitHub Desktop.
Save decklin/1452832 to your computer and use it in GitHub Desktop.
require 'mixlib/cli'
EXIT_CODES = {
'OK' => 0,
'WARNING' => 1,
'CRITICAL' => 2,
'UNKNOWN' => 3,
}
class Sensu
class Check
class CLI
include Mixlib::CLI
EXIT_CODES.each do |status, code|
define_method(status.downcase) do |msg|
puts "#{status}: #{msg}"
code
end
end
def run
unknown "No check implemented! You should override Sensu::Check::CLI#run."
end
@@autorun = self
class << self
def method_added(name)
if name == :run
@@autorun = self
end
end
end
at_exit do
check = @@autorun.new
check.parse_options
exit(check.run)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment