#!/bin/sh
#====================================
# $Name: mysql_check.sh
# $Revision: 1.0
# $Function: This Nagios plugin can be check MySQL status
# $Author: Shundong Zhao
# $organization: UnixHot
# $Create Date: 2010-08-10
#===================================
MYSQLC="/usr/local/mysql/bin/mysql"
MYSQLADC="/usr/local/mysql/bin/mysqladmin"
MUSER="nagios"
MPASSWD="nagios"
SLOWLOGW="2"
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
mysqlstatus(){
STATUSSTR=`$MYSQLADC -u $MUSER -p$MPASSWD ping`
if [ "$STATUSSTR" == "mysqld is alive" ];then
echo -n "$STATUSSTR";
return 0;
else
echo -n "$STATUSSTR";
exit 2;
fi
}
mysqlslowlog(){
SLOWLOGTMP=`$MYSQLADC -u $MUSER -p$MPASSWD status`
SLOWLOGNU=`echo $SLOWLOGTMP | linuxjishu/13830.html target=_blank class=infotextkey>awk -F ' ' '{print $9}'`
if [ "$SLOWLOGNU" -gt "$SLOWLOGW" ];then
echo -n "Slow queriesSLOWLOGNU";
exit 2;
else
echo -n "Slow QueriteSLOWLOGNU";
fi
}
main(){
mysqlstatus;
echo -n ";";
# mysqlreplication;
mysqlslowlog;
}
main