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. 148
      zabbix_scripts/check_raid_mdadm

@ -27,20 +27,19 @@ use Getopt::Long;
# #
# unused devices: <none> # unused devices: <none>
my $file = "/proc/mdstat"; my $file = "/proc/mdstat";
my $device = "all"; my $device = "all";
# Get command line options. # Get command line options.
GetOptions ('file=s' => \$file, GetOptions (
'device=s' => \$device, 'file=s' => \$file,
'help' => sub { &usage() } ); 'device=s' => \$device,
'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;
@ -50,78 +49,85 @@ my $result = 'OK';
open FILE, "< $file" or die "Can't open $file : $!"; open FILE, "< $file" or die "Can't open $file : $!";
while (<FILE>) { while (<FILE>) {
next if ! /^(md\d+)+\s*:/; next if ! /^(md\d+)+\s*:/;
next if $device ne "all" and $device ne $1; next if $device ne "all" and $device ne $1;
my $dev = $1; my $dev = $1;
push @raids, $dev; push @raids, $dev;
my @array = split(/ /); my @array = split(/ /);
$devs_total{$dev} = 0; $devs_total{$dev} = 0;
my $devs_up = 0; my $devs_up = 0;
my $missing = 0; my $missing = 0;
for $_ (@array) { for $_ (@array) {
$level{$dev} = $1 if /^(raid\d+)$/; $level{$dev} = $1 if /^(raid\d+)$/;
next if ! /(\w+)\[\d+\](\(.\))*/; next if ! /(\w+)\[\d+\](\(.\))*/;
$devs_total{$dev}++; $devs_total{$dev}++;
if ($2 eq "(F)") { if ($2 eq "(F)") {
$failed_devs{$dev} .= "$1,"; $failed_devs{$dev} .= "$1,";
} }
elsif ($2 eq "(S)") { elsif ($2 eq "(S)") {
$spare_devs{$dev} .= "$1,"; $spare_devs{$dev} .= "$1,";
} }
else { else {
$active_devs{$dev} .= "$1,"; $active_devs{$dev} .= "$1,";
$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})){
$_ = <FILE>; $spare_devs{$dev} = "none";
/(\d+)\ blocks\ (.*)(\[.*\])\s?$/; }
$size{$dev} = int($1/1024); else {
#print "$3\n"; $spare_devs{$dev} =~ s/,$//;
$missing = 1 if ($3 =~ m/_/); }
if ($size{$dev} > 1024){ if (! defined($failed_devs{$dev})){
$size{$dev} = int($size{$dev}/1024)."GB"; $failed_devs{$dev} = "none";
} }
else{ else {
$size{$dev} .= "MB"; $failed_devs{$dev} =~ s/,$//;
} }
$_ = <FILE>;
if (($devs_total{$dev} > $devs_up) || ($failed_devs{$dev} ne "none") || (($missing) && (!/recovery/))) { $_ = <FILE>;
$status{$dev} = "Degraded"; /(\d+)\ blocks\ (.*)(\[.*\])\s?$/;
$result = "CRITICAL"; $size{$dev} = int($1/1024);
$retval = $ERRORS{"CRITICAL"}; $missing = 1 if ($3 =~ m/_/);
} if ($size{$dev} > 1024){
else { $size{$dev} = int($size{$dev}/1024)."GB";
$status{$dev} = "Optimal"; }
} else{
if (/recovery|resync/){ $size{$dev} .= "MB";
$status{$dev} = "Rebuilding"; }
if ($result eq "OK"){ $_ = <FILE>;
$result = "WARNING";
$retval = $ERRORS{"WARNING"}; if (($devs_total{$dev} > $devs_up) || ($failed_devs{$dev} ne "none") || (($missing) && (!/recovery/))) {
} $status{$dev} = "Degraded";
} $result = "CRITICAL";
}
else {
$status{$dev} = "Optimal";
}
if (/(recovery|resync)\s*=\s*\d{1,2}(\.\d)?%/){
$status{$dev} = "Rebuilding";
if ($result eq "OK"){
$result = "WARNING";
}
}
} }
print "$result: "; print "$result: ";
foreach my $raid (@raids){ foreach my $raid (@raids){
print "$raid:$level{$raid}:$devs_total{$raid} drives:$size{$raid}:$status{$raid} "; print "$raid:$level{$raid}:$devs_total{$raid} drives:$size{$raid}:$status{$raid} ";
} }
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