ASNMTAP

 view release on metacpan or  search on metacpan

plugins/templates/check_MySQL-database-replication.pl  view on Meta::CPAN

                $returnCode = $ERRORS{CRITICAL};
              } elsif ( $$ref[11] eq 'No' ) {
                $alert = "Replication ERROR: NO Slave SQL Running";
                print "S)-$alert\n" if ( $debug ); 
                $returnCode = $ERRORS{CRITICAL};
              } elsif ( $$ref[18] ne '0' ) {
                $alert = "Replication ERROR '$$ref[18]' for '$binlog' running on slave server";
                print "S)-$alert\n" if ( $debug ); 
                $returnCode = $ERRORS{CRITICAL};
              } elsif ( $$ref[32] eq 'NULL' ) {
                $alert = "Seconds Behind Master: '$$ref[18]' for '$binlog' running on slave server";
                print "S)-$alert\n" if ( $debug );
                $returnCode = $ERRORS{CRITICAL};
              } else {
                $alert .= "+Replicate do DB+" . $$ref[0];
      	        print "S)+Replicate do DB '$binlog' present\n" if ( $debug ); 
              }
            }
          } else {
            $alert = "Replicate do DB '$binlog' not present";
	        print "S)-$alert\n" if ( $debug ); 
            $returnCode = $ERRORS{CRITICAL};
		  }
        } else {
          if ( $cluster eq 'S' ) {
            $alert = "Replication for '$binlog' not running on slave server";
            print "S)-$alert\n" if ( $debug );
            $returnCode = $ERRORS{WARNING};
          }
		}

        $sth->finish() or errorTrapDBI ( 'sth->finish '. $prepareString, "$DBI::err ($DBI::errstr)" );
      }
    }

  # if ( $returnCode eq $ERRORS{OK} ) {
  #   $prepareString = "SHOW TABLE STATUS FROM $database";
  #   $sth = $dbh->prepare($prepareString) or errorTrapDBI ( 'dbh->prepare '. $prepareString, "$DBI::err ($DBI::errstr)" );
  #   $sth->execute or errorTrapDBI ( 'sth->execute '. $prepareString, "$DBI::err ($DBI::errstr)" );

  #   while ( $ref = $sth->fetchrow_arrayref ) {
  #     if ( $$ref[1] eq $table ) {
  #       my $updateTime = $$ref[12];

  #       if ( $debug ) {
  #         print "T) <DBI:mysql:$database:$hostname:$port><$username><$password><$table>\n";
  #         my $autoIncrement = $$ref[10];
  #         my $createTime    = $$ref[11];
  #         if ( defined $autoIncrement ) { print "T) Auto increment <$autoIncrement>\n"; }
  #         if ( defined $createTime )    { print "T) Create  Time   <$createTime>\n"; }
  #         if ( defined $updateTime )    { print "T) Update  Time   <$updateTime>\n"; }

  #         # for(my $i=0; $i<$sth->{NUM_OF_FIELDS}; $i++) {
  #         #   my $field = $$ref[$i];
  #         #   if ( defined $field ) { print "<", $field, ">\n"; }
  #         # }
  #       }

  #       if ( defined $updateTime ) { 
  #         if ( $dbh && defined $warning && defined $critical ) {
  #           my (@currentTime, @updateTime, @diffDateTime);
  #           my ($year, $month, $day, $hour, $min, $sec, undef) = split(/\:/, get_yyyymmddhhmmsswday());
  #           @currentTime  = ($year, $month, $day, $hour, $min, $sec);
  #           print "T) Current Time   <$year-$month-$day $hour:$min:$sec>\n" if ( $debug );
  #           ($year, $month, $day) = split(/\-/, substr($updateTime, 0, 10));
  #           ($hour, $min, $sec)   = split(/\:/, substr($updateTime, 11));
  #           @updateTime   = ($year, $month, $day, $hour, $min, $sec);
  #           print "T) Update  Time   <$year-$month-$day $hour:$min:$sec>\n" if ( $debug );
  #           @diffDateTime = Delta_DHMS(@updateTime, @currentTime); 
  #           my $difference = ($diffDateTime[1]*3600)+($diffDateTime[2]*60)+$diffDateTime[3];
  #           print "T) Difference     <$difference> Warning <$warning> Critical <$critical>\n" if ( $debug );
  #           if ( $alert ne '' ) { $alert .= "+ "; }
  #           $alert .= "Last update from table '$table' is $difference seconds ago";

  #           if ( $difference > $critical ) {
  #             $returnCode = $ERRORS{CRITICAL};
  #           } elsif ( $difference > $warning ) {
  #             $returnCode = $ERRORS{WARNING};
  #           }
  #  	    }
  #       } else {
  #         $alert = "Update time for table '$table' doesn't exist";
  #         $returnCode = $ERRORS{CRITICAL};
  #       }
  #     }
  #  }

  #   $sth->finish() or errorTrapDBI ( 'sth->finish '. $prepareString, "$DBI::err ($DBI::errstr)" );
  # }
  }
} else {
  $alert = "table '$table' doesn't exist";
  $returnCode = $ERRORS{CRITICAL};
}

if ( $dbh ) { $dbh->disconnect or errorTrapDBI ( 'Could not disconnect from MySQL server '. $hostname, "$DBI::err ($DBI::errstr)" ); }

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# End plugin  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

$objectPlugins->pluginValues ( { stateValue => $returnCode, alert => $alert }, $TYPE{APPEND} );
$objectPlugins->exit (7);

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub errorTrapDBI {
  my ($error, $errorDBI) = @_;

  $objectPlugins->pluginValues ( { stateValue => $ERRORS{CRITICAL}, error => "$error - $errorDBI" }, $TYPE{APPEND} );
  $objectPlugins->exit (7);
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

__END__

=head1 NAME

check_MySQL-database-replication.pl

MySQL database replication plugin template for the 'Application Monitor'

The ASNMTAP plugins come with ABSOLUTELY NO WARRANTY.

=head1 AUTHOR

Alex Peeters [alex.peeters@citap.be]

=head1 COPYRIGHT NOTICE



( run in 0.751 second using v1.01-cache-2.11-cpan-39bf76dae61 )