Saftpresse/Plugin/Postfix/Smtpd.pm

filter: Statementstmt 28.0% 14 / 50 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 80.0% 4 / 5 Podpod 0.0% 0 / 1 totaltotal 20.0% 18 / 90 SCAR 45.0
CC
12
Cov
18%
process_smtpd
156.0
BEGIN
1.0
BEGIN
1.0
CRAP 90.2
« Saftpresse/Config.pm ↑ Summary Saftpresse/Plugin/MtPolicyd.pm »
1 package Log::Saftpresse::Plugin::Postfix::Smtpd;
2  
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: plugin to gather postfix/smtpd advanced statistics
6 1 our $VERSION = '1.5'; # VERSION
7  
8 1 ▶use Log::Saftpresse::Plugin::Postfix::Utils qw( gimme_domain );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Time::Seconds;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub process_smtpd {
14 0 ▶ my ( $self, $stash, $notes ) = @_;
Subroutine process_smtpd: not called CC=12 SCAR=50.5
Pod undocumented
15 0 my $service = $stash->{'service'};
16 0 my $message = $stash->{'message'};
17 0 my $qid = $stash->{'queue_id'};
18 0 my $pid = $stash->{'pid'};
19 0 my $time = $stash->{'time'};
20  
21 0 ▶ if( $service eq 'pickup' && $message =~ /^(sender|uid)=/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($service eq "pickup" and $message =~ /^(sender|uid)=/) 0 0 0
Condition0%0/3
$service eq "pickup" and $message =~ /^(sender|uid)=/
!ll&&!rl&&r
000
MC/DC0%0/2
$service eq "pickup" and $message =~ /^(sender|uid)=/
$service eq "pickup" $message =~ /^(sender|uid)=/
Truth table0%0/3
A and B
A= $service eq "pickup"B= $message =~ /^(sender|uid)=/
ABresult
0X0
100
111
22 0 $notes->set( 'client-'.$qid => 'pickup' );
23 }
24  
25 0 ▶ if( $service ne 'smtpd' ) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($service ne "smtpd") 0 0 0
26  
27 0 ▶ if( defined $qid && $message =~ /client=(.+?)(,|$)/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $qid and $message =~ /client=(.+?)(,|$)/) { } 0 0 0
elsif (defined $pid and $message =~ /^connect from /) { } 0 0 0
elsif (defined $pid and my($host) = $message =~ /^disconnect from (.+)$/) { } 0 0 0
Condition0%0/3
defined $qid and $message =~ /client=(.+?)(,|$)/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $qid and $message =~ /client=(.+?)(,|$)/
defined $qid $message =~ /client=(.+?)(,|$)/
Truth table0%0/3
A and B
A= defined $qidB= $message =~ /client=(.+?)(,|$)/
ABresult
0X0
100
111
28 0 $notes->set( 'client-'.$qid => gimme_domain($1) );
29 ▶ } elsif ( defined $pid && $message =~ /^connect from / ) {
Condition0%0/3
defined $pid and $message =~ /^connect from /
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pid and $message =~ /^connect from /
defined $pid $message =~ /^connect from /
Truth table0%0/3
A and B
A= defined $pidB= $message =~ /^connect from /
ABresult
0X0
100
111
30 0 $notes->set( 'pid-connect-'.$pid => $time );
31 0 $self->new_tracking_id($stash, $notes);
32 ▶ } elsif ( defined $pid &&
Condition0%0/3
defined $pid and my($host) = $message =~ /^disconnect from (.+)$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pid and my($host) = $message =~ /^disconnect from (.+)$/
defined $pid my($host) = $message =~ /^disconnect from (.+)$/
Truth table0%0/3
A and B
A= defined $pidB= my($host) = $message =~ /^disconnect from (.+)$/
ABresult
0X0
100
111
33 ( my ($host) = $message =~ /^disconnect from (.+)$/) ) {
34 0 my $host = gimme_domain($host);
35 0 my $conn_time = $notes->get( 'pid-connect-'.$pid );
36 0 ▶ if( ! defined $conn_time ) { return; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $conn_time) 0 0 0
37 0 my $elapsed = $time - $conn_time;
38 0 my $sec = $elapsed->seconds;
39  
40 0 $stash->{'connection_time'} = $sec;
41 0 $stash->{'client'} = $host;
42  
43 0 ▶ if( $self->saftsumm_mode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->saftsumm_mode) 0 0 0
44 0 $self->incr_host_one( $stash, 'conn', 'per_hr', $time->hour);
45 0 $self->incr_host_one( $stash, 'conn', 'per_day', $time->ymd);
46 0 $self->incr_host( $stash, 'conn', 'busy', 'per_hr', $time->hour, $sec);
47 0 $self->incr_host( $stash, 'conn', 'busy', 'per_day', $time->ymd, $sec);
48 0 $self->incr_host_max( $stash, 'conn', 'busy', 'max_per_hr', $time->hour, $sec);
49 0 $self->incr_host_max( $stash, 'conn', 'busy', 'max_per_day', $time->ymd, $sec);
50 0 $self->incr_host_max( $stash, 'conn', 'busy', 'max_per_domain', $host, $sec);
51 }
52 0 $self->incr_host_one( $stash, 'conn', 'per_domain', $host);
53 0 $self->incr_host( $stash, 'conn', 'busy', 'per_domain', $host, $sec);
54  
55 0 $self->incr_host_one( $stash, 'conn', 'total');
56 0 $self->incr_host( $stash, 'conn', 'busy', 'total', $sec);
57  
58 0 $self->clear_tracking_id('pid', $stash, $notes);
59 }
60  
61 0 return;
62 }
63  
64 1 1;
65  
66 __END__
67  
68 =pod
69  
70 =encoding UTF-8
71  
72 =head1 NAME
73  
74 Log::Saftpresse::Plugin::Postfix::Smtpd - plugin to gather postfix/smtpd advanced statistics
75  
76 =head1 VERSION
77  
78 version 1.5
79  
80 =head1 AUTHOR
81  
82 Markus Benning <ich@markusbenning.de>
83  
84 =head1 COPYRIGHT AND LICENSE
85  
86 This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning.
87  
88 This is free software, licensed under:
89  
90 The GNU General Public License, Version 2, June 1991
91  
92 =cut
« Saftpresse/Config.pm ↑ Summary Saftpresse/Plugin/MtPolicyd.pm »