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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
#!/usr/bin/perl -w
##########################################################################
## $Id: clam-update,v 1.7 2004/06/23 15:01:17 kirk Exp $
###########################################################################
#########################################################################
# clam-update script for Logwatch
# Analyzes the Clam Anti-Virus update log
#
# Version: 1.0.0
# Initial release
# Version: 1.0.1
# Add support for pre-0.65 database
#
# Written by: Lars Skjrlund <lars@skjaerlund.dk>
#########################################################################
#########################################################################
# This script is subject to the same copyright as Logwatch itself
#########################################################################
#########################################################################
# Files - all shown with default paths:
#
# /etc/log.d/conf/logfiles/clam-update.conf
# /etc/log.d/conf/services/clam-update.conf
# /etc/log.d/scripts/services/clam-update (this file)
#
# ... and of course
#
# /var/log/clam-update
#########################################################################
#########################################################################
# Important note:
#
# Under normal operation - ie. a detail level of 'lo' (0), no output will
# be produced if no updates have taken place. However, 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 POSIX qw(strftime);
my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};
my $time = time;
my $Date;
my $SearchDate;
my $InRange = 0;
### Variables for new database format (ClamAV > 0.60)
my $MainUptodate = undef;
my $MainUpdated = undef;
my $DailyUptodate = undef;
my $DailyUpdated = undef;
my $Updated = undef;
### Variables for old database format (ClamAV <= 0.60)
my $DBUptodate = undef;
my $DBUpdated = undef;
my $DB2Uptodate = undef;
my $DB2Updated = undef;
my $bDBUptodate = 0;
my $bDB2Uptodate = 0;
my $NotificationOK = 0;
my %Errors;
my %Unmatched;
my $range = $ENV{'LOGWATCH_DATE_RANGE'} || 'all';
if ($range eq 'yesterday') {
$SearchDate = strftime("%b %e", localtime($time-86400));
} elsif ($range eq 'today') {
$SearchDate = strftime("%b %e", localtime($time));
} elsif ($range eq 'all') {
$SearchDate = '... ..';
}
while (defined(my $ThisLine = <STDIN>)) {
if (($ThisLine =~ /^\s*$/) or
($ThisLine =~ /^----------/)
) {
# Do nothing
} elsif (($Date) = ($ThisLine =~ /(\w\w\w [\d ]\d) ..:..:../)) {
$bDBUptodate = 0;
$bDB2Uptodate = 0;
if ($Date =~ $SearchDate) {
$InRange = 1;
} else {
$InRange = 0;
}
} elsif ($InRange == 1) {
chomp($ThisLine);
if ($ThisLine =~ /^main.cvd is up to date/) {
$MainUptodate = $ThisLine;
} elsif ($ThisLine =~ /^daily.cvd is up to date/) {
$DailyUptodate = $ThisLine;
} elsif ($ThisLine =~ /^main.cvd updated/) {
$MainUpdated = $ThisLine;
} elsif ($ThisLine =~ /^daily.cvd updated/) {
$DailyUpdated = $ThisLine;
} elsif ($ThisLine =~ /^Database updated \(\d* signatures\)/) {
$Updated = $ThisLine;
} elsif ((my $Text) = ($ThisLine =~ /^Database updated \((containing .*)\)./)) {
if ($bDBUptodate == 0) {
$DBUpdated = $Text;
} elsif ($bDB2Uptodate == 0) {
$DB2Updated = $Text;
} else {
$Unmatched{$ThisLine}++;
}
} elsif (($Text) = ($ThisLine =~ /^Database updated from (.*).$/)) {
$Updated = $Text;
} elsif ($ThisLine =~ /^viruses\.db is up to date/) {
$bDBUptodate = 1;
$DBUptodate = $ThisLine;
} elsif ($ThisLine =~ /^viruses\.db2 is up to date/) {
$bDB2Uptodate = 1;
$DB2Uptodate = $ThisLine;
} elsif ($ThisLine =~ /^Clamd successfully notified about the update./) {
$NotificationOK++;
} elsif (($Text) = ($ThisLine =~ /^ERROR: (.*)/)) {
$Errors{$Text}++;
} else {
$Unmatched{$ThisLine}++;
}
} else {
if (($ThisLine =~ /^main.cvd is up to date/) or
($ThisLine =~ /^daily.cvd is up to date/) or
($ThisLine =~ /^viruses.db is up to date/) or
($ThisLine =~ /^viruses.db2 is up to date/) or
($ThisLine =~ /^main.cvd updated/) or
($ThisLine =~ /^daily.cvd updated/) or
($ThisLine =~ /^Database updated/) or
($ThisLine =~ /^ERROR: /)) {
#
} else {
chomp($ThisLine);
$Unmatched{$ThisLine}++;
}
}
}
#####################################################################
# This should not be necessary since a header will be inserted by the
# main logwatch program if output is genereated - Kirk
#if (($Detail >= 5) or ($MainUpdated or $DailyUpdated or $DBUpdated or $DB2Updated) or (!$MainUptodate and !$DailyUptodate and !$DBUptodate and !$DB2Uptodate)) {
# print "ClamAV database:\n";
#}
if ($MainUpdated) {
(my $Text, my $Version) = ($MainUpdated =~ /(.*) \((.*)\)/);
print " $Text\n";
if ($Detail >= 10) {
print " $Version\n";
}
} else {
if (($MainUptodate) and ($Detail >= 5)) {
(my $Text, my $Version) = ($MainUptodate =~ /(.*) \((.*)\)/);
print " $Text\n";
if ($Detail >= 10) {
print " $Version\n";
}
}
}
if ($DailyUpdated) {
(my $Text, my $Version) = ($DailyUpdated =~ /(.*) \((.*)\)/);
print " $Text\n";
if ($Detail >= 10) {
print " $Version\n";
}
} else {
if (($DailyUptodate) and ($Detail >= 5)) {
(my $Text, my $Version) = ($DailyUptodate =~ /(.*) \((.*)\)/);
print " $Text\n";
if ($Detail >= 10) {
print " $Version\n";
}
}
}
if ($DBUpdated) {
print " viruses.db updated\n";
if ($Detail >= 10) {
print " Now $DBUpdated\n";
}
} else {
if (($DBUptodate) and ($Detail >= 5)) {
print " $DBUptodate\n";
}
}
if ($DB2Updated) {
print " viruses.db2 updated\n";
if ($Detail >= 10) {
print " Now $DB2Updated\n";
}
} else {
if (($DB2Uptodate) and ($Detail >= 5)) {
print " $DB2Uptodate\n";
}
}
if ($NotificationOK > 0) {
print " Clamd successfully notified about the update $NotificationOK Time(s).\n";
} elsif (($MainUpdated or $DailyUpdated) and ($NotificationOK > 0)) {
print " WARNING\n";
print " Databases are updated, but Clamd is not notified.\n";
}
if (($Updated) and ($Detail >= 10)) {
if ($Updated =~ /^(\w* \w*) \(\d* \w*\)/) {
(my $Text, my $From) = ($Updated =~ /^(\w* \w*) \(\d* \w*\) (.*)\./);
print " $Text $From\n";
} else {
print " Updated from $Updated\n";
}
};
if (!$MainUptodate and !$MainUpdated and
!$DailyUptodate and !$DailyUpdated and
!$DBUptodate and !$DB2Uptodate) {
print " WARNING: Database has not been checked for updates\n";
}
if (keys %Errors) {
print "\nERRORS:\n";
foreach my $Text (keys %Errors) {
print " $Text: $Errors{$Text} Time(s)\n";
}
}
if (keys %Unmatched) {
print "\n**Unmatched Entries**\n";
foreach my $Text (keys %Unmatched) {
print " $Text: $Unmatched{$Text} Time(s)\n";
}
}
exit(0);
# vi: shiftwidth=3 tabstop=3 et
|