more /opt/nagios/nagiosweb/libexec/check_mirror
#!/bin/bash
export LD_liBRARY_PATH=/usr/local/lib
/opt/nagios/nagiosweb/libexec/check_dbmirroringbk -H $1 -o $2 -d $3 -u $4 -p $5
[root@localhost libexec]# more /opt/nagios/nagiosweb/libexec/check_dbmirroringbk
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
use DBI;
# Nagios specific
use lib "/opt/nagios/nagiosweb/libexec/";-----结合nagios安装目录修改
#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_db;
my $o_port;
my $o_user="sa";
my $o_pw="";
my $name="";
my $state="";
my $role="";
sub print_usage {
print "\n";
print "Usage: check_dbmirroring.pl -H <host> -d <database> [-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,
'd:s' => \$o_db,
'u:s' => \$o_user,
'p:s' => \$o_pw,
'o:s' => \$o_port
);
if (!defined ($o_host) || !defined ($o_db)) { 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 d.name,m.mirroring_role_desc,m.mirroring_state_desc
FROM sys.database_mirroring m
JOIN sys.databases d ON m.database_ID = d.database_ID
WHERE mirroring_state_desc IS NOT NulL AND name = '$o_db'");
$sth->execute;
while (my @row = $sth->fetchrow_array) {
$name=$row["0"];
$role=$row["1"];
$state=$row["2"];
}
$exit_val=$ERRORS{"CRITICAL"};
$exit_val=$ERRORS{"OK"} if ( $role eq "PRINCIPAL" ) && ( $state eq "SYNCHRONIZED" );
print "OK - $name - $role - $state\n" if ($exit_val eq $ERRORS{"OK"});
print "CRITICAL - Check your mirroring settings\n" if ($exit_val eq $ERRORS{"CRITICAL"});
exit $exit_val;
添加监控命令
define command{
command_name check_sqlserver_mirroring
command_line $USER1$/check_mirror $HOSTADDRESS$ $_HOSTPORT$ $_SERVICEDBname$ $_HOSTDBUSER$ $_HOSTDBPASSWORD$
}
-------------------------------------------------------------------------------------------
添加监控主机和监控服务
define host{
use windows-server ;
host_name sql186 ;
alias sql186 ;
address xxx..xx.xx186;
_port XXXX
_dbuser XXXXXXXXXXXX
_dbpassword XXXXXXXXXXXXXXX
}
define service{
use generic-service
host_name sql186 ; The name we're giving to this host
_dbname user
normal_check_interval 2
service_description sqlmirror_186_card
check_command check_sqlserver_mirroring
}
参考文献
http://labs.consol.de/nagios/check_mssql_health/
http://www.voidcn.com/article/p-bquiwaer-bbr.html
总结以上是内存溢出为你收集整理的nagios监控sqlserver2005镜像全部内容,希望文章能够帮你解决nagios监控sqlserver2005镜像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)