Created
May 20, 2014 22:09
-
-
Save jtimberman/4758fe39765bdc2bdd31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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