line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HealthCheck::Diagnostic::DBHPing; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Ping a database handle to check its health |
4
|
1
|
|
|
1
|
|
68925
|
use version; |
|
1
|
|
|
|
|
1949
|
|
|
1
|
|
|
|
|
6
|
|
5
|
|
|
|
|
|
|
our $VERSION = 'v1.2.4'; # VERSION |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
103
|
use 5.010; |
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
10
|
1
|
|
|
1
|
|
452
|
use parent 'HealthCheck::Diagnostic'; |
|
1
|
|
|
|
|
301
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
2366
|
use Carp; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
325
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
4
|
|
|
4
|
1
|
4029
|
my ($class, @params) = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Allow either a hashref or even-sized list of params |
18
|
|
|
|
|
|
|
my %params = @params == 1 && ( ref $params[0] || '' ) eq 'HASH' |
19
|
4
|
50
|
33
|
|
|
21
|
? %{ $params[0] } : @params; |
|
0
|
|
|
|
|
0
|
|
20
|
|
|
|
|
|
|
|
21
|
4
|
|
|
|
|
23
|
return $class->SUPER::new( |
22
|
|
|
|
|
|
|
label => 'dbh_ping', |
23
|
|
|
|
|
|
|
%params |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub check { |
28
|
9
|
|
|
9
|
1
|
1342
|
my ( $self, %params ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
9
|
|
|
|
|
22
|
my $dbh = $params{dbh}; |
31
|
9
|
100
|
66
|
|
|
42
|
$dbh ||= $self->{dbh} if ref $self; |
32
|
9
|
100
|
|
|
|
32
|
$dbh = $dbh->(%params) if ref $dbh eq 'CODE'; |
33
|
|
|
|
|
|
|
|
34
|
9
|
100
|
100
|
|
|
1032
|
croak("Valid 'dbh' is required") unless $dbh and do { |
35
|
6
|
|
|
|
|
10
|
local $@; local $SIG{__DIE__}; eval { $dbh->can('ping') } }; |
|
6
|
|
|
|
|
22
|
|
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
243
|
|
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
24
|
my $res = $self->SUPER::check( %params, dbh => $dbh ); |
38
|
4
|
|
|
|
|
322
|
delete $res->{dbh}; # don't include the object in the result |
39
|
|
|
|
|
|
|
|
40
|
4
|
|
|
|
|
99
|
return $res; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub run { |
44
|
4
|
|
|
4
|
1
|
88
|
my ( $self, %params ) = @_; |
45
|
4
|
|
|
|
|
8
|
my $dbh = $params{dbh}; |
46
|
|
|
|
|
|
|
|
47
|
4
|
100
|
|
|
|
16
|
my $status = $dbh->ping ? "OK" : "CRITICAL"; |
48
|
4
|
100
|
|
|
|
98
|
my $successful = $status eq "OK" ? "Successful" : "Unsuccessful"; |
49
|
|
|
|
|
|
|
|
50
|
4
|
|
|
|
|
40
|
my $driver = $dbh->{Driver}->{Name}; |
51
|
4
|
|
|
|
|
25
|
my $info = "$successful $driver ping of $dbh->{Name}"; |
52
|
4
|
100
|
|
|
|
27
|
$info .= " as $dbh->{Username}" if $dbh->{Username}; |
53
|
|
|
|
|
|
|
|
54
|
4
|
|
|
|
|
30
|
return { status => $status, info => $info }; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |