Mon, 26 Jan 2009

Checking portsmon

When tabthorpe and thierry mentored me, tabthorpe told me I have to be reactive with pointyhat and to check portsmon *regularly*. Each time I committed something to the ports tree (PR, or update), I would have a look on portsmon, in spite of all my own tests before committing!
It's a pain to check all your last commits and it's a really embarassing to receive pointyhat mail. So, I wrote a little ruby script.

#! /usr/local/bin/ruby

require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'timeout'
require 'rss'

i = 0

if ARGV.length != 2
	puts "./check_portsmon.rb check your ports commit on portsmon"
	puts "Usage: ./check_portsmon.rb commiter_name xml_limit"
	puts "Example: ./check_portsmon.rb mylogin 20"
	exit 0
end

url = "http://cia.vc/stats/author/" + ARGV[0] + "/.rss?ver=2&medium=plaintext&limit=" + ARGV[1]
flux_result, rss = nil

begin
	timeout(10) do
		open(url) do |s| flux_result = s.read end
		begin
			rss = RSS::Parser.parse(flux_result)
		rescue RSS::InvalidRSSError
			rss = RSS::Parser.parse(flux_result, false)
		end
	end
rescue StandardError => boom
	puts "Error: #{boom}"
rescue Timeout::Error => time
	puts "Error: #{time}"
	exit 0
end

if rss.items[i] != nil
	while i != ARGV[1].to_i
		if rss.items[i].description != nil && rss.items[i].description =~ /([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+)/
			if $1 == "ports"
				uri = "http://portsmon.freebsd.org/portoverview.py?category=" + $2 + "&portname=" + $3
			puts "Testing  #{$1}/#{$2}/#{$3}"
			@portsmon = Hpricot(open(uri))
			@portsmon.search("td.error").each do |e|
				if e.inner_html =~ /([A-Z]{1}[a-z]{2,3}) ([A-Z]{1}[a-z]{2,3}) ([\d]{1,4})/ 
					puts "Date: #{$1} #{$2} #{$3}"
				end
				if e.inner_html =~ /href="(.*\/)#(.*)">/
					puts "Error: #{$2}"
				end
				if e.inner_html =~ /href="(.*.log)"/
					puts "Go to #{$1}"
				end
			end
			end
		end
		i += 1
	end
else
	print "Commiter name invalid"
	exit 1
end

This script will check for you, your n last commit on portsmon. It parses cia.vc and take only the ports commits.
Here is an example:
I commit only in ports and I want to check my last 20 commits:
./check_portsmon.rb jadawin 20
Testing  ports/net-mgmt/p5-Net-CIDR
Testing  ports/archivers/p5-Archive-Tar
Testing  ports/sysutils/phplogcon
Testing  ports/www/hiawatha
Testing  ports/www/p5-Web-Scraper
Testing  ports/math/p5-Math-BaseCalc
Testing  ports/net/spoofer
Testing  ports/devel/p5-EV
Testing  ports/mail/p5-Mail-IMAPClient
Testing  ports/finance/p5-Finance-Currency-Convert
Testing  ports/www/p5-Web-Scraper
Testing  ports/astro/p5-Astro-SpaceTrack
Testing  ports/www/p5-libwww
Testing  ports/audio/ampache
Testing  ports/astro/p5-Astro-SpaceTrack
Testing  ports/security/vuxml
Testing  ports/net/nepim
Testing  ports/devel/p5-Config-General
Testing  ports/sysutils/hammerhead
Testing  ports/misc/p5-Array-Compare
tabthorpe@ commits in ports and in docs and he wants to check his last 10 commits:
./check_portsmon.rb tabthorpe 10
Testing  ports/editors/dkns
Testing  ports/x11-wm/nickleby
Testing  ports/x11-wm/nickleby
Testing  ports/mail/squirrelmail-vlogin-plugin
Testing  ports/mail/squirrelmail-password_forget-plugin
Yeah. Only 5. Because, his has only 5 ports commits in his last 10 commits.
What happens if there is an error on portsmon?
You will see:
Testing  ports/security/ossec-hids-client
Go to http://pointyhat.FreeBSD.org/errorlogs/sparc64-errorlogs/e.6.20090112004632/ossec-hids-client-1.6.log
Error: mtree
Date: Wed Jan 7
Go to http://pointyhat.FreeBSD.org/errorlogs/sparc64-errorlogs/e.6.20090112011936/ossec-hids-client-1.6.log
Error: mtree
Date: Mon Jan 12
A direct link to pointyhat's log, error type and when it happened.

I wrote this script to help commiters to be more reactive. Don't think I had a lot of pointyhat's mails :-)
Please, feel free to download it here. You need www/rubygem-hpricot to run check_portsmon.

I you use this script, please, give me feedback, good or bad!

posted at: 10:14 | tag: freebsd | path: /freebsd | permanent link to this entry