Revision: 134
http://logwatch.svn.sourceforge.net/logwatch/?rev=134&view=rev
Author: stefjakobs
Date: 2013-02-15 14:49:30 +0000 (Fri, 15 Feb 2013)
Log Message:
-----------
changes to the mdadm service script (Thanks Orion Poplawski):
- silence the script with detail = 0
- Use /etc/mdadm.conf to read the device list and binary mdadm as fallback
- remove system() call
Modified Paths:
--------------
scripts/services/mdadm
Modified: scripts/services/mdadm
===================================================================
--- scripts/services/mdadm 2013-02-15 14:40:44 UTC (rev 133)
+++ scripts/services/mdadm 2013-02-15 14:49:30 UTC (rev 134)
@@ -26,80 +26,88 @@
my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
-# TODO: remove awk dependency
-my $devices = `mdadm --examine --scan 2>/dev/null| awk '{print \$2}'`;
+my @devices = ();
+# Sometimes mdadm --examine --scan reports device with different names than
+# what is in use. Use /etc/mdadm.conf instead if it exists.
+if ( -f "/etc/mdadm.conf" ) {
+ open(MDADM,"< /etc/mdadm.conf");
+} else {
+ open(MDADM,"mdadm --examine --scan 2>/dev/null|");
+}
+while (<MDADM>) {
+ if (/^ARRAY/) {
+ push(@devices,(split())[1]);
+ }
+}
+close(MDADM);
-chomp($devices);
+foreach my $dev (@devices) {
+ my %mdhash;
-if ($devices ne '') {
- foreach my $dev (split(/\n/,$devices)) {
- my $md = `mdadm --misc --detail $dev | grep -v $dev`;
- chomp($md);
+ open(MDADM,"mdadm --misc --detail $dev |");
+ while (<MDADM>) {
+ $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\-\_]*)/);
+ }
+ close(MDADM);
- 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 ($Detail <= 4) {
+ if (lc($mdhash{'state'}) =~ /clean|active/) {
+ print "$dev : $mdhash{'state'}\n" if $Detail;
+ } else {
+ print "$dev : $mdhash{'state'}\n";
+ if (defined($mdhash{'middle devices'})) {
+ if (defined($mdhash{'rebuild'}) and ($mdhash{'rebuild'} ne '')) {
+ print "\tRebuilding status: $mdhash{'rebuild'}\n";
}
- if (@{$mdhash{'bad devices'}}) {
- print "\tFailed @{$mdhash{'bad devices'}}\n";
- }
+ print "\tRebuilding @{$mdhash{'middle devices'}}\n";
}
+ if (defined($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";
- }
+ }
+ elsif($Detail <= 9) {
+ if (lc($mdhash{'state'}) =~ /clean|active/) {
+ print "$dev : $mdhash{'state'} - @{$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 (@{$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'}}) {
+ if (@{$mdhash{'bad devices'}}) {
print "\t Failed : @{$mdhash{'bad devices'}}\n";
}
- if ($mdhash{'spare'} ne 0) {
- print "\t Spares : $mdhash{'spare'}\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 "\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";
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.