Nagios plugin to parse the result of a MySQL query


Hello all !  As before, I wrote a Nagios plugin that will perform an arbitrary MySQL query and parse the results.  It is written in Ruby (and tested against 1.9 only, so ymmv).  If that sounds interesting to you, check my my Github.

Usage ./check_mysql_query.rb [-c <config_file>] -q 'SELECT etc...'
    -h, --help                       Help!
    -v, --verbose                    Human output
    -q, --query 'QUERY'              The query to execute
    -s, --result STRING              Expected (string) result. No need for -w or -c.
    -r, --regex REGEX                Expected (string) result expressed as regular expression. No need for -w or -c.
    -w, --warn VALUE                 Warning threshold
    -c, --crit VALUE                 Critical threshold
    -f, --file CONFIG_FILE           Config file (replaces the switches below).
        --host                       MySQL host
        --database                   MySQL database
        --user                       MySQL user
        --pass                       MySQL pass

A YAML config file can used to populate the MySQL criteria (instead of using the arguments each time). Example :

---
:mysql_host: 'db01.your.net'
:mysql_database: 'name_of_database'
:mysql_user: 'username'
:mysql_pass: 'p455w0rd'

If a result of either type string or regular expression is specified :

  • A match is OK and anything else is CRIT.
  • The warn / crit thresholds will be ignored.

The –warn and –crit arguments conform to the threshold format guidelines noted here :
http://nagiosplug.sourceforge.net/developer-guidelines.html

How you choose to implement the plugin is, of course, up to you. Here are some suggestions :

# check a mysql query for a string result
define command {
command_name check_mysql_query-string
command_line /<path>/check_mysql_query.rb -f /<path>/check_mysql_query.yml -q '$ARG1$' -s '$ARG2$'
}
# do the same but check against a regex
define command {
command_name check_mysql_query-regex
command_line /<path>/check_mysql_query.rb -f /<path>/check_mysql_query.yml -q '$ARG1$' -r '$ARG2$'
}
# and finally some standard integer results (good for warn and crit levels)
define command {
command_name check_mysql_query-int
command_line /<path>/check_mysql_query.rb -f /<path>/check_mysql_query.yml -q '$ARG1$' -w '$ARG2$' -c '$ARG3$'
}

Finally, I invite you to peruse the commit history for the list of contributors :
https://github.com/phrawzty/check_mysql_query/commits/master

Github pull requests welcome !

  1. No comments yet.
(will not be published)