update mdstat-parser.pl script to support RAID 0 and report WARNING if array is rebuilding

tags/smeserver-zabbix-agent-0.4.3-1
Daniel Berteaud 12 years ago
parent 912f470706
commit 0de50fc150
  1. 28
      root/var/lib/zabbix/bin/mdstat-parser.pl

@ -6,6 +6,10 @@
# Slightly modified by Daniel B. for integration on SME Server / Zabbix
# 24 Apr 2009
# - One line Repport
# - Support RAID 0 Array
# - Repport Warning if an array is rebuilding
#
# Simple parser for /proc/mdstat that outputs status of all
@ -67,9 +71,13 @@ while (<FILE>) {
push @raids, $dev;
my @array = split(/ /);
$devs_total{$dev} = 0;
my $devs_up = 0;
my $missing = 0;
for $_ (@array) {
$level{$dev} = $1 if /^(raid\d+)$/;
next if ! /(\w+)\[\d+\](\(.\))*/;
$devs_total{$dev}++;
if ($2 eq "(F)") {
$failed_devs{$dev} .= "$1,";
}
@ -78,6 +86,7 @@ while (<FILE>) {
}
else {
$active_devs{$dev} .= "$1,";
$devs_up++;
}
}
if (! defined($active_devs{$dev})) { $active_devs{$dev} = "none"; }
@ -88,18 +97,18 @@ while (<FILE>) {
else { $failed_devs{$dev} =~ s/,$//; }
$_ = <FILE>;
/(\d+)\ blocks\ \[(\d+)\/(\d+)\]\s+\[(.*)\]$/;
/(\d+)\ blocks\ (.*)(\[.*\])\s?$/;
$size{$dev} = int($1/1024);
#print "$3\n";
$missing = 1 if ($3 =~ m/_/);
if ($size{$dev} > 1024){
$size{$dev} = int($size{$dev}/1024)."GB";
}
else{
$size{$dev} .= "MB";
}
$devs_total{$dev} = $2;
my $devs_up = $3;
my $stat = $4;
if ($devs_total{$dev} > $devs_up or $failed_devs{$dev} ne "none") {
$_ = <FILE>;
if (($devs_total{$dev} > $devs_up) || ($failed_devs{$dev} ne "none") || (($missing) && (!/recovery/))) {
$status{$dev} = "Degraded";
$result = "CRITICAL";
$retval = $ERRORS{"CRITICAL"};
@ -107,6 +116,14 @@ while (<FILE>) {
else {
$status{$dev} = "Optimal";
}
if (/recovery/){
$status{$dev} = "Rebuilding";
if ($result eq "OK"){
$result = "WARNING";
$retval = $ERRORS{"WARNING"};
}
}
}
print "$result: ";
@ -125,6 +142,7 @@ Check status of Linux SW RAID
Author: Michal Ludvig <michal\@logix.cz> (c) 2006
http://www.logix.cz/michal/devel/nagios
Modified by Daniel B. <daniel\@firewall-services.com>:
Usage: mdstat-parser.pl [options]

Loading…
Cancel
Save