Fwd: Patch: adding mdadm to the list of monitored services
"Kirk Bauer" <[email protected]>
| Newsgroups | gmane.comp.log.logwatch.devel |
|---|---|
| Message-ID | <[email protected]> |
---------- Forwarded message ---------- From: Pat Riehecky <[email protected]> Date: Tue, May 27, 2008 at 12:17 PM Subject: Patch: adding mdadm to the list of monitored services To: [email protected] Software RAID on linux is rather stable and mature. This patch will make logwatch report on the health of any mdadm arrays. I have found it to be very useful in putting people's mind at ease about using software RAID when we cannot afford a hardware based solution. I would love to see this in main line 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
logwatch_mdadm.diff
(text/x-patch, 4.3 KB)
diff -Nru /tmp/4AmtDIAE5r/logwatch/scripts/services/mdadm /tmp/q2AN6HLevD/logwatch/scripts/services/mdadm
--- logwatch/scripts/services/mdadm 2008-05-27 10:37:20.000000000 -0500
+++ logwatch/scripts/services/mdadm 2008-03-31 12:57:25.000000000 -0500
@@ -0,0 +1,105 @@
+## #!/usr/bin/perl -w
+## use strict;
+## $|++;
+
+my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
+exit if ($^O ne 'linux');
+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";
+ }
+ }
+ }
+
diff -Nru /tmp/4AmtDIAE5r/logwatch/default.conf/services/mdadm.conf /tmp/q2AN6HLevD/logwatch/default.conf/services/mdadm.conf
--- logwatch/default.conf/services/mdadm.conf 2008-05-27 10:37:20.000000000 -0500
+++ logwatch/default.conf/services/mdadm.conf 2008-03-31 12:57:21.000000000 -0500
@@ -0,0 +1,16 @@
+# 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 = NONE
+
+# vi: shiftwidth=3 tabstop=3 et