Simple bash script to check mysql status with Nagios

After updating mysql on a server that is running cpanel, Nagios kept reporting that mysql is down. I double checked and the database server was running just fine, so I proceeded with a step by step analysis, the issue proved to be the following:

[email protected] [~]# /usr/local/nagios/libexec/check_mysql
/usr/local/nagios/libexec/check_mysql: error while loading shared libraries: libmysqlclient.so.15: cannot open shared object file: No such file or directory

I checked to see what’s with the libmysqlclient:

[email protected] [~]# /usr/local/nagios/libexec/check_mysql
/usr/local/nagios/libexec/check_mysql: error while loading shared libraries: libmysqlclient.so.15: cannot open shared object file: No such file or directory

This means I had to recompile the nagios-plugins to use the latest mysql libraries which I wasn’t really in the mood to do this, so I built a little bash script to bypass this issue:

#!/bin/bash
#DO NOT add a blank space between -p and NRPEPASSWORD
mysql_status=`/usr/bin/mysqladmin -u NRPEUSERNAME -pNRPEPASSWORD ping | /bin/cut -d " " -f 3`

case $mysql_status in
  alive)
    echo "OK - $mysql_status Mysql is alive, running fine."
    exit 0
  ;;
  *)
    echo "CRITICAL - $mysql_status Mysql is DOWN."
    exit 2
  ;;
esac

Now everything runs fine, this is how you simply check mysql status:

[email protected]> /usr/local/nagios/libexec/check_nrpe -H se.rv.er.ip -c check_mysql
OK - alive Mysql is alive, running fine.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.