ORACLE DATAGUARD 监控脚本
短信预约 -IT技能 免费直播动态提醒
使用perl来监控ORACLE DATAGUARD脚本
#!/usr/bin/perl
use strict;
use warnings;
use DBI; # Load the DBI module
my $ZabbixServer = "192.168.3.24";
my $ZabbixPort = "10051";
my $HOSTNAME = "ora2";
my $SenderCMD="/usr/local/zabbix/bin/zabbix_sender";
my $Primtns = "test_st";
my $Stantns = "test";
my $KEY = "Oracled.DG.Status";
my $KEYContent1 = "OK";
my $KEYContent2 = "Failed";
my $LogVal = 3;
my $user = "zabbix";
my $passwd = "zabbix";
my $Primseq = 0;
my $Stanseq = 0;
$ENV{"ORACLE_HOME"}='/oracle/product/11.2.0/db_1';
#$ENV{PATH} .= $ENV{PATH} . ':/oracle/product/11.2.0/db_1/bin';
### Perform the connection using the Oracle driver
my $dbh =
DBI->connect( "dbi:Oracle:$Primtns", "$user", "$passwd", { PrintError => 0 } )
or die "Can't connect to Oracle database: $DBI::errstr\n";
my $sth = $dbh->prepare(
"SELECT MAX(SEQUENCE#) MAXSEQ
FROM V\$ARCHIVED_LOG
WHERE RESETLOGS_ID=(
SELECT RESETLOGS_ID FROM V\$DATABASE_INCARNATION
WHERE STATUS='CURRENT') "
);
$sth->execute;
###
while ( my @recs = $sth->fetchrow_array ) {
$Primseq = $recs[0];
###
}
### Now, disconnect from the database
$dbh->disconnect
or warn "Disconnection failed: $DBI::errstr\n";
$dbh =
DBI->connect( "dbi:Oracle:$Stantns", "$user", "$passwd", { PrintError => 0 } )
or die "Can't connect to Oracle database: $DBI::errstr\n";
$sth = $dbh->prepare(
"SELECT MAX(SEQUENCE#) MAXSEQ
FROM V\$ARCHIVED_LOG
WHERE RESETLOGS_ID=(
SELECT RESETLOGS_ID FROM V\$DATABASE_INCARNATION
WHERE STATUS='CURRENT'
AND APPLIED='YES') "
);
$sth->execute;
###
while ( my @recs = $sth->fetchrow_array ) {
$Stanseq = $recs[0];
###
}
### Now, disconnect from the database
$dbh->disconnect
or warn "Disconnection failed: $DBI::errstr\n";
if($Primseq-$Stanseq>=$LogVal){
system("$SenderCMD -z $ZabbixServer -p $ZabbixPort -s $HOSTNAME -k $KEY -o $KEYContent2 >/dev/null 2>&1");
}else{
system("$SenderCMD -z $ZabbixServer -p $ZabbixPort -s $HOSTNAME -k $KEY -o $KEYContent1 >/dev/null 2>&1");
}
exit;
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341