#!/moira/bin/perl -Tw

# $Id: nagios-cluster.gen 4047 2011-08-22 21:04:03Z jweiss $
# The following exit codes are defined and MUST BE CONSISTENT with the
# error codes the library uses:
$MR_DBMS_ERR = 47836421;
$MR_OCONFIG = 47836460;

$outfile = '/moira/dcm/printer-list.out';

use DBI;

umask 022;
open(OUT, ">$outfile") || exit $MR_OCONFIG;

$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
  || exit $MR_DBMS_ERR;

$sth0 = $dbh->prepare("SELECT UNIQUE m.name FROM machine m, printers p " .
		      "WHERE (p.type = 'DORM' OR p.type ='CLUSTER') " .
		      "AND p.mach_id = m.mach_id AND m.status=1 " .
		      "AND (p.status=4 OR p.status=1)")
	|| exit $MR_DBMS_ERR;

$sth0->execute || exit $MR_DBMS_ERR;

while (($name) = $sth0->fetchrow_array) {
    next if $name eq "[NONE]";
    print OUT "$name\n";
}

close(OUT);
$dbh->disconnect;

exit 0;
