#!/usr/bin/perl -w

# showmount check module

# Version: $Revision: 0.7 $
# Author: Benjamin Oshrin
# Date: $Date: 2003/01/29 01:27:17 $
#
# 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;

my %argfmt = ();

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

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

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

exit($r);

sub ShowmountValidate {
    return(MODEXEC_OK, 0, 'Showmount OK');
}

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

    my $SHOWMOUNT = $self->Which('showmount');

    defined $SHOWMOUNT or
	return(MODEXEC_MISCONFIG, 0, 'showmount executable not found');

    open(ANSWER, "$SHOWMOUNT -e $host 2>&1 |");

    my $x = <ANSWER>;  # Only look at the first line
    chomp($x);

    close(ANSWER);

    if($x =~ /[Ee]xport list/) {
	return(MODEXEC_OK, 1, 'Export list found');
    } elsif($x =~ /no exported/) {
	return(MODEXEC_WARNING, 0, 'No exported filesystems');
    } else {
	return(MODEXEC_PROBLEM, 0, $x);
    }
}
