SF.net SVN: logwatch:[278] branches/beta-7-4-2/scripts/logwatch.pl
[email protected] Wed, 24 Dec 2014 14:02:17 +0000
| Newsgroups | gmane.comp.log.logwatch.devel |
|---|---|
| Message-ID | <[email protected]> |
Revision: 278
http://sourceforge.net/p/logwatch/code/278
Author: stefjakobs
Date: 2014-12-24 14:02:17 +0000 (Wed, 24 Dec 2014)
Log Message:
-----------
Test: Looking for unprocessed log entries
Modified Paths:
--------------
branches/beta-7-4-2/scripts/logwatch.pl
Modified: branches/beta-7-4-2/scripts/logwatch.pl
===================================================================
--- branches/beta-7-4-2/scripts/logwatch.pl 2014-12-24 14:01:10 UTC (rev 277)
+++ branches/beta-7-4-2/scripts/logwatch.pl 2014-12-24 14:02:17 UTC (rev 278)
@@ -913,6 +913,37 @@
parselogs();
}
+
+foreach $LogFile (@LogFileList) {
+ next if ($LogFile eq 'none');
+
+ my $LogFileName = $TempDir . $LogFile;
+ next unless -f "$LogFileName";
+ my $MatchedFileText = $LogFileName . "-matched";
+ my $UnmatchedFileText = $LogFileName . "-unmatched";
+ my $Command = "";
+ if (-s $MatchedFileText) {
+ $Command = "grep -Fvf $MatchedFileText $LogFileName > $UnmatchedFileText";
+ } else {
+ $Command = "ln $LogFileName $UnmatchedFileText";
+ }
+ if ($Config{'debug'}>4) {
+ print "\nChecking for unmatched entries in LogFile: " . $LogFile . "\n" . $Command . "\n";
+ }
+ if ($LogFile !~ /^[-_\w\d]+$/) {
+ print STDERR "Unexpected filename: [[$LogFile]]. Not used\n"
+ } else {
+ #System call does the log processing
+ system("$Command");
+ #or die "system '$Command' failed: $?"
+ }
+ if (-s $UnmatchedFileText) {
+ print "Unmatched entries in $LogFile:\n";
+ #system("$Config{'pathtocat'} $UnmatchedFileText");
+ system("awk '{print \$5}' $UnmatchedFileText| sed -e 's/\[[0-9]*\]//' -e s/:// |sort -u");
+ }
+}
+
#Close Filehandle is needed -mgt
close(OUTFILE) unless ($Config{'output'} eq "stdout");
#############################################################################
@@ -1263,9 +1294,16 @@
my $FileText = "";
foreach $ThisFile (@FileList) {
if (-s $TempDir . $ThisFile) {
- $FileText .= ( $TempDir . $ThisFile . " ");
+ $FileText .= ($TempDir . $ThisFile . " ");
}
}
+ # Trim final space
+ $FileText =~ s/ *$//;
+ # If we only process a single log file, we can use tee to generate the matched file
+ my $MatchedFile = "";
+ if ($FileText and $FileText !~ / /) {
+ $MatchedFile = $FileText . "-matched";
+ }
# remove the ENV entries set by previous service
foreach my $Parm (@EnvList) {
@@ -1273,17 +1311,28 @@
}
@EnvList = ();
- my $FilterText = " ";
+ my $FilterText = "";
+ my $ServiceFilter = "";
foreach (sort keys %{$ServiceData{$Service}}) {
my $cmd = $_;
if ($cmd =~ s/^\d+-\*//) {
+ my $CmdPath = "";
if (-f "$ConfigDir/scripts/shared/$cmd") {
- $FilterText .= ("$PerlVersion $ConfigDir/scripts/shared/$cmd '$ServiceData{$Service}{$_}' |" );
+ $CmdPath="$ConfigDir/scripts/shared/$cmd";
} elsif (-f "$BaseDir/scripts/shared/$cmd") {
- $FilterText .= ("$PerlVersion $BaseDir/scripts/shared/$cmd '$ServiceData{$Service}{$_}' |" );
+ $CmdPath="$BaseDir/scripts/shared/$cmd";
} else {
die "Cannot find shared script $cmd\n";
}
+ $FilterText .= "$PerlVersion $CmdPath '$ServiceData{$Service}{$_}' |";
+ if ($cmd =~ /service/) {
+ # If we only process a single log file, we can use tee to generate the matched file
+ if ($FileText and $FileText !~ / /) {
+ $FilterText .= "tee -a $MatchedFile ${MatchedFile}-$Service |";
+ } else {
+ $ServiceFilter = "| $PerlVersion $CmdPath '$ServiceData{$Service}{$_}'";
+ }
+ }
} elsif ($cmd =~ s/^\$//) {
$ENV{$cmd} = $ServiceData{$Service}{$_};
push @EnvList, $cmd;
@@ -1292,6 +1341,14 @@
}
}
}
+ # If we didn't find a service filter, use tee
+ if ($ServiceFilter eq "" and $FilterText !~ /tee -a/ and $MatchedFile) {
+ $FilterText .= "tee -a $MatchedFile ${MatchedFile}-$Service |";
+ }
+ if ($Config{'debug'}>9) {
+ print "ServiceFilter=$ServiceFilter\n";
+ }
+
# set env variables LOGWATCH_mumble_LIST
push @EnvList, 'LOGWATCH_LOGFILE_LIST';
push @EnvList, 'LOGWATCH_ARCHIVE_LIST';
@@ -1405,6 +1462,17 @@
}
&output( $index_par, "\n", "stop");
}
+ # If we are parsing more than one log file, we need to process matches for each
+ if ($FileText =~ / /) {
+ foreach my $MatchLogFile (split(/ /,$FileText)) {
+ $MatchedFile = $MatchLogFile . "-matched";
+ if ($Config{'debug'}>4) {
+ print "\nProcessing matched $Config{'pathtocat'} $MatchLogFile $ServiceFilter >> $MatchedFile\n";
+ }
+ system("$Config{'pathtocat'} $MatchLogFile $ServiceFilter >> $MatchedFile");
+ system("$Config{'pathtocat'} $MatchLogFile $ServiceFilter >> ${MatchedFile}-${Service}");
+ }
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net