5

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 ..

MadHatter
  • 79,770
  • 20
  • 184
  • 232

2 Answers2

7

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).

MadHatter
  • 79,770
  • 20
  • 184
  • 232
  • +1 for check_mysql_query plugIn [link](http://exchange.nagios.org/directory/Plugins/Databases/check_mysql_query-2Epl-%28Advanced-Nagios-Plugins-Collection%29/details) – Ahmad Alhusainy Mar 19 '15 at 09:53
0

Needed to delete the character ; at the end of the query to get it to work. Didn't understand why, but "select * from nagioscheck;" returned an error and "select * from nagioscheck" works.

chicks
  • 3,793
  • 10
  • 27
  • 36
  • 1
    The semicolon (`;`) terminates the query **interactively** but it isn't part of the query itself. When sending SQL statements from code you should usually leave it off. – chicks May 02 '16 at 20:58