Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Created May 20, 2014 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jtimberman/4758fe39765bdc2bdd31 to your computer and use it in GitHub Desktop.
Save jtimberman/4758fe39765bdc2bdd31 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
url = 'https://api.berkshelf.com/status'
begin
statusjson = JSON.parse(open(url).readlines[0])
rescue OpenURI::HTTPError => error
httpresp = error.io
if httpresp.status.first != 200
puts "CRITICAL: Berkshelf API web server or network is NOT ok! HTTP response #{httpresp.status} received when retrieving '#{url}'"
exit 2
end
rescue SocketError, Errno::ECONNREFUSED => error
puts "CRITICAL: Berkshelf API returned #{error.message} for #{url}"
exit 2
end
case statusjson['cache_status']
when 'ok'
puts 'OK: Berkshelf API cache_status is ok'
exit 0
when 'warming'
puts "CRITICAL: Berkshelf API cache_status is warming! Client requests will fail."
exit 2
else
puts "UNKNOWN: Berkshelf API cache_status is unknown: '#{statusjson['cache_status']}'?"
exit 3
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment