-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e7767a9
Showing
16 changed files
with
1,017 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#### 0.0.1.alpha.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[Development Documentation](http://sensu-plugins.github.io/development/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-elasticsearch.svg?branch=master)][1] | ||
[![Gem Version](https://badge.fury.io/rb/sensu-plugins-elasticsearch.svg)][2] | ||
[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-elasticsearch/badges/gpa.svg)][3] | ||
[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-elasticsearch/badges/coverage.svg)][4] | ||
[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-elasticsearch.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-elasticsearch -P MediumSecurity | ||
``` | ||
|
||
You can also download the key from /certs/ within each repository. | ||
|
||
#### Rubygems | ||
|
||
`gem install sensu-plugins-elasticsearch` | ||
|
||
#### 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-elasticsearch' do | ||
options('--prerelease') | ||
version '0.0.1.alpha.4' | ||
end | ||
``` | ||
|
||
Using the Chef **gem_package** resource | ||
``` | ||
gem_package 'sensu-plugins-elasticsearch' do | ||
options('--prerelease') | ||
version '0.0.1.alpha.4' | ||
end | ||
``` | ||
|
||
## Notes | ||
|
||
[1]:[https://travis-ci.org/sensu-plugins/sensu-plugins-elasticsearch] | ||
[2]:[http://badge.fury.io/rb/sensu-plugins-elasticsearch] | ||
[3]:[https://codeclimate.com/github/sensu-plugins/sensu-plugins-elasticsearch] | ||
[4]:[https://codeclimate.com/github/sensu-plugins/sensu-plugins-elasticsearch] | ||
[5]:[https://gemnasium.com/sensu-plugins/sensu-plugins-elasticsearch] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#! /usr/bin/env ruby | ||
# | ||
# check-es-cluster-status | ||
# | ||
# DESCRIPTION: | ||
# This plugin checks the ElasticSearch cluster status, using its API. | ||
# Works with ES 0.9x and ES 1.x | ||
# | ||
# OUTPUT: | ||
# plain text | ||
# | ||
# PLATFORMS: | ||
# Linux | ||
# | ||
# DEPENDENCIES: | ||
# gem: sensu-plugin | ||
# gem: rest-client | ||
# | ||
# USAGE: | ||
# #YELLOW | ||
# | ||
# NOTES: | ||
# | ||
# LICENSE: | ||
# Copyright 2012 Sonian, Inc <[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 'rest-client' | ||
require 'json' | ||
|
||
class ESClusterStatus < Sensu::Plugin::Check::CLI | ||
option :host, | ||
description: 'Elasticsearch host', | ||
short: '-h HOST', | ||
long: '--host HOST', | ||
default: 'localhost' | ||
|
||
option :port, | ||
description: 'Elasticsearch port', | ||
short: '-p PORT', | ||
long: '--port PORT', | ||
proc: proc(&:to_i), | ||
default: 9200 | ||
|
||
option :master_only, | ||
description: 'Use master Elasticsearch server only', | ||
short: '-m', | ||
long: '--master-only', | ||
default: false | ||
|
||
option :timeout, | ||
description: 'Sets the connection timeout for REST client', | ||
short: '-t SECS', | ||
long: '--timeout SECS', | ||
proc: proc(&:to_i), | ||
default: 30 | ||
|
||
def get_es_resource(resource) | ||
r = RestClient::Resource.new("http://#{config[:host]}:#{config[:port]}/#{resource}", timeout: config[:timeout]) | ||
JSON.parse(r.get) | ||
rescue Errno::ECONNREFUSED | ||
critical 'Connection refused' | ||
rescue RestClient::RequestTimeout | ||
critical 'Connection timed out' | ||
rescue Errno::ECONNRESET | ||
critical 'Connection reset by peer' | ||
end | ||
|
||
def acquire_es_version | ||
info = get_es_resource('/') | ||
info['version']['number'] | ||
end | ||
|
||
def master? | ||
if Gem::Version.new(acquire_es_version) >= Gem::Version.new('1.0.0') | ||
master = get_es_resource('_cluster/state/master_node')['master_node'] | ||
local = get_es_resource('/_nodes/_local') | ||
else | ||
master = get_es_resource('/_cluster/state?filter_routing_table=true&filter_metadata=true&filter_indices=true')['master_node'] | ||
local = get_es_resource('/_cluster/nodes/_local') | ||
end | ||
local['nodes'].keys.first == master | ||
end | ||
|
||
def acquire_status | ||
health = get_es_resource('/_cluster/health') | ||
health['status'].downcase | ||
end | ||
|
||
def run | ||
if !config[:master_only] || master? | ||
case acquire_status | ||
when 'green' | ||
ok 'Cluster is green' | ||
when 'yellow' | ||
warning 'Cluster is yellow' | ||
when 'red' | ||
critical 'Cluster is red' | ||
end | ||
else | ||
ok 'Not the master' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#! /usr/bin/env ruby | ||
# | ||
# check-es-file-descriptors | ||
# | ||
# DESCRIPTION: | ||
# This plugin checks the ElasticSearch file descriptor usage, using its API. | ||
# | ||
# OUTPUT: | ||
# plain text | ||
# | ||
# PLATFORMS: | ||
# Linux | ||
# | ||
# DEPENDENCIES: | ||
# gem: sensu-plugin | ||
# gem: json | ||
# gem: rest-client | ||
# | ||
# USAGE: | ||
# #YELLOW | ||
# | ||
# NOTES: | ||
# | ||
# LICENSE: | ||
# Author: S. Zachariah Sprackett <[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 'rest-client' | ||
require 'json' | ||
|
||
class ESClusterStatus < Sensu::Plugin::Check::CLI | ||
option :host, | ||
description: 'Elasticsearch host', | ||
short: '-h HOST', | ||
long: '--host HOST', | ||
default: 'localhost' | ||
|
||
option :port, | ||
description: 'Elasticsearch port', | ||
short: '-p PORT', | ||
long: '--port PORT', | ||
proc: proc(&:to_i), | ||
default: 9200 | ||
|
||
option :timeout, | ||
description: 'Sets the connection timeout for REST client', | ||
short: '-t SECS', | ||
long: '--timeout SECS', | ||
proc: proc(&:to_i), | ||
default: 30 | ||
|
||
option :critical, | ||
description: 'Critical percentage of FD usage', | ||
short: '-c PERCENTAGE', | ||
proc: proc(&:to_i), | ||
default: 90 | ||
|
||
option :warning, | ||
description: 'Warning percentage of FD usage', | ||
short: '-w PERCENTAGE', | ||
proc: proc(&:to_i), | ||
default: 80 | ||
|
||
def get_es_resource(resource) | ||
r = RestClient::Resource.new("http://#{config[:host]}:#{config[:port]}/#{resource}", timeout: config[:timeout]) | ||
JSON.parse(r.get) | ||
rescue Errno::ECONNREFUSED | ||
warning 'Connection refused' | ||
rescue RestClient::RequestTimeout | ||
warning 'Connection timed out' | ||
end | ||
|
||
def acquire_open_fds | ||
stats = get_es_resource('/_nodes/_local/stats?process=true') | ||
begin | ||
keys = stats['nodes'].keys | ||
stats['nodes'][keys[0]]['process']['open_file_descriptors'].to_i | ||
rescue NoMethodError | ||
warning 'Failed to retrieve open_file_descriptors' | ||
end | ||
end | ||
|
||
def acquire_max_fds | ||
info = get_es_resource('/_nodes/_local?process=true') | ||
begin | ||
keys = info['nodes'].keys | ||
info['nodes'][keys[0]]['process']['max_file_descriptors'].to_i | ||
rescue NoMethodError | ||
warning 'Failed to retrieve max_file_descriptors' | ||
end | ||
end | ||
|
||
def run | ||
open = acquire_open_fds | ||
max = acquire_max_fds | ||
used_percent = ((open.to_f / max.to_f) * 100).to_i | ||
|
||
if used_percent >= config[:critical] | ||
critical "fd usage #{used_percent}% exceeds #{config[:critical]}% (#{open}/#{max})" | ||
elsif used_percent >= config[:warning] | ||
warning "fd usage #{used_percent}% exceeds #{config[:warning]}% (#{open}/#{max})" | ||
else | ||
ok "fd usage at #{used_percent}% (#{open}/#{max})" | ||
end | ||
end | ||
end |
Oops, something went wrong.