Mini Shell
#!/bin/bash
# This is a nagios plugin to check if general query logging has been left on
# Written by Erik S. (e@inmotion.net / ext 834)
#define our states
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
# Get local mysql version
fullversion=`mysqladmin -uimhnagios -p1mhN4g10z variables | grep " version " | awk '{print $4}'`
# Get major and minor version of mysql
majorv=`echo $fullversion | awk -F'.' '{print $1}'`
minorv=`echo $fullversion | awk -F'.' '{print $2}'`
# Determine running version and get the appropriate log variable
if [[ "$majorv" = "4" ]] || [[ "$majorv" = "5" && "$minorv" = "0" ]] ; then
genq=`mysqladmin -uimhnagios -p1mhN4g10z variables | grep " log " | awk '{print $4}'`
else
genq=`mysqladmin -uimhnagios -p1mhN4g10z variables | grep " general_log " | awk '{print $4}'`
fi
if [ "$genq" == "ON" ]; then
if [ -f /var/log/MySQLGenLog ]; then
NOW=$(date +%s)
START_TIME=$(stat --format=%X /var/log/MySQLGenLog)
MINSOLD=`echo $START_TIME $NOW | awk '{ print ($2 - $1)/60 }'`
MINSOLDINT=`echo $MINSOLD | cut -d. -f1`
if [ $MINSOLDINT -gt 60 ]; then
echo "CRITICAL - mySQL general queries logging to disk for $MINSOLDINT minutes."
exit $STATE_CRITICAL;
else
echo "WARNING - mySQL general queries logging to disk for $MINSOLDINT minutes."
exit $STATE_WARNING;
fi
else
echo "OK - General Query logging is enabled and writing to /dev/null"
exit $STATE_OK;
fi
else
echo "OK - General Query logging is disabled from the mySQL server."
exit $STATE_OK;
fi
Zerion Mini Shell 1.0