Re: RFC: ConfigDir option
"Jason Pyeron" <[email protected]> Mon, 28 Nov 2016 22:34:21 -0500
| Newsgroups | gmane.comp.log.logwatch.devel |
|---|---|
| Organization | PD Inc |
| Message-ID | <A9A98CE891F848B7ACCA64612FD8BC20@black7> |
> -----Original Message-----
> From: Bjorn
> Sent: Monday, November 28, 2016 21:39
>
> Jason,
>
> I don't quite follow what you are trying to accomplish. You
Sorry if I was not clear.
> mention the
> need "to support a runtime
As opposed to patching code, /etc/logwatch is hard coded.
> configuration for the loading of a
> configuration."
>
> In your code you declare a new switch, --configdir. But
> presumably that
> option is passed statically.
set up tests in /tmp/tmp.iNtm32ostN/etc/
then run
logwatch.pl --configdir /tmp/tmp.iNtm32ostN/etc/
> Also, I don't see where that gets used,
> other than printing it. And finally, I don't understand what goes in
> that newly declared directory.
E.g.
# find /etc/logwatch/
/etc/logwatch/
/etc/logwatch/conf
/etc/logwatch/conf/override.conf
/etc/logwatch/conf/logwatch.conf
/etc/logwatch/conf/logfiles
/etc/logwatch/conf/services
/etc/logwatch/conf/ignore.conf
/etc/logwatch/scripts
/etc/logwatch/scripts/logfiles
/etc/logwatch/scripts/services
/etc/logwatch/scripts/shared
>
>
> Bjorn
>
>
>
> On 11/28/2016 04:27 PM, Jason Pyeron wrote:
> > Request for comments, concerns, objections, suggestions.
> >
> > Background:
> >
> > While developing a testing framework, we needed to support
> a runtime configuration for the loading of a configuration.
> >
> > Solution:
> >
> > --configdir option
> >
> > Implementation:
> >
> > root@black7 /projects/logwatch
> > $ git diff
> > diff --git a/scripts/logwatch.pl b/scripts/logwatch.pl
> > index 0167755..fd5dd6a 100755
> > --- a/scripts/logwatch.pl
> > +++ b/scripts/logwatch.pl
> > @@ -62,6 +62,11 @@ use File::Temp qw/ tempdir /;
> > eval "use lib \"$BaseDir/lib\";";
> > eval "use Logwatch \':dates\'";
> >
> > #The current placement of the GetOptions is well after the
> contents of /etc/logwatch/ are ingested. So a preliminary
> call is added before:
> > # http://search.cpan.org/dist/Getopt-Long/lib/Getopt/Long.pm
> > #Since Getopt::Long modifies ARGV, then we clone the array.
> > +my @argvClone = @ARGV;
> > #Most usage of Getopt::Long is based on a global context
> and the configuration would impact the second call later on,
> so lets use a OO desgin and instantiate an instance.
> > +my $gop = Getopt::Long::Parser->new;
> > #ignore the unknown options, we only care about --configdir
> > +$gop->configure("pass_through");
> > #extract confdir, if it exists
> > +$gop->getoptionsfromarray(\@argvClone, "confdir=s" => \$ConfigDir);
> > +
> > my (%Config, @ServiceList, @LogFileList, %ServiceData,
> %LogFileData);
> > my (@AllShared, @AllLogFiles, @FileList);
> > # These need to not be global variables one day
> > @@ -135,6 +140,7 @@ my %wordsToInts = (yes => 1, no => 0,
> >
> > # Load main config file...
> > if ($Config{'debug'} > 8) {
> > # debug the confdir
> > + print "\nConfigDir:$ConfigDir\n";
> > print "\nDefault Config:\n";
> > &PrintConfig();
> > }
> > @@ -192,6 +198,7 @@ my ($tmp_mailto, $tmp_savefile);
> >
> > &GetOptions ("d|detail=s" => \$Config{'detail'},
> > "l|logfile=s@" => \@TempLogFileList,
> > #this is here for error handling
> > + "confdir=s" => \$ConfigDir,
> > "logdir=s" => \$Config{'logdir'},
> > "s|service=s@" => \@TempServiceList,
> > "m|mailto=s" => \$tmp_mailto,
> > @@ -1088,6 +1095,7 @@ sub Usage () {
> > print "--detail <level>: Report Detail Level - High,
> Med, Low or any #.\n";
> > print "--logfile <name>: *Name of a logfile definition
> to report on.\n";
> > print "--logdir <name>: Name of default directory where
> logs are stored.\n";
> > #the confdir option help
> > + print "--confdir <name>: Name of default directory
> where configuration is stored.\n";
> > print "--service <name>: *Name of a service definition
> to report on.\n";
> > print "--output <output type>: Report Output - stdout
> [default], mail, file.\n"; #8.0
> > print "--format <formatting>: Report Format - text
> [default], html.\n"; #8.0
> >
> >
> > -Jason
> >
> > --
> > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> > - -
> > - Jason Pyeron PD Inc. http://www.pdinc.us -
> > - Principal Consultant 10 West 24th Street #100 -
> > - +1 (443) 269-1555 x333 Baltimore, Maryland 21218 -
> > - -
> > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> >
> >
> >
> --------------------------------------------------------------
> ----------------
> > _______________________________________________
> > Logwatch-devel mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/logwatch-devel
> >
>
>
> --------------------------------------------------------------
> ----------------
> _______________________________________________
> Logwatch-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/logwatch-devel
>
------------------------------------------------------------------------------