Skip to content

Commit 5e6ab7f

Browse files
Got enough working now to set up a build monitor of a hudson build.
1 parent c01a1f6 commit 5e6ab7f

3 files changed

Lines changed: 120 additions & 0 deletions

File tree

‎greenscreen.rb‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require 'rubygems'
2+
require 'sinatra'
3+
require 'erb'
4+
require 'rexml/document'
5+
require 'hpricot'
6+
require 'open-uri'
7+
8+
get '/' do
9+
@projects = []
10+
11+
servers = YAML.load_file 'config.yml'
12+
13+
return "Add the details of build server to the config.yml file to get started" unless servers
14+
15+
servers.each do |server|
16+
xml = REXML::Document.new(open(server["url"], :http_basic_authentication=>[server["username"], server["password"]]))
17+
projects = xml.elements["//Projects"]
18+
@projects = @projects + projects.collect {|project| Project.new(project)}
19+
end
20+
21+
@columns = 1.0
22+
@columns = 2.0 if @projects.size > 4
23+
@columns = 3.0 if @projects.size > 10
24+
@columns = 4.0 if @projects.size > 21
25+
26+
@rows = (@projects.size / @columns).ceil
27+
28+
erb :index
29+
end
30+
31+
class Project
32+
attr_reader :name, :last_build_status, :activity, :last_build_time, :web_url, :last_build_label
33+
34+
def initialize(project)
35+
@activity = project.attributes["activity"]
36+
@last_build_time = Time.parse(project.attributes["lastBuildTime"]).localtime
37+
@web_url = project.attributes["webUrl"]
38+
@last_build_label = project.attributes["lastBuildLabel"]
39+
@last_build_status = project.attributes["lastBuildStatus"].downcase
40+
@name = project.attributes["name"]
41+
end
42+
end

‎public/styles.css‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
body {
2+
text-align: center;
3+
font-size: small;
4+
margin: 0;
5+
}
6+
7+
div {
8+
margin: 0
9+
padding: 0;
10+
}
11+
12+
h1 {
13+
margin-bottom: 0;
14+
padding: 0;
15+
}
16+
17+
a {
18+
text-decoration: none;
19+
color: #000000;
20+
}
21+
22+
.clear {
23+
border: none;
24+
clear: both;
25+
}
26+
27+
.status {
28+
float: left;
29+
}
30+
31+
.border {
32+
height: 100%;
33+
border: black 1px solid;
34+
}
35+
36+
.success {
37+
background-color: #76EE00;
38+
}
39+
40+
.failure {
41+
background-color: #FA8072;
42+
}
43+
44+
.unknown {
45+
background-color: #999999;
46+
}
47+
48+
.building {
49+
text-decoration: blink;
50+
}

‎views/index.erb‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<html>
2+
<head>
3+
<title>Green Screen - Monitor Your Builds</title>
4+
<meta http-equiv="refresh" content="15" />
5+
<link rel='stylesheet' href='/styles.css' type='text/css' media="screen">
6+
</head>
7+
<body>
8+
<style type="text/css">
9+
.status {
10+
width: <%= 100 / @columns %>%;
11+
height: <%= 100 / @rows %>%;
12+
}
13+
h1 {
14+
margin-top: <%= 50 / @rows %>px;
15+
font-size: <%= 100 / @rows * 3 %>px;
16+
}
17+
</style>
18+
19+
<% @projects.each do |project| %>
20+
<div class="status <%= project.last_build_status %>">
21+
<div class='border'>
22+
<h1 class="<%= project.activity %>"><a href="<%= project.web_url%>"><%= project.name %></a></h1>
23+
Build <%= project.last_build_label %> was a <%= project.last_build_status %> at <%= project.last_build_time %>
24+
</div>
25+
</div>
26+
<% end %>
27+
</body>
28+
</html>

0 commit comments

Comments
 (0)