Perl-скрипт проверки RAID массива MegaRaid. Скачаиваем утилиту MegaCli54 и юзаем код
#!/usr/bin/perl my $CMD="/usr/bin/sudo /usr/local/sbin/MegaCli64 -pdlist -aALL -NoLog"; my @result=`$CMD`; my $EXIT_CODE=0; my $MSG; my $slot_number; my $count=0; my $hsp_count=0; my $online_count=0; my %disks; foreach (@result) { chomp; if (/Slot Number: (\d+)/) { $slot_number=$1; $count++; } if (/Error Count: (\d+)/) { $disks{$slot_number}->{error}+=$1; if ($1) { $MSG.="Disk ".$slot_number." has ".$1." errors. "; if (!$EXIT_CODE) { $EXIT_CODE=1; } } } if (/Predictive Failure Count: (\d+)/) { $disks{$slot_number}->{failure}+=$1; if ($1) { $MSG.="Disk ".$slot_number." has ".$1." predictive failures. "; if (!$EXIT_CODE) { $EXIT_CODE=1; } } } if (/Firmware state: (\w+)/g) { my $state=$1; $disks{$slot_number}->{state}=$state; if ($state eq "Online") { $online_count++; } elsif ($state eq "Hotspare") { $hsp_count++; } else { $MSG.="Disk ".$slot_number." is ".$state.". "; $EXIT_CODE=2; } } } $MSG=$count." disks: ".$online_count." online, ".$hsp_count." hotspare.".$MSG; print $MSG; exit($EXIT_CODE); |
Обновлено 04.04.2016 09:59