Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
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
add comment

2 Answers

up vote 3 down vote accepted

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;
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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