Viewing file: logwatch (47.66 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/perl -w
use strict;
##########################################################################
# $Id: logwatch.pl,v 1.171 2006/03/24 23:16:55 kirk Exp $
##########################################################################
# Most current version can always be found at:
# ftp://ftp.logwatch.org/pub/redhat/RPMS
########################################################
# Specify version and build-date:
my $Version = '7.3';
my $VDate = '03/24/06';
#######################################################
# This was written and is maintained by:
# Kirk Bauer
#
# Please send all comments, suggestions, bug reports,
# etc, to logwatch@logwatch.org.
#
########################################################
# About the locale: some functions use locale information. In particular,
# Logwatch makes use of strftime, which makes use of LC_TIME variable. Other
# functions may also use locale information.
#
# Because the parsing must be in the same locale as the logged information,
# and this appears to be "C", "POSIX", or "en_US", we set LC_ALL for
# this and other scripts invoked by this script. We use "C" because it
# is always (?) available, whereas POSIX or en_US may not. They all use
# the same time formats and rely on the ASCII character set.
#
# Variables REAL_LANG and REAL_LC_ALL keep the original values for use by
# scripts that need native language.
$ENV{'REAL_LANG'}=$ENV{'LANG'} if $ENV{'LANG'};
$ENV{'REAL_LC_ALL'}=$ENV{'LC_ALL'} if $ENV{'LC_ALL'};
# Setting ENV for scripts invoked by this script.
$ENV{'LC_ALL'} = "C";
# Using setlocale to set locale for this script.
use POSIX qw(locale_h);
setlocale(LC_ALL, "C");
my $BaseDir = "/usr/share/logwatch";
my $ConfigDir = "/etc/logwatch";
my $PerlVersion = "$^X";
#############################################################################
use Getopt::Long;
use POSIX qw(uname);
use File::Temp qw/ tempdir /;
eval "use lib \"$BaseDir/lib\";";
eval "use Logwatch \':dates\'";
my (%Config, @ServiceList, @LogFileList, %ServiceData, %LogFileData);
my (@AllShared, @AllLogFiles, @FileList);
# These need to not be global variables one day
my (@ReadConfigNames, @ReadConfigValues);
# Default config here...
$Config{'detail'} = 0;
$Config{'mailto'} = "root";
$Config{'mailfrom'} = "Logwatch";
$Config{'save'} = "";
$Config{'print'} = 0;
$Config{'range'} = "yesterday";
$Config{'debug'} = 0;
$Config{'archives'} = 0;
$Config{'tmpdir'} = "/var/cache/logwatch";
$Config{'splithosts'} = 0;
$Config{'multiemail'} = 0;
$Config{'numeric'} = 0;
$Config{'pathtocat'} = "cat";
$Config{'pathtozcat'} = "zcat";
$Config{'output'} = "unformatted";
$Config{'encode'} = 0;
if (-e "$ConfigDir/conf/html/header.html") {
$Config{'html_header'} = "$ConfigDir/conf/html/header.html";
} else {
$Config{'html_header'} = "$BaseDir/default.conf/html/header.html";
}
if (-e "$ConfigDir/conf/html/footer.html") {
$Config{'html_footer'} = "$ConfigDir/conf/html/footer.html";
} else {
$Config{'html_footer'} = "$BaseDir/default.conf/html/footer.html";
}
# Logwatch now does some basic searching for logs
# So if the log file is not in the log path it will check /var/adm
# and then /var/log -mgt
$Config{'logdir'} = "/var/log";
#Added to create switches for different os options -mgt
#Changed to POSIX to remove calls to uname and hostname
my ($OSname, $hostname, $release, $version, $machine) = POSIX::uname();
$Config{'hostname'} = "$hostname";
#############################################################################
sub Usage () {
# Show usage for this program
print "\nUsage: $0 [--detail ] [--logfile ]\n" .
" [--print] [--mailto ] [--archives] [--range ] [--debug ]\n" .
" [--save ] [--help] [--version] [--service ]\n" .
" [--numeric] [--output ]\n" .
" [--splithosts] [--multiemail] [--no-oldfiles-log]\n\n";
print "--detail : Report Detail Level - High, Med, Low or any #.\n";
print "--logfile : *Name of a logfile definition to report on.\n";
print "--logdir : Name of default directory where logs are stored.\n";
print "--service : *Name of a service definition to report on.\n";
print "--print: Display report to stdout.\n";
print "--mailto : Mail report to .\n";
print "--archives: Use archived log files too.\n";
print "--save : Save to .\n";
print "--range : Date range: Yesterday, Today, All, Help\n";
print " where help will describe additional options\n";
print "--numeric: Display ddresses numerically rather than symbolically and numerically\n";
print " (saves a nameserver address-to-name lookup).\n";
print "--debug : Debug Level - High, Med, Low or any #.\n";
# hostname needs to be cleaned up and explained
# print "--hostname :
print "--splithosts: Create a report for each host in syslog.\n";
print "--multiemail: Send each host report in a separate email. Ignored if \n";
print " not using --splithosts.\n";
print "--output |