Created
November 22, 2013 09:04
-
-
Save tonyklawrence/7596999 to your computer and use it in GitHub Desktop.
Evironments Dashing Widget
This file contains hidden or 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
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