line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Saftpresse::Plugin::MtPolicyd; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
815
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
3832
|
use Log::Saftpresse::Log4perl; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
372
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: plugin to parse mtpolicyd logs |
8
|
|
|
|
|
|
|
our $VERSION = '1.5'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
extends 'Log::Saftpresse::Plugin'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'Log::Saftpresse::Plugin::Role::CounterUtils'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub process { |
16
|
0
|
|
|
0
|
1
|
|
my ( $self, $stash ) = @_; |
17
|
0
|
|
|
|
|
|
my $program = $stash->{'program'}; |
18
|
0
|
0
|
0
|
|
|
|
if( ! defined $program || $program ne 'mtpolicyd' ) { |
19
|
0
|
|
|
|
|
|
return; |
20
|
|
|
|
|
|
|
} |
21
|
0
|
|
|
|
|
|
my ( $vhost, $instance, $time, $plugin, $result ); |
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
if ( my ( @fields ) = $stash->{'message'} =~ /^([^:]+): instance=([^,]+), type=[^,]+, t=(\d+)ms,(?: plugin=([^,]+),)? result=(.*)$/ ) { |
24
|
0
|
|
|
|
|
|
( $vhost, $instance, $time, $plugin, $result ) = @fields; |
25
|
0
|
|
|
|
|
|
@$stash{'vhost', 'instance', 'elapsed' } = @fields; |
26
|
0
|
0
|
|
|
|
|
if( $fields[3] ) { |
27
|
0
|
|
|
|
|
|
$stash->{'plugin'} = $fields[3]; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} else { |
30
|
0
|
|
|
|
|
|
$log->debug('unhandled output format of mtpolicyd'); |
31
|
0
|
|
|
|
|
|
return; |
32
|
|
|
|
|
|
|
} |
33
|
0
|
|
|
|
|
|
my ( $action, $reason ); |
34
|
0
|
0
|
|
|
|
|
if( $result ne '' ) { |
35
|
0
|
|
|
|
|
|
( $action, $reason ) = split(/\s+/, $result, 2); |
36
|
0
|
|
|
|
|
|
$stash->{'action'} = $action; |
37
|
0
|
0
|
0
|
|
|
|
if( defined $reason && $reason ne '' ) { |
38
|
0
|
|
|
|
|
|
$stash->{'reason'} = $reason; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$self->incr_host_one($stash, 'total' ); |
43
|
0
|
|
|
|
|
|
$self->incr_host($stash, 'time', $time ); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$self->incr_host_one($stash, 'vhost', $vhost, 'count' ); |
46
|
0
|
|
|
|
|
|
$self->incr_host($stash, 'vhost', $vhost, 'time', $time ); |
47
|
0
|
0
|
|
|
|
|
if( defined $action ) { |
48
|
0
|
|
|
|
|
|
$self->incr_host_one($stash, 'vhost', $vhost, lc($action) ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if( defined $plugin ) { |
52
|
0
|
|
|
|
|
|
$self->incr_host_one($stash, 'plugin', $plugin, 'count' ); |
53
|
0
|
|
|
|
|
|
$self->incr_host($stash, 'plugin', $plugin, 'time', $time ); |
54
|
0
|
0
|
|
|
|
|
if( defined $action ) { |
55
|
0
|
|
|
|
|
|
$self->incr_host_one($stash, 'plugin', $plugin, lc($action) ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=pod |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=encoding UTF-8 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Log::Saftpresse::Plugin::MtPolicyd - plugin to parse mtpolicyd logs |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 VERSION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
version 1.5 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 Description |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This plugin parses mtpolicyd log files |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 Synopsis |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
<Plugin mtpolicyd> |
85
|
|
|
|
|
|
|
module = "MtPolicyd" |
86
|
|
|
|
|
|
|
</Plugin> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 Input |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This plugin expects a log line with |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
'program' => 'mtpolicyd' |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
and an message like |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
'message' => 'reputation: instance=25d8.55f1aea2.3adb.0, type=smtpd_access_policy, t=2ms, result=dunno' |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
or with mtpolicyd > 0.20: |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
'message' => 'reputation: instance=25d8.55f1aea2.3adb.0, type=smtpd_access_policy, t=2ms, plugin=whitelist, result=dunno' |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 Output |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
It will output the following fields: |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
vhost |
107
|
|
|
|
|
|
|
instance |
108
|
|
|
|
|
|
|
elapsed |
109
|
|
|
|
|
|
|
action |
110
|
|
|
|
|
|
|
reason |
111
|
|
|
|
|
|
|
plugin (mtpolicyd version >= 0.20) |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 Counters |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
The plugin will create the following counters: |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
<host>.total |
118
|
|
|
|
|
|
|
<host>.time |
119
|
|
|
|
|
|
|
<host>.vhost.<vhost>.count |
120
|
|
|
|
|
|
|
<host>.vhost.<vhost>.time |
121
|
|
|
|
|
|
|
<host>.vhost.<vhost>.<action> |
122
|
|
|
|
|
|
|
<host>.plugin.<plugin>.count |
123
|
|
|
|
|
|
|
<host>.plugin.<plugin>.time |
124
|
|
|
|
|
|
|
<host>.plugin.<plugin>.<action> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This is free software, licensed under: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |