sensu-plugins-elasticsearch-boutetnico 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c78a7a41d888f48500399ed36bea486e5b26cbca
4
+ data.tar.gz: a86a9c2155e8fbf9d72511dcada8a817c8273584
5
+ SHA512:
6
+ metadata.gz: 5042cf0cb9e54c3b3d74a85b0fc68570f2c82c1be7ee8ffbc7f4ebdf7b21520d83ba7d5be7d63570e09ea4cc9d58c1fbe89440b6a62f6db54ea73fc25e18faed
7
+ data.tar.gz: 8b8e53c6b1e4d01d4c5832fe035da4316bd6e2efb77ad861dc742377f92fbd43ca531573553c9b3e7f03369cc8654a108b886d05a02219e3f08dc854d31ad287
@@ -0,0 +1 @@
1
+ Can be found at [https://github.com/boutetnico/sensu-plugins-elasticsearch/releases](https://github.com/boutetnico/sensu-plugins-elasticsearch/releases).
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sensu-Plugins
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,60 @@
1
+ ## Sensu-Plugins-elasticsearch
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugins-elasticsearch-boutetnico.svg)](https://badge.fury.io/rb/sensu-plugins-elasticsearch-boutetnico.svg)
4
+ [![Sensu Bonsai Asset](https://img.shields.io/badge/Bonsai-Download%20Me-brightgreen.svg?colorB=89C967&logo=sensu)](https://bonsai.sensu.io/assets/boutetnico/sensu-plugins-elasticsearch)
5
+
6
+ ## This is an unofficial fork
7
+
8
+ Due to the lack of activity from owners of [sensu-plugins-elasticsearch](https://github.com/sensu-plugins/sensu-plugins-elasticsearch) I have created this fork. It is automatically tested, built and published to [RubyGems](https://rubygems.org/gems/sensu-plugins-elasticsearch-boutetnico/) and [Bonsai](https://bonsai.sensu.io/assets/boutetnico/sensu-plugins-elasticsearch). It includes some improvements. Please check the changelog at the [GitHub Releases page](https://github.com/boutetnico/sensu-plugins-elasticsearch/releases).
9
+
10
+ ## Sensu Asset
11
+ The Sensu assets packaged from this repository are built against the Sensu ruby runtime environment. When using these assets as part of a Sensu Go resource (check, mutator or handler), make sure you include the corresponding Sensu ruby runtime asset in the list of assets needed by the resource. The current ruby-runtime assets can be found [here](https://bonsai.sensu.io/assets/sensu/sensu-ruby-runtime) in the [Bonsai Asset Index](bonsai.sensu.io).
12
+
13
+ ## Functionality
14
+
15
+ ## Files
16
+ * /bin/check-es-circuit-breakers.rb
17
+ * /bin/check-es-cluster-health.rb
18
+ * /bin/check-es-cluster-status.rb
19
+ * /bin/check-es-file-descriptors.rb
20
+ * /bin/check-es-heap.rb
21
+ * /bin/check-es-indices-field-count.rb
22
+ * /bin/check-es-indexes.rb
23
+ * /bin/check-es-indicies-sizes.rb
24
+ * /bin/check-es-node-status.rb
25
+ * /bin/check-es-query-count.rb
26
+ * /bin/check-es-query-exists.rb
27
+ * /bin/check-es-query-ratio.rb
28
+ * /bin/check-es-shard-allocation-status.rb
29
+ * /bin/handler-es-delete-indices.rb
30
+ * /bin/metrics-es-cluster.rb
31
+ * /bin/metrics-es-node.rb
32
+ * /bin/metrics-es-node-graphite.rb
33
+
34
+ ## Usage
35
+
36
+ ## Installation
37
+
38
+ [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
39
+
40
+ ## Notes
41
+ When using `handler-es-delete-indices.rb` with Sensu Go, you will need to use the event mapping commandline option, see `handler-es-delete-indices.rb --help` for details. And please read [the sensu-plugin README](https://github.com/sensu-plugins/sensu-plugin#sensu-go-enablement) for more information on the event mapping functionality.
42
+
43
+ ## Testing
44
+
45
+ This repository uses the [Kitchen](https://kitchen.ci/) suite for it's tests.
46
+
47
+ Note: The test suite uses an elasticsearch instance in order to have passing tests. Execute the following command to create a mock elasticsearch 7 instance:
48
+
49
+ ```bash
50
+ docker run -d --name sensu-elasticsearch-7 docker.elastic.co/elasticsearch/elasticsearch:7.1.1
51
+ ```
52
+
53
+ Running the tests:
54
+
55
+ ```bash
56
+ bundle install --path vendor/bundle
57
+ bundle exec kitchen test
58
+ ```
59
+
60
+ You can find sample output for all tests running successfully in [this gist](https://gist.github.com/alexandrustaetu/d19feea1296d2ce7e367542265252d7a).
@@ -0,0 +1,151 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-es-circuit-breakers
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks whether the ElasticSearch circuit breakers have been tripped,
7
+ # using the node stats API.
8
+ # Works with ES 0.9x and ES 1.x
9
+ #
10
+ # OUTPUT:
11
+ # plain text
12
+ #
13
+ # PLATFORMS:
14
+ # Linux
15
+ #
16
+ # DEPENDENCIES:
17
+ # gem: sensu-plugin
18
+ # gem: rest-client
19
+ #
20
+ # USAGE:
21
+ # check-es-circuit-breakers --help
22
+ #
23
+ # NOTES:
24
+ #
25
+ # LICENSE:
26
+ # Copyright 2012 Sonian, Inc <chefs@sonian.net>
27
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
28
+ # for details.
29
+ #
30
+
31
+ require 'sensu-plugin/check/cli'
32
+ require 'rest-client'
33
+ require 'json'
34
+ require 'base64'
35
+
36
+ class ESCircuitBreaker < Sensu::Plugin::Check::CLI
37
+ option :host,
38
+ description: 'Elasticsearch host',
39
+ short: '-h HOST',
40
+ long: '--host HOST',
41
+ default: 'localhost'
42
+
43
+ option :port,
44
+ description: 'Elasticsearch port',
45
+ short: '-p PORT',
46
+ long: '--port PORT',
47
+ proc: proc(&:to_i),
48
+ default: 9200
49
+
50
+ option :timeout,
51
+ description: 'Sets the connection timeout for REST client',
52
+ short: '-t SECS',
53
+ long: '--timeout SECS',
54
+ proc: proc(&:to_i),
55
+ default: 30
56
+
57
+ option :user,
58
+ description: 'Elasticsearch User',
59
+ short: '-u USER',
60
+ long: '--user USER'
61
+
62
+ option :password,
63
+ description: 'Elasticsearch Password',
64
+ short: '-P PASS',
65
+ long: '--password PASS'
66
+
67
+ option :https,
68
+ description: 'Enables HTTPS',
69
+ short: '-e',
70
+ long: '--https'
71
+
72
+ option :cert_file,
73
+ description: 'Cert file to use',
74
+ long: '--cert-file CERT'
75
+
76
+ option :localhost,
77
+ description: 'only check local node',
78
+ short: '-l',
79
+ long: '--localhost',
80
+ boolean: true,
81
+ default: false
82
+
83
+ def get_es_resource(resource)
84
+ headers = {}
85
+ if config[:user] && config[:password]
86
+ auth = 'Basic ' + Base64.strict_encode64("#{config[:user]}:#{config[:password]}").chomp
87
+ headers = { 'Authorization' => auth }
88
+ end
89
+
90
+ protocol = if config[:https]
91
+ 'https'
92
+ else
93
+ 'http'
94
+ end
95
+
96
+ r = if config[:cert_file]
97
+ RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}",
98
+ ssl_ca_file: config[:cert_file].to_s,
99
+ timeout: config[:timeout],
100
+ headers: headers)
101
+ else
102
+ RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}",
103
+ timeout: config[:timeout],
104
+ headers: headers)
105
+ end
106
+ JSON.parse(r.get)
107
+ rescue Errno::ECONNREFUSED
108
+ critical 'Connection refused'
109
+ rescue RestClient::RequestTimeout
110
+ critical 'Connection timed out'
111
+ rescue RestClient::ServiceUnavailable
112
+ warning 'Service is unavailable'
113
+ rescue Errno::ECONNRESET
114
+ critical 'Connection reset by peer'
115
+ end
116
+
117
+ def breaker_status
118
+ breakers = {}
119
+ status = if config[:localhost]
120
+ get_es_resource('/_nodes/_local/stats/breaker')
121
+ else
122
+ get_es_resource('/_nodes/stats/breaker')
123
+ end
124
+ status['nodes'].each_pair do |_node, stat|
125
+ host = stat['host']
126
+ breakers[host] = {}
127
+ breakers[host]['breakers'] = []
128
+ stat.each_pair do |key, val|
129
+ if key == 'breakers'
130
+ val.each_pair do |bk, bv|
131
+ if bv['tripped'] != 0
132
+ breakers[host]['breakers'] << bk
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ breakers
139
+ end
140
+
141
+ def run
142
+ breakers = breaker_status
143
+ tripped = false
144
+ breakers.each_pair { |_k, v| tripped = true unless v['breakers'].empty? }
145
+ if tripped
146
+ critical "Circuit Breakers: #{breakers.each_pair { |k, _v| k }} trippped!"
147
+ else
148
+ ok 'All circuit breakers okay'
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,132 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-es-cluster-health
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks the ElasticSearch cluster health and status.
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: elasticsearch
17
+ # gem: aws_es_transport
18
+ #
19
+ # USAGE:
20
+ # Checks against the ElasticSearch api for cluster health using the
21
+ # elasticsearch gem
22
+ #
23
+ # NOTES:
24
+ #
25
+ # LICENSE:
26
+ # Brendan Gibat <brendan.gibat@gmail.com>
27
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
28
+ # for details.
29
+ #
30
+
31
+ require 'sensu-plugin/check/cli'
32
+ require 'elasticsearch'
33
+ require 'aws_es_transport'
34
+ require 'sensu-plugins-elasticsearch'
35
+
36
+ #
37
+ # ES Cluster Health
38
+ #
39
+ class ESClusterHealth < Sensu::Plugin::Check::CLI
40
+ include ElasticsearchCommon
41
+
42
+ option :transport,
43
+ long: '--transport TRANSPORT',
44
+ description: 'Transport to use to communicate with ES. Use "AWS" for signed AWS transports.'
45
+
46
+ option :region,
47
+ long: '--region REGION',
48
+ description: 'Region (necessary for AWS Transport)'
49
+
50
+ option :host,
51
+ description: 'Elasticsearch host',
52
+ short: '-h HOST',
53
+ long: '--host HOST',
54
+ default: 'localhost'
55
+
56
+ option :level,
57
+ description: 'Level of detail to check returend information ("cluster", "indices", "shards").',
58
+ short: '-l LEVEL',
59
+ long: '--level LEVEL'
60
+
61
+ option :local,
62
+ description: 'Return local information, do not retrieve the state from master node.',
63
+ long: '--local',
64
+ boolean: true
65
+
66
+ option :port,
67
+ description: 'Elasticsearch port',
68
+ short: '-p PORT',
69
+ long: '--port PORT',
70
+ proc: proc(&:to_i),
71
+ default: 9200
72
+
73
+ option :scheme,
74
+ description: 'Elasticsearch connection scheme, defaults to https for authenticated connections',
75
+ short: '-s SCHEME',
76
+ long: '--scheme SCHEME'
77
+
78
+ option :password,
79
+ description: 'Elasticsearch connection password',
80
+ short: '-P PASSWORD',
81
+ long: '--password PASSWORD'
82
+
83
+ option :user,
84
+ description: 'Elasticsearch connection user',
85
+ short: '-u USER',
86
+ long: '--user USER'
87
+
88
+ option :timeout,
89
+ description: 'Elasticsearch query timeout in seconds',
90
+ short: '-t TIMEOUT',
91
+ long: '--timeout TIMEOUT',
92
+ proc: proc(&:to_i),
93
+ default: 30
94
+
95
+ option :alert_status,
96
+ description: 'Only alert when status matches given RED/YELLOW/GREEN or if blank all statuses',
97
+ long: '--alert-status STATUS',
98
+ default: '',
99
+ in: ['RED', 'YELLOW', 'GREEN', '']
100
+
101
+ def run
102
+ options = {}
103
+ unless config[:level].nil?
104
+ options[:level] = config[:level]
105
+ end
106
+ unless config[:local].nil?
107
+ options[:local] = config[:local]
108
+ end
109
+ unless config[:index].nil?
110
+ options[:index] = config[:index]
111
+ end
112
+ health = client.cluster.health options
113
+ case health['status']
114
+ when 'yellow'
115
+ if ['YELLOW', ''].include? config[:alert_status]
116
+ warning 'Cluster state is Yellow'
117
+ else
118
+ ok 'Not alerting on yellow'
119
+ end
120
+ when 'red'
121
+ if ['RED', ''].include? config[:alert_status]
122
+ critical 'Cluster state is Red'
123
+ else
124
+ ok 'Not alerting on red'
125
+ end
126
+ when 'green'
127
+ ok
128
+ else
129
+ unknown "Cluster state is in an unknown health: #{health['status']}"
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,177 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-es-cluster-status
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks the ElasticSearch cluster status, using its API.
7
+ # Works with ES 0.9x and ES 1.x
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 2012 Sonian, Inc <chefs@sonian.net>
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugin/check/cli'
31
+ require 'rest-client'
32
+ require 'json'
33
+ require 'base64'
34
+
35
+ #
36
+ # ES Cluster Status
37
+ #
38
+ class ESClusterStatus < Sensu::Plugin::Check::CLI
39
+ option :host,
40
+ description: 'Elasticsearch host',
41
+ short: '-h HOST',
42
+ long: '--host HOST',
43
+ default: 'localhost'
44
+
45
+ option :port,
46
+ description: 'Elasticsearch port',
47
+ short: '-p PORT',
48
+ long: '--port PORT',
49
+ proc: proc(&:to_i),
50
+ default: 9200
51
+
52
+ option :master_only,
53
+ description: 'Use master Elasticsearch server only',
54
+ short: '-m',
55
+ long: '--master-only',
56
+ default: false
57
+
58
+ option :timeout,
59
+ description: 'Sets the connection timeout for REST client',
60
+ short: '-t SECS',
61
+ long: '--timeout SECS',
62
+ proc: proc(&:to_i),
63
+ default: 30
64
+
65
+ option :status_timeout,
66
+ description: 'Sets the time to wait for the cluster status to be green',
67
+ short: '-T SECS',
68
+ long: '--status_timeout SECS',
69
+ proc: proc(&:to_i)
70
+
71
+ option :user,
72
+ description: 'Elasticsearch User',
73
+ short: '-u USER',
74
+ long: '--user USER'
75
+
76
+ option :password,
77
+ description: 'Elasticsearch Password',
78
+ short: '-P PASS',
79
+ long: '--password PASS'
80
+
81
+ option :https,
82
+ description: 'Enables HTTPS',
83
+ short: '-e',
84
+ long: '--https'
85
+
86
+ option :cert_file,
87
+ description: 'Cert file to use',
88
+ long: '--cert-file CERT_FILE'
89
+
90
+ option :alert_status,
91
+ description: 'Only alert when status matches given RED/YELLOW/GREEN or if blank all statuses',
92
+ long: '--alert-status STATUS',
93
+ default: '',
94
+ in: ['RED', 'YELLOW', 'GREEN', '']
95
+
96
+ def get_es_resource(resource)
97
+ headers = {}
98
+ if config[:user] && config[:password]
99
+ auth = 'Basic ' + Base64.strict_encode64("#{config[:user]}:#{config[:password]}").chomp
100
+ headers = { 'Authorization' => auth }
101
+ end
102
+
103
+ protocol = if config[:https]
104
+ 'https'
105
+ else
106
+ 'http'
107
+ end
108
+
109
+ r = if config[:cert_file]
110
+ RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}",
111
+ ssl_ca_file: config[:cert_file].to_s,
112
+ timeout: config[:timeout],
113
+ headers: headers)
114
+ else
115
+ RestClient::Resource.new("#{protocol}://#{config[:host]}:#{config[:port]}#{resource}",
116
+ timeout: config[:timeout],
117
+ headers: headers)
118
+ end
119
+ JSON.parse(r.get)
120
+ rescue Errno::ECONNREFUSED
121
+ critical 'Connection refused'
122
+ rescue RestClient::RequestTimeout
123
+ critical 'Connection timed out'
124
+ rescue RestClient::ServiceUnavailable
125
+ critical 'Service is unavailable'
126
+ rescue Errno::ECONNRESET
127
+ critical 'Connection reset by peer'
128
+ end
129
+
130
+ def acquire_es_version
131
+ info = get_es_resource('/')
132
+ info['version']['number']
133
+ end
134
+
135
+ def master?
136
+ if Gem::Version.new(acquire_es_version) >= Gem::Version.new('1.0.0')
137
+ master = get_es_resource('/_cluster/state/master_node')['master_node']
138
+ local = get_es_resource('/_nodes/_local')
139
+ else
140
+ master = get_es_resource('/_cluster/state?filter_routing_table=true&filter_metadata=true&filter_indices=true')['master_node']
141
+ local = get_es_resource('/_cluster/nodes/_local')
142
+ end
143
+ local['nodes'].keys.first == master
144
+ end
145
+
146
+ def acquire_status
147
+ health = if config[:status_timeout]
148
+ get_es_resource("/_cluster/health?wait_for_status=green&timeout=#{config[:status_timeout]}s")
149
+ else
150
+ get_es_resource('/_cluster/health')
151
+ end
152
+ health['status'].downcase
153
+ end
154
+
155
+ def run
156
+ if !config[:master_only] || master?
157
+ case acquire_status
158
+ when 'green'
159
+ ok 'Cluster is green'
160
+ when 'yellow'
161
+ if ['YELLOW', ''].include? config[:alert_status]
162
+ warning 'Cluster state is Yellow'
163
+ else
164
+ ok 'Not alerting on yellow'
165
+ end
166
+ when 'red'
167
+ if ['RED', ''].include? config[:alert_status]
168
+ critical 'Cluster state is Red'
169
+ else
170
+ ok 'Not alerting on red'
171
+ end
172
+ end
173
+ else
174
+ ok 'Not the master'
175
+ end
176
+ end
177
+ end