Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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