Link to home
Start Free TrialLog in
Avatar of M DXYZ
M DXYZFlag for United States of America

asked on

Running nagios plugins in zenoss

Hi, I need assistance running a perl script (nagios plugin) on a zenoss server.  and I get the following error.

./check_ipmi_sensors.pl -H 192.168.10.130 -u ADMIN -p mypassword
Can't locate Nagios/Plugin.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at ./check_ipmi_sensors.pl line 27.
BEGIN failed--compilation aborted at ./check_ipmi_sensors.pl line 27.


I would appreciate your input

#!/usr/bin/perl -w
 
### check_ipmi_sensors.pl
# based on check_stuff.pl
 
# Alexander Greiner-Baer <alexander.greiner-baer@web.der> 2007
# mainly inspired by check_ipmi: Chris Wilson <check_ipmi@qwirx.com>, 2005-06-04
# see Chris Wilson's site: http://www.qwirx.com/check_ipmi
# 
# Nagios plugin using the Nagios::Plugin module and ipmitool.  
# see: http://ipmitool.sourceforge.net/
# tested with ipmitool 1.8.8
#
# checks status of temperature sensors and fans
#
# License: GPL
#
# Changelog:
# 1.1	perform checking on command line options
#	--
# 1	initial release
# 
##############################################################################
use strict;
use warnings;
 
use Nagios::Plugin ;
 
use vars qw($VERSION $PROGNAME  $verbose $warn $critical $timeout $result);
$VERSION = 1.1;
 
$PROGNAME = "check_ipmi_sensors";
 
# ipmi privilege level
my $PRIV = "USER";
 
# Path to ipmitool
my $IPMITOOL = "/usr/local/nagios/libexec/myplugins/ipmitool";
 
# sdr command
my $SDR = "sdr list full";
 
# instantiate Nagios::Plugin
my $p = Nagios::Plugin->new(
	usage => "Usage: %s [ -v|--verbose ]  [-t <timeout>]
	[ -H|--Host <ipaddr> ] [ -u|--user <username> ] [ -p|--pass <password> ]",
	version => $VERSION,
	blurb => 'This plugin checks Sensors with IPMI and will output 
	OK or CRITICAL. Requires ipmitool.', 
 
	extra => ""
);
 
# add all arguments 
$p->add_arg(
	spec => 'Host|H=s',
	help =>
	qq{-H, --Host=STRING
	Specify the remote station on the command line.},
	required => 0,
);
 
$p->add_arg(
	spec => 'user|u=s',
	help =>
	qq{-u, --user=STRING
	Specify the IPMI user on the command line.},
	required => 0,
);
 
$p->add_arg(
	spec => 'pass|p=s',
	help =>
	qq{-p, --pass=STRING
	Specify the IPMI password on the command line.},
	required => 0,
);
 
# parse arguments
$p->getopts;
 
# perform checking on command line options
if ( ( (defined $p->opts->Host) || (defined $p->opts->user) || (defined $p->opts->pass) )
	&& !( (defined $p->opts->Host) && (defined $p->opts->user) && (defined $p->opts->pass) ) ) {
	$p->nagios_exit(
		return_code => UNKNOWN,
		message	=> "Specify username, password and host on the command line."
	)
}
 
# helper
sub trim ($) {
	my ($v) = @_;
	$v =~ s/^ +//;
	$v =~ s/ +$//;
	return $v;
}
 
 
my $result=OK;
my $message="";
my %goodresults;
my %badresults;
 
# open ipmitool with remote connection if host, user and password exists
if ( (defined $p->opts->Host) && (defined $p->opts->user) && (defined $p->opts->pass) ) {
	my $host = $p->opts->Host;
	my $user = $p->opts->user;
	my $pass = $p->opts->pass;
	open IPMI, "$IPMITOOL -L $PRIV -H $host -U $user -P $pass $SDR |" or 
	$p->nagios_exit( 
		return_code => UNKNOWN, 
		message => "ipmitool: $!" 
	);
}
else {
	# fall back to local execution (for use with nrpe)
	open IPMI, "$IPMITOOL -L $PRIV $SDR |" or 
	$p->nagios_exit( 
		return_code => UNKNOWN, 
		message => "ipmitool: $!" 
	);
}
 
# parse ipmitool output
# mainly based on Chris Wilson's code
while ( my $line = <IPMI> ) {
	chomp $line;
	print "$line\n" if ( $p->opts->verbose );
	unless ($line =~ m/^(.*) \| (.*) \| (\w+)$/)
	{
		$p->nagios_exit(
			return_code => UNKNOWN,
			message => "Bad format in ipmitool output: $line"
		);
	}
	my $name  = trim $1;
	my $value = trim $2;
	my $state = trim $3;
 
	# $uname is used as key, check for doublets 
	my $counter = 1;
	my $uname = "$name";
	while ($goodresults{$uname}) {
		$uname = $name . $counter++;
	}
 
	$counter = 1;
	$uname = "$name";
	while ($badresults{$uname}) {
		$uname = $name . $counter++;
	}
 
	# skip not readable entries
	next if $state eq "ns";
 
	# put bad entries in %badresults
	if ($state ne "ok") {
		$badresults{$uname} = $state;
	}
 
	# rest is good
	$goodresults{$uname} = $value;
 
}
 
close IPMI or 
$p->nagios_exit( 
	return_code => UNKNOWN, 
	message => "ipmitool: $! $?" 
);
 
# check results an build a readable output 
if (keys %badresults) {
	$result = CRITICAL;
	foreach my $name (sort keys %badresults) {
		if ( $message ne "" ) {
			$message = $message."; ";
		}
		$message = $message.$name.": ".$badresults{$name};
	}
}
else {
	foreach my $name (sort keys %goodresults) {
		next unless $name =~ m/(fan)|(temp)/i or $goodresults{$name} =~ m/(degrees)|(rpm)/i;
		if ( $message ne "" ) {
			$message = $message."; ";
		}
		my $value = $goodresults{$name};
		$value =~ s/degrees C//;
		$value =~ s/RPM//;
		$value = trim $value;
		$message = $message.$name.": ".$value;
	}
}
 
print "result $result\n " if $p->opts->verbose;
 
$p->nagios_exit( 
	return_code => $result, 
	message => "$message" 
);

Open in new window

Avatar of Adam314
Adam314

You either
1) Need to install the Nagios::Plugin module
2) Need to include the directory that has Nagios::Plugin in @INC  (@INC is the list of directories perl searches for modules)

If you don't think you have this module installed anywhere, you can install it with (as root, with internet access):
    cpan Nagios::Plugin

If you have it installed somewhere other than the default @INC, you can add a directory to this with either:
a) Put it in the PERL5LIB environment variable
b) Add a   use lib /path/to/module;  statement to the code
c) Use the -I command line option with starting perl
Avatar of M DXYZ

ASKER

HI the script works fine, now I need help with the actual script so it will get to ignore certain values. For instance on the 4th column I would care for any other value than ok, nr, na, 0x0100.

I would appreciate your assistance.

Regards,

Michael

CPU Temp 1       | 38.000     | degrees C  | ok    | na        | na        | na        | 76.000    | 78.000    | 80.000    
CPU Temp 2       | 35.000     | degrees C  | ok    | na        | na        | na        | 76.000    | 78.000    | 80.000    
CPU Temp 3       | na         | degrees C  | na    | na        | na        | na        | 76.000    | 78.000    | 80.000    
CPU Temp 4       | na         | degrees C  | na    | na        | na        | na        | 76.000    | 78.000    | 80.000    
Sys Temp         | 40.000     | degrees C  | ok    | na        | na        | na        | 76.000    | 78.000    | 80.000    
CPU1 Vcore       | 1.280      | Volts      | ok    | 0.680     | 0.688     | 0.696     | 1.624     | 1.632     | 1.640     
CPU2 Vcore       | 1.304      | Volts      | ok    | 0.680     | 0.688     | 0.696     | 1.624     | 1.632     | 1.640     
3.3V             | 3.344      | Volts      | ok    | 2.912     | 2.928     | 2.944     | 3.648     | 3.664     | 3.680     
5V               | 4.944      | Volts      | ok    | 4.416     | 4.440     | 4.464     | 5.520     | 5.544     | 5.568     
12V              | 11.712     | Volts      | ok    | 10.464    | 10.560    | 10.656    | 13.344    | 13.440    | 13.536    
-12V             | -12.100    | Volts      | ok    | -10.500   | -10.600   | -10.700   | -13.300   | -13.400   | -13.500   
1.5V             | 1.520      | Volts      | ok    | 1.296     | 1.312     | 1.328     | 1.664     | 1.680     | 1.696     
5VSB             | 4.968      | Volts      | ok    | 4.416     | 4.440     | 4.464     | 5.520     | 5.544     | 5.568     
VBAT             | 3.264      | Volts      | ok    | 2.912     | 2.928     | 2.944     | 3.648     | 3.664     | 3.680     
Fan1             | 0.000      | RPM        | nr    | 200.000   | 300.000   | 400.000   | na        | na        | na        
Fan2             | 0.000      | RPM        | nr    | 200.000   | 300.000   | 400.000   | na        | na        | na        
Fan3             | 0.000      | RPM        | nr    | 200.000   | 300.000   | 400.000   | na        | na        | na        
Fan4             | 0.000      | RPM        | nr    | 200.000   | 300.000   | 400.000   | na        | na        | na        
Fan5             | 4100.000   | RPM        | ok    | 200.000   | 300.000   | 400.000   | na        | na        | na        
Fan6             | 4100.000   | RPM        | ok    | 200.000   | 300.000   | 400.000   | na        | na        | na        
Fan7/CPU1        | 0.000      | RPM        | nr    | 200.000   | 300.000   | 400.000   | na        | na        | na        
Fan8/CPU2        | 0.000      | RPM        | nr    | 200.000   | 300.000   | 400.000   | na        | na        | na        
Intrusion        | 0x0        | discrete   | 0x0100| na        | na        | na        | na        | na        | na        
Power Supply     | 0x0        | discrete   | 0x0000| na        | na        | na        | na        | na        | na        
CPU0 Internal E  | 0x0        | discrete   | 0x0000| na        | na        | na        | na        | na        | na        
CPU1 Internal E  | 0x0        | discrete   | 0x0000| na        | na        | na        | na        | na        | na        
CPU Overheat     | 0x0        | discrete   | 0x0000| na        | na        | na        | na        | na        | na        
Thermal Trip0    | 0x0        | discrete   | 0x0000| na        | na        | na        | na        | na        | na        
Thermal Trip1    | 0x0        | discrete   | 0x0000| na        | na        | na        | na        | na        | na        

Open in new window

Do you want to ignore "ok", or anything other than "ok"?

I can't test this, but from looking at the code, I think this is what you need to change, at line 127.  I gave code to both skip "ok" records, and to skip non-"ok" records.  You'll only want one of these.
...
while ( my $line = <IPMI> ) {                        #EXISTING LINE
    chomp $line;                                     #EXISTING LINE
    my $column4 = (split(/\s*\|\s*/, $line))[3];     #NEW LINE
    next if $column4 eq 'ok';                        #NEW LINE - To skip "ok" records
    next if $column4 ne 'ok';                        #NEW LINE - To skip non-"ok" records
    print "$line\n" if ( $p->opts->verbose );        #EXISTING LINE
...

Open in new window

Avatar of M DXYZ

ASKER

How would I be able to skip more than 1 code. For instance, I would like to skip ok, nr, na, 0x0100, anything else I need to see.

Would I be able to put multiple commas, or how can I accomplish this.

Regards,

Michael

#### Option 1: separate line for each
    next if $column4 eq 'ok';    #NEW LINE - To skip "ok" records
    next if $column4 eq 'nr';    #NEW LINE - To skip "nr" records
    next if $column4 eq 'na';    #NEW LINE - To skip "na" records
 
 
##### Option 2: Single line for all
    next if $column4 =~ /^(ok|nr|na)$/;  #NEW LINE - To skip "ok" and "nr" and "na" records

Open in new window

Avatar of M DXYZ

ASKER

Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 1.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 2.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 3.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 4.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 5.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 6.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 7.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 8.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 9.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 10.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 11.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 12.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 13.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 14.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 15.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 16.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 17.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 18.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 19.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 20.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 21.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 22.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 23.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 24.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 25.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 26.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 27.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 28.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 29.
IPMI_SENSORS CRITICAL - Fan1: nr; Fan2: nr; Fan3: nr; Fan4: nr; Fan7/CPU1: nr; Fan8/CPU2: nr; Intrusion: nc
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 1.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 2.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 3.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 4.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 5.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 6.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 7.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 8.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 9.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 10.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 11.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 12.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 13.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 14.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 15.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 16.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 17.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 18.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 19.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 20.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 21.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 22.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 23.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 24.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 25.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 26.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 27.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 28.
Use of uninitialized value in pattern match (m//) at ./check_ipmi_sensors.pl line 139, <IPMI> line 29.
IPMI_SENSORS CRITICAL - Fan1: nr; Fan2: nr; Fan3: nr; Fan4: nr; Fan7/CPU1: nr; Fan8/CPU2: nr; Intrusion: nc

Please take a look at the newly modified script.

Thanks,

Michael



#!/usr/bin/perl -w
 
### check_ipmi_sensors.pl
# based on check_stuff.pl
 
# Alexander Greiner-Baer <alexander.greiner-baer@web.der> 2007
# mainly inspired by check_ipmi: Chris Wilson <check_ipmi@qwirx.com>, 2005-06-04
# see Chris Wilson's site: http://www.qwirx.com/check_ipmi
# 
# Nagios plugin using the Nagios::Plugin module and ipmitool.  
# see: http://ipmitool.sourceforge.net/
# tested with ipmitool 1.8.8
#
# checks status of temperature sensors and fans
#
# License: GPL
#
# Changelog:
# 1.1   perform checking on command line options
#       --
# 1     initial release
# 
##############################################################################
use strict;
use warnings;
 
use Nagios::Plugin ;
 
use vars qw($VERSION $PROGNAME  $verbose $warn $critical $timeout $result);
$VERSION = 1.1;
 
$PROGNAME = "check_ipmi_sensors";
 
# ipmi privilege level
my $PRIV = "USER";
 
# Path to ipmitool
#my $IPMITOOL = "/usr/local/nagios/libexec/myplugins/ipmitool";
my $IPMITOOL = "/usr/bin/ipmitool";
 
# sdr command
my $SDR = "sdr list full";
 
# instantiate Nagios::Plugin
my $p = Nagios::Plugin->new(
        usage => "Usage: %s [ -v|--verbose ]  [-t <timeout>]
        [ -H|--Host <ipaddr> ] [ -u|--user <username> ] [ -p|--pass <password> ]",
        version => $VERSION,
        blurb => 'This plugin checks Sensors with IPMI and will output 
        OK or CRITICAL. Requires ipmitool.', 
 
        extra => ""
);
 
# add all arguments 
$p->add_arg(
        spec => 'Host|H=s',
        help =>
        qq{-H, --Host=STRING
        Specify the remote station on the command line.},
        required => 0,
);
 
$p->add_arg(
        spec => 'user|u=s',
        help =>
        qq{-u, --user=STRING
        Specify the IPMI user on the command line.},
        required => 0,
);
 
$p->add_arg(
        spec => 'pass|p=s',
        help =>
        qq{-p, --pass=STRING
        Specify the IPMI password on the command line.},
        required => 0,
);
 
# parse arguments
$p->getopts;
 
# perform checking on command line options
if ( ( (defined $p->opts->Host) || (defined $p->opts->user) || (defined $p->opts->pass) )
        && !( (defined $p->opts->Host) && (defined $p->opts->user) && (defined $p->opts->pass) ) ) {
        $p->nagios_exit(
                return_code => UNKNOWN,
                message => "Specify username, password and host on the command line."
        )
}
 
# helper
sub trim ($) {
        my ($v) = @_;
        $v =~ s/^ +//;
        $v =~ s/ +$//;
        return $v;
}
 
 
my $result=OK;
my $message="";
my %goodresults;
my %badresults;
 
# open ipmitool with remote connection if host, user and password exists
if ( (defined $p->opts->Host) && (defined $p->opts->user) && (defined $p->opts->pass) ) {
        my $host = $p->opts->Host;
        my $user = $p->opts->user;
        my $pass = $p->opts->pass;
        open IPMI, "$IPMITOOL -L $PRIV -H $host -U $user -P $pass $SDR |" or 
        $p->nagios_exit( 
                return_code => UNKNOWN, 
                message => "ipmitool: $!" 
        );
}
else {
        # fall back to local execution (for use with nrpe)
        open IPMI, "$IPMITOOL -L $PRIV $SDR |" or 
        $p->nagios_exit( 
                return_code => UNKNOWN, 
                message => "ipmitool: $!" 
        );
}
 
# parse ipmitool output
# mainly based on Chris Wilson's code
while ( my $line = <IPMI> ) {
        chomp $line;
        print "$line\n" if ( $p->opts->verbose );
        unless ($line =~ m/^(.*) \| (.*) \| (\w+)$/)
        {
                $p->nagios_exit(
                        return_code => UNKNOWN,
                        message => "Bad format in ipmitool output: $line"
                );
        }
        my $column4 = (split(/\s*\|\s*/, $line))[3];
        next if $column4 =~ /^(ok|nr|na)$/;  #NEW LINE - To skip "ok" and "nr" and "na" records 
        print "$line\n" if ( $p->opts->verbose );
        my $name  = trim $1;
        my $value = trim $2;
        my $state = trim $3;
 
        # $uname is used as key, check for doublets 
        my $counter = 1;
        my $uname = "$name";
        while ($goodresults{$uname}) {
                $uname = $name . $counter++;
        }
 
        $counter = 1;
        $uname = "$name";
        while ($badresults{$uname}) {
                $uname = $name . $counter++;
        }
 
        # skip not readable entries
        next if $state eq "ns";
 
        # put bad entries in %badresults
        if ($state ne "ok") {
                $badresults{$uname} = $state;
        }
 
        # rest is good
        $goodresults{$uname} = $value;
 
}
 
close IPMI or 
$p->nagios_exit( 
        return_code => UNKNOWN, 
        message => "ipmitool: $! $?" 
);
 
# check results an build a readable output 
if (keys %badresults) {
        $result = CRITICAL;
        foreach my $name (sort keys %badresults) {
                if ( $message ne "" ) {
                        $message = $message."; ";
                }
                $message = $message.$name.": ".$badresults{$name};
        }
}
else {
        foreach my $name (sort keys %goodresults) {
                next unless $name =~ m/(fan)|(temp)/i or $goodresults{$name} =~ m/(degrees)|(rpm)/i;
                if ( $message ne "" ) {
                        $message = $message."; ";
                }
                my $value = $goodresults{$name};
                $value =~ s/degrees C//;
                $value =~ s/RPM//;
                $value = trim $value;
                $message = $message.$name.": ".$value;
        }
}
 
print "result $result\n " if $p->opts->verbose;
 
$p->nagios_exit( 
        return_code => $result, 
        message => "$message" 
);

Open in new window

What is the output from this (replace $host, $user and $pass with appropriate values):
/usr/bin/ipmitool -L USER -H $host -U $user -P $pass sdr list full
/usr/bin/ipmitool -L USER sdr list full

Open in new window

Avatar of M DXYZ

ASKER

I have posted the output above.
Avatar of M DXYZ

ASKER

When I ran the commands that you have posted I get the following:

Invalid privilege level root
ipmitool: invalid option -- u
ipmitool version 1.8.8

usage: ipmitool [options...] <command>


I have to use a remote ip address since the zenoss server does not have an ipmi interface.


I was asking because the warnings you got meant the output was not as I expected.

Do you get the output in 24897737 with or without the verbose option?  What is the output the other way?
Avatar of M DXYZ

ASKER

I am not quite sure what that number means, I do not use the verbose option. Running the first script I get the following result:

IPMI_SENSORS CRITICAL - Fan1: nr; Fan2: nr; Fan3: nr; Fan4: nr; Fan7/CPU1: nr; Fan8/CPU2: nr; Intrusion: nc


The number was the post ID - the number after "ID:" on the title of each post.

So, the script gives you 1 line of output?  How do you get the table output posted above?
Avatar of M DXYZ

ASKER

I simply run the command

ipmitool -H 192.168.10.132 -U ADMIN -P mypassword sensor list
So do you want a new script that gives the table ouptut, but skipping certain rows?
Avatar of M DXYZ

ASKER

No I want to simply report any other value than ok and cr. as simple as that. And it it find something else it will report the entire line affected.

Thanx
Avatar of M DXYZ

ASKER

One more thing it would be great if the script will report also the ip address with the problem.

Thanx
I'm not understanding.

If you run the script as is, you get a single line of output.  What should be done with this?  I don't see any ok or cr in this output.

If you run the ipmitool program, you get the table output.  I don't see any ip addresses.
Avatar of M DXYZ

ASKER

Hi,  when I run the script this is what I get:

IPMI_SENSORS CRITICAL - Fan1: nr; Fan2: nr; Fan3: nr; Fan4: nr; Fan7/CPU1: nr; Fan8/CPU2: nr; Intrusion: nc

Now, what I would like to to is to avoid any values related to nr.  Please remember that this script will be executed by a remote monitoring server on different hosts.

So what you'd like to see is this?
    IPMI_SENSORS CRITICAL - Intrusion: nc


Avatar of M DXYZ

ASKER

you got it
Add this after line 185
foreach my $name (sort keys %goodresults) {                                                #EXISTING LINE
    next unless $name =~ m/(fan)|(temp)/i or $goodresults{$name} =~ m/(degrees)|(rpm)/i;   #EXISTING LINE
    next if $value eq 'nr';                                                                #NEW LINE
    next if $value eq 'ok';  #Add one line like this for each status to skip               #NEW LINE
    if ( $message ne "" ) {                                                                #EXISTING LINE
        $message = $message."; ";                                                          #EXISTING LINE
    }                                                                                      #EXISTING LINE

Open in new window

Avatar of M DXYZ

ASKER

HI I get the following error:

Global symbol "$value" requires explicit package name at ./check_ipmi_sensors.pl line 186.
Global symbol "$value" requires explicit package name at ./check_ipmi_sensors.pl line 187.
Execution of ./check_ipmi_sensors.pl aborted due to compilation errors.


Try this update.  I've moved around a few of the existing lines, and added a line.
foreach my $name (sort keys %goodresults) {
    next unless $name =~ m/(fan)|(temp)/i or $goodresults{$name} =~ m/(degrees)|(rpm)/i;
    my $value = $goodresults{$name};
    $value =~ s/degrees C//;
    $value =~ s/RPM//;
    $value = trim $value;
    next if $value eq 'nr';      #NEW LINE
    if ( $message ne "" ) {
        $message = $message."; ";
    }
    $message = $message.$name.": ".$value;
}

Open in new window

Avatar of M DXYZ

ASKER

hi, this is the error I get

Global symbol "$value" requires explicit package name at ./check_ipmi_sensors.pl line 186.
Global symbol "$value" requires explicit package name at ./check_ipmi_sensors.pl line 187.
Execution of ./check_ipmi_sensors.pl aborted due to compilation errors.


and this is the code added



#!/usr/bin/perl -w
 
### check_ipmi_sensors.pl
# based on check_stuff.pl
 
# Alexander Greiner-Baer <alexander.greiner-baer@web.der> 2007
# mainly inspired by check_ipmi: Chris Wilson <check_ipmi@qwirx.com>, 2005-06-04
# see Chris Wilson's site: http://www.qwirx.com/check_ipmi
# 
# Nagios plugin using the Nagios::Plugin module and ipmitool.  
# see: http://ipmitool.sourceforge.net/
# tested with ipmitool 1.8.8
#
# checks status of temperature sensors and fans
#
# License: GPL
#
# Changelog:
# 1.1   perform checking on command line options
#       --
# 1     initial release
# 
##############################################################################
use strict;
use warnings;
 
use Nagios::Plugin ;
 
use vars qw($VERSION $PROGNAME  $verbose $warn $critical $timeout $result);
$VERSION = 1.1;
 
$PROGNAME = "check_ipmi_sensors";
 
# ipmi privilege level
my $PRIV = "USER";
 
# Path to ipmitool
my $IPMITOOL = "/usr/bin/ipmitool";
 
# sdr command
my $SDR = "sdr list full";
vi -c 1 check_ipmi_sensors.pl
#!/usr/bin/perl -w
 
### check_ipmi_sensors.pl
# based on check_stuff.pl
 
# Alexander Greiner-Baer <alexander.greiner-baer@web.der> 2007
# mainly inspired by check_ipmi: Chris Wilson <check_ipmi@qwirx.com>, 2005-06-04
# see Chris Wilson's site: http://www.qwirx.com/check_ipmi
#
# Nagios plugin using the Nagios::Plugin module and ipmitool.
# see: http://ipmitool.sourceforge.net/
# tested with ipmitool 1.8.8
#
# checks status of temperature sensors and fans
#
# License: GPL
#
# Changelog:
# 1.1   perform checking on command line options
#       --
# 1     initial release
#
##############################################################################
use strict;
use warnings;
 
use Nagios::Plugin ;
 
use vars qw($VERSION $PROGNAME  $verbose $warn $critical $timeout $result);
$VERSION = 1.1;
 
$PROGNAME = "check_ipmi_sensors";
 
# ipmi privilege level
my $PRIV = "USER";
 
# Path to ipmitool
my $IPMITOOL = "/usr/bin/ipmitool";
 
# sdr command
my $SDR = "sdr list full";
 
# instantiate Nagios::Plugin
my $p = Nagios::Plugin->new(
        usage => "Usage: %s [ -v|--verbose ]  [-t <timeout>]
        [ -H|--Host <ipaddr> ] [ -u|--user <username> ] [ -p|--pass <password> ]",
        version => $VERSION,
        blurb => 'This plugin checks Sensors with IPMI and will output
        OK or CRITICAL. Requires ipmitool.',
 
        extra => ""
);
 
# add all arguments
$p->add_arg(
        spec => 'Host|H=s',
        help =>
        qq{-H, --Host=STRING
        Specify the remote station on the command line.},
        required => 0,
);
 
$p->add_arg(
        spec => 'user|u=s',
        help =>
        qq{-u, --user=STRING
        Specify the IPMI user on the command line.},
        required => 0,
);
------------------------
 
# instantiate Nagios::Plugin
my $p = Nagios::Plugin->new(
        usage => "Usage: %s [ -v|--verbose ]  [-t <timeout>]
        [ -H|--Host <ipaddr> ] [ -u|--user <username> ] [ -p|--pass <password> ]",
        version => $VERSION,
        blurb => 'This plugin checks Sensors with IPMI and will output 
        OK or CRITICAL. Requires ipmitool.', 
 
        extra => ""
);
 
# add all arguments 
$p->add_arg(
        spec => 'Host|H=s',
        help =>
        qq{-H, --Host=STRING
        Specify the remote station on the command line.},
        required => 0,
);
 
$p->add_arg(
        spec => 'user|u=s',
        help =>
        qq{-u, --user=STRING
        Specify the IPMI user on the command line.},
        required => 0,
);
 
$p->add_arg(
        spec => 'pass|p=s',
        help =>
        qq{-p, --pass=STRING
        Specify the IPMI password on the command line.},
        required => 0,
);
 
# parse arguments
$p->getopts;
 
# perform checking on command line options
if ( ( (defined $p->opts->Host) || (defined $p->opts->user) || (defined $p->opts->pass) )
        && !( (defined $p->opts->Host) && (defined $p->opts->user) && (defined $p->opts->pass) ) ) {
        $p->nagios_exit(
                return_code => UNKNOWN,
                message => "Specify username, password and host on the command line."
        )
}
 
# helper
sub trim ($) {
        my ($v) = @_;
        $v =~ s/^ +//;
        $v =~ s/ +$//;
        return $v;
}
 
 
my $result=OK;
my $message="";
my %goodresults;
my %badresults;
 
# open ipmitool with remote connection if host, user and password exists
if ( (defined $p->opts->Host) && (defined $p->opts->user) && (defined $p->opts->pass) ) {
        my $host = $p->opts->Host;
        my $user = $p->opts->user;
        my $pass = $p->opts->pass;
        open IPMI, "$IPMITOOL -L $PRIV -H $host -U $user -P $pass $SDR |" or 
        $p->nagios_exit( 
                return_code => UNKNOWN, 
                message => "ipmitool: $!" 
        );
}
else {
        # fall back to local execution (for use with nrpe)
        open IPMI, "$IPMITOOL -L $PRIV $SDR |" or 
        $p->nagios_exit( 
                return_code => UNKNOWN, 
                message => "ipmitool: $!" 
        );
}
 
# parse ipmitool output
# mainly based on Chris Wilson's code
while ( my $line = <IPMI> ) {
        chomp $line;
        print "$line\n" if ( $p->opts->verbose );
        unless ($line =~ m/^(.*) \| (.*) \| (\w+)$/)
        {
                $p->nagios_exit(
                        return_code => UNKNOWN,
                        message => "Bad format in ipmitool output: $line"
                );
        }
        my $name  = trim $1;
        my $value = trim $2;
        my $state = trim $3;
 
        # $uname is used as key, check for doublets 
        my $counter = 1;
        my $uname = "$name";
        while ($goodresults{$uname}) {
                $uname = $name . $counter++;
        }
 
        $counter = 1;
        $uname = "$name";
        while ($badresults{$uname}) {
                $uname = $name . $counter++;
        }
 
        # skip not readable entries
        next if $state eq "ns";
 
        # put bad entries in %badresults
        if ($state ne "ok") {
                $badresults{$uname} = $state;
        }
 
        # rest is good
        $goodresults{$uname} = $value;
 
}
 
close IPMI or 
$p->nagios_exit( 
        return_code => UNKNOWN, 
        message => "ipmitool: $! $?" 
);
 
# check results an build a readable output 
if (keys %badresults) {
        $result = CRITICAL;
        foreach my $name (sort keys %badresults) {
                if ( $message ne "" ) {
                        $message = $message."; ";
                }
                $message = $message.$name.": ".$badresults{$name};
        }
}
else {
        foreach my $name (sort keys %goodresults) {
                next unless $name =~ m/(fan)|(temp)/i or $goodresults{$name} =~ m/(degrees)|(rpm)/i;
                next if $value eq 'nr';  #NEW LINE
                next if $value eq 'ok';  #Add one line like this for each status to skip     #NEW LINE
                if ( $message ne "" ) {
                        $message = $message."; ";
                }
                my $value = $goodresults{$name};
                $value =~ s/degrees C//;
                $value =~ s/RPM//;
                $value = trim $value;
                next if $value eq 'nr';
                $message = $message.$name.": ".$value;
        }
}
 
print "result $result\n " if $p->opts->verbose;
 
$p->nagios_exit( 
        return_code => $result, 
        message => "$message" 
);

Open in new window


#!/usr/bin/perl -w
 
### check_ipmi_sensors.pl
# based on check_stuff.pl
 
# Alexander Greiner-Baer <alexander.greiner-baer@web.der> 2007
# mainly inspired by check_ipmi: Chris Wilson <check_ipmi@qwirx.com>, 2005-06-04
# see Chris Wilson's site: http://www.qwirx.com/check_ipmi
# 
# Nagios plugin using the Nagios::Plugin module and ipmitool.  
# see: http://ipmitool.sourceforge.net/
# tested with ipmitool 1.8.8
#
# checks status of temperature sensors and fans
#
# License: GPL
#
# Changelog:
# 1.1	perform checking on command line options
#	--
# 1	initial release
# 
##############################################################################
use strict;
use warnings;
 
use Nagios::Plugin ;
 
use vars qw($VERSION $PROGNAME  $verbose $warn $critical $timeout $result);
$VERSION = 1.1;
 
$PROGNAME = "check_ipmi_sensors";
 
# ipmi privilege level
my $PRIV = "USER";
 
# Path to ipmitool
my $IPMITOOL = "/usr/local/nagios/libexec/myplugins/ipmitool";
 
# sdr command
my $SDR = "sdr list full";
 
# instantiate Nagios::Plugin
my $p = Nagios::Plugin->new(
	usage => "Usage: %s [ -v|--verbose ]  [-t <timeout>]
	[ -H|--Host <ipaddr> ] [ -u|--user <username> ] [ -p|--pass <password> ]",
	version => $VERSION,
	blurb => 'This plugin checks Sensors with IPMI and will output 
	OK or CRITICAL. Requires ipmitool.', 
 
	extra => ""
);
 
# add all arguments 
$p->add_arg(
	spec => 'Host|H=s',
	help =>
	qq{-H, --Host=STRING
	Specify the remote station on the command line.},
	required => 0,
);
 
$p->add_arg(
	spec => 'user|u=s',
	help =>
	qq{-u, --user=STRING
	Specify the IPMI user on the command line.},
	required => 0,
);
 
$p->add_arg(
	spec => 'pass|p=s',
	help =>
	qq{-p, --pass=STRING
	Specify the IPMI password on the command line.},
	required => 0,
);
 
# parse arguments
$p->getopts;
 
# perform checking on command line options
if ( ( (defined $p->opts->Host) || (defined $p->opts->user) || (defined $p->opts->pass) )
	&& !( (defined $p->opts->Host) && (defined $p->opts->user) && (defined $p->opts->pass) ) ) {
	$p->nagios_exit(
		return_code => UNKNOWN,
		message	=> "Specify username, password and host on the command line."
	)
}
 
# helper
sub trim ($) {
	my ($v) = @_;
	$v =~ s/^ +//;
	$v =~ s/ +$//;
	return $v;
}
 
 
my $result=OK;
my $message="";
my %goodresults;
my %badresults;
 
# open ipmitool with remote connection if host, user and password exists
if ( (defined $p->opts->Host) && (defined $p->opts->user) && (defined $p->opts->pass) ) {
	my $host = $p->opts->Host;
	my $user = $p->opts->user;
	my $pass = $p->opts->pass;
	open IPMI, "$IPMITOOL -L $PRIV -H $host -U $user -P $pass $SDR |" or 
	$p->nagios_exit( 
		return_code => UNKNOWN, 
		message => "ipmitool: $!" 
	);
}
else {
	# fall back to local execution (for use with nrpe)
	open IPMI, "$IPMITOOL -L $PRIV $SDR |" or 
	$p->nagios_exit( 
		return_code => UNKNOWN, 
		message => "ipmitool: $!" 
	);
}
 
# parse ipmitool output
# mainly based on Chris Wilson's code
while ( my $line = <IPMI> ) {
	chomp $line;
	print "$line\n" if ( $p->opts->verbose );
	unless ($line =~ m/^(.*) \| (.*) \| (\w+)$/)
	{
		$p->nagios_exit(
			return_code => UNKNOWN,
			message => "Bad format in ipmitool output: $line"
		);
	}
	my $name  = trim $1;
	my $value = trim $2;
	my $state = trim $3;
 
	# $uname is used as key, check for doublets 
	my $counter = 1;
	my $uname = "$name";
	while ($goodresults{$uname}) {
		$uname = $name . $counter++;
	}
 
	$counter = 1;
	$uname = "$name";
	while ($badresults{$uname}) {
		$uname = $name . $counter++;
	}
 
	# skip not readable entries
	next if $state eq "ns";
 
	# put bad entries in %badresults
	if ($state ne "ok") {
		$badresults{$uname} = $state;
	}
 
	# rest is good
	$goodresults{$uname} = $value;
 
}
 
close IPMI or 
$p->nagios_exit( 
	return_code => UNKNOWN, 
	message => "ipmitool: $! $?" 
);
 
# check results an build a readable output 
if (keys %badresults) {
	$result = CRITICAL;
	foreach my $name (sort keys %badresults) {
		if ( $message ne "" ) {
			$message = $message."; ";
		}
		$message = $message.$name.": ".$badresults{$name};
	}
}
else {
	foreach my $name (sort keys %goodresults) {
		next unless $name =~ m/(fan)|(temp)/i or $goodresults{$name} =~ m/(degrees)|(rpm)/i;
		my $value = $goodresults{$name};
		$value =~ s/degrees C//;
		$value =~ s/RPM//;
		$value = trim $value;
		next if $value eq 'nr';
		if ( $message ne "" ) {
			$message = $message."; ";
		}
		$message = $message.$name.": ".$value;
	}
}
 
print "result $result\n " if $p->opts->verbose;
 
$p->nagios_exit( 
	return_code => $result, 
	message => "$message" 
);

Open in new window

Avatar of M DXYZ

ASKER

Isn't that the original code, I already got that.
Lines 184 - 195 have been changed.
Avatar of M DXYZ

ASKER

I still get the same results from the original file, it does not suppress certain messages.
ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of M DXYZ

ASKER

HI Adam, here is the output

Creating Nagios::Plugin object...
 Calling add_arg-1  
Calling add_arg-2  
Calling add_arg-3
Getting options
Checking command line
 Checking ipmitool  
Using long command line  
Got line: CPU Temp 3       | no reading        | ns  
Got line: CPU Temp 4       | no reading        | ns  
Got line: Fan1             | 0 RPM             | nr  
Got line: Fan2             | 0 RPM             | nr
 Got line: Fan3             | 0 RPM             | nr  
Got line: Fan4             | 0 RPM             | nr  
Got line: Fan7/CPU1        | 0 RPM             | nr  
Got line: Fan8/CPU2        | 0 RPM             | nr  
Got line: Intrusion        | 0 unspecified     | nc
 IPMI_SENSORS UNKNOWN - ipmitool:  0

I can work with that, what I am doing now is to run the script and parse it with grep -Ev "ok" so I displayed the output above.

Thank you very much for your efforts in making this script work.

Regards,

Michael