sensu-plugins-edgelab 1.16.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5ae185b0178726421cb6424a2520cbda7097bb27b95032cbf6ab936effd88bf
4
- data.tar.gz: e7c6d24454546237899cd3fa42dc02364132a78c82bf1f01cfbc312478523501
3
+ metadata.gz: 02abb4c1626d01a1c9434ab4ad55dba2b1be0c225f7f7a63b8e06d549bbeb17c
4
+ data.tar.gz: 6c2593babae5d55aebe767a562fc187e618d72b49b57860f09f89bb84a3db8de
5
5
  SHA512:
6
- metadata.gz: 584fde208f1a8d1c5da5838098970d3a7b035469518245b067d904a8dcff10fec6847fca1f40e08a94891b278ad7d34437babd8fa51c8b3c52a62877fc134f58
7
- data.tar.gz: ea4dd7edef755088d26b4d1db51891ae3c3d647c68acebf29812f72a294b0a360efa213aa4fc73fd11bf2540f324dc431ea9396fd79eea4604c4b36e8ace4c11
6
+ metadata.gz: 45f18be0e7706239fc5444e6c8d55c6fc91252e2eadf080f3e61668a8a13b07a53820025341a39a7cdac528055253b9846b4e4624892c5c6633d6bc38b0bbeae
7
+ data.tar.gz: b8cf6b8a55bad75d16fd975926ee3daec82611111ff07b5be9e87b6d44f0b186e35618b6583568817f004ad60165acd54b07c24e80f770b612f852c5b02b6c95
@@ -0,0 +1,142 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-elasticsearch-cluster-health
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks the Elasticsearch cluster health from its status and number of nodes present.
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: elasticsearch
17
+ #
18
+ # USAGE:
19
+ # Checks against the Elasticsearch api for cluster health using the
20
+ # Elasticsearch gem
21
+ #
22
+ # NOTES:
23
+ # Adapted from sensu-plugins-elasticsearch `check-es-cluster-health.rb`
24
+ #
25
+ # LICENSE:
26
+ # Jonathan Ballet <jballet@edgelab.ch>
27
+ # Brendan Gibat <brendan.gibat@gmail.com>
28
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
29
+ # for details.
30
+
31
+ require 'sensu-plugin/check/cli'
32
+ require 'elasticsearch'
33
+
34
+ class ESClusterHealth < Sensu::Plugin::Check::CLI
35
+ option :host,
36
+ description: 'Elasticsearch host',
37
+ short: '-h HOST',
38
+ long: '--host HOST',
39
+ default: 'localhost'
40
+
41
+ option :port,
42
+ description: 'Elasticsearch port',
43
+ short: '-p PORT',
44
+ long: '--port PORT',
45
+ proc: proc(&:to_i),
46
+ default: 9200
47
+
48
+ option :scheme,
49
+ description: 'Elasticsearch connection scheme, defaults to https for authenticated connections',
50
+ short: '-s SCHEME',
51
+ long: '--scheme SCHEME'
52
+
53
+ option :password,
54
+ description: 'Elasticsearch connection password',
55
+ short: '-P PASSWORD',
56
+ long: '--password PASSWORD'
57
+
58
+ option :user,
59
+ description: 'Elasticsearch connection user',
60
+ short: '-u USER',
61
+ long: '--user USER'
62
+
63
+ option :timeout,
64
+ description: 'Elasticsearch query timeout in seconds',
65
+ short: '-t TIMEOUT',
66
+ long: '--timeout TIMEOUT',
67
+ proc: proc(&:to_i),
68
+ default: 30
69
+
70
+ option :min_nodes,
71
+ description: 'Minimum of nodes that should be present in the cluster',
72
+ short: '-n NB_NODES',
73
+ long: '--minimum-nodes NB_NODES',
74
+ proc: proc(&:to_i),
75
+ default: 0
76
+
77
+ # From sensu-plugins-elasticsearch's ElasticsearchCommon
78
+ def client
79
+ transport_class = nil
80
+
81
+ host = {
82
+ host: config[:host],
83
+ port: config[:port],
84
+ request_timeout: config[:timeout],
85
+ scheme: config[:scheme]
86
+ }
87
+
88
+ if !config[:user].nil? && !config[:password].nil?
89
+ host[:user] = config[:user]
90
+ host[:password] = config[:password]
91
+ host[:scheme] = 'https' unless config[:scheme]
92
+ end
93
+
94
+ transport_options = {}
95
+
96
+ if config[:headers]
97
+
98
+ headers = {}
99
+
100
+ config[:headers].split(',').each do |header|
101
+ h, v = header.split(':', 2)
102
+ headers[h.strip] = v.strip
103
+ end
104
+
105
+ transport_options[:headers] = headers
106
+
107
+ end
108
+
109
+ @client ||= Elasticsearch::Client.new(transport_class: transport_class, hosts: [host], transport_options: transport_options)
110
+ end
111
+
112
+ def run
113
+ options = {}
114
+ health = client.cluster.health options
115
+
116
+ message = ''
117
+
118
+ case health['status']
119
+ when 'yellow'
120
+ cb = method(:warning)
121
+ message += 'Cluster state is Yellow'
122
+ when 'red'
123
+ cb = method(:critical)
124
+ critical 'Cluster state is Red'
125
+ when 'green'
126
+ cb = method(:ok)
127
+ message = 'Cluster state is Green'
128
+ else
129
+ cb = method(:unknown)
130
+ message = "Cluster state is in an unknown health: #{health['status']}"
131
+ end
132
+
133
+ message += " (#{health['active_shards_percent_as_number'].round(2)} % of active shards)"
134
+
135
+ if health['number_of_nodes'] < config[:min_nodes]
136
+ cb = method(:critical)
137
+ message = "Not enough nodes: #{health['number_of_nodes']} < #{config[:min_nodes]} - " + message
138
+ end
139
+
140
+ cb.call(message)
141
+ end
142
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-edgelab
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.0
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edgelab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-28 00:00:00.000000000 Z
11
+ date: 2018-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cassandra-driver
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.8.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: elasticsearch
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.0.14
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.14
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: sensu-plugin
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -184,6 +198,7 @@ executables:
184
198
  - check-apt-expired-keys.rb
185
199
  - check-cassandra-nodes.rb
186
200
  - check-consul-services.rb
201
+ - check-elasticsearch-cluster-health.rb
187
202
  - check-logstash-pipeline.rb
188
203
  - check-nomad-jobs.rb
189
204
  - check-nomad-leader.rb
@@ -200,6 +215,7 @@ files:
200
215
  - bin/check-apt-expired-keys.rb
201
216
  - bin/check-cassandra-nodes.rb
202
217
  - bin/check-consul-services.rb
218
+ - bin/check-elasticsearch-cluster-health.rb
203
219
  - bin/check-logstash-pipeline.rb
204
220
  - bin/check-nomad-jobs.rb
205
221
  - bin/check-nomad-leader.rb