#!/usr/bin/perl

#
#  Ce script est appelle par snmpd. Il indique si le slave MySQL est running ou non,
#       et si la synchro est correcte.
#
# 2005.02.10 Yann GROSSEL
#               Rééecriture en perl de l'ancien script .sh.
#

use strict;
use warnings;

my $mlf = '?';          # Master_Log_File
my $mlp = '?';          # Read_Master_Log_Pos
my $sir = '?';          # Slave_IO_Running
my $ssr = '?';          # Slave_SQL_Running

open PIPE, "/usr/bin/mysql -u 'root' -p'xxxx' -qse 'show slave status\\G' |"
        or die "! ! ! !\n";

while (<PIPE>)
{
        s/^\s+//g;
        m/^Master_Log_File:\s+([^\s]+)/o                        and $mlf = $1, next;
        m/^Read_Master_Log_Pos:\s+([^\s]+)/o    and $mlp = $1, next;
        m/^Slave_IO_Running:\s+([^\s]+)/o               and $sir = $1, next;
        m/^Slave_SQL_Running:\s+([^\s]+)/o              and $ssr = $1, next;
}

close PIPE;

print "$mlf $mlp $sir $ssr\n";

# vim: set ts=3 sw=3:

