Saftpresse/Plugin/Postfix/Tls.pm

filter: Statementstmt 12.5% 5 / 40 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 33.3% 1 / 3 Podpod 0.0% 0 / 2 totaltotal 7.5% 6 / 80 SCAR 51.4
CC
14
Cov
7%
process_tls
210.0
incr_tls_stats
2.0
BEGIN
1.0
CRAP 170.4
« Saftpresse/Plugin/Apache.pm ↑ Summary Saftpresse/Input/RELP/Frame.pm »
1 package Log::Saftpresse::Plugin::Postfix::Tls;
2  
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: plugin to gather TLS statistics
6 1 our $VERSION = '1.5'; # VERSION
7  
8 sub process_tls {
9 0 ▶ my ( $self, $stash, $notes ) = @_;
Subroutine process_tls: not called CC=14 SCAR=53.5
Pod undocumented
10 0 my $service = $stash->{'service'};
11 0 my $pid = $stash->{'pid'};
12 0 my $message = $stash->{'message'};
13 0 my $queue_id = $stash->{'queue_id'};
14  
15 0 ▶ if( $service ne 'smtp' && $service ne 'smtpd' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($service ne "smtp" and $service ne "smtpd") 0 0 0
Condition0%0/3
$service ne "smtp" and $service ne "smtpd"
!ll&&!rl&&r
000
MC/DC0%0/2
$service ne "smtp" and $service ne "smtpd"
$service ne "smtp" $service ne "smtpd"
Truth table0%0/3
A and B
A= $service ne "smtp"B= $service ne "smtpd"
ABresult
0X0
100
111
16 0 return;
17 }
18  
19 0 ▶ if( my ($tlsLevel,$tlsHost, $tlsAddr, $tlsProto, $tlsCipher, $tlsKeylen) =
Branch: 1 branch
BranchTrueFalseTotal
if (() = $message =~ m<^(\S+) TLS connection established (?:from|to) ([^\[]+)\[([^\]]+)\]:(?:\d+:)? (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)>) 0 0 0
20 $message =~ /^(\S+) TLS connection established (?:from|to) ([^\[]+)\[([^\]]+)\]:(?:\d+:)? (\S+) with cipher (\S+) \((\d+)\/(\d+) bits\)/ ) {
21 0 my $tls_params = {
22 'tls_level' => $tlsLevel,
23 'tls_proto' => $tlsProto,
24 'tls_chipher' => $tlsCipher,
25 'tls_keylen' => $tlsKeylen,
26 };
27 0 $self->incr_tls_stats( $stash, $tls_params, 'tls_conn', $service);
28 0 @$stash{keys %$tls_params} = values %$tls_params;
29 0 $notes->set($service.'-tls-'.$pid, $tls_params);
30  
31 0 return;
32 }
33  
34 0 my $tls_params = $notes->get($service.'-tls-'.$pid);
35 0 ▶ if( defined $tls_params ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $tls_params) { } 0 0 0
elsif (defined $queue_id and defined($tls_params = $notes->get($service . '-tls-' . $queue_id))) { } 0 0 0
36 0 ▶ if( $service eq 'smtpd' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($service eq 'smtpd') { } 0 0 0
elsif ($service eq 'smtp' and $message =~ /status=(sent|bounced|deferred)/) { } 0 0 0
37 0 ▶ if( $message =~ /^connect from/ ) { # we missed the disconnect?
Branch: 3 branches
BranchTrueFalseTotal
if ($message =~ /^connect from/) { } 0 0 0
elsif ($message =~ /^disconnect/) { } 0 0 0
elsif ($message =~ /^client=/) { } 0 0 0
38 0 $notes->remove($service.'-tls-'.$pid);
39 0 return;
40 } elsif( $message =~ /^disconnect/ ) {
41 0 $notes->remove($service.'-tls-'.$pid);
42 } elsif( $message =~ /^client=/ ) {
43 0 $self->incr_tls_stats( $stash, $tls_params, 'tls_msg', $service);
44 }
45 0 @$stash{keys %$tls_params} = values %$tls_params;
46 ▶ } elsif( $service eq 'smtp' &&
Condition0%0/3
$service eq "smtp" and $message =~ /status=(sent|bounced|deferred)/
!ll&&!rl&&r
000
MC/DC0%0/2
$service eq "smtp" and $message =~ /status=(sent|bounced|deferred)/
$service eq "smtp" $message =~ /status=(sent|bounced|deferred)/
Truth table0%0/3
A and B
A= $service eq "smtp"B= $message =~ /status=(sent|bounced|deferred)/
ABresult
0X0
100
111
47 $message =~ /status=(sent|bounced|deferred)/ ) {
48 0 $self->incr_tls_stats( $stash, $tls_params, 'tls_msg', $service);
49 0 $notes->remove($service.'-tls-'.$pid);
50 # postfix/smtp closes the TLS connection after each delivery
51 # see postfix-users maillist (2015-02-05)
52 # but there may be more than one recipients so remember
53 # TLS parameters for this queue_id
54 0 ▶ if( defined $queue_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $queue_id) 0 0 0
55 0 $notes->set($service.'-tls-'.$queue_id, $tls_params);
56 }
57 }
58 ▶ } elsif( defined $queue_id &&
Condition0%0/3
defined $queue_id and defined($tls_params = $notes->get($service . '-tls-' . $queue_id))
!ll&&!rl&&r
000
MC/DC0%0/2
defined $queue_id and defined($tls_params = $notes->get($service . '-tls-' . $queue_id))
defined $queue_id defined($tls_params = $notes->get($service . '-tls-' . $queue_id))
Truth table0%0/3
A and B
A= defined $queue_idB= defined($tls_params = $notes->get($service . '-tls-' . $queue_id))
ABresult
0X0
100
111
59 defined($tls_params = $notes->get($service.'-tls-'.$queue_id))
60 ) {
61 0 @$stash{keys %$tls_params} = values %$tls_params;
62 }
63  
64 0 return;
65 }
66  
67 sub incr_tls_stats {
68 0 ▶ my ( $self, $stash, $tls_params, @path ) = @_;
Subroutine incr_tls_stats: not called CC=1 SCAR=6.9
Pod undocumented
69  
70 0 $self->incr_host_one( $stash, @path, 'total');
71 0 $self->incr_host_one( $stash, @path, 'level', $tls_params->{'tls_level'});
72 0 $self->incr_host_one( $stash, @path, 'proto', $tls_params->{'tls_proto'});
73 0 $self->incr_host_one( $stash, @path, 'cipher', $tls_params->{'tls_chipher'});
74 0 $self->incr_host_one( $stash, @path, 'keylen', $tls_params->{'tls_keylen'});
75  
76 0 return;
77 }
78  
79 1 1;
80  
81 __END__
82  
83 =pod
84  
85 =encoding UTF-8
86  
87 =head1 NAME
88  
89 Log::Saftpresse::Plugin::Postfix::Tls - plugin to gather TLS statistics
90  
91 =head1 VERSION
92  
93 version 1.5
94  
95 =head1 AUTHOR
96  
97 Markus Benning <ich@markusbenning.de>
98  
99 =head1 COPYRIGHT AND LICENSE
100  
101 This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning.
102  
103 This is free software, licensed under:
104  
105 The GNU General Public License, Version 2, June 1991
106  
107 =cut
« Saftpresse/Plugin/Apache.pm ↑ Summary Saftpresse/Input/RELP/Frame.pm »