#! /usr/bin/perl -w

# lpd check module

# Version: $Revision: 0.1 $
# Author: Matt Selsky <selsky@columbia.edu>
# Date: $Date: 2004/06/11 22:02:44 $

# Copyright (c) 2002 - 2003
# The Trustees of Columbia University in the City of New York
# Academic Information Systems
# 
# License restrictions apply, see doc/license.html for details.

use strict;
use FindBin;
use lib "$FindBin::Bin/../common";
use Survivor::Check;

use Net::Printer;

my %argfmt = ('queue' => 'string');

my $sc = new Survivor::Check();

$sc->GetOpt(\%argfmt, \&LpdValidate);

my $r = $sc->Exec( \&LpdCheck);

exit($r);

sub LpdValidate {
    return(MODEXEC_OK, 0, 'Lpd OK');
}

sub LpdCheck {
    my $self = shift;
    my $host = shift;

    my $queue = $self->Arg('queue');

    my $lp = new Net::Printer( server => $host,
			       printer => $queue );

    my @result;

    eval {
	@result = $lp->queuestatus();
    };
    if ($@) {
	print $@, "\n";
    } else {
	print @result;
    }

    exit;

    return(MODEXEC_PROBLEM, 0, "Connection failed: $!")
	unless @result;

    foreach (@result) {
	print "line: ", $_;
    }

    print "\n";

    return(MODEXEC_OK, 1, "foo");
}
