The SQL base nagios class could probably have some factorized code around here too.