0

I would like to check number of MySQL databases. I've created simple test "plugin":

Location: `/var/lib64/nagios/plugins

test:

#!/bin/bash

db=$(mysql -e 'SHOW DATABASES' | wc -l)
echo $db

It works from the local machine:

# ./test 
71
  • however when executed from Nagios server it displays "0"

NRPE config:

command[test]=/usr/lib64/nagios/plugins/test

Nagios server:

# ./check_nrpe -H 192.168.1.10 -c "test"
0

Reagrds

  • 1
    Log the output of the db=$(mysql -e 'SHOW DATABASES' | wc -l) to a file. Possibly mysql is not in $PATH and/or the user as which it runs has no access to MySQL. – faker Jun 27 '12 at 12:28
  • 1
    Has the nagios user access to run the mysql command without any passwords etc? Try with su! – HampusLi Jun 27 '12 at 13:08
3

NPRE commands usually run as nagios. It seems like your query is actually polling how many databases your nagios user can see.

There are several solutions to your problem:

  • Add user and password information to your command (mysql -uroot -proot -e 'SHOW DATABASES' | wc -l);
  • Add nagios to your sudoers file, so that he can run mysql as root (nagios ALL=(ALL) NOPASSWD:/usr/bin/mysql -e 'SHOW DATABASES');
  • Add a nagios user to your database with sufficient permissions to see all databases (mysql documentation) - RECOMMENDED;
2

BTW, you should consult http://nagios.sourceforge.net/docs/3_0/pluginapi.html as the output from the shown in your plug-in script is quite non-standard for Nagios andf will cause problems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.