Skip to content

Instantly share code, notes, and snippets.

@gnilchee
Created October 31, 2017 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnilchee/6f6abb08c52282ecac9434e282bea514 to your computer and use it in GitHub Desktop.
Save gnilchee/6f6abb08c52282ecac9434e282bea514 to your computer and use it in GitHub Desktop.
Crystal-Lang example using http/client, logger and option_parser
require "http/client"
require "option_parser"
require "logger"
destination = "changeme"
help = ""
log = Logger.new(STDOUT)
log.level = Logger::INFO
OptionParser.parse! do |parser|
parser.banner = "Usage: #{PROGRAM_NAME} (-d NAME | --destination=NAME)"
parser.on("-d NAME", "--destination=NAME", "Defines endpoint to inspect (prod-1 or prod-2)") { |name| destination = name}
parser.on("-h", "--help", "Show this help") { puts parser }
end
if destination == "changeme"
log.error("Please supply a valid endpoint to test!")
exit 1
end
resp = HTTP::Client.get "http://#{destination}.example.io/api/master"
if resp.status_code == 200 && resp.body == "true"
log.info("Yes, #{destination} is master")
exit 0
else
log.warn("No, #{destination} is NOT master")
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment