Skip to content

Instantly share code, notes, and snippets.

@tonyklawrence
Created November 22, 2013 09:04
Show Gist options
  • Save tonyklawrence/7596999 to your computer and use it in GitHub Desktop.
Save tonyklawrence/7596999 to your computer and use it in GitHub Desktop.
Evironments Dashing Widget
require 'net/http'
require 'json'
environments = {}
SCHEDULER.every '30s' do
status = 'good'
environments['Prod'] = { label: 'Production', value: health('http://prod/openapi/dashboard/health') }
environments['UAT'] = { label: 'User Testing', value: health('http://suat/openapi/dashboard/health') }
environments['Dev'] = { label: 'Development', value: health('http://dev/openapi/dashboard/health') }
environments['Koala'] = { label: 'App', value: ping('http://app/Ping') }
environments.each do |i|
status='warning' if i[1][:value] != 'Up'
end
send_event('environments', { items: environments.values, status: status })
end
def ping(url)
begin
Net::HTTP.get(URI(url)) == 'Pong' ? 'Up' : 'Down'
rescue Exception
'Down'
end
end
def health(url)
begin
response = Net::HTTP.get(URI(url))
JSON.parse(response)['database'] == 'ok' ? 'Up' : 'Down'
rescue Exception
'Down'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment