root/lib/Resmon/Module_to_convert/BACULAJOBS.pm

Revision 8ffd658c4e0e54188a1d93131a91b916f504c0ee, 1.0 kB (checked in by Mark Harrison <mark@omniti.com>, 5 years ago)

Move all original modules to a to_convert directory

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@274 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100755
Line 
1 package Resmon::Module::BACULAJOBS;
2 use Resmon::Module;
3 use vars qw/@ISA/;
4 @ISA = qw/Resmon::Module/;
5
6 use lib qw(/www/CPAN/lib/site_perl /opt/CPAN/lib/site_perl);
7 use DBI;
8 use DBD::Pg;
9
10 sub handler {
11         my $arg = shift;
12         my $jobname = $arg->{'object'};
13         my $level = $arg->{'level'};
14         my $age = $arg->{'age'};
15         print "$jobname, $level, $age\n";
16
17         my $db_name= 'bacula';
18         my $db_user = 'bacula';
19         my $db_pass = '';
20        
21         my $dsn = "DBI:Pg:database=$db_name;host=127.0.0.1;port=5432";
22         my $dbh = DBI->connect($dsn, $db_user, $db_pass, { PrintError => 1, AutoCommit => 1 });
23         my $query = "SELECT count(*) FROM job j WHERE j.name=? AND j.type='B' AND j.level=? AND j.jobstatus='T' AND j.starttime > current_timestamp - ? * interval '1 hours'";
24         my $sth = $dbh->prepare($query);
25         $sth->execute($jobname, $level, $age) || die $dbh->errstr;
26        
27         my $count = $sth->fetchrow_hashref->{'count'};
28         my $status;
29        
30         if ($count > 0) {
31                 $status = 'OK';
32         } else {
33                 $status = 'BAD';
34         }
35        
36         $sth->finish;
37         $dbh->disconnect;
38
39         return $status, "$count job(s) in the last $age hours";
40 }
41
42 1;
Note: See TracBrowser for help on using the browser.