Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sensu-plugin committed Feb 11, 2015
0 parents commit 3b9cf38
Show file tree
Hide file tree
Showing 18 changed files with 785 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#### 0.0.1.alpha.1
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Development Documentation](http://sensu-plugins.github.io/development/)
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2015 [email protected]

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.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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]
43 changes: 43 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -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 = <<EOF
sudo yum update -y
sudo yum groupinstall -y development
sudo yum install -y vim nano
#sudo yum install -y ImagicMagic ImageMagick-devel mysql-devel # needed for bundle install
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
curl -L get.rvm.io | bash -s stable
source /home/vagrant/.rvm/scripts/rvm
rvm reload
#rvm install 1.9.3
rvm install 2.1.4
#rvm install 2.0.0
#rvm use 1.9.3@sensu_plugins --create
#rvm use 2.0.0@sensu_plugins --create
rvm use 2.1.4@sensu_plugins --create
rvm use 2.1.4@sensu_plugins --default
EOF

config.vm.provision 'shell', inline: script, privileged: false
end
72 changes: 72 additions & 0 deletions bin/check-redis-info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env ruby
#
# Checks checks variables from redis INFO http://redis.io/commands/INFO
#
# ===
#
# Depends on redis gem
# gem install redis
#
# ===
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
#
# Heavily inspired in check-redis-slave-status.rb
# https://github.com/sensu/sensu-community-plugins/blob/master/plugins/redis/check-redis-slave-status.rb
#
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-plugin/check/cli'
require 'redis'

class RedisSlaveCheck < 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 :redis_info_key,
short: '-K VALUE',
long: '--redis-info-key KEY',
description: 'Redis info key to monitor',
required: false,
default: 'role'

option :redis_info_value,
short: '-V VALUE',
long: '--redis-info-key-value VALUE',
description: 'Redis info key value to trigger alarm',
required: false,
default: 'master'

def run
options = { host: config[:host], port: config[:port] }
options[:password] = config[:password] if config[:password]
redis = Redis.new(options)

if redis.info.fetch("#{config[:redis_info_key]}") == "#{config[:redis_info_value]}"
ok "Redis #{config[:redis_info_key]} is #{config[:redis_info_value]}"
else
critical "Redis #{config[:redis_info_key]} is #{redis.info.fetch("#{config[:redis_info_key]}")}!"
end

rescue
message "Could not connect to Redis server on #{config[:host]}:#{config[:port]}"
exit 1
end
end
84 changes: 84 additions & 0 deletions bin/check-redis-list-length.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env ruby
#
# Checks number of items in a Redis list key
# ===
#
# Depends on redis gem
# gem install redis
#
# Copyright (c) 2013, Piavlo <[email protected]>
#
# 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
Loading

0 comments on commit 3b9cf38

Please sign in to comment.