1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
########################################################
# Please file all bug reports, patches, and feature
# requests under:
# https://sourceforge.net/p/logwatch/_list/tickets
# Help requests and discusion can be filed under:
# https://sourceforge.net/p/logwatch/discussion/
########################################################
########################################################
# clam-update script for Logwatch
# Analyzes the Clam Anti-Virus update log
#
# Originally written by: Lars Skjrlund <lars@skjaerlund.dk>
########################################################
########################################################
## Copyright (c) 2008 Lars Skjrlund
## Covered under the included MIT/X-Consortium License:
## http://www.opensource.org/licenses/mit-license.php
## All modifications and contributions by other persons to
## this script are assumed to have been donated to the
## Logwatch project and thus assume the above copyright
## and licensing terms. If you want to make contributions
## under your own copyright or a different license this
## must be explicitly stated in the contribution an the
## Logwatch project reserves the right to not accept such
## contributions. If you have made significant
## contributions to this script and want to claim
## copyright please contact logwatch-devel@lists.sourceforge.net.
#########################################################
#########################################################################
# Files - all shown with default paths:
#
# /usr/share/logwatch/default.conf/logfiles/clam-update.conf
# /usr/share/logwatch/default.conf/services/clam-update.conf
# /usr/share/logwatch/scripts/services/clam-update (this file)
#
# ... and of course
#
# /var/log/clamav/freshclam.log
#########################################################################
#########################################################################
# Important note:
#
# If no update attempt has been done, an alert will be output to inform
# you about this (which probably means that freshclam isn't running).
#
# If you have stopped using ClamAV and would like to get rid of the
# alert, you should delete the logfile. If there's no logfile, no alerts
# will be output - but if Logwatch finds a logfile and no update attempts
# have been made for whatever timeperiod Logwatch is analyzing, an alert
# will be output.
#########################################################################
use strict;
use warnings;
use Logwatch ':dates';
my $Debug = $ENV{'LOGWATCH_DEBUG'} || 0;
my $Detail;
if (defined $ENV{'clam_update_detail'}) {
$Detail = $ENV{'clam_update_detail'};
if ($Debug) {
print ("Detail set to $Detail from conf/services/clam-update.conf\n");
}
} elsif (defined $ENV{'LOGWATCH_DETAIL_LEVEL'}) {
$Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};
if ($Debug) {
print ("Detail set to $Detail from conf/logwatch.conf\n");
}
} else {
$Detail = 0;
if ($Debug) {
print ("Detail set to $Detail from conf/logwatch.conf\n");
}
}
my $Ignore_Outdated = $ENV{'ignore_outdated'} || 0;
my $Ignore_No_Updates = $ENV{'ignore_no_updates'} || 0;
my $Last_Run_Only = $ENV{'last_run_only'} || 0;
my $time = time;
my $Date;
my $SearchDate;
my $InRange = 0;
my $UpdatedNum = 0;
my $Status = "";
my $Version = "";
my %Starts;
my %Errors;
my %Warnings;
$SearchDate = TimeFilter("%b %e");
while (defined(my $ThisLine = <STDIN>)) {
# Freshclam ends log messages with a newline. If using the LogSyslog option, this is
# turned into a space. So we remove a space from every line, if it exists.
$ThisLine =~ s/ $//;
#If LogTime = yes in freshclam.conf then strip it
$ThisLine =~ s/^... ... .. ..:..:.. .... \-\> //;
if (
# separator of 38 dashes
($ThisLine =~ /^\-{38}$/) or
# the following failure is also recorded with ERROR later on
($ThisLine =~ /^Giving up/) or
# SIGALRM, SIGUSR1, and SIGHIP signals
($ThisLine =~ /^Received signal \d*,? wake up$/) or
($ThisLine =~ /^Received signal \d*,? re-opening log file$/) or
# Newer versions use different syntax. Above two lines to be deleted.
($ThisLine =~ /^Received signal: wake up$/) or
($ThisLine =~ /^Received signal: re-opening log file$/) or
# temporary failure
($ThisLine =~ /^Trying again/) ) {
# Do nothing for the above statements
} elsif ($ThisLine =~ /^Received signal \d*,? terminating$/) {
$InRange = 0;
$Status = "Last Status:\n Freshclam daemon was terminated, and is not currently running\n";
} elsif ((my $Temp) = ($ThisLine =~ /^freshclam daemon (.*)/)) {
# just set version for now, to be used later
$Version = $Temp;
} elsif (($Date) = ($ThisLine =~ /^ClamAV update process started at \w{3} (\w{3} [\d ]\d ..:..:.. \d{4})$/)) {
if ($Date =~ $SearchDate) {
$InRange = 1;
$UpdatedNum++;
$Status = "Last " . $ThisLine . "\nLast Status:\n";
if ($Version) {
# $Starts is only set if $Version was set just before the current update process
$Starts{$Version}++;
}
if ($Last_Run_Only) {
%Errors = ();
%Warnings = ();
}
} else {
$InRange = 0;
}
# $Version was already logged if necessary, so now we clear it
$Version = "";
} elsif ($InRange) {
$Status = $Status . " " . $ThisLine;
chomp($ThisLine);
if ((my $Text) = ($ThisLine =~ /^ERROR: (.*)/)) {
$Errors{$Text}++;
} elsif (($Text) = ($ThisLine =~ /^WARNING: (.*)/)) {
if (! (($Text =~ /OUTDATED|Local version/) &&
$Ignore_Outdated)) {
$Warnings{$Text}++;
}
}
}
}
#####################################################################
if (keys %Starts and ($Detail >= 5)) {
print "\nThe following version(s) of the freshclam daemon were started\n";
foreach my $Version (sort keys %Starts) {
print " $Version: $Starts{$Version} Time(s)\n";
}
}
if ($UpdatedNum) {
print "\nThe ClamAV update process was started $UpdatedNum time(s)\n"
if ($Detail >= 5);
}
elsif ($Ignore_No_Updates == 0) {
print "\nNo updates detected in the log for the freshclam daemon (the\n";
print "ClamAV update process). If the freshclam daemon is not running,\n";
print "you may need to restart it. (Or if run from a cron job, ensure\n";
print "it is run periodically.) Other options:\n\n";
if ($ENV{'LOGWATCH_LOGFILE_LIST'} ne "") {
print "-> If you no longer wish to run freshclam, deleting the log file\n";
print " (configured is $ENV{'LOGWATCH_LOGFILE_LIST'}) " .
"will suppress this error message.\n\n";
}
print "-> If you use a different log file, update the appropriate\n";
print " configuration file. For example:\n";
print " echo \"LogFile = log_file\" >> /etc/logwatch/conf/logfiles/clam-update.conf\n";
print " where log_file is the filename of the freshclam log file.\n\n";
print "-> If you are logging using syslog, you need to indicate that your\n";
print " log file uses the syslog format. For example:\n";
print " echo \"*OnlyService = freshclam\" >> /etc/logwatch/conf/logfiles/clam-update.conf\n";
print " echo \"*RemoveHeaders = \" >> /etc/logwatch/conf/logfiles/clam-update.conf\n";
}
if ($Status and (($Detail > 0) or (keys %Errors) or (keys %Warnings))) {
print "\n" . $Status;
};
if ($Detail >= 10) {
if ((keys %Errors) or (keys %Warnings)) {
print "\nThe following ERRORS and/or WARNINGS were detected when\n";
print "running the ClamAV update process. If these ERRORS and/or\n";
print "WARNINGS do not show up in the \"Last Status\" section above,\n";
print "then their underlying cause has probably been corrected.\n";
}
if (keys %Errors) {
print "\nERRORS:\n";
foreach my $Text (keys %Errors) {
print " $Text: $Errors{$Text} Time(s)\n";
}
}
if (keys %Warnings) {
print "\nWARNINGS:\n";
foreach my $Text (keys %Warnings) {
print " $Text: $Warnings{$Text} Time(s)\n";
}
}
}
exit(0);
# vi: shiftwidth=3 tabstop=3 syntax=perl et
# Local Variables:
# mode: perl
# perl-indent-level: 3
# indent-tabs-mode: nil
# End:
|