Configuring mysql check

Using icinga verison r2.10.3-1 on a linux/debian machine.
I am trying to add a mysql check for my localhost. In the /etc/icinga2/conf.d/services.conf I have added the following -

}

apply Service “mysql” {
import “generic-service”

check_command = “mysql”
vars.mysql.user = “mysqluser”

assign where host.name == NodeName
}

The check shows up on my icingweb2 but it gives an error “Access denied for user nagios@localhost Using password : NO” . When i run the command /usr/lib/nagios/plugins/check_mysql as root user the command executes properly. I was trying to get the icinga check to use the user i specified but since that wasn’t working I created the user and granted all privilege on all databases on my machine but still no luck. Any help would be appreciated.

Hi @hza2331

That’s because the checks are exectued by the icinga user, in your case user ‘nagios’.

The custom variable should be vars.mysql_username and not vars.mysql.user. With vars.mysql_password you can also specify a password. Link to ITL

Please note that it is not recommended to provide a plaintext password.

Kind regards

I’ve replaced the variable with the one you suggested but i still receive the same error. In the /var/log/mysql/error.log it repeatedly sends the message “2021-03-18 11:57:50 4166 [Warning] Access denied for user ‘nagios’@‘localhost’ (using password: NO)”. The error is confusing as I’ve granted user nagios all privileges on all databases using the command - GRANT ALL PRIVILEGGES ON . TO ‘nagios’;

Did you create a user account and a password for the mysql user ‘nagios’?

SELECT host,user FROM mysql.user WHERE user='nagios';

I had not done this before but i did after seeing your suggestion , unfortunately I am still getting the same error.

Okay, can you try to run the script as the icinga user? This should give you a hint of what is going wrong.
sudo -u nagios /usr/lib/nagios/plugins/check_mysql -u user -p password

1 Like

I am facing the same issue. If I inspect the command, I get the following:

### Executed Command
'/usr/lib/nagios/plugins/check_mysql' '-H' 'localhost' '-f' '/etc/my.cnf'

If I run that exact command directly on the server, it works like a charm:

sudo su -l nagios -s /bin/bash -c "/usr/lib/nagios/plugins/check_mysql -H localhost -f /etc/my.cnf"
Uptime: 161775  Threads: 9  Questions: 188001449  Slow queries: 4099419  Opens: 37087  Flush tables: 3  Open tables: 33461  Queries per second avg: 1162.116|Connections=140382c;;; Open_files=6;;; Open_tables=33461;;; Queries=188001450c;;; Questions=62865450c;;; Table_locks_waited=0c;;; Threads_connected=8;;; Threads_running=2;;; Uptime=161775c;;;

The Plugin output is

### Plugin Output
Access denied for user 'nagios'@'localhost' (using password: NO)

I don’t even know where to start searching for the issue - any ideas?

Turns out that I had to explicitly turn on “Run on Agent”.