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:

root@cpanel [~]# /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:

root@cpanel [~]# /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:

cristian@monitoring> /usr/local/nagios/libexec/check_nrpe -H se.rv.er.ip -c check_mysql
OK - alive Mysql is alive, running fine.

 

2 thoughts on “Simple bash script to check mysql status with Nagios”

    • Hi Michael, this was not actually a proper script to check mysql status it was just a “hack” at that point in time 🙂 As you may see, it only provides 2 states, OK and whatever else is “critical” which is not always the case.
      Glad to hear that you found it useful though.

      Reply

Leave a Reply to michael Cancel reply

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