lib/App/MadEye/Plugin/Agent/MySQLSlave.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 70 CC 7 SCAR 35.9
CC
7
Cov
0%
is_dead
56.0
BEGIN
2.0
BEGIN
2.0
CRAP 36.4
1 package App::MadEye::Plugin::Agent::MySQLSlave;
2 use strict;
3 use warnings;
4 use App::MadEye::Plugin::Agent::Base;
5  
6 use DBI;
7  
8 sub is_dead {
9 my ($self, $dsn) = @_;
10  
11 App::MadEye->context->log('debug' => "watching $dsn");
12  
13 my $user = $self->config->{config}->{user} or die "missing user";
14 my $password = $self->config->{config}->{password};
15 my $threshold = $self->config->{config}->{threshold} or die "missing threshold";
16  
17 my $dbh;
18 eval {
19 $dbh = DBI->connect(
20 $dsn,
21 $user,
22 $password,
23 { RaiseError => 1, AutoCommit => 1 }
24 ) or return 'cannot connect';
25 };
26 if ($@) {
27 return $@;
28 }
29  
30 my $sth = $dbh->prepare(q{SHOW SLAVE STATUS;});
31 $sth->execute() or return 'DBI error: ' . $dbh->errstr;
32  
33 if (my $row = $sth->fetchrow_hashref) {
34 # see. http://dev.mysql.com/doc/refman/4.1/ja/show-slave-status.html
35  
36 if (my $le = $row->{'Last_Error'}) {
37 return "replication error : $le\n";
38 }
39  
40 if ( $row->{'Slave_IO_Running'} ne 'Yes' ) {
41 return "Slave IO Not Running\n";
42 }
43  
44 if ( $row->{'Slave_SQL_Running'} ne 'Yes' ) {
45 return "Slave SQL Not Running\n";
46 }
47  
48 my $rmlp = $row->{'Read_Master_Log_Pos'};
49 my $emlp = $row->{'Exec_Master_Log_Pos'};
50 if ( abs($rmlp - $emlp) > $threshold ) {
51 return "considerable delay : $rmlp $emlp\n";
52 }
53  
54 return; # alive!
55 } else {
56 return "this is not a slave!";
57 }
58 }
59  
60 1;
61 __END__