« lib/App/MadEye/Plugin/Agent/TheSchwartz/Error.pm
↑ Summary
lib/App/MadEye/Plugin/Agent/SNMP/Disk.pm »
| 1 | package App::MadEye::Plugin::Agent::TheSchwartz::Job; | ||
| 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 | my $conf = $self->config->{config}; | ||
| 12 | my $user = $conf->{user} or die "missing user"; | ||
| 13 | my $password = $conf->{password} || ''; | ||
| 14 | my $threshold = $conf->{threshold} or die "missing threshold"; | ||
| 15 | |||
| 16 | my $dbh; | ||
| 17 | eval { | ||
| 18 | $dbh = DBI->connect( | ||
| 19 | $dsn, | ||
| 20 | $user, | ||
| 21 | $password, | ||
| 22 | {RaiseError => 1, AutoCommit => 1} | ||
| 23 | ); | ||
| 24 | }; | ||
| 25 | |||
| 26 | if ($@) { | ||
| 27 | return $@; | ||
| 28 | } else { | ||
| 29 | my ($cnt) = $dbh->selectrow_array(q{select count(*) from job}); | ||
| 30 | if ($cnt > $threshold) { | ||
| 31 | return "job count: $cnt"; | ||
| 32 | } else { | ||
| 33 | return; # alive | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | 1; | ||
| 39 | __END__ |