Created
November 29, 2016 08:45
-
-
Save Zazcallabah/5beb88a114e0fe71961b743009dca429 to your computer and use it in GitHub Desktop.
Dashing dependency status
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
{ | |
"info" : { | |
"buildId" : "20161128.7", | |
"buildDate" : "2016-11-28 14:01:33Z", | |
"commitHash" : "5a0bf8b4c25b897f0dee3c7e315422e96a182472", | |
"deployDate" : "2016-11-28 14:03:44Z", | |
"error" : null | |
}, | |
"dependencies" : [{ | |
"name" : "Api1", | |
"host" : "http://s1", | |
"versionInfo" : { | |
"buildId" : null, | |
"buildDate" : null, | |
"commitHash" : null, | |
"deployDate" : null, | |
"error" : "Error: NotFound" | |
} | |
}, { | |
"name" : "Api2", | |
"host" : "http://s2", | |
"versionInfo" : { | |
"buildId" : "20161128.1", | |
"buildDate" : "2016-11-28 17:28:29Z", | |
"commitHash" : "5169b7e32440274cbb00fb5e2354a8c8c1cb4245", | |
"deployDate" : "2016-11-28 17:29:53Z", | |
"error" : null | |
} | |
}, { | |
"name" : "Api3", | |
"host" : "http://s3", | |
"versionInfo" : { | |
"buildId" : "Client-20161128.2", | |
"buildDate" : "2016-11-28 17:28:43Z", | |
"commitHash" : "6a69b7e32410274ccb00fb5e2354a8c8c1cb4245", | |
"deployDate" : "2016-11-28 17:30:03Z", | |
"error" : null | |
} | |
} | |
] | |
} |
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 'uri' | |
require 'json' | |
require 'time' | |
def getDependencyInfo(urlstr) | |
uri = URI.parse(urlstr) | |
http = Net::HTTP.new(uri.host, uri.port) | |
request = Net::HTTP::Get.new(uri.request_uri) | |
response = http.request(request) | |
return response | |
end | |
def since(timestr) | |
if timestr == nil | |
return nil | |
end | |
a = Time.parse(timestr) | |
b = Time.new().utc | |
s = (b-a) | |
if s < 90 then | |
res = s.round.to_s+"s" | |
elsif s < 90*60 then | |
res = (s/60).round.to_s+"m" | |
elsif s < 30*3600 then | |
res = (s/3600).round.to_s+"h" | |
else | |
res = (s/(3600*24)).round.to_s+"d" | |
end | |
return res | |
end | |
def fixData(urlstr) | |
begin | |
response = getDependencyInfo(urlstr) | |
if response.code == "200" | |
data = JSON.parse(response.body) | |
if data.key?("info") && data["info"].key?("deployDate") | |
data["info"]["since"] = since( data["info"]["deployDate"] ) | |
end | |
data["dependencies"].each { |dep| | |
if dep.key?("versionInfo") && dep["versionInfo"].key?("deployDate") | |
dep["versionInfo"]["since"] = since( dep["versionInfo"]["deployDate"] ) | |
end | |
} | |
return data | |
end | |
return { "info" => {"since" => "" }, "dependencies" => [] } | |
rescue Exception => e | |
return { "info" => {"since" => "" }, "dependencies" => [] } | |
end | |
end |
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
SCHEDULER.every '30s' do | |
data = fixData('http://example.uri/api') # see data.json | |
send_event('s1', data) | |
end | |
SCHEDULER.every '30s' do | |
data = fixData('http://example2.uri/api') # see data.json | |
send_event('s2', data) | |
end | |
SCHEDULER.every '30s' do | |
data = fixData('http://example3.uri/api') # see data.json | |
send_event('s3', data) | |
end | |
SCHEDULER.every '30s' do | |
data = fixData('http://example4.uri/api') # see data.json | |
send_event('s4', data) | |
end |
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
<% content_for :title do %>QA Dashboard<% end %> | |
<div class="gridster"> | |
<ul> | |
<li data-row="1" data-col="1" data-sizex="1" data-sizey="2"> | |
<div data-id="s1" data-view="ServerStatus" data-title="S1"></div> | |
</li> | |
<li data-row="1" data-col="2" data-sizex="1" data-sizey="2"> | |
<div data-id="s2" data-view="ServerStatus" data-title="S2" style="background-color: #0b0"></div> | |
</li> | |
<li data-row="1" data-col="3" data-sizex="1" data-sizey="2"> | |
<div data-id="s3" data-view="ServerStatus" data-title="S3" style="background-color: #ec0"></div> | |
</li> | |
<li data-row="1" data-col="3" data-sizex="1" data-sizey="2"> | |
<div data-id="s4" data-view="ServerStatus" data-title="S4" style="background-color: #b0e"></div> | |
</li> | |
</ul> | |
</div> |
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
class Dashing.ServerStatus extends 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
<h1 class="title" data-bind="title"></h1> | |
<p class="subtitle"> | |
Last deploy: <span data-bind="info.since"></span> | |
<span class="red" data-removeif="info.since"><i class="fa fa-exclamation-circle"></i></span> | |
</p> | |
<p><strong>Dependencies</strong></p> | |
<ul> | |
<li data-foreach-item="dependencies"> | |
<span class="label" data-bind="item.name"></span> | |
<span class="value" data-bind="item.versionInfo.since"></span> | |
<span class="value" data-removeif="item.versionInfo.since"><div class="red"><i class="fa fa-exclamation-circle"></i></div></span> | |
</li> | |
</ul> | |
<p class="more-info" data-bind="moreinfo"></p> | |
<p class="updated-at" data-bind="updatedAtMessage"></p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment