forked from glenpp/cacti-uloganalyser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestdata2tmp
executable file
·74 lines (61 loc) · 1.88 KB
/
testdata2tmp
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
#!/usr/bin/perl
use strict;
use warnings;
my $glob = "testdata/*";
if ( defined $ARGV[0] ) {
$glob = $ARGV[0];
}
foreach my $file (glob $glob) {
open TD, '<', $file or die "FATAL - can't open \"$file\": $!\n";
if ( $file =~ /\.raw$/ ) {
print <TD>;
close TD;
next;
}
my $tmpline = '';
while ( defined ( my $line = <TD> ) ) {
if ( $line =~ /^##/ ) { next; }
chomp $line;
if ( $line =~ /^\/[^\s]+\.pm \d{8}:\d+/
or $line =~ /^\/[^\s]+\.pm:\d+ version \d{8}/ ) {
# new line - output old
processline ( $tmpline );
$tmpline = $line;
} else {
$tmpline =~ s/\s$//;
$tmpline .= " $line";
}
}
close TD;
processline ( $tmpline );
}
sub processline {
my ( $line ) = @_;
$line =~ s/\s+$//;
if ( $line =~ s/^\/[^\s]+postfix\.pm \d{8}:\d+ \/[^:]+:\d+ unknown:\s+// ) {
print "$line\n\n";
} elsif ( $line =~ s/^\/[^\s]+postfix\.pm:\d+ version \d{8}\s+/Mon 00 00:00:00 hostname / ) {
if ( $line =~ /^\w+ \d+ \d+:\d+:\d+ \w+ \$message:\s/ ) {
# ignore $message lines
} else {
$line =~ s/\[\\w\\\.\\-\]\+\\\[\[\\w\\\.:\]\+\\\]/host.domain.tld[254.254.254.254]/g;
$line =~ s/<\.\+>/<user\@domain.tld>/g;
$line =~ s/smtp\\\[\\d\+\\\]:\\s\*/smtp[9999]: /;
print "$line\n\n";
}
} elsif ( $line =~ s/^\/[^\s]+dovecot\.pm \d{8}:\d+ \/[^:]+:\d+ unknown dovecot:\s+// ) {
print "$line\n\n";
} elsif ( $line =~ s/^\/[^\s]+dovecot\.pm \d{8}:\d+ \"doveadm who\" unknown dovecot:\s+// ) {
print "$line\n";
} elsif ( $line =~ s/^\/[^\s]+fail2ban\.pm \d{8}:\d+ \/[^:]+:\d+ unknown (class "[^"]+" )?fail2ban:\s+// ) {
print "$line\n\n";
} elsif ( $line =~ s/^\/[^\s]+dkim\.pm \d{8}:\d+ \/[^:]+:\d+ unknown:\s+// ) {
print "$line\n\n";
} elsif ( $line eq '' ) {
# ignore
} elsif ( $line =~ s/^ *Deferral reasons: postfix-loganalyser \d{8} ==============================================// ) {
# ignore
} else {
warn __FILE__." UNKNOWN $line\n\n";
}
}