WebSVN - scripts - Rev 9 - /perl/trunk/v1.0/check_nfs.pl

thorko Repositories scripts

Rev

Blame | Last modification | View Log | RSS feed

#!/usr/bin/perl
#
# check_nfs plugin for netsaint
#
# usage:
#    check_nfs.pl server
#
# Check if a nfs server is registered and running
# using rpcinfo -p <arg1>.
# 100003 is the rpc programmnumber for nfs.
# <arg1> is the server queried.

use strict;
use warnings;

my $server = "";
my $rstr = "";
my $rcode = 0;
my $v;

$server = shift;
if ( $server eq "" ) {
        print "Usage: check_nfs.pl <server>\n";
        exit 1;
}

my %ERRORS = ( 0 => "OK", 1 => "WARNING", 2 => "CRITICAL" );

# probe the server
open CMD,"/usr/sbin/rpcinfo -p $server |";

while ( my $line = <CMD> ) {
  if ( $line =~ /\s+100003\s+[0-9]\s+tcp/ ) {
        $v = (split(/\s+/, $line))[2];
        $rstr = $rstr." version: $v tcp,";
  } elsif ( $line =~ /\s+100003\s+[0-9]\s+udp/ ) {
        $v = (split(/\s+/, $line))[2];
        $rstr = $rstr." version: $v udp,";
  }
}

close CMD;

# if no tcp or udp of nfs found
if ( $rstr eq "" ) {
        $rcode = 2;
        $rstr = " no nfs (100003) prog responding!";
} elsif ( $rstr =~ /.*udp.*tcp/ ) {
        $rcode = 0;
} else {
        $rcode = 1;
        $rstr = " nfs tcp or udp missing - ".$rstr;
}

print $ERRORS{$rcode}." $rstr\n";

exit $rcode;