I developed my first Nagios plugin from scratch and I'm getting some issues regarding the way nagios interprets its output.
Execution from CLI returns good output (even $? is as 0), but nagios interface recognizes it as CRITICAL witn an output of '(null)'.
From command line:
The command definition:nagios@my_Server:/usr/local/nagios/libexec#./my_get_consumo_ups.pl <my_UPS_IP> <my_Community>
CONSUMO OK - Consumo: 10.252kW; | 'Consumo[kW]'=10.252kW;11;14;
The plugin codedefine command{
command_name ups_consumos
command_line /usr/local/nagios/libexec/my_get_consumo_ups.pl <my_UPS_IP> <my_Community>
}
Code: Select all
#!/usr/bin/perl -w
use Net::SNMP;
use Getopt::Long;
use warnings;
use strict;
use utils qw(%ERRORS $TIMEOUT);
use lib "/usr/local/nagios/libexec";
my $session = undef;
my $error = undef;
my $ups_current_I = undef;
my $ups_current_II = undef;
my $ups_current_III = undef;
my $ups_consumption_I = undef;
my $ups_consumption_II = undef;
my $ups_consumption_III = undef;
my $total_consumption = undef;
my $status = undef;
# requires a hostname and a community string as its arguments
($session,$error) = Net::SNMP->session(Hostname => $ARGV[0],
Community => $ARGV[1]);
die "SNMP - Erro de Sessao: $error" unless ($session);
$ups_current_I = $session->get_request("1.3.6.1.2.1.33.1.4.4.1.3.1");
$ups_current_II = $session->get_request("1.3.6.1.2.1.33.1.4.4.1.3.2");
$ups_current_III = $session->get_request("1.3.6.1.2.1.33.1.4.4.1.3.3");
die "request error: ".$session->error unless (defined $ups_current_I);
$ups_consumption_I = $ups_current_I->{"1.3.6.1.2.1.33.1.4.4.1.3.1"} * 22 * 0.001;
$ups_consumption_II = $ups_current_II->{"1.3.6.1.2.1.33.1.4.4.1.3.2"} * 22 * 0.001;
$ups_consumption_III = $ups_current_III->{"1.3.6.1.2.1.33.1.4.4.1.3.3"} * 22 * 0.001;
$total_consumption = $ups_consumption_I + $ups_consumption_II + $ups_consumption_III;
$total_consumption=sprintf("%.0f" , $total_consumption);
$status="OK";
#check if output is critical
if($total_consumption > 14){
$status="CRITICAL";
print $status . ": Consumo " . $total_consumption . "kW\n";
exit $ERRORS{"CRITICAL"};
} else {
if($total_consumption > 11) {
$status="WARNING";
print $status . ": Consumo " . $total_consumption . "kW\n";
exit $ERRORS{"WARNING"};
}
}
#close SNMP session
$session->close;
#print output and return exit code
print "CONSUMO " . $status . " - Consumo: " . $total_consumption . "kW; | 'Consumo[kW]'=" .$total_consumption . "kW;11;14;\n";
exit $ERRORS{"OK"};
Well, I'm hoping this is a very simple issue.
All similar issues I've seen either end up related to perl 'use' clause (libraries or paths) or with permissions.
Best regards,
sebastiaopburnay