Mysql – Nagios alert based on scheduled MySQL queries results

linux-networkingMySQLnagios

I have installed Nagios 4.0 on my Ubuntu 14.0 and i want a plugin to alert me based on daily scheduled MySql queries ..

if the result of ( select count(*) from tableName > 10 ) raise a critical alert or < 10 warning alert this query run every day for example.

is it even possible ?! if so can you tell any suggested plugins , ideas or where to start ..

Best Answer

I do exactly that. The test is pretty trivial, inasmuch as it connects to a custom database called nagios and selects from a table that contains just a single numeric value, alerting if that value isn't 74581 - but I figure if mysql works well enough to retrieve that exact number from a table, it's probably fine. You could run more complex queries, though.

command[check_mysql]=/usr/lib64/nagios/plugins/check_mysql_query -H 127.0.0.1 -d nagios -u user -p pass -q "select * from nagioscheck;" -c 74581:74581 -w 74581:74581

This is invoked by NRPE (hence the format of the above, which is from nrpe.cfg); the check_mysql_query plugin is a standard nagios plugin, at least in my distro (CentOS 6 with the nagios-plugins package from RPMForge). It can also be found here (with thanks to the OP for the link).