[Nagiosplug-devel] Nagios plugin work in command, but not in Nagios

Fallsen, Tommy Tommy.Fallsen at kongsberg.com
Mon May 12 06:00:02 CEST 2003


Hi
I've written a little perl script to report if anything is wrong with
the Metadevices on a Solaris Server.
Problem is that the script works perfectly in command mode, debugging
show that it
print some text and exit with exit $ERRORS{'CRITICAL'}; when metastat
report error. However in Nagios all i get
is OK and no output. 

Here is the script, please note that i learned perl while creating this,
so the problem might be the script.
I think its made after the criterias in Nagios plug-in development
guidelines.


#!/usr/bin/perl -w

use strict;
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_H $PROGNAME);
use lib "/opt/sfw/nagios/libexec"  ;
use utils qw(%ERRORS &print_revision &support &usage);

my $remote_user = "root";
my $path_to_rsh = "/usr/bin/rsh -n";
my $METADB="/usr/sbin/metadb";
my $METAHS="/usr/sbin/metahs";
my $METASTAT="/usr/sbin/metastat";
my @state;
my @avail;
my $Row;
my $newFld;
my @Fld;
my $dbtrouble;
my @mdtrouble;
my @hstrouble;

$PROGNAME = "check_sds";
$ENV{'PATH'}='';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Getopt::Long::Configure('bundling');
GetOptions
        ("V"   => \$opt_V, "version"    => \$opt_V,
         "h"   => \$opt_h, "help"       => \$opt_h,
         "H=s" => \$opt_H, "hostname=s" => \$opt_H,);

if ($opt_V) {
        print_revision($PROGNAME,'$Revision: 0.1 $');
        exit $ERRORS{'OK'};
}
if ($opt_h) {
        print_help();
        exit $ERRORS{'OK'};
}
($opt_H) || usage("Host name/address not specified\n");
my $host = $1 if ($opt_H =~ /([-.A-Za-z0-9]+)/);
($host) || usage("Invalid host: $opt_H\n");



#
# Check replicas for problems, capital letters in the flags indicate an
error. 
# 
$dbtrouble=`$path_to_rsh -l $remote_user $opt_H $METADB`; chomp
$dbtrouble; if ($dbtrouble =~ /[A-Z]/) {
        print "One or more Database replicas are not active\n";
        exit $ERRORS{'CRITICAL'};
}


#
# Check the metadevice state, if the state is not Okay, something is up.

# 
@mdtrouble=`$path_to_rsh -l $remote_user $host $METASTAT`; @state = grep
/State:/ , at mdtrouble; foreach $Row (@state) {
        chomp $Row;
        @Fld=split(":",$Row);
        foreach $newFld ($Fld[1]) {

        if ($newFld !~ /Okay*/) {
                print ("One or more Metadevices are not Okay\n");
                exit $ERRORS{'CRITICAL'};
        }
    }
}



#
# Check the hotspares to see if any have been used.
# Not used yet.
#@hstrouble=`$path_to_rsh -l $remote_user $host $METAHS -i`; #@avail =
grep /blocks/ , at hstrouble; # #foreach (@avail) {
#        if (!/Available/) {
#                print "Hot spares in usage\n";
#                $eval=1;
#                exit $ERRORS{'WARNING'};
#        }
#}


sub print_help {
        print "\n\n";
        print "This plugin checks Disksuite status on a remote Solaris
system \n\n";
        print "Usage:\t-H, --hostname=<HOST>\n\n\n";
        support();
}


Thanks

Tommy Fallsen	

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20030512/9a76dbe1/attachment.html>


More information about the Devel mailing list