[root@localhost libexec]# vim check_dbjob
use DBI;
# Nagios specific
use lib "/opt/nagios/nagiosweb/libexec/";
#use lib "/usr/lib/nagios/plugins";
use utils qw(%ERRORS $TIMEOUT);
#my $TIMEOUT = 15;
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNowN'=>3,'DEPENDENT'=>4);
my $o_host;
my $o_port;
my $o_user="sa";
my $o_pw="";
my $name="";
sub print_usage {
print "\n";
print "Usage: check_dbmirroring.pl -H <host> [-u <username>] [-p <password>] [-o <port>]\n";
print "\n";
print "\tDefault Username is 'sa' without a password\n\n";
print "\tScript should be run on the PRINCIPAL with a read-only user\n";
print "\tIf you want to run it on the MIRROR,the user MUST have SYSADMIN rights on the sql-Server\n";
print "\totherwise you get NULL\n";
print "\n";
}
sub check_options {
Getopt::Long::Configure ("bundling");
Getoptions(
'H:s' => \$o_host,
'u:s' => \$o_user,
'p:s' => \$o_pw,
'o:s' => \$o_port
);
if (!defined ($o_host)) { print_usage(); exit $ERRORS{"UNKNowN"}};
}
########## MAIN #######
check_options();
my $exit_val;
# Connect to database
my $dbh =DBI->connect("dbi:Sybase:server=$o_host:$o_port","$o_user","$o_pw") or exit $ERRORS{"UNKNowN"};
my $sth=$dbh->prepare("select count(*) num from msdb.dbo.sysjobservers,msdb.dbo.sysjobs_view where msdb.dbo.sysjobs_view.job_id=msdb.dbo.sysjobservers.job_id and msdb.dbo.sysjobs_view.enabled =1 and msdb.dbo.sysjobservers.last_run_date>0 and msdb.dbo.sysjobservers.last_run_outcome <>1");
$sth->execute;
while (my @row = $sth->fetchrow_array) {
$name=$row["0"];
}
$exit_val=$ERRORS{"CRITICAL"};
$exit_val=$ERRORS{"OK"} if ( $name eq "0" );
print "OK -JOB IS OK\n" if ($exit_val eq $ERRORS{"OK"});
print "CRITICAL JOB has a error\n" if ($exit_val eq $ERRORS{"CRITICAL"});
exit $exit_val;
-----------------------------------------------------------------------------------------------------------------------------
[root@localhost libexec]# /opt/nagios/nagiosweb/libexec/check_dbjob -H xxxxx -u xxxx -p xxxx -o 38141 OK -JOB IS OK [root@localhost libexec]#
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。