sensu-plugins-consul 1.2.0 → 1.3.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 +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +1 -0
- data/bin/check-consul-failures.rb +8 -2
- data/bin/check-consul-leader.rb +7 -1
- data/bin/check-consul-maintenance.rb +80 -0
- data/bin/check-consul-members.rb +7 -1
- data/bin/check-consul-servers.rb +7 -1
- data/lib/sensu-plugins-consul/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 870e22095ff80e366b05399e1b81077b6777d6f6
|
4
|
+
data.tar.gz: 651dc79e9d5863b4f64ff4f4060cda87a292c64d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e9595c8e3af5afbdb7924adb958ddf574d8341bc42f692061b5db1599e596a97579eec7c04ad3f182d71af966f7ce83eeba1ccc6867d624567a27116b341380
|
7
|
+
data.tar.gz: 194f2b1cd975584efbc87ec7e218717245e861b3810f6bc00bd7fabf0b6e13a48dfc5506014a5f72fe9e29bc7e4674c0c4c2e3dbb350c398bf32296b16a29984
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
|
+
## [1.3.0] 2017-05-05
|
8
|
+
### Added
|
9
|
+
- `check-consul-failures`, `check-consul-leader`, `check-consul-members`, and `check-consul-servers` now accept a --scheme parameter (@akatch)
|
10
|
+
- Add consul maintenance check @okushchenko
|
7
11
|
|
8
12
|
## [1.2.0] - 2017-01-26
|
9
13
|
### Added
|
@@ -71,7 +75,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
71
75
|
### Added
|
72
76
|
- initial release
|
73
77
|
|
74
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.
|
78
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.3.0...HEAD
|
79
|
+
[1.3.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/2.1.0...1.3.0
|
75
80
|
[1.2.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.1.0...1.2.0
|
76
81
|
[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.0.0...1.1.0
|
77
82
|
[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/0.1.7...1.0.0
|
data/README.md
CHANGED
@@ -37,14 +37,20 @@ class ConsulStatus < Sensu::Plugin::Check::CLI
|
|
37
37
|
long: '--port PORT',
|
38
38
|
default: '8500'
|
39
39
|
|
40
|
+
option :scheme,
|
41
|
+
description: 'consul listener scheme',
|
42
|
+
short: '-S SCHEME',
|
43
|
+
long: '--scheme SCHEME',
|
44
|
+
default: 'http'
|
45
|
+
|
40
46
|
def run
|
41
|
-
r = RestClient::Resource.new("
|
47
|
+
r = RestClient::Resource.new("#{config[:scheme]}://#{config[:server]}:#{config[:port]}/v1/agent/members", timeout: 5).get
|
42
48
|
if r.code == 200
|
43
49
|
failing_nodes = JSON.parse(r).find_all { |node| node['Status'] == 4 }
|
44
50
|
if !failing_nodes.nil? && !failing_nodes.empty?
|
45
51
|
failing_nodes.each_entry do |node|
|
46
52
|
puts "Name: #{node['Name']}"
|
47
|
-
RestClient::Resource.new("
|
53
|
+
RestClient::Resource.new("#{config[:scheme]}://#{config[:server]}:#{config[:port]}/v1/agent/force-leave/#{node['Name']}", timeout: 5).get
|
48
54
|
end
|
49
55
|
ok 'Removed failed consul nodes'
|
50
56
|
else
|
data/bin/check-consul-leader.rb
CHANGED
@@ -47,6 +47,12 @@ class ConsulStatus < Sensu::Plugin::Check::CLI
|
|
47
47
|
long: '--port PORT',
|
48
48
|
default: '8500'
|
49
49
|
|
50
|
+
option :scheme,
|
51
|
+
description: 'consul listener scheme',
|
52
|
+
short: '-S SCHEME',
|
53
|
+
long: '--scheme SCHEME',
|
54
|
+
default: 'http'
|
55
|
+
|
50
56
|
def valid_ip(ip)
|
51
57
|
case ip.to_s
|
52
58
|
when Resolv::IPv4::Regex
|
@@ -71,7 +77,7 @@ class ConsulStatus < Sensu::Plugin::Check::CLI
|
|
71
77
|
end
|
72
78
|
|
73
79
|
def run
|
74
|
-
r = RestClient::Resource.new("
|
80
|
+
r = RestClient::Resource.new("#{config[:scheme]}://#{config[:server]}:#{config[:port]}/v1/status/leader", timeout: 5).get
|
75
81
|
if r.code == 200
|
76
82
|
if valid_ip(strip_ip(r.body))
|
77
83
|
ok 'Consul is UP and has a leader'
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-consul-maintenance
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks if maintenance mode is enabled
|
7
|
+
# for the node in Consul
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# plain text
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: diplomat
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./check-consul-maintenance -n localhost
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Copyright 2016 Oleksandr Kushchenko <gearok@gmail.com>
|
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 'diplomat'
|
32
|
+
|
33
|
+
#
|
34
|
+
# Maintenance Status
|
35
|
+
#
|
36
|
+
class MaintenanceStatus < Sensu::Plugin::Check::CLI
|
37
|
+
option :consul,
|
38
|
+
description: 'consul server',
|
39
|
+
long: '--consul SERVER',
|
40
|
+
default: 'http://localhost:8500'
|
41
|
+
|
42
|
+
option :node,
|
43
|
+
description: 'consul node name',
|
44
|
+
short: '-n NODE',
|
45
|
+
long: '--node NODE',
|
46
|
+
default: 'localhost'
|
47
|
+
|
48
|
+
# Get the maintenance data for the node from consul
|
49
|
+
#
|
50
|
+
def acquire_maintenance_data
|
51
|
+
result = Diplomat::Health.node(config[:node]).select do |check|
|
52
|
+
check['CheckID'] == '_node_maintenance'
|
53
|
+
end
|
54
|
+
if !result.empty?
|
55
|
+
{ enabled: true, reason: result.first['Notes'] }
|
56
|
+
else
|
57
|
+
{ enabled: false, reason: nil }
|
58
|
+
end
|
59
|
+
rescue Faraday::ConnectionFailed => e
|
60
|
+
warning "Connection error occurred: #{e}"
|
61
|
+
rescue StandardError => e
|
62
|
+
unknown "Exception occurred when checking consul node maintenace: #{e}"
|
63
|
+
end
|
64
|
+
|
65
|
+
# Main function
|
66
|
+
#
|
67
|
+
def run
|
68
|
+
Diplomat.configure do |dc|
|
69
|
+
dc.url = config[:consul]
|
70
|
+
end
|
71
|
+
|
72
|
+
data = acquire_maintenance_data
|
73
|
+
|
74
|
+
if data[:enabled]
|
75
|
+
critical "Maintenance enabled for node #{config[:node]}: #{data[:reason]}"
|
76
|
+
else
|
77
|
+
ok "Maintenance disabled for node #{config[:node]}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/bin/check-consul-members.rb
CHANGED
@@ -68,8 +68,14 @@ class ConsulStatus < Sensu::Plugin::Check::CLI
|
|
68
68
|
long: '--wan',
|
69
69
|
boolean: false
|
70
70
|
|
71
|
+
option :scheme,
|
72
|
+
description: 'consul listener scheme',
|
73
|
+
short: '-S SCHEME',
|
74
|
+
long: '--scheme SCHEME',
|
75
|
+
default: 'http'
|
76
|
+
|
71
77
|
def run
|
72
|
-
url = "
|
78
|
+
url = "#{config[:scheme]}://#{config[:server]}:#{config[:port]}/v1/agent/members"
|
73
79
|
if config[:wan]
|
74
80
|
url += '?wan=1'
|
75
81
|
end
|
data/bin/check-consul-servers.rb
CHANGED
@@ -59,8 +59,14 @@ class ConsulStatus < Sensu::Plugin::Check::CLI
|
|
59
59
|
long: '--expect EXPECT',
|
60
60
|
default: 5
|
61
61
|
|
62
|
+
option :scheme,
|
63
|
+
description: 'consul listener scheme',
|
64
|
+
short: '-S SCHEME',
|
65
|
+
long: '--scheme SCHEME',
|
66
|
+
default: 'http'
|
67
|
+
|
62
68
|
def run
|
63
|
-
json = RestClient::Resource.new("
|
69
|
+
json = RestClient::Resource.new("#{config[:scheme]}://#{config[:server]}:#{config[:port]}/v1/status/peers", timeout: 5).get
|
64
70
|
peers = JSON.parse(json).length.to_i
|
65
71
|
if peers < config[:min].to_i
|
66
72
|
critical "[#{peers}] peers is below critical threshold of [#{config[:min]}]"
|
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: 1.
|
4
|
+
version: 1.3.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: 2017-
|
11
|
+
date: 2017-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|
@@ -187,6 +187,7 @@ executables:
|
|
187
187
|
- check-consul-failures.rb
|
188
188
|
- check-consul-kv-ttl.rb
|
189
189
|
- check-consul-leader.rb
|
190
|
+
- check-consul-maintenance.rb
|
190
191
|
- check-consul-members.rb
|
191
192
|
- check-consul-servers.rb
|
192
193
|
- check-consul-service-health.rb
|
@@ -200,6 +201,7 @@ files:
|
|
200
201
|
- bin/check-consul-failures.rb
|
201
202
|
- bin/check-consul-kv-ttl.rb
|
202
203
|
- bin/check-consul-leader.rb
|
204
|
+
- bin/check-consul-maintenance.rb
|
203
205
|
- bin/check-consul-members.rb
|
204
206
|
- bin/check-consul-servers.rb
|
205
207
|
- bin/check-consul-service-health.rb
|