sensu-plugins-consul 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +2 -0
- data/bin/check-consul-quorum.rb +91 -0
- data/bin/check-consul-stale-peers.rb +73 -0
- data/lib/sensu-plugins-consul/check/base.rb +103 -0
- data/lib/sensu-plugins-consul/version.rb +2 -2
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7c1ef8f95efae49bd9e72c798be02494c70fb337c8494b874e95a746d3f3208
|
4
|
+
data.tar.gz: e17a0003846a9a8d0369c787c02c708a81d99e3e9cb1006be03dd39cdf15bee7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 054f69b81bd27515f83eca13b9ad4bf6b4b937801e4593219eaf38ddd77100464b49ecfa55ce6507bedff57e423423e5d95ae91cc41a74d09ef35fc38562f909
|
7
|
+
data.tar.gz: 11c947c6fb23a653d124e8486e0d0860dc24f0895e8fe556643bc7c129b13006d1e867fa45493605844277096440fc731753cb84c4e023a288af3d9ddd9ac5f0
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,11 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
|
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## [2.1.0] - 2018-03-29
|
9
|
+
### Added
|
10
|
+
- `check-consul-quorum.rb`: Check how many servers can be lost while maintaining quorum (@roboticcheese)
|
11
|
+
- `check-consul-stale-peers.rb`: Check for stale peers in the raft configuration (@roboticcheese)
|
12
|
+
|
8
13
|
## [2.0.1] - 2018-03-27
|
9
14
|
### Security
|
10
15
|
- updated yard dependency to `~> 0.9.11` per: https://nvd.nist.gov/vuln/detail/CVE-2017-17042 (@majormoses)
|
@@ -119,7 +124,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
|
|
119
124
|
### Added
|
120
125
|
- initial release
|
121
126
|
|
122
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/2.0
|
127
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/2.1.0...HEAD
|
128
|
+
[2.1.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/2.0.1...2.1.0
|
123
129
|
[2.0.1]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/2.0.0...2.0.1
|
124
130
|
[2.0.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.6.1...2.0.0
|
125
131
|
[1.6.1]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.6.0...1.6.1
|
data/README.md
CHANGED
@@ -0,0 +1,91 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# frozen_string_literal: false
|
3
|
+
|
4
|
+
#
|
5
|
+
# check-consul-quorum
|
6
|
+
#
|
7
|
+
# DESCRIPTION:
|
8
|
+
# This plugin checks how many nodes the cluster will be able to lose while
|
9
|
+
# still maintaining quorum.
|
10
|
+
#
|
11
|
+
# OUTPUT:
|
12
|
+
# plain text
|
13
|
+
#
|
14
|
+
# PLATFORMS:
|
15
|
+
# Linux
|
16
|
+
#
|
17
|
+
# DEPENDENCIES:
|
18
|
+
# gem: sensu-plugin
|
19
|
+
# gem: rest-client
|
20
|
+
#
|
21
|
+
# USAGE:
|
22
|
+
# Connect to localhost, go critical when the cluster is at its minimum for
|
23
|
+
# quorum:
|
24
|
+
# ./check-consul-quorum
|
25
|
+
#
|
26
|
+
# Connect to a remote Consul server over HTTPS:
|
27
|
+
# ./check-consul-quorum -s 192.168.42.42 -p 4443 -P https
|
28
|
+
#
|
29
|
+
# Go critical when the cluster can lose one more server and keep quorum:
|
30
|
+
# ./check-consul-quorum -W 2 -C 1
|
31
|
+
#
|
32
|
+
# NOTES:
|
33
|
+
#
|
34
|
+
# LICENSE:
|
35
|
+
# Copyright 2018, Jonathan Hartman <j@hartman.io>
|
36
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
37
|
+
# for details.
|
38
|
+
#
|
39
|
+
|
40
|
+
require 'sensu-plugins-consul/check/base'
|
41
|
+
|
42
|
+
#
|
43
|
+
# Consul quorum status
|
44
|
+
#
|
45
|
+
class ConsulQuorumStatus < SensuPluginsConsul::Check::Base
|
46
|
+
option :warning,
|
47
|
+
description: 'Warn when the cluster has this many spare servers ' \
|
48
|
+
'beyond the minimum for quorum',
|
49
|
+
short: '-W NUMBER_OF_SPARE_SERVERS',
|
50
|
+
long: '--warning NUMBER_OF_SPARE_SERVERS',
|
51
|
+
proc: proc(&:to_i),
|
52
|
+
default: 1
|
53
|
+
|
54
|
+
option :critical,
|
55
|
+
description: 'Go critical when the cluster has this many spare ' \
|
56
|
+
'servers beyond the minimum for quorum',
|
57
|
+
short: '-C NUMBER_OF_SPARE_SERVERS',
|
58
|
+
long: '--critical NUMBER_OF_SPARE_SERVERS',
|
59
|
+
proc: proc(&:to_i),
|
60
|
+
default: 0
|
61
|
+
|
62
|
+
def run
|
63
|
+
raft = consul_get('operator/raft/configuration')
|
64
|
+
members = consul_get('agent/members')
|
65
|
+
|
66
|
+
total = raft['Servers'].select { |s| s['Voter'] == true }.length
|
67
|
+
required = total / 2 + 1
|
68
|
+
alive = members.select do |m|
|
69
|
+
m.key?('Tags') && m['Tags']['role'] == 'consul' && m['Status'] == 1
|
70
|
+
end.length
|
71
|
+
|
72
|
+
spares = alive - required
|
73
|
+
|
74
|
+
msg = "Cluster has #{alive}/#{total} servers alive and"
|
75
|
+
msg = if spares < 0
|
76
|
+
"#{msg} has lost quorum"
|
77
|
+
elsif spares.zero?
|
78
|
+
"#{msg} has the minimum required for quorum"
|
79
|
+
else
|
80
|
+
"#{msg} can lose #{spares} more without losing quorum"
|
81
|
+
end
|
82
|
+
|
83
|
+
if spares < 0 || spares <= config[:critical]
|
84
|
+
critical msg
|
85
|
+
elsif spares <= config[:warning]
|
86
|
+
warning msg
|
87
|
+
else
|
88
|
+
ok msg
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# frozen_string_literal: false
|
3
|
+
|
4
|
+
#
|
5
|
+
# check-consul-stale-peers
|
6
|
+
#
|
7
|
+
# DESCRIPTION:
|
8
|
+
# This plugin checks the raft configuration for stale ("unknown") peers.
|
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
|
+
# Connect to localhost, go critical when there are any stale peers:
|
22
|
+
# ./check-consul-stale-peers
|
23
|
+
#
|
24
|
+
# Connect to a remote Consul server over HTTPS:
|
25
|
+
# ./check-consul-stale-peers -s 192.168.42.42 -p 4443 -P https
|
26
|
+
#
|
27
|
+
# Go critical when the cluster has two or more stale peers:
|
28
|
+
# ./check-consul-stale-peers -W 1 -C 2
|
29
|
+
#
|
30
|
+
# NOTES:
|
31
|
+
#
|
32
|
+
# LICENSE:
|
33
|
+
# Copyright 2018, Jonathan Hartman <j@hartman.io>
|
34
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
35
|
+
# for details.
|
36
|
+
#
|
37
|
+
|
38
|
+
require 'sensu-plugins-consul/check/base'
|
39
|
+
|
40
|
+
#
|
41
|
+
# Consul stale peers
|
42
|
+
#
|
43
|
+
class ConsulStalePeers < SensuPluginsConsul::Check::Base
|
44
|
+
option :warning,
|
45
|
+
description: 'Warn when there are this many stale peers',
|
46
|
+
short: '-W NUMBER_OF_PEERS',
|
47
|
+
long: '--warning NUMBER_OF_PEERS',
|
48
|
+
proc: proc(&:to_i),
|
49
|
+
default: 1
|
50
|
+
|
51
|
+
option :critical,
|
52
|
+
description: 'Go critical when there are this many stale peers',
|
53
|
+
short: '-C NUMBER_OF_PEERS',
|
54
|
+
long: '--critical NUMBER_OF_PEERS',
|
55
|
+
proc: proc(&:to_i),
|
56
|
+
default: 1
|
57
|
+
|
58
|
+
def run
|
59
|
+
raft = consul_get('operator/raft/configuration')
|
60
|
+
|
61
|
+
res = raft['Servers'].select { |s| s['Node'] == '(unknown)' }.length
|
62
|
+
|
63
|
+
msg = "Cluster contains #{res} stale peer#{'s' unless res == 1}"
|
64
|
+
|
65
|
+
if res >= config[:critical]
|
66
|
+
critical msg
|
67
|
+
elsif res >= config[:warning]
|
68
|
+
warning msg
|
69
|
+
else
|
70
|
+
ok msg
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
#
|
4
|
+
# sensu-plugins-consul/check/base
|
5
|
+
#
|
6
|
+
# DESCRIPTION:
|
7
|
+
# This class defines some of the common config options and helper methods for
|
8
|
+
# other Consul plugins to use.
|
9
|
+
#
|
10
|
+
# OUTPUT:
|
11
|
+
# N/A
|
12
|
+
#
|
13
|
+
# PLATFORMS:
|
14
|
+
# Linux
|
15
|
+
#
|
16
|
+
# DEPENDENCIES:
|
17
|
+
# gem: sensu-plugin
|
18
|
+
# gem: rest-client
|
19
|
+
#
|
20
|
+
# USAGE:
|
21
|
+
# Import this file and create subclasses of the included plugin class.
|
22
|
+
# require 'sensu-plugins-consul/check/base'
|
23
|
+
# class ConsulTestStatus < SensuPluginsConsul::Check::Base
|
24
|
+
# ...
|
25
|
+
#
|
26
|
+
# NOTES:
|
27
|
+
#
|
28
|
+
# LICENSE:
|
29
|
+
# Copyright 2018, Jonathan Hartman <j@hartman.io>
|
30
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
31
|
+
# for details.
|
32
|
+
#
|
33
|
+
|
34
|
+
require 'json'
|
35
|
+
require 'rest-client'
|
36
|
+
require 'sensu-plugin/check/cli'
|
37
|
+
|
38
|
+
#
|
39
|
+
# Consul shared base plugin
|
40
|
+
#
|
41
|
+
module SensuPluginsConsul
|
42
|
+
class Check
|
43
|
+
class Base < Sensu::Plugin::Check::CLI
|
44
|
+
option :server,
|
45
|
+
description: 'Consul server',
|
46
|
+
short: '-s SERVER',
|
47
|
+
long: '--server SERVER',
|
48
|
+
default: '127.0.0.1'
|
49
|
+
|
50
|
+
option :port,
|
51
|
+
description: 'Consul HTTP port',
|
52
|
+
short: '-p PORT',
|
53
|
+
long: '--port PORT',
|
54
|
+
proc: proc(&:to_i),
|
55
|
+
default: 8500
|
56
|
+
|
57
|
+
option :protocol,
|
58
|
+
description: 'Consul listener protocol',
|
59
|
+
short: '-P PROTOCOL',
|
60
|
+
long: '--protocol PROTOCOL',
|
61
|
+
in: %w[http https],
|
62
|
+
default: 'http'
|
63
|
+
|
64
|
+
option :insecure,
|
65
|
+
description: 'Set this flag to disable SSL verification',
|
66
|
+
short: '-k',
|
67
|
+
long: '--insecure',
|
68
|
+
boolean: true,
|
69
|
+
default: false
|
70
|
+
|
71
|
+
option :capath,
|
72
|
+
description: 'Absolute path to an alternative CA file',
|
73
|
+
short: '-c CAPATH',
|
74
|
+
long: '--capath CAPATH'
|
75
|
+
|
76
|
+
option :timeout,
|
77
|
+
description: 'Connection will time out after this many seconds',
|
78
|
+
short: '-t TIMEOUT_IN_SECONDS',
|
79
|
+
long: '--timeout TIMEOUT_IN_SECONDS',
|
80
|
+
proc: proc(&:to_i),
|
81
|
+
default: 5
|
82
|
+
|
83
|
+
#
|
84
|
+
# Fetch and return the parsed JSON data from a specified Consul API endpoint.
|
85
|
+
#
|
86
|
+
def consul_get(endpoint)
|
87
|
+
url = "#{config[:protocol]}://#{config[:server]}:#{config[:port]}/" \
|
88
|
+
"v1/#{endpoint}"
|
89
|
+
options = { timeout: config[:timeout],
|
90
|
+
verify_ssl: !config[:insecure],
|
91
|
+
ssl_ca_file: config[:capath] }
|
92
|
+
|
93
|
+
JSON.parse(RestClient::Resource.new(url, options).get)
|
94
|
+
rescue Errno::ECONNREFUSED
|
95
|
+
critical 'Consul is not responding'
|
96
|
+
rescue RestClient::RequestTimeout
|
97
|
+
critical 'Consul connection timed out'
|
98
|
+
rescue RestClient::Exception => e
|
99
|
+
unknown "Consul returned: #{e}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-consul
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu Plugins and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|
@@ -189,8 +189,10 @@ executables:
|
|
189
189
|
- check-consul-leader.rb
|
190
190
|
- check-consul-maintenance.rb
|
191
191
|
- check-consul-members.rb
|
192
|
+
- check-consul-quorum.rb
|
192
193
|
- check-consul-servers.rb
|
193
194
|
- check-consul-service-health.rb
|
195
|
+
- check-consul-stale-peers.rb
|
194
196
|
- check-service-consul.rb
|
195
197
|
extensions: []
|
196
198
|
extra_rdoc_files: []
|
@@ -203,10 +205,13 @@ files:
|
|
203
205
|
- bin/check-consul-leader.rb
|
204
206
|
- bin/check-consul-maintenance.rb
|
205
207
|
- bin/check-consul-members.rb
|
208
|
+
- bin/check-consul-quorum.rb
|
206
209
|
- bin/check-consul-servers.rb
|
207
210
|
- bin/check-consul-service-health.rb
|
211
|
+
- bin/check-consul-stale-peers.rb
|
208
212
|
- bin/check-service-consul.rb
|
209
213
|
- lib/sensu-plugins-consul.rb
|
214
|
+
- lib/sensu-plugins-consul/check/base.rb
|
210
215
|
- lib/sensu-plugins-consul/version.rb
|
211
216
|
homepage: https://github.com/sensu-plugins/sensu-plugins-consul
|
212
217
|
licenses:
|