Skip to content

Commit

Permalink
Merge pull request fatz#3 from TheFlyingCorpse/master
Browse files Browse the repository at this point in the history
Add ALERTS, fix NVRAM check and add perfdata to FSSPACE
  • Loading branch information
Jan Ulferts authored Jan 30, 2017
2 parents 23615ed + 8f256c1 commit 0004606
Showing 1 changed file with 113 additions and 20 deletions.
133 changes: 113 additions & 20 deletions nagios_check/check_datadomain
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This plugins monitors some states of your datadomain via snmp. It can monitor fo
=head1 VERSION
Version 0.1r1
Version 0.3
=head1 SYNOPSIS
Expand Down Expand Up @@ -40,14 +40,16 @@ SNMP protocol version [1,2c]
=item -m, --method <checkmethod>
check method one of PSU, NVRAM, FAN, DISKSTATE, FSSPACE, IFSTATE
check method one of PSU, NVRAM, ALERTS, FAN, DISKSTATE, FSSPACE, IFSTATE
=over 1
=item PSU: State of all Powersupplies
=item NVRAM: NVRAM battery state
=item ALERTS: Active alerts on the system
=item FAN: Fan state of all enclosures
=item DISKSTATE: disk states
Expand Down Expand Up @@ -149,6 +151,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=item 04.06.2015: Version 0.2 Fixed wrong interface state handling. Thx. @Thomas
=item 18.01.2017: Version 0.3 Add Alerts as a check, Fix NVRAM check and add perfdata to FSSPACE.
=back
=cut
Expand Down Expand Up @@ -254,9 +258,10 @@ sub print_usage () {
print " -P, --protocol\n";
print " SNMP protocol version [1,2c]\n";
print " -m, --method\n";
print " check method one of PSU, NVRAM, FAN, DISKSTATE, FSSPACE, IFSTATE\n";
print " check method one of PSU, NVRAM, ALERTS, FAN, DISKSTATE, FSSPACE, IFSTATE\n";
print " PSU: State of all Powersupplies\n";
print " NVRAM: NVRAM battery state\n";
print " ALERTS: Active alerts on the system\n";
print " FAN: Fan state of all enclosures\n";
print " DISKSTATE: disk states\n";
print " FSSPACE: used filesystem space. -w for waring % -c for critical %\n";
Expand Down Expand Up @@ -326,7 +331,7 @@ foreach (keys %{$t}) {
}
my @enclosures = keys %{$r};

my ( $output, $out );
my ( $output, $out, $perfdata );
if ($opt_m eq "PSU") {
my $state = $ERRORS{'OK'};
foreach my $enclosure (sort @enclosures) {
Expand Down Expand Up @@ -374,38 +379,119 @@ if ($opt_m eq "PSU") {
exit $ERRORS{'UNKNOWN'};
}
} elsif ($opt_m eq "NVRAM") {
my @req;
foreach my $enclosure (sort @enclosures) {
push(@req, $oids->{nvram}.".".$enclosure);
}
my $res = $session->get_request(@req);
foreach my $enclosure (@enclosures) {
my $req = $oids->{'nvram'};
my $result = $session->get_table($req);

while(my($k,$v) = each %$result) {
my $state;
my $val = $res->{$oids->{nvram}.".".$enclosure};
if ( $val == 0 ) {
$state = $ERRORS{'OK'};
} elsif ( $val > 0 && $val < 3 ) {
$state = $ERRORS{'CRITICAL'};
my $batteryId = $k;
$batteryId =~ s/$oids->{'nvram'}.//;
my $val = $v;
if ( defined $val ) {
if ( $val == 0 ) {
$state = $ERRORS{'OK'};
} elsif ( $val > 0 && $val < 3 ) {
$state = $ERRORS{'CRITICAL'};
} else {
print "UNKNOWN - plugin in unknown state\n";
exit $ERRORS{'UNKNOWN'};
}
push(@{$out->{$state}}, sprintf("%s - NVRAM battery %i is in '%s' state", uc(state_reverse($state)), $batteryId, $nvramBatteryStatus->{$val}))
} else {
print "UNKNOWN - plugin in unknown state\n";
exit $ERRORS{'UNKNOWN'};
$state = $ERRORS{'UNKNOWN'};
push(@{$out->{$state}}, sprintf("%s - NVRAM battery %i state is not known", uc(state_reverse($state)), $batteryId))
}
push(@{$out->{$state}}, sprintf("%s - NVRAM battery in enclosure %i is in ", uc(state_reverse($state)), $enclosure, $nvramBatteryStatus->{$val}))
}

if ($out->{$ERRORS{'CRITICAL'}}) {
if (defined $out->{$ERRORS{'CRITICAL'}} && scalar @{$out->{$ERRORS{'CRITICAL'}}} > 0) {
printf("CRITICAL - %i nvram batteries in critical state\n", scalar @{$out->{$ERRORS{'CRITICAL'}}});
print join("\n",@{$out->{$ERRORS{'CRITICAL'}}})."\n";
print join("\n",@{$out->{$ERRORS{'OK'}}})."\n";
exit $ERRORS{'CRITICAL'};
} elsif ($out->{$ERRORS{'OK'}}) {
} elsif (defined $out->{$ERRORS{'UNKNOWN'}} && scalar @{$out->{$ERRORS{'UNKNOWN'}}} > 0) {
printf("UNKNOWN - %i nvram batteries in unknown state\n", scalar @{$out->{$ERRORS{'UNKNOWN'}}});
print join("\n",@{$out->{$ERRORS{'UNKNOWN'}}})."\n";
print join("\n",@{$out->{$ERRORS{'OK'}}})."\n";
exit $ERRORS{'UNKNOWN'};
} elsif (defined $out->{$ERRORS{'OK'}} && scalar @{$out->{$ERRORS{'OK'}}} > 0) {
printf("OK - %i nvram batteries in ok state\n", scalar @{$out->{$ERRORS{'OK'}}});
print join("\n",@{$out->{$ERRORS{'OK'}}})."\n";
exit $ERRORS{'OK'};
} else {
print "UNKNOWN - plugin in unknown state\n";
exit $ERRORS{'UNKNOWN'};
}
} elsif ($opt_m eq "ALERTS") {
my $state=$ERRORS{'UNKNOWN'};
my $q = $oids->{'alerts'};
$result = $session->get_table($q);
my @alerts;

while(my($k,$v) = each %$result) {
my $inputkey = $k;
my $vdesc = undef;
if ($inputkey =~ m/$oids->{'alertdesc'}/) {
$inputkey =~ s/$oids->{'alertdesc'}.//;
$vdesc = "desc";
} elsif ($inputkey =~ m/$oids->{'alertsev'}/) {
$inputkey =~ s/$oids->{'alertsev'}.//;
$vdesc = "severity";
} elsif ($inputkey =~ m/$oids->{'alerttime'}/) {
$inputkey =~ s/$oids->{'alerttime'}.//;
$vdesc = "time";
} elsif ($inputkey =~ m/$oids->{'alertid'}/) {
$inputkey =~ s/$oids->{'alertid'}.//;
$vdesc = "id";
}
if (defined $vdesc) {
$alerts[$inputkey]{$vdesc} = $v;
}
}

# Remove undefined elements
@alerts = grep defined, @alerts;

foreach my $alert (@alerts){
if ($alert->{'severity'} =~ "CRITICAL") {
$state = $ERRORS{'CRITICAL'};
} elsif ($alert->{'severity'} =~ "WARNING") {
$state = $ERRORS{'WARNING'};
} else {
$state = $ERRORS{'UNKNOWN'};
}
push(@{$out->{$state}},sprintf("%s - Alert %s from %s: %s",uc(state_reverse($state)),$alert->{'id'},$alert->{'time'},$alert->{'desc'}));
}

if (defined $out->{$ERRORS{'CRITICAL'}} && scalar @{$out->{$ERRORS{'CRITICAL'}}} > 0) {
printf "CRITICAL - %i alerts in critical state\n", scalar @{$out->{$ERRORS{'CRITICAL'}}};
print join("\n",@{$out->{$ERRORS{'CRITICAL'}}})."\n";
print join("\n",@{$out->{$ERRORS{'WARNING'}}})."\n" if $out->{$ERRORS{'WARNING'}};
print join("\n",@{$out->{$ERRORS{'UNKNOWN'}}})."\n" if $out->{$ERRORS{'UNKNOWN'}};
print join("\n",@{$out->{$ERRORS{'OK'}}})."\n" if $out->{$ERRORS{'OK'}};
exit $ERRORS{'CRITICAL'};
} elsif (defined $out->{$ERRORS{'WARNING'}} && scalar @{$out->{$ERRORS{'WARNING'}}} > 0) {
printf "WARNING - %i alerts in warning state\n", scalar @{$out->{$ERRORS{'WARNING'}}};
print join("\n",@{$out->{$ERRORS{'WARNING'}}})."\n";
print join("\n",@{$out->{$ERRORS{'UNKNOWN'}}})."\n" if $out->{$ERRORS{'UNKNOWN'}};
print join("\n",@{$out->{$ERRORS{'OK'}}})."\n" if $out->{$ERRORS{'OK'}};
exit $ERRORS{'WARNING'};
} elsif (defined $out->{$ERRORS{'UNKNOWN'}} && scalar @{$out->{$ERRORS{'UNKNOWN'}}} > 0) {
printf "UNKNOWN - %i alerts in unknown state\n", scalar @{$out->{$ERRORS{'UNKNOWN'}}};
print join("\n",@{$out->{$ERRORS{'UNKNOWN'}}})."\n";
print join("\n",@{$out->{$ERRORS{'CRITICAL'}}})."\n" if $out->{$ERRORS{'CRITICAL'}};
print join("\n",@{$out->{$ERRORS{'OK'}}})."\n" if $out->{$ERRORS{'OK'}};
exit $ERRORS{'UNKNOWN'};
} else {
if (scalar @alerts == 0) {
printf "OK - No alerts\n";
} else {
printf "OK - %i alerts\n", scalar @{$out->{$ERRORS{'OK'}}};
print join("\n",@{$out->{$ERRORS{'OK'}}})."\n";
print join("\n",@{$out->{$ERRORS{'CRITICAL'}}})."\n" if $out->{$ERRORS{'CRITICAL'}};
print join("\n",@{$out->{$ERRORS{'UNKNOWN'}}})."\n" if $out->{$ERRORS{'UNKNOWN'}};
}
exit $ERRORS{'OK'};
}
} elsif ($opt_m eq "FAN") {
my $state=$ERRORS{'OK'};
$result = {'state' => $session->get_table($oids->{'fanstate'}), 'name' => $session->get_table($oids->{'fanname'}),};
Expand Down Expand Up @@ -527,21 +613,28 @@ if ($opt_m eq "PSU") {
exit $ERRORS{'UNKNOWN'};
}
push(@{$out->{$state}}, sprintf("%s - Filesystem %s filled %i%% %4.2fG available", uc(state_reverse($state)), $result->{$oids->{fsname}.".".$_}, $result->{$oids->{fsperc}.".".$_},$result->{$oids->{fsavail}.".".$_}));
push(@{$perfdata}, sprintf(" '%s_perc'=%s%%;%s;%s;0;100 '%s_avail'=%s;;;;", $result->{$oids->{fsname}.".".$_}, $result->{$oids->{fsperc}.".".$_}, $warn, $crit, $result->{$oids->{fsname}.".".$_}, $result->{$oids->{fsavail}.".".$_}));
}
if (defined $out->{$ERRORS{'CRITICAL'}} && scalar @{$out->{$ERRORS{'CRITICAL'}}} > 0) {
printf "CRITICAL - %i filesystems in critical state\n", scalar @{$out->{$ERRORS{'CRITICAL'}}};
print join("\n",@{$out->{$ERRORS{'CRITICAL'}}})."\n";
print join("\n",@{$out->{$ERRORS{'WARNING'}}})."\n" if $out->{$ERRORS{'WARNING'}};
print join("\n",@{$out->{$ERRORS{'OK'}}})."\n" if $out->{$ERRORS{'OK'}};
print " | ";
print join("", @{$perfdata});
exit $ERRORS{'CRITICAL'};
} elsif (defined $out->{$ERRORS{'WARNING'}} && scalar @{$out->{$ERRORS{'WARNING'}}} > 0) {
printf "WARNING - %i filesystems in warning state\n", scalar @{$out->{$ERRORS{'WARNING'}}};
print join("\n",@{$out->{$ERRORS{'WARNING'}}})."\n";
print join("\n",@{$out->{$ERRORS{'OK'}}})."\n" if $out->{$ERRORS{'OK'}};
print " | ";
print join("", @{$perfdata});
exit $ERRORS{'WARNING'};
} else {
printf "OK - %i filesystems ok\n", scalar @{$out->{$ERRORS{'OK'}}};
print join("\n",@{$out->{$ERRORS{'OK'}}})."\n";
print " | ";
print join("", @{$perfdata});
exit $ERRORS{'OK'}
}
} else {
Expand Down

0 comments on commit 0004606

Please sign in to comment.