Instantly share code, notes, and snippets.

@maazanjum /monitor_gg.pl Secret
Last active Dec 30, 2015

Embed
What would you like to do?
#!/usr/bin/perl -w
use strict;
use warnings;
use Switch;
###################################################
# Change this variables as per your environment #
# Alternatively, this could just as well be a #
# parameter that is passed to this script. #
# For example: #
# #
# my $ggdir = $ARGV[0] #
# #
my $ggdir = "/tmp/ggate";
# #
###################################################
#
# GoldenGate Status, Lag etc variables
#
my $program;
my $status;
my $statusid;
my $group;
my $lagatchkpt;
my $timesincechkpt;
my $hours;
my $minutes;
my $seconds;
#
# File Variables
#
my $line;
#my $ggobjects = "/EXTRACT/||/REPLICAT/||/MANAGER/";
# Execute GGSCI check
#
my @buf = `$ggdir/ggsci << EOF
info all
EOF`;
# Parse the extracted lines and display piped output
# GROUP|PROGRAM|STATUS|LAGATCHKPT|TIMESINCHKPT|STATUSID
#
# For Example:
#
# MANAGER|MANAGER|RUNNING|0|0
# R_PRD|REPLICAT|RUNNING|0|6|0
#
foreach $line (@buf)
{
chomp($line);
if($line =~ m/(MANAGER|EXTRACT|REPLICAT)/)
{
no warnings 'uninitialized';
($program, $status, $group, $lagatchkpt, $timesincechkpt) = split(" ", $line);
if ($group eq "") {
$group = $program }
# Parse Lag at CheckPoint
if ($lagatchkpt eq "") {
$lagatchkpt = "00:00:00" }
($hours, $minutes, $seconds) = split (/:/, $lagatchkpt);
$lagatchkpt = ($hours*60*60)+($minutes*60)+($seconds);
# Parse Time Since Last CheckPoint
if ($timesincechkpt eq "") {
$timesincechkpt = "00:00:00" }
($hours, $minutes, $seconds) = split (/:/, $timesincechkpt);
$timesincechkpt = ($hours*60*60)+($minutes*60)+($seconds);
switch ($status) {
case("RUNNING") { $statusid=0; }
case("STOPPED") { $statusid=1; }
case("ABENDED") { $statusid=2; }
}
print "$group|$program|$status|$lagatchkpt|$timesincechkpt|$statusid\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment