Return Code of 141 is out of bounds, sometimes

I have a plugin, that logs into a cisco device via ssh and pings an IP. The check runs fine when I run it from command line, and it runs fine in nagios. The only problem, from time to time I get a “Return code of 141 is out of bounds” error in nagios. I’m not sure exactly what is causing the 141 error. Below is the code for the check.

[code]#!/usr/bin/perl

Use: usr/local/sbin/check_cisco_ping_ssh

use strict;

use Net::SSH::Perl;

$ENV{‘HOME’} = ‘/var/lib/nagios’;

my $router=$ARGV[0];
my $port=$ARGV[1];

my $user=$ARGV[2];
my $pass=$ARGV[3];

my $ip=$ARGV[4];

my $crit=$ARGV[5];

my $sesion_ssh = Net::SSH::Perl->new($router, protocol=>1, cipher=>‘DES’, port=>$port, debug=> ‘false’, use_pty=>0);
$sesion_ssh->login($user, $pass);

my $command=“ping $ip”;

my($output, $output_error, $value_exit) = $sesion_ssh->cmd($command);

$output =~ /Success rate is (\d*) (.*)/;

my $rate=$1;

if ( $rate <= 0 ) {
print “PROBLEM: $ip is DOWN Rate=$rate%\n”;
exit 2;
}

if ( $rate <= 100 ) {
print “OK: $ip is UP Rate=$rate%\n”;
exit 0;
[/code]

are you considering the case the rate is only say 80%? what happens to your plugin in that case? what does it return? and how does nagios handle that result?

Yes I considered those cases, please check modified code. Yet I still get the occasional “return code of 141” I am not sure what is causing this return code of 141.

[code]#!/usr/bin/perl

Use: usr/local/sbin/check_cisco_ping_ssh

#use strict;

use Net::SSH::Perl;

$ENV{‘HOME’} = ‘/var/lib/nagios’;

my $router=$ARGV[0];
my $port=$ARGV[1];

my $user=$ARGV[2];
my $pass=$ARGV[3];

my $ip=$ARGV[4];

my $warn=$ARGV[5];
my $crit=$ARGV[6];

my $sesion_ssh = Net::SSH::Perl->new($router, protocol=>1,2, cipher=>‘DES’, port=>$port, debug=> ‘false’, use_pty=>0);
$sesion_ssh->login($user, $pass);

my $command=“ping $ip”;

my($output, $output_error, $value_exit) = $sesion_ssh->cmd($command);

$output =~ /Success rate is (\d*) (.*)/;

my $rate=$1;

if ( $rate <= $crit ) {
print “PROBLEM: $ip is DOWN Rate=$rate%\n”;
exit(2);
}

if ( $rate <= $warn ) {
print “WARNING: $ip is at Rate=$rate%\n”;
exit(1);
}

if ( $rate <= 100 ) {
print “OK: $ip is UP Rate=$rate%\n”;
exit(0);
}

exit(3);
[/code]

had a googling round and i’m thinking about trying a different thing :slight_smile:

define $return_code=3 at the beginning and only use
exit($return_code)

redefine $return_code as required at the end when you are sure of the result.

This way you shouldn’t have exit codes different than unknown, which from what i read cause the 141 return code… why 141? no idea, sorry :?

[quote=“luca”]had a googling round and i’m thinking about trying a different thing :slight_smile:

define $return_code=3 at the beginning and only use
exit($return_code)

redefine $return_code as required at the end when you are sure of the result.

This way you shouldn’t have exit codes different than unknown, which from what i read cause the 141 return code… why 141? no idea, sorry :?[/quote]

Hi Luca,

I have tried your suggestion but to no avail, I still am getting the 141 return code. :frowning: