phrawzty / check_mysql_query Goto Github PK
View Code? Open in Web Editor NEWNagios plugin that makes a MySQL query and parses the results.
Home Page: http://www.dark.ca/
Nagios plugin that makes a MySQL query and parses the results.
Home Page: http://www.dark.ca/
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 !
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
+-- Client Section/Connection
client = Mysql2::Client.new(
:host => host,
:username => user,
:password => pass,
:database => db)
If you have any idea for fix it for work with mysql2, you're welcome :-)
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 @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 @options[:warn] or @options[:crit] then
class String
def numeric?
Float(result) != nil rescue 'Result contains non-numeric characters.'
end
end
end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.