From 3b9cf388c347fcedad7e55ea00e456754f7821f9 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Wed, 11 Feb 2015 02:21:19 -0500 Subject: [PATCH] initial commit --- CHANGELOG.md | 1 + CONTRIBUTING.md | 1 + LICENSE | 22 ++++++ README.md | 62 +++++++++++++++++ Rakefile | 43 ++++++++++++ Vagrantfile | 32 +++++++++ bin/check-redis-info.rb | 72 +++++++++++++++++++ bin/check-redis-list-length.rb | 84 ++++++++++++++++++++++ bin/check-redis-memory.rb | 79 +++++++++++++++++++++ bin/check-redis-ping.rb | 73 ++++++++++++++++++++ bin/check-redis-slave-status.rb | 50 ++++++++++++++ bin/extensions/handlers/redis_output.rb | 38 ++++++++++ bin/redis-graphite.rb | 92 +++++++++++++++++++++++++ bin/redis-llen-metric.rb | 53 ++++++++++++++ certs/sensu-plugins.pem | 21 ++++++ lib/sensu-plugins-redis.rb | 7 ++ sensu-plugins-redis.gemspec | 53 ++++++++++++++ test/spec_helper.rb | 2 + 18 files changed, 785 insertions(+) create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 Rakefile create mode 100644 Vagrantfile create mode 100755 bin/check-redis-info.rb create mode 100755 bin/check-redis-list-length.rb create mode 100755 bin/check-redis-memory.rb create mode 100755 bin/check-redis-ping.rb create mode 100755 bin/check-redis-slave-status.rb create mode 100644 bin/extensions/handlers/redis_output.rb create mode 100755 bin/redis-graphite.rb create mode 100755 bin/redis-llen-metric.rb create mode 100644 certs/sensu-plugins.pem create mode 100644 lib/sensu-plugins-redis.rb create mode 100644 sensu-plugins-redis.gemspec create mode 100644 test/spec_helper.rb diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f8c9a53 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +#### 0.0.1.alpha.1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..ba15939 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1 @@ +[Development Documentation](http://sensu-plugins.github.io/development/) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6a08171 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2015 devops@yieldbot.com + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4518bcc --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +## Sensu-Plugins-disk-checks + +[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-redis.svg?branch=master)][1] +[![Gem Version](https://badge.fury.io/rb/sensu-plugins-redis.svg)][2] +[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-redis/badges/gpa.svg)][3] +[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-redis/badges/coverage.svg)][4] +[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-redis.svg)][5] + +## Functionality + +## Files + * + * + * + * + +## Usage + +## Installation + +Add the public key (if you haven’t already) as a trusted certificate + +``` +gem cert --add <(curl -Ls https://raw.githubusercontent.com/sensu-plugins/sensu-plugins.github.io/master/certs/sensu-plugins.pem) +gem install sensu-plugins-redis -P MediumSecurity +``` + +You can also download the key from /certs/ within each repository. + +#### Rubygems + +`gem install sensu-plugins-redis` + +#### Bundler + +Add *sensu-plugins-disk-checks* to your Gemfile and run `bundle install` or `bundle update` + +#### Chef + +Using the Sensu **sensu_gem** LWRP +``` +sensu_gem 'sensu-plugins-redis' do + options('--prerelease') + version '0.0.1.alpha.4' +end +``` + +Using the Chef **gem_package** resource +``` +gem_package 'sensu-plugins-redis' do + options('--prerelease') + version '0.0.1.alpha.4' +end +``` + +## Notes + +[1]:[https://travis-ci.org/sensu-plugins/sensu-plugins-redis] +[2]:[http://badge.fury.io/rb/sensu-plugins-redis] +[3]:[https://codeclimate.com/github/sensu-plugins/sensu-plugins-redis] +[4]:[https://codeclimate.com/github/sensu-plugins/sensu-plugins-redis] +[5]:[https://gemnasium.com/sensu-plugins/sensu-plugins-redis] diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..4e5d83a --- /dev/null +++ b/Rakefile @@ -0,0 +1,43 @@ + +require 'bundler/gem_tasks' + +require 'rspec/core/rake_task' + +require 'yard' + +require 'github/markup' + +require 'rubocop/rake_task' + +require 'redcarpet' + +require 'yard/rake/yardoc_task' + + +desc 'Don\'t run Rubocop for unsupported versions' +begin + if RUBY_VERSION >= '2.0.0' + args = [:spec, :make_bin_executable, :yard, :rubocop] + else + args = [:spec, :make_bin_executable, :yard] + end +end + +YARD::Rake::YardocTask.new do |t| + OTHER_PATHS = %w() + t.files = ['lib/**/*.rb', 'bin/**/*.rb', OTHER_PATHS] + t.options = %w(--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md) +end + +Rubocop::RakeTask.new + +RSpec::Core::RakeTask.new(:spec) do |r| + r.pattern = FileList['**/**/*_spec.rb'] +end + +desc 'Make all plugins executable' +task :make_bin_executable do + `chmod -R +x bin/*` +end + +task default: args diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..033525b --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,32 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +VAGRANTFILE_API_VERSION = '2' + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + + config.vm.box = 'chef/centos-6.6' + config.vm.box_download_checksum = true + config.vm.box_download_checksum_type = 'md5' + config.vm.hostname = 'sensu-plugins-dev' + + script = < +# +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. + +require 'rubygems' if RUBY_VERSION < '1.9.0' +require 'sensu-plugin/check/cli' +require 'redis' + +class RedisListLengthCheck < Sensu::Plugin::Check::CLI + option :host, + short: '-h HOST', + long: '--host HOST', + description: 'Redis Host to connect to', + required: false, + default: '127.0.0.1' + + option :port, + short: '-p PORT', + long: '--port PORT', + description: 'Redis Port to connect to', + proc: proc(&:to_i), + required: false, + default: 6379 + + option :database, + short: '-n DATABASE', + long: '--dbnumber DATABASE', + description: 'Redis database number to connect to', + proc: proc(&:to_i), + required: false, + default: 0 + + option :password, + short: '-P PASSWORD', + long: '--password PASSWORD', + description: 'Redis Password to connect with' + + option :warn, + short: '-w COUNT', + long: '--warning COUNT', + description: 'COUNT warning threshold for number of items in Redis list key', + proc: proc(&:to_i), + required: true + + option :crit, + short: '-c COUNT', + long: '--critical COUNT', + description: 'COUNT critical threshold for number of items in Redis list key', + proc: proc(&:to_i), + required: true + + option :key, + short: '-k KEY', + long: '--key KEY', + description: 'Redis list KEY to check', + required: true + + def run + options = { host: config[:host], port: config[:port], db: config[:database] } + options[:password] = config[:password] if config[:password] + redis = Redis.new(options) + + length = redis.llen(config[:key]) + + if length >= config[:crit] + critical "Redis list #{config[:key]} length is above the CRITICAL limit: #{length} length / #{config[:crit]} limit" + elsif length >= config[:warn] + warning "Redis list #{config[:key]} length is above the WARNING limit: #{length} length / #{config[:warn]} limit" + else + ok "Redis list #{config[:key]} length is below thresholds" + end + rescue + unknown "Could not connect to Redis server on #{config[:host]}:#{config[:port]}" + end +end diff --git a/bin/check-redis-memory.rb b/bin/check-redis-memory.rb new file mode 100755 index 0000000..5114f2e --- /dev/null +++ b/bin/check-redis-memory.rb @@ -0,0 +1,79 @@ +#!/usr/bin/env ruby +# +# Checks Redis INFO stats and limits values +# === +# +# Copyright (c) 2012, Panagiotis Papadomitsos +# +# Released under the same terms as Sensu (the MIT license); see LICENSE +# for details. + +require 'rubygems' if RUBY_VERSION < '1.9.0' +require 'sensu-plugin/check/cli' +require 'redis' + +class RedisChecks < Sensu::Plugin::Check::CLI + option :host, + short: '-h HOST', + long: '--host HOST', + description: 'Redis Host to connect to', + required: false, + default: '127.0.0.1' + + option :port, + short: '-p PORT', + long: '--port PORT', + description: 'Redis Port to connect to', + proc: proc(&:to_i), + required: false, + default: 6379 + + option :password, + short: '-P PASSWORD', + long: '--password PASSWORD', + description: 'Redis Password to connect with' + + option :warn_mem, + short: '-w KB', + long: '--warnmem KB', + description: "Allocated KB of Redis memory on which we'll issue a WARNING", + proc: proc(&:to_i), + required: true + + option :crit_mem, + short: '-c KB', + long: '--critmem KB', + description: "Allocated KB of Redis memory on which we'll issue a CRITICAL", + proc: proc(&:to_i), + required: true + + option :crit_conn, + long: '--crit-conn-failure', + boolean: true, + description: 'Critical instead of warning on connection failure', + default: false + + def run + options = { host: config[:host], port: config[:port] } + options[:password] = config[:password] if config[:password] + redis = Redis.new(options) + + used_memory = redis.info.fetch('used_memory').to_i.div(1024) + warn_memory = config[:warn_mem] + crit_memory = config[:crit_mem] + if used_memory >= crit_memory + critical "Redis running on #{config[:host]}:#{config[:port]} is above the CRITICAL limit: #{used_memory} KB used / #{crit_memory} KB limit" + elsif used_memory >= warn_memory + warning "Redis running on #{config[:host]}:#{config[:port]} is above the WARNING limit: #{used_memory} KB used / #{warn_memory} KB limit" + else + ok 'Redis memory usage is below defined limits' + end + rescue + message = "Could not connect to Redis server on #{config[:host]}:#{config[:port]}" + if config[:crit_conn] + critical message + else + warning message + end + end +end diff --git a/bin/check-redis-ping.rb b/bin/check-redis-ping.rb new file mode 100755 index 0000000..43dabc3 --- /dev/null +++ b/bin/check-redis-ping.rb @@ -0,0 +1,73 @@ +#! /usr/bin/env ruby +# encoding: UTF-8 +#