Sha256: 4c6a5564922b4cbd78ae861bed7a73340997c3669f658c6d5f39a2d1948ce9ef
Contents?: true
Size: 1.68 KB
Versions: 2
Compression:
Stored size: 1.68 KB
Contents
module LitmusPaper module CLI class AgentCheck def parse_args(args) options = {} optparser = OptionParser.new do |opts| opts.on("-s", "--service SERVICE", "Service to check") do |s| options[:service] = s end opts.on("-c", "--config CONFIG", "Path to config file") do |c| options[:config] = c end opts.on("-h", "--help", "Help text") do |h| options[:help] = h end end begin optparser.parse! args rescue OptionParser::InvalidOption => e puts e puts optparser exit 1 end if options[:help] puts optparser exit 0 end if !options.has_key?(:service) puts "Error: `-s SERVICE` required" puts optparser exit 1 end options end def output_service_status(service, stdout) output = [] health = LitmusPaper.check_service(service) if health.nil? output << "failed#NOT_FOUND" else case health.direction when :up, :health output << "ready" when :down output << "drain" when :none if health.ok? output << "ready" else output << "down" end end output << "#{health.value.to_s}%" end stdout.printf("%s\r\n", output.join("\t")) end def run(args) options = parse_args(args) LitmusPaper.configure(options[:config]) output_service_status(options[:service], $stdout) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
litmus_paper-0.9.5 | lib/litmus_paper/cli/agent_check.rb |
litmus_paper-0.9.4 | lib/litmus_paper/cli/agent_check.rb |