Hi Eric.
I'm making You aware of it because I know that many of us users may not
be aware that when some things change - like a log file it has an
impact on some other programs like F2B or the spamdyke script, and then
You will be swammed by emails asking a lot of issues not really related
to QMT - TAKING YOUR TIME OFF FUTURE QMT ENHANCEMENTS ;-)
I have inserted the Spamdyke-stats-report.pl script below, I have not
changed anything but I guess that timestamp have to change from tai64
and file and filelocation will be the needed changes.
NB - THIS IS ONLY FOR LATEST QMT FOR COS6 where logfiles has changed /
will change to be written in /var/log/maillog
#!/usr/bin/perl -w
# Spamdyke-Stats-Report.pl
#
# by Brent Gardner
#
# Uses spamdyke-stats script to generate a report about the previous
# day's Spamdyke activity.
#
# Uses qmail-inject to email the report to a specified recipient
#
#####################################################################
use diagnostics;
use strict;
use Time::TAI64 qw(:tai);
use Time::HiRes qw(time);
use Date::Calc qw(Today Add_Delta_Days);
use POSIX qw(strftime);
# This is the machine that's running this script.
# In my world it's also the machine that generated the SMTP logs that are
# processed by this script.
#
my $MachineName = "your domain";
# This is the directory containing this script and the spamdyke-stats
script.
#
my $ScriptRoot = "/usr/share/qmt/scripts";
# This is used as a root name for temp files generated by this script.
# The sample setting implies a directory called 'tmp' in the $ScriptRoot
# directory.
#
my $TempFile = "$ScriptRoot/tmp/spamdyke-stats-report";
# This is the path to the directory containing the SMTP log files generated
# by qmail.
#
my $SMTPLogRoot = "/var/log/qmail/smtp";
# Today's date in this format: YYYY/MM/DD
#
my $Today = sprintf( "%04d/%02d/%02d", Today() );
# Yesterday's date in this format: YYYY/MM/DD
#
my $Yesterday = sprintf( "%04d/%02d/%02d", Add_Delta_Days( Today(), -1 ) );
# This is the email address that the report will be sent to.
# The '@' symbol needs to be escaped.
#
my $MailTo = "postmaster\@Your domaine";
my $LogFilePath = "";
my $LogFile = "";
my $LogFileTime = "";
my $ScriptOutput = "";
# Open a temporary output file for log content,
# overwriting any existing content in that file.
#
open TempFileRaw, ">$TempFile.raw" or die $!;
# Process the current qmail SMTP log file
#
$LogFilePath = "$SMTPLogRoot/current";
ProcessQmailSMTPLog($LogFilePath);
# Look for qmail SMTP log files that are older than current but were
# modified today or yesterday
#
opendir LogDir, $SMTPLogRoot or die $!;
while ( $LogFile = readdir(LogDir) ) {
# Only look at files that are probably qmail log files
#
next unless ( $LogFile =~ /\.[su]$/ );
# Only look at log files where the modified date is today or yesterday
#
$LogFileTime = strftime "%Y/%m/%d",
localtime((stat("$SMTPLogRoot/$LogFile"))[9]);
next unless ( ( $LogFileTime eq $Yesterday ) or ( $LogFileTime eq
$Today ) );
# Process targeted log files. (entries that match yesterday's
# date are copied to the temp output file)
#
ProcessQmailSMTPLog("$SMTPLogRoot/$LogFile");
}
closedir LogDir;
close TempFileRaw;
# Prepare an email message to be sent using qmail-inject
#
open MailBody, ">$TempFile.body" or die $!;
# Begin the message.
#
print MailBody "To: <$MailTo>\n";
print MailBody "subject: $MachineName Spamdyke Stats Report for
$Yesterday\n\n";
print MailBody "This report contains statistical information about
messages that were \n";
print MailBody "rejected by Spamdyke on $MachineName because of RBL
lookups or misbehaved \n";
print MailBody "remote SMTP server.\n\n";
print MailBody "These messages were rejected before $MachineName
acknowleged receipt of the \n";
print MailBody "message. This means that the sending server is
responsible for generating \n";
print MailBody "any Non-Delivery Report.\n\n";
print MailBody "This also means that SpamAssassin did not have to
process these messages. \n";
print MailBody "This saves a lot of processing power. SpamAssassin
checks can be CPU, \n";
print MailBody "memory and network-intensive.\n\n";
print MailBody "This report was generated ";
print MailBody localtime() . "\n\n\n";
# Add info from the spamdyke-stats script.
#
$ScriptOutput = `cat $TempFile.raw | $ScriptRoot/spamdyke-stats`;
print MailBody "$ScriptOutput\n\n\n";
print MailBody "Path to this script:
$ScriptRoot/Spamdyke-Stats-Report.pl\n";
close MailBody;
# Mail the report using qmail-inject.
#
system("/var/qmail/bin/qmail-inject -f$MachineName < $TempFile.body");
# This sub will copy log entries that match yesterday's date into the temp
# file.
#
sub ProcessQmailSMTPLog {
my $Path = shift;
my $TimeStamp = "";
open SMTPLog, "<", $Path or die $!;
while (<SMTPLog>) {
my $Line = $_;
# log file lines that don't start with '@' will be ignored.
#
if ( substr($Line,0,1) eq '@' ) {
$TimeStamp = substr($Line,0,25);
# if the date in the timestamp is yesterday then it is copied to
# the temp file.
#
if ( tai2strftime($TimeStamp,"%Y/%m/%d") eq $Yesterday ) {
print TempFileRaw $Line;
}
}
}
close SMTPLog;
}
Cheers,
Finn
Den 12-07-2014 18:34, Eric Shubert skrev:
> On 07/12/2014 02:32 AM, Finn Buhelt wrote:
>> Hi Eric.
>>
>> Am I correct that Spamdyke-stats-report.pl needs to be altered to read
>> the mighty maillog log file now in order to compile other than 0's in
>> the report ? ;-)
>>
>> Cheers
>> Finn
>>
>> ---------------------------------------------------------------------
>
> I expect that you are. :)
>
> I don't appear to have a copy of that script anywhere. Can you post your
> copy (duly modified would be nice)? I'll then include it in the
> qmailtoaster-util package.
>
>
> I didnt' mean to ignore your post about F2B and logging, but I'll reply
> here.
>
> I expect you're correct that F2B configurations will also need to be
> modified as well when logging changes are made. This will need to be
> done by individual F2B users, as there's not yet a stock F2B package for
> QMT. I'd like to include a F2B package with QMT at some point, but I
> want to get logging changes done first, so logging is stable when F2B is
> implemented.
>
> My understanding of F2B at this point (I haven't used it yet) is that it
> scans the pertinent log files. I think it'd be better implemented as a
> service if that's possible, with a copy of whatever log messages are
> pertinent being fed to it real-time. Perhaps that's the way it's done, I
> don't know. In any case, I think it can be efficiently integrated into
> the syslog process once that's established, and I hope to do so at some
> point. F2B will be a nice 'stock' addition to QMT.
>
> Thanks.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]