Quote:
Originally Posted by aratnaweera I managed to get this done by hacking zmlogger. |
Unfortunately, the above didn't work out, as zmlogger is keeping an eye on /var/log/zimbra-stats.log and not zimbra.log.
The following script worked, although not the neatest way of doing it. This requires File::Tail (libfile-tail-perl on Ubuntu).
Code:
#!/usr/bin/perl
use strict;
use File::Tail;
my $log = File::Tail->new(name => '/var/log/zimbra.log', maxinterval => 2, interval => 1);
my $logregex = qr/^.{15} ((\d+\.\d+\.\d+\.\d+)|(\S+)) postfix\/lmtp\[\d+\]: .* to=<([^>]*)>, .* Delivery OK\)$/o;
while (defined(my $line = $log->read)) {
chomp $line;
if ($line =~ m/$logregex/) {
my $email = $4;
$email =~ s/[^a-zA-Z0-9@\._-]//g;
system("/usr/local/bin/notify.sh '$email'");
}
}