GithubHelp home page GithubHelp logo

check_mysql_query's Introduction

This is a plugin for Nagios that makes a MySQL query and parses the results.
It is written in Ruby (and tested against 1.9 only - ymmv).
Much of this plugin is recycled my check_http_json.rb plugin.  All this and more at http://github.com/phrawzty .

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 !

check_mysql_query's People

Contributors

phrawzty avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

lupen92

check_mysql_query's Issues

[Proposal] - Decimal issue when result return an decimal number

With mysql2 class there is an issue for number returned as decimal return.

I have switched back on mysql lib instead of mysql2 lib and works fine.

See bellow what i changed:

+-- Require Section

  • Before:
  • require 'mysql2'
  • After:
  • require 'mysql'

+-- Client Section/Connection

  • Before:
  •    client = Mysql2::Client.new(
            :host => host,
            :username => user,
            :password => pass,
            :database => db)
    
  • After:
  • client = Mysql.new host, user, pass, db

If you have any idea for fix it for work with mysql2, you're welcome :-)

Numeric Check wrong

When i used -w 1 or -c 1, it keep return "Result contains non-numeric characters."

See bellow what i changed for fix it

Before :

If we're looking for a numeric result...

if @options[:warn] or @options[:crit] then
if result =~ /\D/ then
result = 'Result contains non-numeric characters.'
puts @options[:crit]
puts @options[:warn]
exit_code = 3
end
end

Fix :

If we're looking for a numeric result...

if @options[:warn] or @options[:crit] then
class String
def numeric?
Float(result) != nil rescue 'Result contains non-numeric characters.'
end
end
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.