mirror of
https://github.com/opinkerfi/nagios-plugins.git
synced 2024-11-24 11:23:47 +01:00
Update check_apcext.pl
Fix snmp session get without community defined
This commit is contained in:
parent
944d47e18e
commit
13cab5608e
@ -4,7 +4,7 @@
|
|||||||
# check_apcext.pl - APC Extra gear monitoring plugin for Nagios
|
# check_apcext.pl - APC Extra gear monitoring plugin for Nagios
|
||||||
# 05.02.07 Paul Venezia
|
# 05.02.07 Paul Venezia
|
||||||
#
|
#
|
||||||
# v0.0.1
|
# v0.0.2
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
@ -35,6 +35,14 @@ my $metric = $opt{m};
|
|||||||
my $list = $opt{l};
|
my $list = $opt{l};
|
||||||
my $sensor_int_name = $opt{s};
|
my $sensor_int_name = $opt{s};
|
||||||
|
|
||||||
|
my ($session, $error) = Net::SNMP->session(
|
||||||
|
-hostname => $host,
|
||||||
|
-community => $comm,
|
||||||
|
-version => 'snmpv2c',
|
||||||
|
-port => "161"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
my ($oid, $oidbase, $fval, $unit, $outmsg);
|
my ($oid, $oidbase, $fval, $unit, $outmsg);
|
||||||
my $retval = 0;
|
my $retval = 0;
|
||||||
my %rpduamps;
|
my %rpduamps;
|
||||||
@ -199,15 +207,10 @@ my %oids = (
|
|||||||
if ($list) {
|
if ($list) {
|
||||||
my ($baseoid, $int_name_id, $value_id) = @_;
|
my ($baseoid, $int_name_id, $value_id) = @_;
|
||||||
|
|
||||||
my ($session, $error) = Net::SNMP->session(
|
|
||||||
-hostname => $host,
|
|
||||||
-community => $comm,
|
|
||||||
-version => 1,
|
|
||||||
# -translate => [-octetstring => 0x0],
|
|
||||||
-port => "161"
|
|
||||||
);
|
|
||||||
my $response = $session->get_table(-baseoid => ".1.3.6.1.4.1.5528.100.2.1.1");
|
my $response = $session->get_table(-baseoid => ".1.3.6.1.4.1.5528.100.2.1.1");
|
||||||
|
|
||||||
my $err = $session->error;
|
my $err = $session->error;
|
||||||
|
|
||||||
if ($err){
|
if ($err){
|
||||||
$retval = 3;
|
$retval = 3;
|
||||||
$outmsg = "UNKNOWN";
|
$outmsg = "UNKNOWN";
|
||||||
@ -215,23 +218,22 @@ if ($list) {
|
|||||||
print "$outmsg $err - SNMP Error connecting to $host\n";
|
print "$outmsg $err - SNMP Error connecting to $host\n";
|
||||||
exit $retval;
|
exit $retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
my %sensor;
|
my %sensor;
|
||||||
foreach my $k (keys %{$response}) {
|
foreach my $key (keys %{$response}) {
|
||||||
my ($type, $id) = (split(/\./, $k))[-2,-1];
|
my ($type, $id) = (split(/\./, $key))[-2,-1];
|
||||||
next if ($type != 1 and $type != 4);
|
next if ($type != 1 and $type != 4);
|
||||||
next if ($id < 2000000000);
|
next if ($id < 2000000000);
|
||||||
if ($type == 1) {
|
if ($type == 1) {
|
||||||
$sensor{$id}->{"int_name"} = $response->{$k};
|
$sensor{$id}->{"int_name"} = $response->{$key};
|
||||||
} else {
|
} else {
|
||||||
$sensor{$id}->{"friendly_name"} = $response->{$k};
|
$sensor{$id}->{"friendly_name"} = $response->{$key};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print <<" EO";
|
print <<" EO";
|
||||||
Specify a sensor by using the -s and the INTERNAL name of the sensor
|
Specify a sensor by using the -s and the INTERNAL name of the sensor
|
||||||
|
|
||||||
Detected sensors:
|
Detected sensors:
|
||||||
|
|
||||||
EO
|
EO
|
||||||
printf("\t%-32s %s\n", "Friendly Name", "Internal Name");
|
printf("\t%-32s %s\n", "Friendly Name", "Internal Name");
|
||||||
foreach my $id (sort { $sensor{$a}->{"friendly_name"} cmp $sensor{$b}->{"friendly_name"} } keys %sensor) {
|
foreach my $id (sort { $sensor{$a}->{"friendly_name"} cmp $sensor{$b}->{"friendly_name"} } keys %sensor) {
|
||||||
@ -248,22 +250,13 @@ Detected sensors:
|
|||||||
$oidbase = $oids{$param}->{oidbase};
|
$oidbase = $oids{$param}->{oidbase};
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($session, $error) = Net::SNMP->session(
|
|
||||||
-hostname => $host,
|
|
||||||
-community => $comm,
|
|
||||||
-version => 1,
|
|
||||||
# -translate => [-octetstring => 0x0],
|
|
||||||
-port => "161"
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
if ($param eq "rpduamps") {
|
if ($param eq "rpduamps") {
|
||||||
# $param = "RackPDU";
|
# $param = "RackPDU";
|
||||||
my $i;
|
for (my $i=1;$i<4;$i++) {
|
||||||
for ($i=1;$i<4;$i++) {
|
|
||||||
my $phoid = $oid . $i;
|
my $phoid = $oid . $i;
|
||||||
my $response = $session->get_request($phoid);
|
my $response = $session->get_request($phoid);
|
||||||
my $err = $session->error;
|
my $err = $session->error;
|
||||||
|
|
||||||
if ($err){
|
if ($err){
|
||||||
$retval = 3;
|
$retval = 3;
|
||||||
$outmsg = "UNKNOWN";
|
$outmsg = "UNKNOWN";
|
||||||
@ -271,6 +264,7 @@ if ($param eq "rpduamps") {
|
|||||||
print "$outmsg $err - SNMP Error connecting to $host\n";
|
print "$outmsg $err - SNMP Error connecting to $host\n";
|
||||||
exit $retval;
|
exit $retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rpduamps{$i} = $response->{$phoid};
|
$rpduamps{$i} = $response->{$phoid};
|
||||||
}
|
}
|
||||||
$session->close;
|
$session->close;
|
||||||
@ -306,10 +300,12 @@ if ($param eq "rpduamps") {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
my $val;
|
my $val;
|
||||||
|
|
||||||
if ($oid) {
|
if ($oid) {
|
||||||
my $response = $session->get_request($oid);
|
my $response = $session->get_request($oid);
|
||||||
|
|
||||||
my $err = $session->error;
|
my $err = $session->error;
|
||||||
|
|
||||||
if ($err){
|
if ($err){
|
||||||
$retval = 3;
|
$retval = 3;
|
||||||
$outmsg = "UNKNOWN";
|
$outmsg = "UNKNOWN";
|
||||||
@ -324,8 +320,11 @@ if ($param eq "rpduamps") {
|
|||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
my $snmpd = getmasked_values($oidbase, { $oids{$param}->{sensor_key} => 'sensor_key',
|
my $snmpd = getmasked_values(
|
||||||
$oids{$param}->{sensor_val} => 'sensor_val' });
|
$oidbase, {
|
||||||
|
$oids{$param}->{sensor_key} => 'sensor_key',
|
||||||
|
$oids{$param}->{sensor_val} => 'sensor_val' }
|
||||||
|
);
|
||||||
|
|
||||||
if ((keys %{$snmpd}) > 1 && !$sensor_int_name) {
|
if ((keys %{$snmpd}) > 1 && !$sensor_int_name) {
|
||||||
print "UNKNOWN - Many sensors found but none specified, see -s and -l\n";
|
print "UNKNOWN - Many sensors found but none specified, see -s and -l\n";
|
||||||
@ -352,6 +351,7 @@ if ($param eq "rpduamps") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($param eq "acscstatus" || $param eq "acrcstatus") {
|
if ($param eq "acscstatus" || $param eq "acrcstatus") {
|
||||||
|
|
||||||
if ($val == 1) {
|
if ($val == 1) {
|
||||||
$fval = "Standby";
|
$fval = "Standby";
|
||||||
$retval = 1;
|
$retval = 1;
|
||||||
@ -401,16 +401,13 @@ APC NetBotz
|
|||||||
nbmstemp NetBotz main sensor temp | nbmshum NetBotz main sensor humidity
|
nbmstemp NetBotz main sensor temp | nbmshum NetBotz main sensor humidity
|
||||||
nbmsairflow NetBotz main sensor airflow | nbmsaudio NetBotz main sensor audio
|
nbmsairflow NetBotz main sensor airflow | nbmsaudio NetBotz main sensor audio
|
||||||
-l List connected sensors | -s sensor Sensor we want info from
|
-l List connected sensors | -s sensor Sensor we want info from
|
||||||
|
|
||||||
APC Metered Rack PDU
|
APC Metered Rack PDU
|
||||||
rpduamps Amps on each phase
|
rpduamps Amps on each phase
|
||||||
|
|
||||||
APC ACSC In-Row
|
APC ACSC In-Row
|
||||||
acscstatus System status (on/standby) | acscload Cooling load
|
acscstatus System status (on/standby) | acscload Cooling load
|
||||||
acscoutput Cooling output | acscsupair Supply air
|
acscoutput Cooling output | acscsupair Supply air
|
||||||
acscairflow Air flow | acscracktemp Rack inlet temp
|
acscairflow Air flow | acscracktemp Rack inlet temp
|
||||||
acsccondin Condenser input temp | acsccondout Condenser outlet temp
|
acsccondin Condenser input temp | acsccondout Condenser outlet temp
|
||||||
|
|
||||||
APC ACRC In-Row
|
APC ACRC In-Row
|
||||||
acrcstatus System status (on/standby) | acrcload Cooling load
|
acrcstatus System status (on/standby) | acrcload Cooling load
|
||||||
acrcoutput Cooling output | acrcairflow Air flow
|
acrcoutput Cooling output | acrcairflow Air flow
|
||||||
@ -433,12 +430,6 @@ sub f2c($) {
|
|||||||
sub getmasked_values ($$) {
|
sub getmasked_values ($$) {
|
||||||
my ($baseoid, $values) = @_;
|
my ($baseoid, $values) = @_;
|
||||||
|
|
||||||
my ($session, $error) = Net::SNMP->session(
|
|
||||||
-hostname => $host,
|
|
||||||
-community => $comm,
|
|
||||||
-version => 1,
|
|
||||||
-port => "161"
|
|
||||||
);
|
|
||||||
my $response = $session->get_table(-baseoid => $baseoid);
|
my $response = $session->get_table(-baseoid => $baseoid);
|
||||||
my $err = $session->error;
|
my $err = $session->error;
|
||||||
if ($err){
|
if ($err){
|
||||||
|
Loading…
Reference in New Issue
Block a user