cat /etc/zabbix/script/mysql_slave_status.sh

#!/bin/bash

USER="root"
PASSWD="xxx"
NAME=$1

function IO {
    Slave_IO_Running=`mysql -u $USER -p$PASSWD -e "show slave status/G;" 2> /dev/null |grep Slave_IO_Running |awk '{print $2}'`
    if [ $Slave_IO_Running == "Yes" ];then
        echo 0 
    else
        echo 1 
    fi
}

function SQL {
    Slave_SQL_Running=`mysql -u $USER -p$PASSWD -e "show slave status/G;" 2> /dev/null |grep Slave_SQL_Running: |awk '{print $2}'`
    if [ $Slave_SQL_Running == "Yes" ];then
        echo 0 
    else
        echo 1 
    fi

}

case $NAME in
   io)
       IO
   ;;
   sql)
       SQL
   ;;
   *)
        echo -e "Usage: $0 [io | sql]"
esac

cat /etc/zabbix/zabbix_agentd.d/userparameter_mysql_slave.conf

# 获取MySQL slave状态
UserParameter=mysql.slave[*],/etc/zabbix/script/mysql_slave_status.sh $1