Fwd: Improved configuration hierarchy

"Kirk Bauer" <[email protected]>
Newsgroups gmane.comp.log.logwatch.devel
Message-ID <[email protected]>
Not sure if we want to separate default and dist... but if we weren't
treating all directories equally I think we should.

Unfortunately these days it is all I can do to forward these to the
list, I'm not doing as much pre-screening as I normally do.  Hopefully
this is a useful patch.


---------- Forwarded message ----------
From: Chris O'Regan <[email protected]>
Date: Tue, Feb 12, 2008 at 3:40 PM
Subject: Improved configuration hierarchy
To: [email protected]


Hello,

 I am adapting LogWatch to our environment. Fortunately a lot of the work
 has been done to help customize the configuration but I have made some
 changes. In particular, the HOWTO states that the configuration
 structure is the same for all three directories, but in practice this is
 not always true. This patch ensures that logwatch.pl will look in all
 three places for its configuration, and in the proper order.

 Also, I found it useful to separate the "default" and "dist"
 configuration directories. I associate the "default" with what comes
 with this particular version of logwatch and it should refer to the
 package installation directory. The "dist" directory contains
 modifications that affect all my servers. They should reside in a shared
 directory outside of the package so that it is easy to upgrade. I have
 also changed the naming convention to fit my environment.

 Not sure if these are of interest to you but I figured I would share
 them anyway.


 Thanks,

 Chris



-- 
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.pl.patch (text/x-patch, 8.1 KB)
--- .old/logwatch.pl.20080211.124358	2007-05-19 20:24:20.000000000 -0400
+++ logwatch.pl	2008-02-11 14:08:00.000000000 -0500
@@ -8,7 +8,7 @@
 
 ########################################################
 # Specify version and build-date:
-my $Version = '7.3.6';
+my $Version = '7.3.6-encs';
 my $VDate = '05/19/07';
 
 #######################################################
@@ -18,6 +18,8 @@
 # Please send all comments, suggestions, bug reports,
 #    etc, to [email protected].
 #
+# 2008-02-11 Chris O'Regan: Improve three-tier configuration structure
+#
 ########################################################
 
 # About the locale:  some functions use locale information.  In particular,
@@ -41,8 +43,10 @@
 use POSIX qw(locale_h);
 setlocale(LC_ALL, "C");
 
-my $BaseDir = "/usr/share/logwatch";
-my $ConfigDir = "/etc/logwatch";
+#my $BaseDir = "/usr/share/logwatch";
+my $BaseDir = "/common/pkg/logwatch-7.3.6/root";
+my $DistDir = "/common/Share/logwatch";
+my $ConfigDir = "/local/data/logwatch";
 my $PerlVersion = "$^X";
 
 #############################################################################
@@ -81,18 +85,18 @@
 
 if (-e "$ConfigDir/conf/html/header.html") {
    $Config{'html_header'} = "$ConfigDir/conf/html/header.html";
-} elsif (-e "$BaseDir/dist.conf/html/header.html") {
-   $Config{'html_header'} = "$BaseDir/dist.conf/html/header.html";
+} elsif (-e "$DistDir/conf/html/header.html") {
+   $Config{'html_header'} = "$DistDir/conf/html/header.html";
 } else {
-   $Config{'html_header'} = "$BaseDir/default.conf/html/header.html";
+   $Config{'html_header'} = "$BaseDir/conf/html/header.html";
 }
 
 if (-e "$ConfigDir/conf/html/footer.html") {
    $Config{'html_footer'} = "$ConfigDir/conf/html/footer.html";
-} elsif (-e "$BaseDir/dist.conf/html/footer.html") {
-   $Config{'html_footer'} = "$BaseDir/dist.conf/html/footer.html";
+} elsif (-e "$DistDir/conf/html/footer.html") {
+   $Config{'html_footer'} = "$DistDir/conf/html/footer.html";
 } else {
-   $Config{'html_footer'} = "$BaseDir/default.conf/html/footer.html";
+   $Config{'html_footer'} = "$BaseDir/conf/html/footer.html";
 }
 
 # Logwatch now does some basic searching for logs
@@ -283,8 +287,9 @@
 @ReadConfigNames = ();
 @ReadConfigValues = ();
 
-ReadConfigFile ("$BaseDir/default.conf/logwatch.conf", "");
-ReadConfigFile ("$BaseDir/dist.conf/logwatch.conf", "");
+ReadConfigFile ("$BaseDir/conf/logwatch.conf", "");
+ReadConfigFile ("$DistDir/conf/logwatch.conf", "");
+ReadConfigFile ("$DistDir/conf/override.conf", "logwatch");
 ReadConfigFile ("$ConfigDir/conf/logwatch.conf", "");
 ReadConfigFile ("$ConfigDir/conf/override.conf", "logwatch");
 
@@ -450,7 +455,7 @@
 my (@CmdList, @CmdArgList, @Separators, $ThisFile, $count);
 
 
-foreach my $ServicesDir ("$BaseDir/default.conf", "$BaseDir/dist.conf", "$ConfigDir/conf") {
+foreach my $ServicesDir ("$ConfigDir/conf", "$DistDir/conf", "$BaseDir/conf") {
    if (-d "$ServicesDir/services") {
       opendir(SERVICESDIR, "$ServicesDir/services") or
          die "$ServicesDir $!";
@@ -474,9 +479,11 @@
    @ReadConfigValues = ();
    @Separators = ();
    push (@Separators, scalar(@ReadConfigNames));
-   ReadConfigFile("$BaseDir/default.conf/services/$f", "");
+   ReadConfigFile("$BaseDir/conf/services/$f", "");
+   push (@Separators, scalar(@ReadConfigNames));
+   ReadConfigFile("$DistDir/conf/services/$f", "");
    push (@Separators, scalar(@ReadConfigNames));
-   ReadConfigFile("$BaseDir/dist.conf/services/$f", "");
+   ReadConfigFile("$DistDir/conf/override.conf", "services/$ThisService");
    push (@Separators, scalar(@ReadConfigNames));
    ReadConfigFile("$ConfigDir/conf/services/$f","");
    push (@Separators, scalar(@ReadConfigNames));
@@ -519,7 +526,7 @@
 
 # Find out what logfiles are defined...
 my @logfiles = ();
-foreach my $LogfilesDir ("$BaseDir/default.conf", "$BaseDir/dist.conf", "$ConfigDir/conf") {
+foreach my $LogfilesDir ("$BaseDir/conf", "$DistDir/conf", "$ConfigDir/conf") {
    if (-d "$LogfilesDir/logfiles") {
       opendir(LOGFILEDIR, "$LogfilesDir/logfiles") or
          die "$LogfilesDir $!";
@@ -540,9 +547,11 @@
          @ReadConfigValues = ();
          @Separators = ();
          push (@Separators, scalar(@ReadConfigNames));
-         ReadConfigFile("$BaseDir/default.conf/logfiles/$ThisFile", "");
+         ReadConfigFile("$BaseDir/conf/logfiles/$ThisFile", "");
          push (@Separators, scalar(@ReadConfigNames));
-         ReadConfigFile("$BaseDir/dist.conf/logfiles/$ThisFile", "");
+         ReadConfigFile("$DistDir/conf/logfiles/$ThisFile", "");
+         push (@Separators, scalar(@ReadConfigNames));
+         ReadConfigFile("$DistDir/conf/override.conf", "logfiles/$ThisLogFile");
          push (@Separators, scalar(@ReadConfigNames));
          ReadConfigFile("$ConfigDir/conf/logfiles/$ThisFile", "");
          push (@Separators, scalar(@ReadConfigNames));
@@ -918,6 +927,8 @@
       if ($cmd =~ s/^\d+-\*//) {
          if (-f "$ConfigDir/scripts/shared/$cmd") {
             $FilterText .= ("| $PerlVersion $ConfigDir/scripts/shared/$cmd '$LogFileData{$LogFile}{$_}'" );
+         } elsif (-f "$DistDir/scripts/shared/$cmd") {
+            $FilterText .= ("| $PerlVersion $DistDir/scripts/shared/$cmd '$LogFileData{$LogFile}{$_}'" );
          } elsif (-f "$BaseDir/scripts/shared/$cmd") {
             $FilterText .= ("| $PerlVersion $BaseDir/scripts/shared/$cmd '$LogFileData{$LogFile}{$_}'" );
          } else {
@@ -939,11 +950,22 @@
       }
       closedir (LOGDIR);
    }
-   if (opendir (LOGDIR, "$BaseDir/scripts/logfiles/" . $LogFile)) {
+   if (opendir (LOGDIR, "$DistDir/scripts/logfiles/" . $LogFile)) {
       foreach (sort readdir(LOGDIR)) {
-         unless (( -d "$BaseDir/scripts/logfiles/$LogFile/$_") or
+         unless (( -d "$DistDir/scripts/logfiles/$LogFile/$_") or
                  # if in ConfigDir, then the ConfigDir version is used
                  ( -f "$ConfigDir/scripts/logfiles/$LogFile/$_")) {
+            $FilterText .= ("| $PerlVersion $DistDir/scripts/logfiles/$LogFile/$_");
+         }
+      }
+      closedir (LOGDIR);
+   }
+   if (opendir (LOGDIR, "$BaseDir/scripts/logfiles/" . $LogFile)) {
+      foreach (sort readdir(LOGDIR)) {
+         unless (( -d "$BaseDir/scripts/logfiles/$LogFile/$_") or
+                 # if in ConfigDir or DistDir, then that version is used
+                 ( -f "$ConfigDir/scripts/logfiles/$LogFile/$_") or
+                 ( -f "$DistDir/scripts/logfiles/$LogFile/$_")) {
             $FilterText .= ("| $PerlVersion $BaseDir/scripts/logfiles/$LogFile/$_");
          }
       }
@@ -1090,9 +1112,19 @@
 
    #Load our ignore file
    my @IGNORE;
+   if ( -e "$BaseDir/conf/ignore.conf") {
+      open( IGNORE, "$BaseDir/conf/ignore.conf" )  or return undef;
+      push(@IGNORE, grep {!/(^#|^\s+$)/} <IGNORE>);
+      close IGNORE;
+   }
+   if ( -e "$DistDir/conf/ignore.conf") {
+      open( IGNORE, "$DistDir/conf/ignore.conf" )  or return undef;
+      push(@IGNORE, grep {!/(^#|^\s+$)/} <IGNORE>);
+      close IGNORE;
+   }
    if ( -e "$ConfigDir/conf/ignore.conf") {
       open( IGNORE, "$ConfigDir/conf/ignore.conf" )  or return undef;
-      @IGNORE = grep {!/(^#|^\s+$)/} <IGNORE>;
+      push(@IGNORE, grep {!/(^#|^\s+$)/} <IGNORE>);
       close IGNORE;
    }
 
@@ -1129,6 +1161,8 @@
          if ($cmd =~ s/^\d+-\*//) {
             if (-f "$ConfigDir/scripts/shared/$cmd") {
                $FilterText .= ("$PerlVersion $ConfigDir/scripts/shared/$cmd '$ServiceData{$Service}{$_}' |" );
+            } elsif (-f "$DistDir/scripts/shared/$cmd") {
+               $FilterText .= ("$PerlVersion $DistDir/scripts/shared/$cmd '$ServiceData{$Service}{$_}' |" );
             } elsif (-f "$BaseDir/scripts/shared/$cmd") {
                $FilterText .= ("$PerlVersion $BaseDir/scripts/shared/$cmd '$ServiceData{$Service}{$_}' |" );
             } else {
@@ -1150,6 +1184,8 @@
       my $ServiceExec = "$BaseDir/scripts/services/$Service";
       if (-f "$ConfigDir/scripts/services/$Service") {
          $ServiceExec = "$ConfigDir/scripts/services/$Service";
+      } elsif (-f "$DistDir/scripts/services/$Service") {
+         $ServiceExec = "$DistDir/scripts/services/$Service";
       } else {
          $ServiceExec = "$BaseDir/scripts/services/$Service";
       }
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.