require 'hpricot' require 'open-uri' require 'x10/cm17a' def there_are_failing_builds() retry_count = 0 begin doc = Hpricot(open("http://teamcity:8080/externalStatus.html")) failingBuildElements = doc.search("//img[@title='Build configuration is failing']") return (failingBuildElements.length > 0) rescue if retry_count < 3 retry_count += 1 puts "Network not available. Sleeping for 10 seconds then retrying" sleep 10 #Wait for a bit to see if the network will come up retry else puts "Could not open web page (Network is down?)" return false end end end def turn_on_lamp() puts "BUILD BROKEN! Turning On Lamp" #Do it twice because sometimes the first doesn't take X10.device('C1').on X10.device('C1').on end def turn_off_lamp() #Do it twice because sometimes the first doesn't take puts "Build A-Ok! Turning off lamp" X10.device('C1').off X10.device('C1').off end puts "Welcome to the Build Monitor" while(true) if(there_are_failing_builds()) turn_on_lamp() else turn_off_lamp() end puts "Next status check in 60 seconds..." sleep 60 end