|
Packit |
57988d |
###########################################################################
|
|
Packit |
57988d |
# clam-update script for Logwatch
|
|
Packit |
57988d |
# Analyzes the Clam Anti-Virus update log
|
|
Packit |
57988d |
#
|
|
Packit |
57988d |
# Originally written by: Lars Skjærlund <lars@skjaerlund.dk>
|
|
Packit |
57988d |
#
|
|
Packit |
57988d |
# Please send all comments, suggestions, bug reports,
|
|
Packit |
57988d |
# etc, to logwatch-devel@lists.sourceforge.net
|
|
Packit |
57988d |
#########################################################################
|
|
Packit |
57988d |
|
|
Packit |
57988d |
########################################################
|
|
Packit |
57988d |
## Copyright (c) 2008 Lars Skjærlund
|
|
Packit |
57988d |
## Covered under the included MIT/X-Consortium License:
|
|
Packit |
57988d |
## http://www.opensource.org/licenses/mit-license.php
|
|
Packit |
57988d |
## All modifications and contributions by other persons to
|
|
Packit |
57988d |
## this script are assumed to have been donated to the
|
|
Packit |
57988d |
## Logwatch project and thus assume the above copyright
|
|
Packit |
57988d |
## and licensing terms. If you want to make contributions
|
|
Packit |
57988d |
## under your own copyright or a different license this
|
|
Packit |
57988d |
## must be explicitly stated in the contribution an the
|
|
Packit |
57988d |
## Logwatch project reserves the right to not accept such
|
|
Packit |
57988d |
## contributions. If you have made significant
|
|
Packit |
57988d |
## contributions to this script and want to claim
|
|
Packit |
57988d |
## copyright please contact logwatch-devel@lists.sourceforge.net.
|
|
Packit |
57988d |
#########################################################
|
|
Packit |
57988d |
|
|
Packit |
57988d |
#########################################################################
|
|
Packit |
57988d |
# Files - all shown with default paths:
|
|
Packit |
57988d |
#
|
|
Packit |
57988d |
# /usr/share/logwatch/default.conf/logfiles/clam-update.conf
|
|
Packit |
57988d |
# /usr/share/logwatch/default.conf/services/clam-update.conf
|
|
Packit |
57988d |
# /usr/share/logwatch/scripts/services/clam-update (this file)
|
|
Packit |
57988d |
#
|
|
Packit |
57988d |
# ... and of course
|
|
Packit |
57988d |
#
|
|
Packit |
57988d |
# /var/log/clamav/freshclam.log
|
|
Packit |
57988d |
#########################################################################
|
|
Packit |
57988d |
|
|
Packit |
57988d |
#########################################################################
|
|
Packit |
57988d |
# Important note:
|
|
Packit |
57988d |
#
|
|
Packit |
57988d |
# If no update attempt has been done, an alert will be output to inform
|
|
Packit |
57988d |
# you about this (which probably means that freshclam isn't running).
|
|
Packit |
57988d |
#
|
|
Packit |
57988d |
# If you have stopped using ClamAV and would like to get rid of the
|
|
Packit |
57988d |
# alert, you should delete the logfile. If there's no logfile, no alerts
|
|
Packit |
57988d |
# will be output - but if Logwatch finds a logfile and no update attempts
|
|
Packit |
57988d |
# have been made for whatever timeperiod Logwatch is analyzing, an alert
|
|
Packit |
57988d |
# will be output.
|
|
Packit |
57988d |
#########################################################################
|
|
Packit |
57988d |
|
|
Packit |
57988d |
use Logwatch ':dates';
|
|
Packit |
57988d |
|
|
Packit |
57988d |
my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};
|
|
Packit |
57988d |
|
|
Packit |
57988d |
my $time = time;
|
|
Packit |
57988d |
my $Date;
|
|
Packit |
57988d |
my $SearchDate;
|
|
Packit |
57988d |
my $InRange = 0;
|
|
Packit |
57988d |
my $UpdatedNum = 0;
|
|
Packit |
57988d |
my $Status = "";
|
|
Packit |
57988d |
my $Version = "";
|
|
Packit |
57988d |
|
|
Packit |
57988d |
my %Starts;
|
|
Packit |
57988d |
my %Errors;
|
|
Packit |
57988d |
my %Warnings;
|
|
Packit |
57988d |
|
|
Packit |
57988d |
|
|
Packit |
57988d |
$SearchDate = TimeFilter("%b %e");
|
|
Packit |
57988d |
|
|
Packit |
57988d |
while (defined(my $ThisLine = <STDIN>)) {
|
|
Packit |
57988d |
# Freshclam ends log messages with a newline. If using the LogSyslog option, this is
|
|
Packit |
57988d |
# turned into a space. So we remove a space from every line, if it exists.
|
|
Packit |
57988d |
$ThisLine =~ s/ $//;
|
|
Packit |
57988d |
#If LogTime = yes in freshclam.conf then strip it
|
|
Packit |
57988d |
$ThisLine =~ s/^... ... .. ..:..:.. .... \-\> //;
|
|
Packit |
57988d |
if (
|
|
Packit |
57988d |
# separator of 38 dashes
|
|
Packit |
57988d |
($ThisLine =~ /^\-{38}$/) or
|
|
Packit |
57988d |
# the following failure is also recorded with ERROR later on
|
|
Packit |
57988d |
($ThisLine =~ /^Giving up/) or
|
|
Packit |
57988d |
# SIGALRM, SIGUSR1, and SIGHIP signals
|
|
Packit |
57988d |
($ThisLine =~ /^Received signal \d*,? wake up$/) or
|
|
Packit |
57988d |
($ThisLine =~ /^Received signal \d*,? re-opening log file$/) or
|
|
Packit |
57988d |
# Newer versions use different syntax. Above two lines to be deleted.
|
|
Packit |
57988d |
($ThisLine =~ /^Received signal: wake up$/) or
|
|
Packit |
57988d |
($ThisLine =~ /^Received signal: re-opening log file$/) or
|
|
Packit |
57988d |
# temporary failure
|
|
Packit |
57988d |
($ThisLine =~ /^Trying again/) ) {
|
|
Packit |
57988d |
# Do nothing for the above statements
|
|
Packit |
57988d |
} elsif ($ThisLine =~ /^Received signal \d*,? terminating$/) {
|
|
Packit |
57988d |
$InRange = 0;
|
|
Packit |
57988d |
$Status = "Last Status:\n Freshclam daemon was terminated, and is not currently running\n";
|
|
Packit |
57988d |
} elsif ((my $Temp) = ($ThisLine =~ /^freshclam daemon (.*)/)) {
|
|
Packit |
57988d |
# just set version for now, to be used later
|
|
Packit |
57988d |
$Version = $Temp;
|
|
Packit |
57988d |
} elsif (($Date) = ($ThisLine =~ /^ClamAV update process started at \w{3} (\w{3} [\d ]\d ..:..:.. \d{4})$/)) {
|
|
Packit |
57988d |
if ($Date =~ $SearchDate) {
|
|
Packit |
57988d |
$InRange = 1;
|
|
Packit |
57988d |
$UpdatedNum++;
|
|
Packit |
57988d |
$Status = "Last " . $ThisLine . "\nLast Status:\n";
|
|
Packit |
57988d |
if ($Version) {
|
|
Packit |
57988d |
# $Starts is only set if $Version was set just before the current update process
|
|
Packit |
57988d |
$Starts{$Version}++;
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
} else {
|
|
Packit |
57988d |
$InRange = 0;
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
# $Version was already logged if necessary, so now we clear it
|
|
Packit |
57988d |
$Version = "";
|
|
Packit |
57988d |
} elsif ($InRange) {
|
|
Packit |
57988d |
$Status = $Status . " " . $ThisLine;
|
|
Packit |
57988d |
chomp($ThisLine);
|
|
Packit |
57988d |
if ((my $Text) = ($ThisLine =~ /^ERROR: (.*)/)) {
|
|
Packit |
57988d |
$Errors{$Text}++;
|
|
Packit |
57988d |
} elsif (($Text) = ($ThisLine =~ /^WARNING: (.*)/)) {
|
|
Packit |
57988d |
$Warnings{$Text}++;
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
|
|
Packit |
57988d |
|
|
Packit |
57988d |
#####################################################################
|
|
Packit |
57988d |
if (keys %Starts and ($Detail >= 5)) {
|
|
Packit |
57988d |
print "\nThe following version(s) of the freshclam daemon were started\n";
|
|
Packit |
57988d |
foreach my $Version (sort keys %Starts) {
|
|
Packit |
57988d |
print " $Version: $Starts{$Version} Time(s)\n";
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
|
|
Packit |
57988d |
if ($UpdatedNum) {
|
|
Packit |
57988d |
print "\nThe ClamAV update process was started $UpdatedNum time(s)\n"
|
|
Packit |
57988d |
if ($Detail >= 5);
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
else {
|
|
Packit |
57988d |
print "\nNo updates detected in the log for the freshclam daemon (the\n";
|
|
Packit |
57988d |
print "ClamAV update process). If the freshclam daemon is not running,\n";
|
|
Packit |
57988d |
print "you may need to restart it. Other options:\n\n";
|
|
Packit |
57988d |
print "A. If you no longer wish to run freshclam, deleting the log file\n";
|
|
Packit |
57988d |
print " (configured is $ENV{'LOGWATCH_LOGFILE_LIST'}) will suppress this error message.\n\n";
|
|
Packit |
57988d |
print "B. If you use a different log file, update the appropriate\n";
|
|
Packit |
57988d |
print " configuration file. For example:\n";
|
|
Packit |
57988d |
print " echo \"LogFile = log_file\" >> /etc/logwatch/conf/logfiles/clam-update.conf\n";
|
|
Packit |
57988d |
print " where log_file is the filename of the freshclam log file.\n\n";
|
|
Packit |
57988d |
print "C. If you are logging using syslog, you need to indicate that your\n";
|
|
Packit |
57988d |
print " log file uses the syslog format. For example:\n";
|
|
Packit |
57988d |
print " echo \"*OnlyService = freshclam\" >> /etc/logwatch/conf/logfiles/clam-update.conf\n";
|
|
Packit |
57988d |
print " echo \"*RemoveHeaders\" >> /etc/logwatch/conf/logfiles/clam-update.conf\n";
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
|
|
Packit |
57988d |
if ($Status) {
|
|
Packit |
57988d |
print "\n" . $Status;
|
|
Packit |
57988d |
};
|
|
Packit |
57988d |
|
|
Packit |
57988d |
if ($Detail >= 10) {
|
|
Packit |
57988d |
if ((keys %Errors) or (keys %Warnings)) {
|
|
Packit |
57988d |
print "\nThe following ERRORS and/or WARNINGS were detected when\n";
|
|
Packit |
57988d |
print "running the ClamAV update process. If these ERRORS and/or\n";
|
|
Packit |
57988d |
print "WARNINGS do not show up in the \"Last Status\" section above,\n";
|
|
Packit |
57988d |
print "then their underlying cause has probably been corrected.\n";
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
|
|
Packit |
57988d |
if (keys %Errors) {
|
|
Packit |
57988d |
print "\nERRORS:\n";
|
|
Packit |
57988d |
foreach my $Text (keys %Errors) {
|
|
Packit |
57988d |
print " $Text: $Errors{$Text} Time(s)\n";
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
|
|
Packit |
57988d |
if (keys %Warnings) {
|
|
Packit |
57988d |
print "\nWARNINGS:\n";
|
|
Packit |
57988d |
foreach my $Text (keys %Warnings) {
|
|
Packit |
57988d |
print " $Text: $Warnings{$Text} Time(s)\n";
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
}
|
|
Packit |
57988d |
|
|
Packit |
57988d |
exit(0);
|
|
Packit |
57988d |
|
|
Packit |
57988d |
# vi: shiftwidth=3 tabstop=3 syntax=perl et
|
|
Packit |
57988d |
# Local Variables:
|
|
Packit |
57988d |
# mode: perl
|
|
Packit |
57988d |
# perl-indent-level: 3
|
|
Packit |
57988d |
# indent-tabs-mode: nil
|
|
Packit |
57988d |
# End:
|