Don't WARN when device is being checked, only when it's rebuilding

tags/zabbix-agent-addons-0.2.24-1
Daniel Berteaud 7 years ago
parent 0c9fad57bd
commit b4f79b94e4
  1. 46
      zabbix_scripts/check_raid_mdadm

@ -31,16 +31,15 @@ my $file = "/proc/mdstat";
my $device = "all"; my $device = "all";
# Get command line options. # Get command line options.
GetOptions ('file=s' => \$file, GetOptions (
'file=s' => \$file,
'device=s' => \$device, 'device=s' => \$device,
'help' => sub { &usage() } ); 'help' => sub { &usage() }
);
## Strip leading "/dev/" from --device in case it has been given ## Strip leading "/dev/" from --device in case it has been given
$device =~ s/^\/dev\///; $device =~ s/^\/dev\///;
## Return codes for Nagios
my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
## This is a global return value - set to the worst result we get overall ## This is a global return value - set to the worst result we get overall
my $retval = 0; my $retval = 0;
@ -74,17 +73,28 @@ while (<FILE>) {
$devs_up++; $devs_up++;
} }
} }
if (! defined($active_devs{$dev})) { $active_devs{$dev} = "none"; } if (! defined($active_devs{$dev})){
else { $active_devs{$dev} =~ s/,$//; } $active_devs{$dev} = "none";
if (! defined($spare_devs{$dev})) { $spare_devs{$dev} = "none"; } }
else { $spare_devs{$dev} =~ s/,$//; } else {
if (! defined($failed_devs{$dev})) { $failed_devs{$dev} = "none"; } $active_devs{$dev} =~ s/,$//;
else { $failed_devs{$dev} =~ s/,$//; } }
if (! defined($spare_devs{$dev})){
$spare_devs{$dev} = "none";
}
else {
$spare_devs{$dev} =~ s/,$//;
}
if (! defined($failed_devs{$dev})){
$failed_devs{$dev} = "none";
}
else {
$failed_devs{$dev} =~ s/,$//;
}
$_ = <FILE>; $_ = <FILE>;
/(\d+)\ blocks\ (.*)(\[.*\])\s?$/; /(\d+)\ blocks\ (.*)(\[.*\])\s?$/;
$size{$dev} = int($1/1024); $size{$dev} = int($1/1024);
#print "$3\n";
$missing = 1 if ($3 =~ m/_/); $missing = 1 if ($3 =~ m/_/);
if ($size{$dev} > 1024){ if ($size{$dev} > 1024){
$size{$dev} = int($size{$dev}/1024)."GB"; $size{$dev} = int($size{$dev}/1024)."GB";
@ -93,23 +103,20 @@ while (<FILE>) {
$size{$dev} .= "MB"; $size{$dev} .= "MB";
} }
$_ = <FILE>; $_ = <FILE>;
if (($devs_total{$dev} > $devs_up) || ($failed_devs{$dev} ne "none") || (($missing) && (!/recovery/))) { if (($devs_total{$dev} > $devs_up) || ($failed_devs{$dev} ne "none") || (($missing) && (!/recovery/))) {
$status{$dev} = "Degraded"; $status{$dev} = "Degraded";
$result = "CRITICAL"; $result = "CRITICAL";
$retval = $ERRORS{"CRITICAL"};
} }
else { else {
$status{$dev} = "Optimal"; $status{$dev} = "Optimal";
} }
if (/recovery|resync/){ if (/(recovery|resync)\s*=\s*\d{1,2}(\.\d)?%/){
$status{$dev} = "Rebuilding"; $status{$dev} = "Rebuilding";
if ($result eq "OK"){ if ($result eq "OK"){
$result = "WARNING"; $result = "WARNING";
$retval = $ERRORS{"WARNING"};
} }
} }
} }
print "$result: "; print "$result: ";
foreach my $raid (@raids){ foreach my $raid (@raids){
@ -117,11 +124,10 @@ foreach my $raid (@raids){
} }
print "\n"; print "\n";
close FILE; close FILE;
exit $retval; exit 0;
# ===== # =====
sub usage() sub usage(){
{
printf(" printf("
Check status of Linux SW RAID Check status of Linux SW RAID

Loading…
Cancel
Save