Saftpresse/Plugin/MtPolicyd.pm

filter: Statementstmt 25.0% 10 / 40 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 18.5% 13 / 70 SCAR 44.1
CC
11
Cov
16%
process
132.0
BEGIN
1.0
BEGIN
1.0
CRAP 82.4
« Saftpresse/Plugin/Postfix/Smtpd.pm ↑ Summary Saftpresse/Plugin/Role/CounterUtils.pm »
1 package Log::Saftpresse::Plugin::MtPolicyd;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Log::Saftpresse::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # ABSTRACT: plugin to parse mtpolicyd logs
8 1 our $VERSION = '1.5'; # VERSION
9  
10  
11 1 extends 'Log::Saftpresse::Plugin';
12  
13 1 with 'Log::Saftpresse::Plugin::Role::CounterUtils';
14  
15 sub process {
16 0 ▶ my ( $self, $stash ) = @_;
Subroutine process: not called CC=11 SCAR=48.8
Pod documented
17 0 my $program = $stash->{'program'};
18 0 ▶ if( ! defined $program || $program ne 'mtpolicyd' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $program or $program ne "mtpolicyd") 0 0 0
Condition0%0/3
not defined $program or $program ne "mtpolicyd"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $program or $program ne "mtpolicyd"
not defined $program $program ne "mtpolicyd"
Truth table0%0/3
not(A) or B
A= not defined $programB= $program ne "mtpolicyd"
ABresult
1X1
011
000
19 0 return;
20 }
21 0 my ( $vhost, $instance, $time, $plugin, $result );
22  
23 0 ▶ if ( my ( @fields ) = $stash->{'message'} =~ /^([^:]+): instance=([^,]+), type=[^,]+, t=(\d+)ms,(?: plugin=([^,]+),)? result=(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@fields) = $stash->{'message'} =~ /^([^:]+): instance=([^,]+), type=[^,]+, t=(\d+)ms,(?: plugin=([^,]+),)? result=(.*)$/) { } 0 0 0
24 0 ( $vhost, $instance, $time, $plugin, $result ) = @fields;
25 0 @$stash{'vhost', 'instance', 'elapsed' } = @fields;
26 0 ▶ if( $fields[3] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fields[3]) 0 0 0
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 ▶ if( $result ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result ne "") 0 0 0
35 0 ( $action, $reason ) = split(/\s+/, $result, 2);
36 0 $stash->{'action'} = $action;
37 0 ▶ if( defined $reason && $reason ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $reason and $reason ne "") 0 0 0
Condition0%0/3
defined $reason and $reason ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $reason and $reason ne ""
defined $reason $reason ne ""
Truth table0%0/3
A and B
A= defined $reasonB= $reason ne ""
ABresult
0X0
100
111
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 ▶ if( defined $action ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $action) 0 0 0
48 0 $self->incr_host_one($stash, 'vhost', $vhost, lc($action) );
49 }
50  
51 0 ▶ if( defined $plugin ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $plugin) 0 0 0
52 0 $self->incr_host_one($stash, 'plugin', $plugin, 'count' );
53 0 $self->incr_host($stash, 'plugin', $plugin, 'time', $time );
54 0 ▶ if( defined $action ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $action) 0 0 0
55 0 $self->incr_host_one($stash, 'plugin', $plugin, lc($action) );
56 }
57 }
58  
59 0 return;
60 }
61  
62 1 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
« Saftpresse/Plugin/Postfix/Smtpd.pm ↑ Summary Saftpresse/Plugin/Role/CounterUtils.pm »