line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HealthCheck::Diagnostic::SMTP; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
71227
|
use strict; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
457
|
use parent 'HealthCheck::Diagnostic'; |
|
1
|
|
|
|
|
380
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5456
|
use Net::SMTP; |
|
1
|
|
|
|
|
102898
|
|
|
1
|
|
|
|
|
63
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# https://metacpan.org/pod/distribution/perl/pod/perl5140delta.pod#Exception-Handling |
11
|
1
|
|
|
1
|
|
9
|
use constant UNSTABLE_DOLLARAT => $] lt '5.013002'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# ABSTRACT: Verify connectivity to an SMTP mail server |
14
|
1
|
|
|
1
|
|
7
|
use version; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
15
|
|
|
|
|
|
|
our $VERSION = 'v0.0.4'; # VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
1
|
|
|
1
|
1
|
647
|
my ($class, @params) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my %params = @params == 1 && ( ref $params[0] || '' ) eq 'HASH' |
21
|
1
|
50
|
33
|
|
|
8
|
? %{ $params[0] } : @params; |
|
0
|
|
|
|
|
0
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
11
|
return $class->SUPER::new( |
24
|
|
|
|
|
|
|
id => 'smtp', |
25
|
|
|
|
|
|
|
label => 'SMTP', |
26
|
|
|
|
|
|
|
%params, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub check { |
31
|
1
|
|
|
1
|
1
|
22
|
my ($self, %params) = @_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Make it so that the diagnostic can be used as an instance or a |
34
|
|
|
|
|
|
|
# class, and the `check` params get preference. |
35
|
1
|
50
|
|
|
|
5
|
if ( ref $self ) { |
36
|
|
|
|
|
|
|
$params{ $_ } = $self->{ $_ } |
37
|
1
|
|
|
|
|
7
|
foreach grep { ! defined $params{ $_ } } keys %$self; |
|
2
|
|
|
|
|
12
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
9
|
return $self->SUPER::check( %params ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub run { |
44
|
4
|
|
|
4
|
1
|
1425
|
my ($self, %params) = @_; |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
8
|
local $@ unless UNSTABLE_DOLLARAT; |
47
|
4
|
|
|
|
|
16
|
my $smtp = $self->smtp_connect( %params ); |
48
|
|
|
|
|
|
|
|
49
|
2
|
100
|
|
|
|
31
|
unless ( $smtp ) { |
50
|
|
|
|
|
|
|
return { |
51
|
1
|
|
|
|
|
9
|
status => 'CRITICAL', |
52
|
|
|
|
|
|
|
info => "$@", |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
4
|
my $banner = $smtp->banner; |
57
|
1
|
|
|
|
|
7
|
$smtp->quit; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return { |
60
|
1
|
|
|
|
|
15
|
status => 'OK', |
61
|
|
|
|
|
|
|
info => $banner, |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub smtp_connect { |
66
|
2
|
|
|
2
|
|
6
|
my ( $self, %params ) = @_; |
67
|
|
|
|
|
|
|
|
68
|
2
|
50
|
|
|
|
22
|
my $host = $params{ host } or die "host is required\n"; |
69
|
0
|
|
0
|
|
|
|
my $port = $params{ port } // 25; |
70
|
0
|
|
0
|
|
|
|
my $timeout = $params{ timeout } // 5; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
$host = $host->( %params ) if ref $host eq 'CODE'; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return Net::SMTP->new( $host, Timeout => $timeout, Port => $port ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |