mirror of
https://github.com/opinkerfi/nagios-plugins.git
synced 2024-11-22 10:23:46 +01:00
Various check_brocade_env.pl fixes
This commit is contained in:
parent
c8cdc90147
commit
b9ada8f469
@ -17,23 +17,21 @@
|
|||||||
|
|
||||||
use Nagios::Plugin;
|
use Nagios::Plugin;
|
||||||
use Net::SNMP;
|
use Net::SNMP;
|
||||||
use Getopt::Long;
|
|
||||||
use Data::Dumper;
|
|
||||||
use vars qw/ %opt /;
|
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
|
||||||
|
# OID Base for Sensor Data
|
||||||
|
|
||||||
my $oidbase = "1.3.6.1.4.1.1588.2.1.1.1.1.22";
|
my $oidbase = "1.3.6.1.4.1.1588.2.1.1.1.1.22";
|
||||||
|
|
||||||
|
|
||||||
|
# Friendly type names for sensors
|
||||||
my %sensorTypes = (
|
my %sensorTypes = (
|
||||||
1 => "temperature",
|
1 => "temperature",
|
||||||
2 => "fan",
|
2 => "fan",
|
||||||
3 => "power-supply"
|
3 => "power-supply"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# Friendly status names for sensors
|
||||||
my %sensorStatus = (
|
my %sensorStatus = (
|
||||||
1 => "Unknown",
|
1 => "Unknown",
|
||||||
2 => "Faulty",
|
2 => "Faulty",
|
||||||
@ -45,12 +43,14 @@ my %sensorStatus = (
|
|||||||
|
|
||||||
sub snmp_fetchbase($$$$);
|
sub snmp_fetchbase($$$$);
|
||||||
|
|
||||||
|
# Create the Nagios plugin object
|
||||||
my $np = Nagios::Plugin->new(
|
my $np = Nagios::Plugin->new(
|
||||||
usage => "Usage: %s -H <hostname> -c <snmp_community>",
|
usage => "Usage: %s -H <hostname> -c <snmp_community>",
|
||||||
version => "0.01",
|
version => "0.01",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
# Add valid arguments
|
||||||
$np->add_arg(
|
$np->add_arg(
|
||||||
spec => 'hostname|H=s',
|
spec => 'hostname|H=s',
|
||||||
help => '-H, --hostname=<hostname>',
|
help => '-H, --hostname=<hostname>',
|
||||||
@ -77,9 +77,11 @@ $np->add_arg(
|
|||||||
required => 0,
|
required => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# Parse Arguments
|
||||||
$np->getopts();
|
$np->getopts();
|
||||||
|
|
||||||
|
|
||||||
|
# Fetch the snmp data from the switch
|
||||||
my $snmp_sensor_data = snmp_fetchbase(
|
my $snmp_sensor_data = snmp_fetchbase(
|
||||||
$np->opts->hostname,
|
$np->opts->hostname,
|
||||||
$np->opts->community,
|
$np->opts->community,
|
||||||
@ -87,66 +89,83 @@ my $snmp_sensor_data = snmp_fetchbase(
|
|||||||
$oidbase);
|
$oidbase);
|
||||||
|
|
||||||
|
|
||||||
|
# Re-format snmp sensor data to easily parsable for the plugin
|
||||||
my %sensordata;
|
my %sensordata;
|
||||||
foreach my $k (keys %{$snmp_sensor_data}) {
|
foreach my $k (keys %{$snmp_sensor_data}) {
|
||||||
|
# Remove spaces from front/end
|
||||||
my $v = $snmp_sensor_data->{$k};
|
my $v = $snmp_sensor_data->{$k};
|
||||||
$v =~ s/^\s+//g;
|
$v =~ s/^\s+//g;
|
||||||
$v =~ s/\s+$//g;
|
$v =~ s/\s+$//g;
|
||||||
|
|
||||||
if ($k =~ /^1\.3\.6\.1\.4\.1\.1588\.2\.1\.1\.1\.1\.22\.1\.(\d+)\.(\d+)$/) {
|
if ($k =~ /^1\.3\.6\.1\.4\.1\.1588\.2\.1\.1\.1\.1\.22\.1\.(\d+)\.(\d+)$/) {
|
||||||
$sensordata{$2}->{$1} = $v;
|
$sensordata{$2}->{$1} = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Hack for multiline status output
|
||||||
$np->add_message( OK, "" ) if ($np->opts->longserviceoutput);
|
$np->add_message( OK, "" ) if ($np->opts->longserviceoutput);
|
||||||
foreach my $sensor (sort keys %sensordata) {
|
|
||||||
if ($sensorStatus{$sensordata{$sensor}->{3}} ne "Nominal") {
|
|
||||||
$np->add_message( CRITICAL, "$sensordata{$sensor}->{5} is $sensorStatus{$sensordata{$sensor}->{3}}");
|
|
||||||
} else {
|
|
||||||
$np->add_message( OK, "$sensordata{$sensor}->{5} is $sensorStatus{$sensordata{$sensor}->{3}}");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
# Loop through each installed sensor
|
||||||
|
foreach my $sensor (sort keys %sensordata) {
|
||||||
|
my $label = "";
|
||||||
|
|
||||||
|
# Add the performance data
|
||||||
if ($sensorTypes{$sensordata{$sensor}->{2}} eq "temperature") {
|
if ($sensorTypes{$sensordata{$sensor}->{2}} eq "temperature") {
|
||||||
|
$label = '°';
|
||||||
$np->add_perfdata(
|
$np->add_perfdata(
|
||||||
label => $sensordata{$sensor}->{5},
|
label => $sensordata{$sensor}->{5},
|
||||||
value => $sensordata{$sensor}->{4},
|
value => $sensordata{$sensor}->{4},
|
||||||
uom => "Celsius");
|
uom => "Celsius");
|
||||||
} elsif ($sensorTypes{$sensordata{$sensor}->{2}} eq "fan") {
|
} elsif ($sensorTypes{$sensordata{$sensor}->{2}} eq "fan") {
|
||||||
|
$label = 'RPM';
|
||||||
$np->add_perfdata(
|
$np->add_perfdata(
|
||||||
label => $sensordata{$sensor}->{5},
|
label => $sensordata{$sensor}->{5},
|
||||||
value => $sensordata{$sensor}->{4},
|
value => $sensordata{$sensor}->{4},
|
||||||
uom => "RPM");
|
uom => "RPM");
|
||||||
}
|
}
|
||||||
#printf("Type: %-14s Name: %-22s Status: %-12s Value: %i\n",
|
|
||||||
#$sensorTypes{$sensordata{$sensor}->{2}},
|
# Are you OK ?
|
||||||
#$sensordata{$sensor}->{5},
|
if ($sensorStatus{$sensordata{$sensor}->{3}} ne "Nominal") {
|
||||||
#$sensorStatus{$sensordata{$sensor}->{3}},
|
$np->add_message( CRITICAL, "$sensordata{$sensor}->{5} is $sensorStatus{$sensordata{$sensor}->{3}} $sensordata{$sensor}->{4}$label");
|
||||||
#$sensordata{$sensor}->{4});
|
# Nominal data
|
||||||
|
} else {
|
||||||
|
$np->add_message( OK, "$sensordata{$sensor}->{5} is $sensorStatus{$sensordata{$sensor}->{3}} $sensordata{$sensor}->{4}$label");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
my ($code, $message) = $np->check_messages("join" => ($np->opts->longserviceoutput ? "\n" : ""));
|
# Process messages and get return code
|
||||||
|
my ($code, $message) = $np->check_messages("join" => ($np->opts->longserviceoutput ? "\n" : " - "));
|
||||||
|
|
||||||
|
# We're done, return exit code, message and perfdata
|
||||||
$np->nagios_exit( $code, $message );
|
$np->nagios_exit( $code, $message );
|
||||||
|
|
||||||
|
# Fetch SNMP data
|
||||||
sub snmp_fetchbase($$$$) {
|
sub snmp_fetchbase($$$$) {
|
||||||
my $host = shift;
|
my $host = shift;
|
||||||
my $community = shift;
|
my $community = shift;
|
||||||
my $version = shift;
|
my $version = shift;
|
||||||
my $oidbase = shift;
|
my $oidbase = shift;
|
||||||
|
|
||||||
|
# Setup SNMP session
|
||||||
my ($session, $error) = Net::SNMP->session(
|
my ($session, $error) = Net::SNMP->session(
|
||||||
-hostname => $host,
|
-hostname => $host,
|
||||||
-community => $community,
|
-community => $community,
|
||||||
-version => $version,
|
-version => $version,
|
||||||
-port => "161"
|
-port => "161"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# Handle errors
|
||||||
$np->nagios_exit(CRITICAL, "Unable to connect to snmp host, $error") if ($error);
|
$np->nagios_exit(CRITICAL, "Unable to connect to snmp host, $error") if ($error);
|
||||||
|
|
||||||
|
# Fetch oids
|
||||||
my $response = $session->get_table(-baseoid => $oidbase);
|
my $response = $session->get_table(-baseoid => $oidbase);
|
||||||
|
|
||||||
my $err = $session->error;
|
my $err = $session->error;
|
||||||
$np->nagios_exit(CRITICAL, "Unable to retrieve snmp data, $err") if ($err);
|
$np->nagios_exit(CRITICAL, "Unable to retrieve snmp data, $err") if ($err);
|
||||||
|
|
||||||
|
# Return SNMP Table hash
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user