File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env ruby
2+ #
3+ # check-es-indices-status
4+ #
5+ # DESCRIPTION:
6+ # This plugin checks the ElasticSearch indices status, using its API.
7+ # Works with ES ES 1.4+
8+ #
9+ # OUTPUT:
10+ # plain text
11+ #
12+ # PLATFORMS:
13+ # Linux
14+ #
15+ # DEPENDENCIES:
16+ # gem: sensu-plugin
17+ # gem: rest-client
18+ #
19+ # USAGE:
20+ # #YELLOW
21+ #
22+ # NOTES:
23+ #
24+ # LICENSE:
25+ # Copyright 2015 Alert Logic, Inc
26+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27+ # for details.
28+ #
29+
30+ require 'rubygems' if RUBY_VERSION < '1.9.0'
31+ require 'sensu-plugin/check/cli'
32+ require 'json'
33+ require 'open-uri'
34+
35+ class ESIndicesStatus < Sensu ::Plugin ::Check ::CLI
36+ def run
37+ indicies_status = JSON . parse ( open ( 'http://localhost:9200/_cluster/health?level=indices' ) . read )
38+ yellow = [ ]
39+ red = [ ]
40+ indicies_status [ "indices" ] . sort_by { |name | name } . each do |name , details |
41+ next if details [ "status" ] == "green"
42+ yellow << name if details [ "status" ] == "yellow"
43+ red << name if details [ "status" ] == "red"
44+ puts "Index '#{ name } ' is not healthy. Status: #{ details [ "status" ] } "
45+ end
46+
47+ exit 2 unless red . empty?
48+ exit 1 unless yellow . empty?
49+ puts "All #{ indicies_status [ "indices" ] . size } indices are healthy"
50+ exit 0
51+ end
52+ end
You can’t perform that action at this time.
0 commit comments