1

I have Nagios 3 running on Debian Wheezy. I am able to run the query the following query from the command line. The credentials for the mysql db are stored in ~nagios/.my.cnf

nagios@intranet:~$ /usr/lib/nagios/plugins/check_mysql_query -H 'myhost.mydomain.com' -q "SELECT cast(AVG(availability)*100 AS DECIMAL(5,2)   ) FROM crm.api_clients;" -w 70:100 -c 40:100
QUERY OK: 'SELECT cast(AVG(availability)*100 AS DECIMAL(5,2)   ) FROM crm.api_clients;' returned 100.000000

But when the same command is invoked from Nagios, it can't connect to the database.

The relevant sections of the command and service definition are

define command{
        command_name    check_proxy
        command_line    /usr/lib/nagios/plugins/check_mysql_query -H 'myhost.mydomain.com' -q "SELECT cast(AVG(availability)*100 AS DECIMAL(5,2)   ) FROM crm.api_clients;"  -w '$ARG1$' -c '$ARG2$'
}

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       rds_read_replica
        service_description             Proxy availability
        check_command                   check_proxy!70:100!40:100
}

In the web console, I see the following error against the service:

QUERY CRITICAL: Access denied for user 'nagios'@'172.33.13.112' (using password: NO)

It works the console when I pass the username and password to the command. But I would like to have the check_mysql_query use the credentials stored in .my.cnf. How can I achieve this?

2

Nagios will run the plugins with no ENV, and therefore no $HOME set. You can simulate this with env -i for manual testing.

You can change your check command to something like HOME=/home/nagios && /usr/lib/nagios/plugins/check_mysql_query ... (or whatever the path is).

If you can't get that to work, wrap that whole check_command in a shell script that sets HOME before calling the real plugin. Also be sure to grab the return code and pass it through the wrapper script too.

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.