From 57f02273f8aae960434b70e484d0e521e4f6f63d Mon Sep 17 00:00:00 2001 From: Jan Synacek Date: Tue, 22 Jan 2013 09:24:25 +0100 Subject: [PATCH] Improve mdadm script --- logwatch-mdadm.patch | 152 +++++++++++++++++++++++++++++++++++++++++++ logwatch.spec | 7 +- 2 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 logwatch-mdadm.patch diff --git a/logwatch-mdadm.patch b/logwatch-mdadm.patch new file mode 100644 index 0000000..91d9eec --- /dev/null +++ b/logwatch-mdadm.patch @@ -0,0 +1,152 @@ +Author: Orion Poplawski + +Index: scripts/services/mdadm +=================================================================== +--- scripts/services/mdadm (revision 130) ++++ scripts/services/mdadm (working copy) +@@ -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 () { ++ 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 () { ++ $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"; + } + } + diff --git a/logwatch.spec b/logwatch.spec index 5c601d8..29ea72e 100644 --- a/logwatch.spec +++ b/logwatch.spec @@ -1,7 +1,7 @@ Summary: A log file analysis program Name: logwatch Version: 7.4.0 -Release: 22.20130102svn127%{?dist} +Release: 23.20130102svn127%{?dist} License: MIT Group: Applications/System URL: http://www.logwatch.org/ @@ -29,6 +29,7 @@ Patch17: logwatch-http-error.patch # Not upstreamed yet Patch18: logwatch-secure-username.patch Patch19: logwatch-dovecot-timestamps.patch +Patch20: logwatch-mdadm.patch Requires: textutils sh-utils grep mailx Requires: perl(Date::Manip) Requires: perl(Sys::CPU) @@ -53,6 +54,7 @@ of the package on many systems. %patch17 -p1 %patch18 -p1 %patch19 -p1 +%patch20 -p0 rm -f scripts/services/*.orig %build @@ -143,6 +145,9 @@ echo "# Configuration overrides for specific logfiles/services may be placed her %{_mandir}/man*/* %changelog +* Tue Jan 22 2013 Jan Synáček - 7.4.0-23.20130102svn127 +- Improve mdadm script + * Fri Jan 11 2013 Jan Synáček - 7.4.0-22.20130102svn127 - Add secure-username patch to properly ignore "password check failed for user" (rhbz#894272)