| 1 |
#!/usr/bin/perl -w |
| 2 |
# |
| 3 |
# Copyright (c) 2003 Martin A. Godisch for Debian GNU/Linux, GPL |
| 4 |
|
| 5 |
=head1 NAME |
| 6 |
|
| 7 |
syslog2eximlog - make syslog output suitable for eximstats |
| 8 |
|
| 9 |
=head1 SYNOPSIS |
| 10 |
|
| 11 |
B<syslog2eximlog> B<<> I<mail.log> B<|> B<eximstats> |
| 12 |
|
| 13 |
=head1 DESCRIPTION |
| 14 |
|
| 15 |
syslog2eximlog converts logfiles produced by syslog when using |
| 16 |
B<log_file_path = syslog> in your I<exim.conf> back to exim |
| 17 |
logfile format, suitable for B<eximstats>. B<syslog_timestamp> |
| 18 |
may be B<true> or B<false>. |
| 19 |
|
| 20 |
The program always succeeds, invalid lines will be ignored. |
| 21 |
|
| 22 |
=head1 BUGS |
| 23 |
|
| 24 |
Please report any bugs directly to the author. |
| 25 |
|
| 26 |
=head1 AUTHOR |
| 27 |
|
| 28 |
Martin A. Godisch <[email protected]> for Debian GNU/Linux. |
| 29 |
|
| 30 |
=head1 SEE ALSO |
| 31 |
|
| 32 |
B<eximstats>(8) |
| 33 |
|
| 34 |
=cut |
| 35 |
|
| 36 |
my @date = localtime(time); |
| 37 |
$date[4] += 1; |
| 38 |
$date[5] += 1900; |
| 39 |
my %names = ( |
| 40 |
"Jan", "01", "Feb", "02", "Mar", "03", "Apr", "04", |
| 41 |
"May", "05", "Jun", "06", "Jul", "07", "Aug", "08", |
| 42 |
"Sep", "09", "Oct", "10", "Nov", "11", "Dec", "12" |
| 43 |
); |
| 44 |
|
| 45 |
while (<>) { |
| 46 |
next unless (s/^(\w{3})\s([\s\d]\d)\s(\d\d):(\d\d):(\d\d)\s\S+\sexim\[\d+\]:\s//); |
| 47 |
|
| 48 |
my ($month, $day, $hour, $min, $sec) = ($names{$1}, $2, $3, $4, $5); |
| 49 |
|
| 50 |
if (/^\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d\s/) { |
| 51 |
print $_; |
| 52 |
} else { |
| 53 |
printf "%04d-%02d-%02d %02d:%02d:%02d %s", |
| 54 |
# assume current year if month/day <= today, otherwise assume last year |
| 55 |
$month > $date[4] || $month == $date[4] && $day > $date[3] ? $date[5] - 1 : $date[5], |
| 56 |
$month, $day, $hour, $min, $sec, $_; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
exit 0; |