#!/usr/bin/perl -w
use strict;
use DBI;
# To change the database monitored change below var
my $database="database-name";
# Script to test MySQL replication by TRD 08/01/2008
# Script written by Thibs
# http://qmailrocks.thibs.com
if (scalar(@ARGV)==3) {
        #Variables
                my $dbServer="DBI:mysql:database=$database;host=$ARGV[0]";
                my $dbUser=$ARGV[1];
                my $dbPwd=$ARGV[2];
                                
#Connect to DB
                my $db=DBI->connect($dbServer,$dbUser,$dbPwd) || exit 2;
                                                
                my $rs=$db->prepare('show slave status');
                $rs->execute();
                my $dr=$rs->fetchrow_hashref();
                my $Slave_IO_Running=$dr->{'Slave_IO_Running'};
                my $Slave_SQL_Running=$dr->{'Slave_SQL_Running'};
                $rs->finish();
                $db->disconnect();
if (($Slave_IO_Running eq 'Yes') && ($Slave_SQL_Running eq 'Yes')) {
print "Database $database is in replication :)\n";
exit 0;
}
                                                                                                                                                else {
                                                                                                                                                                exit 2;
                                                                                                                                                                        }
                                                                                                                                                                        }
                                                                                                                                                                        else {
                                                                                                                                                                                print "Missing parameter\n";
                                                                                                                                                                                        exit 1;
                                                                                                                                                                                        }
