#!/moira/bin/perl -Tw
# $Id: spwatch.gen 4051 2011-09-08 18:46:37Z zacheiss $
#
# 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/spwatch.out';

use DBI;

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

$sth = $dbh->prepare("SELECT m.name FROM printers p, ".
		     "machine m WHERE p.type = 'SAP' AND p.mach_id = ".
		     "m.mach_id AND (p.status = 1 OR p.status = 2 OR p.status = 4) AND m.status != 3 " .
		     "ORDER BY m.name") || exit $MR_DBMS_ERR;

$sth->execute || exit $MR_DBMS_ERR;

umask 022;
open(OUT, ">$outfile") || exit $MR_OCONFIG;
print OUT "# This File is automatically generated by Moira.  Do not edit.\n";

while (($hostname) = $sth->fetchrow_array) {
    next if $hostname eq "[NONE]";
    $row = "$hostname\n";
    $row =~ s/\0//g;
    print OUT $row;
}

close OUT;
exit 0;
