Created
May 25, 2011 20:46
-
-
Save nicklewis/991917 to your computer and use it in GitHub Desktop.
Jenkins lava lamp
This file contains 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
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'uri' | |
require 'rubygems' | |
require 'atom' | |
# Light lava lamps based on Jenkins build status RSS feed | |
# Green lamp lights if all builds are good; | |
# Red lamp lights if any build fails. | |
# | |
# Requires atom gem and bottlerocket X10 control software to be installed. | |
# | |
class JenkinsLava | |
def initialize | |
@BOTTLE_ROCKET_COMMAND="/usr/local/bin/br" | |
@GREEN_LAMP='1' # codes set on X10 lamp moduels | |
@RED_LAMP='2' | |
end | |
def usage | |
puts "jenkinsLava [jenkinsRssFeedUrl]" | |
puts " Light lava lamps based on Jenkins build status RSS feed." | |
puts " jenkinsRssFeedUrl: URL of RSS feed for builds you want to monitor; must contain SUCCESS and FAILURE messages." | |
end | |
def parse_args | |
if ARGV.size == 1 then | |
@FEED_URL = ARGV[0] | |
else | |
usage | |
exit | |
end | |
end | |
def get_rss_feed(feed) | |
data = `curl #{feed} 2> /dev/null` | |
Atom::Feed.new(data) | |
end | |
def parse_rss_feed(feed_data) | |
feed_data.entries.map do |entry| | |
entry.title =~ /(.+)\s+#\w+\s\(([\w ]+)\)/ | |
{$1 => $2} | |
end.inject(&:merge) | |
end | |
def get_failed_builds(build_data) | |
build_data.select {|name, status| status.include? 'broken'}.map(&:first) | |
end | |
def lava_lamp(status, lamp) | |
system "#{@BOTTLE_ROCKET_COMMAND} --#{status}=#{lamp}" | |
end | |
def light_green_lamp | |
lava_lamp("on", @GREEN_LAMP) | |
lava_lamp("off", @RED_LAMP) | |
end | |
def light_red_lamp | |
lava_lamp("on", @RED_LAMP) | |
lava_lamp("off", @GREEN_LAMP) | |
end | |
def light_lava_lamp(failed_builds) | |
if failed_builds.empty? | |
puts "No failed builds- lamp is green." | |
light_green_lamp | |
else | |
puts "Failed builds- lamp is red:" | |
failed_builds.each do |name| | |
puts "\t#{name}" | |
end | |
light_red_lamp | |
end | |
end | |
def main | |
parse_args | |
feed_data = get_rss_feed(@FEED_URL) | |
build_data = parse_rss_feed(feed_data) | |
failed_builds = get_failed_builds(build_data) | |
light_lava_lamp(failed_builds) | |
end | |
end | |
if $0 == __FILE__ | |
JenkinsLava.new.main | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment