Fwd: support for mdadm on linux
"Kirk Bauer" <[email protected]>
| Newsgroups | gmane.comp.log.logwatch.devel |
|---|---|
| Message-ID | <[email protected]> |
---------- Forwarded message ---------- From: Pat Riehecky <[email protected]> Date: Mon, 31 Mar 2008 13:22:27 -0500 Subject: support for mdadm on linux To: [email protected] This patch adds support for keeping an eye on software RAID arrays via mdadm. I have been using it for a few days now and it seems to work perfectly on both systems with and without mdadm. I would like to offer it to you for inclusion in the next version of logwatch. Pat -- Kirk Bauer <[email protected]> http://linux.kaybee.org | www.logwatch.org Author, Automating UNIX & Linux Administration _______________________________________________ Logwatch-Devel mailing list [email protected] http://www2.list.logwatch.org:81/mailman/listinfo/logwatch-devel
mdadm.diff
(text/x-patch, 4 KB)
--- scripts/services/mdadm 2008-03-31 12:52:59.000000000 -0500
+++ scripts/services/mdadm 2008-03-31 12:36:49.000000000 -0500
@@ -0,0 +1,105 @@
+#!/usr/bin/perl -w
+use strict;
+$|++;
+
+my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
+
+my $devices = `mdadm --examine --scan 2>/dev/null| awk '{print \$2}'`;
+
+chomp($devices);
+
+if ($devices ne '')
+ {
+ foreach my $dev (split(/\n/,$devices))
+ {
+ my $md = `mdadm --misc --detail $dev | grep -v $dev`;
+ chomp($md);
+
+ my %mdhash;
+ foreach (split(/\n/,$md))
+ {
+ $mdhash{'level'} = $1 if ($_ =~ /Raid Level ?: ?(.*)$/);
+ $mdhash{'active'} = $1 if ($_ =~ /Active Devices ?: ?(.*)$/);
+ $mdhash{'working'} = $1 if ($_ =~ /Working Devices ?: ?(.*)$/);
+ $mdhash{'failed'} = $1 if ($_ =~ /Failed Devices ?: ?(.*)$/);
+ $mdhash{'spare'} = $1 if ($_ =~ /Spare Devices ?: ?(.*)$/);
+ $mdhash{'state'} = $1 if ($_ =~ /State ?: ?(.*)$/);
+ $mdhash{'rebuild'} = $1 if ($_ =~ /Rebuild Status ?: ?(.*)$/);
+ push(@{$mdhash{'good devices'}},$1) if ($_ =~ /sync .*(\/dev\/[\w\d\-\_]*)/);
+ push(@{$mdhash{'middle devices'}},$1) if ($_ =~ /rebuilding .*(\/dev\/[\w\d\-\_]*)/);
+ push(@{$mdhash{'bad devices'}},$1) if ($_ =~ /faulty .*(\/dev\/[\w\d\-\_]*)/);
+ }
+
+ if ($Detail <= 4)
+ {
+ if (lc($mdhash{'state'}) =~ /clean|active/)
+ {
+ print "$dev : $mdhash{'state'}\n";
+ }
+ else
+ {
+ print "$dev : $mdhash{'state'}\n";
+ if (@{$mdhash{'middle devices'}})
+ {
+ if (defined($mdhash{'rebuild'}) and ($mdhash{'rebuild'} ne ''))
+ {
+ print "\tRebuilding status: $mdhash{'rebuild'}\n";
+ }
+ print "\tRebuilding @{$mdhash{'middle devices'}}\n";
+ }
+ if (@{$mdhash{'bad devices'}})
+ {
+ print "\tFailed @{$mdhash{'bad devices'}}\n";
+ }
+ }
+ }
+ elsif($Detail <= 9)
+ {
+ if (lc($mdhash{'state'}) =~ /clean|active/)
+ {
+ print "$dev : $mdhash{'state'} - @{$mdhash{'good devices'}}\n";
+ }
+ else
+ {
+ print "$dev : $mdhash{'state'}\n";
+ if (@{$mdhash{'middle devices'}})
+ {
+ if (defined($mdhash{'rebuild'}) and ($mdhash{'rebuild'} ne ''))
+ {
+ print "\tRebuilding status: $mdhash{'rebuild'}\n";
+ }
+ print "\t Rebuilding : @{$mdhash{'middle devices'}}\n";
+ }
+ if (@{$mdhash{'bad devices'}})
+ {
+ print "\t Failed : @{$mdhash{'bad devices'}}\n";
+ }
+ print "\t Good : @{$mdhash{'good devices'}}\n";
+ }
+ }
+ else
+ {
+ print "$dev : $mdhash{'state'}\n";
+ print "\t Raid Level : $mdhash{'level'}\n";
+ print "\tGood Devices : @{$mdhash{'good devices'}}\n";
+ if (defined ($mdhash{'middle devices'}) and @{$mdhash{'middle devices'}})
+ {
+ if (defined($mdhash{'rebuild'}) and ($mdhash{'rebuild'} ne ''))
+ {
+ print "\tRebuilding status: $mdhash{'rebuild'}\n";
+ }
+ print "\t Rebuilding : @{$mdhash{'middle devices'}}\n";
+ }
+ if (defined($mdhash{'bad devices'}) and @{$mdhash{'bad devices'}})
+ {
+ print "\t Failed : @{$mdhash{'bad devices'}}\n";
+ }
+ if ($mdhash{'spare'} ne 0)
+ {
+ print "\t Spares : $mdhash{'spare'}\n";
+ }
+ print "\n";
+ }
+ }
+ }
+
--- conf/services/mdadm.conf 2008-03-31 12:52:59.000000000 -0500
+++ conf/services/mdadm.conf 2008-03-31 12:49:09.000000000 -0500
@@ -0,0 +1,15 @@
+# You can put comments anywhere you want to. They are effective for the
+# rest of the line.
+
+# this is in the format of <name> = <value>. Whitespace at the beginning
+# and end of the lines is removed. Whitespace before and after the = sign
+# is removed. Everything is case *insensitive*.
+
+# Yes = True = On = 1
+# No = False = Off = 0
+
+Title = "Mdadm"
+
+# Which logfile group...
+LogFile = messages
+