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