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?