Using Perl to monitor Oracle Dataguard scripts
#!/usr/bin/perluse strict;use warnings;use dbi; # load the DBI modulemy $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 $KEYContent 1 = "OK";my $KEYContent 2 = "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 drivermy $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 $KEYContent 2 >/dev/null 2>&1 "); }else{ system ("$SenderCMD -z $ZabbixServer -p $ZabbixPort -s $HOSTNAME -k $KEY -o $KEYContent 1 >/dev/null 2>&1 ");} Exit
This article is from the "Days together with it" blog, so be sure to keep this source http://raugher.blog.51cto.com/3472678/1551506
ORACLE DATAGUARD Monitoring Scripts