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