Page 1 of 1

MySQL Service monitoring on Debian

Posted: Tue Dec 21, 2010 3:30 am
by andrew.nicolson
Hi All...
I am currently in the process of evaluating the NagiosXI product. We have an environment with mostly Debian servers. MySQL is a very important part of this setup also. Whilst 90% of NagiosXI installed out of the box and worked very well, there were a couple of "false negatives" that it picked up. The cron and syslog services were highlighted as down (because the init.d scripts did not support the status argument). The most important issue was that MySQL was marked as "Stopped".
This puzzled me significantly as the DB was running fine. I turned the nrpe agent debugging on and had a look at the output.

Dec 19 12:20:09 app-dv-01 nrpe[30201]: Host is asking for command 'check_init_service' to be run...
Dec 19 12:20:09 app-dv-01 nrpe[30201]: Running command: /usr/lib/nagios/plugins/check_init_service mysql
Dec 19 12:20:10 app-dv-01 nrpe[30201]: Command completed with return code 2 and output: MySQL is stopped..
Dec 19 12:20:10 app-dv-01 nrpe[30201]: Return Code: 2, Output: MySQL is stopped..

Remembering that the nrep agent is running as the nagios user, I discovered that the command was not executing for 2 reasons:

1.
nagios@app-dv-01:~$ /usr/lib/nagios/plugins/check_init_service mysql
cat: /var/run/mysqld/mysqld.pid: Permission denied
MySQL is stopped..
invoke-rc.d: initscript mysql, action "status" failed.
nagios@app-dv-01:~$ ls -l /var/run/mysqld/mysqld.pid
-rw-rw---- 1 mysql mysql 5 2010-12-21 18:57 /var/run/mysqld/mysqld.pid

2.
nagios@app-dv-01:~$ /usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf
Could not open required defaults file: /etc/mysql/debian.cnf
Fatal error in defaults handling. Program aborted
nagios@app-dv-01:~$ ls -l /etc/mysql/debian.cnf
-rw------- 1 root root 312 2008-11-12 16:46 /etc/mysql/debian.cnf

My resolution:
(This may or may not work for you. It may or may not be suitable for your system and DB security)

1. Add the nagios user to the mysql group
2. allow the debian.cnf to be group readable and change the group to mysql
app-dv-01:/var/log# chmod 640 /etc/mysql/debian.cnf
app-dv-01:/var/log# chgrp mysql /etc/mysql/debian.cnf

Now NagiosXI thinks that MySQL is running!

Hope this helps. I welcome feedback and any suggestions on improvement.

Andrew
http://www.fdc.net.nz

Re: MySQL Service monitoring on Debian

Posted: Tue Dec 21, 2010 10:08 am
by tonyyarusso
Another way of accomplishing this is to create a sudoers rule to let /usr/lib/nagios/plugins/check_init_service execute as a more privileged user. Which way you choose will of course depend on your internal requirements.

Thanks for the tip!