sensu-plugins-consul-magec 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +161 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/bin/check-consul-failures.rb +103 -0
- data/bin/check-consul-kv-ttl.rb +176 -0
- data/bin/check-consul-leader.rb +129 -0
- data/bin/check-consul-maintenance.rb +98 -0
- data/bin/check-consul-members.rb +136 -0
- data/bin/check-consul-quorum.rb +91 -0
- data/bin/check-consul-servers.rb +118 -0
- data/bin/check-consul-service-health.rb +161 -0
- data/bin/check-consul-stale-peers.rb +73 -0
- data/bin/check-service-consul.rb +160 -0
- data/lib/sensu-plugins-consul.rb +3 -0
- data/lib/sensu-plugins-consul/check/base.rb +112 -0
- data/lib/sensu-plugins-consul/version.rb +11 -0
- metadata +246 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4664c93f956375d6da0ba008a75bf0ed645af87b
|
4
|
+
data.tar.gz: 8a873cf4cf0998ad7b0f5eaa2f8c485514054901
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 84653760d23291dbe703782d9db4491705ad1144ad73b9807b595c9c43b76e700d5e19e07eb37ff53e9bf28d0e4bced120d1828d6d6102518b65a47190df5548
|
7
|
+
data.tar.gz: cb9559419ed49ee3887514a6330b89cbb161292530ad6c7bc9ec2dda62a6b22ac468e5c3d949a162e5ccd0cf3feeed3947e173be436b51c56a6f021e0bc9e148
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
# Change Log
|
2
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
3
|
+
|
4
|
+
This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)
|
5
|
+
|
6
|
+
## [Unreleased]
|
7
|
+
|
8
|
+
## [2.2.1] - 2018-10-01
|
9
|
+
### Fixed
|
10
|
+
- check-consul-failures: use a put when requesting to remove a node from the agent api (@majormoses)
|
11
|
+
|
12
|
+
## [2.2.0] - 2018-06-11
|
13
|
+
### Added
|
14
|
+
- add ACL support to all consul checks (@scalp42)
|
15
|
+
|
16
|
+
## [2.1.1] - 2018-05-31
|
17
|
+
### Fixed
|
18
|
+
- `check-consul-leader.rb`: Timeout option must be an integer (@scalp42)
|
19
|
+
|
20
|
+
## [2.1.0] - 2018-03-29
|
21
|
+
### Added
|
22
|
+
- `check-consul-quorum.rb`: Check how many servers can be lost while maintaining quorum (@roboticcheese)
|
23
|
+
- `check-consul-stale-peers.rb`: Check for stale peers in the raft configuration (@roboticcheese)
|
24
|
+
|
25
|
+
## [2.0.1] - 2018-03-27
|
26
|
+
### Security
|
27
|
+
- updated yard dependency to `~> 0.9.11` per: https://nvd.nist.gov/vuln/detail/CVE-2017-17042 (@majormoses)
|
28
|
+
|
29
|
+
### Changed
|
30
|
+
- appeased the cops (@majormoses)
|
31
|
+
|
32
|
+
## [2.0.0] - 2018-03-07
|
33
|
+
### Security
|
34
|
+
- updated rubocop dependency to `~> 0.51.0` per: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-8418. (@majormoses)
|
35
|
+
|
36
|
+
### Breaking Changes
|
37
|
+
- removed ruby `< 2.1` support (@majormoses)
|
38
|
+
|
39
|
+
### Changed
|
40
|
+
- appeased the cops (@majormoses)
|
41
|
+
|
42
|
+
## [1.6.1] - 2018-03-02
|
43
|
+
### Fixed
|
44
|
+
- Bug fix for `check-consul-servers` so timeout option works (@joshbenner)
|
45
|
+
|
46
|
+
## [1.6.0] - 2017-09-30
|
47
|
+
### Added
|
48
|
+
- `check-consul-leader`, `check-consul-members`, and `check-consul-servers` now accept `--insecure`, `--capath`, `--timeout` arguments (@akatch)
|
49
|
+
|
50
|
+
### Changed
|
51
|
+
- update Changelog guideline location (@majormoses)
|
52
|
+
|
53
|
+
## [1.5.0] - 2017-08-09
|
54
|
+
### Added
|
55
|
+
- `check-consul-failures` now accepts `--keep-failures` and `--critical` arguments (@psyhomb)
|
56
|
+
|
57
|
+
## [1.4.1] 2017-08-06
|
58
|
+
### Fixed
|
59
|
+
- Bug fix for `check-consul-service-health` [#26](https://github.com/sensu-plugins/sensu-plugins-consul/pull/26) (@psyhomb)
|
60
|
+
|
61
|
+
### Added
|
62
|
+
- ruby 2.4.1 testing (@majormoses)
|
63
|
+
|
64
|
+
## [1.4.0] 2017-08-05
|
65
|
+
### Added
|
66
|
+
- `check-consul-service-health` now accept a `--node` argument that will check all autodiscovered consul services running on the specified node (@psyhomb)
|
67
|
+
|
68
|
+
## [1.3.0] 2017-05-05
|
69
|
+
### Added
|
70
|
+
- `check-consul-failures`, `check-consul-leader`, `check-consul-members`, and `check-consul-servers` now accept a --scheme parameter (@akatch)
|
71
|
+
- Add consul maintenance check @okushchenko
|
72
|
+
|
73
|
+
## [1.2.0] - 2017-01-26
|
74
|
+
### Added
|
75
|
+
- `check-consul-service-health` and `check-service-consul` now accept a --tags filter (@wg-tsuereth)
|
76
|
+
|
77
|
+
### Fixed
|
78
|
+
- check-service-consul should look for 'critical' instead of 'failing' (@mattcl)
|
79
|
+
|
80
|
+
## [1.1.0] - 2016-08-03
|
81
|
+
### Added
|
82
|
+
- check-consul-service-health and check-service-consul now accept a --fail-if-not-found argument @wg-tsuereth
|
83
|
+
|
84
|
+
## [1.0.0] - 2016-06-28
|
85
|
+
### Fixed
|
86
|
+
- Fixed check-consul-service-health and check-service-consul --all argument @wg-tsuereth
|
87
|
+
|
88
|
+
### Added
|
89
|
+
- check-consul-service-health and check-service-consul now accept a --consul argument to specify a server @wg-tsuereth
|
90
|
+
- Support for Ruby 2.3.0
|
91
|
+
|
92
|
+
### Removed
|
93
|
+
- Support for Ruby 1.9.3
|
94
|
+
|
95
|
+
## [0.1.7] - 2016-04-03
|
96
|
+
### Added
|
97
|
+
- check-consul-service-health will check the health of a specific service (Yieldbot)
|
98
|
+
- check-consul-kv-ttl will check Consul KV namespace for timed out global operations (Yieldbot)
|
99
|
+
- Added check to alert on consul cluster members, supports querying wan members @aianchici
|
100
|
+
|
101
|
+
## [0.0.7] - 2015-11-12
|
102
|
+
### Changed
|
103
|
+
- Consul checks with UNKNOWN status should fail gracefully
|
104
|
+
|
105
|
+
### Fixed
|
106
|
+
- Consul service check fixes
|
107
|
+
|
108
|
+
## [0.0.6] - 2015-09-29
|
109
|
+
### Changed
|
110
|
+
- Bug fixes for check-consul-servers.rb
|
111
|
+
|
112
|
+
## [0.0.5] - 2015-09-28
|
113
|
+
### Added
|
114
|
+
- Added check to alert on consul peer servers
|
115
|
+
|
116
|
+
## [0.0.4] - 2015-07-14
|
117
|
+
### Added
|
118
|
+
- Adding script to remove failed consul nodes prior to 72 hour consul window.
|
119
|
+
|
120
|
+
## [0.0.3] - 2015-07-14
|
121
|
+
### Changed
|
122
|
+
- updated sensu-plugin gem to 1.2.0
|
123
|
+
|
124
|
+
### Fixed
|
125
|
+
- Added check to support removing of failed consul nodes from the cluster
|
126
|
+
|
127
|
+
## [0.0.2] - 2015-06-02
|
128
|
+
### Fixed
|
129
|
+
- added binstubs
|
130
|
+
|
131
|
+
### Changed
|
132
|
+
- removed cruft from /lib
|
133
|
+
|
134
|
+
## [0.0.1] - 2015-05-21
|
135
|
+
|
136
|
+
### Added
|
137
|
+
- initial release
|
138
|
+
|
139
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/2.2.1...HEAD
|
140
|
+
[2.2.1]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/2.2.0...2.2.1
|
141
|
+
[2.2.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/2.1.1...2.2.0
|
142
|
+
[2.1.1]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/2.1.0...2.1.1
|
143
|
+
[2.1.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/2.0.1...2.1.0
|
144
|
+
[2.0.1]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/2.0.0...2.0.1
|
145
|
+
[2.0.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.6.1...2.0.0
|
146
|
+
[1.6.1]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.6.0...1.6.1
|
147
|
+
[1.6.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.5.0...1.6.0
|
148
|
+
[1.5.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.4.1...1.5.0
|
149
|
+
[1.4.1]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.4.0...1.4.1
|
150
|
+
[1.4.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.3.0...1.4.0
|
151
|
+
[1.3.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/2.1.0...1.3.0
|
152
|
+
[1.2.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.1.0...1.2.0
|
153
|
+
[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/1.0.0...1.1.0
|
154
|
+
[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/0.1.7...1.0.0
|
155
|
+
[0.1.7]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/0.0.7...0.1.7
|
156
|
+
[0.0.7]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/0.0.6...0.0.7
|
157
|
+
[0.0.6]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/0.0.5...0.0.6
|
158
|
+
[0.0.5]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/0.0.4...0.0.5
|
159
|
+
[0.0.4]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/0.0.3...0.0.4
|
160
|
+
[0.0.3]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/0.0.2...0.0.3
|
161
|
+
[0.0.2]: https://github.com/sensu-plugins/sensu-plugins-consul/compare/0.0.1...0.0.2
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
## Sensu-Plugins-consul
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-consul.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-consul)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/sensu-plugins-consul.svg)](http://badge.fury.io/rb/sensu-plugins-consul)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-consul/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-consul)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-consul/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-consul)
|
7
|
+
[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-consul.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-consul)
|
8
|
+
|
9
|
+
## Functionality
|
10
|
+
|
11
|
+
## Files
|
12
|
+
* bin/check-consul-kv-ttl.rb
|
13
|
+
* bin/check-consul-service-health.rb
|
14
|
+
* bin/check-consul-failures.rb
|
15
|
+
* bin/check-consul-leader.rb
|
16
|
+
* bin/check-consul-servers.rb
|
17
|
+
* bin/check-consul-members.rb
|
18
|
+
* bin/check-service-consul.rb
|
19
|
+
* bin/check-consul-maintenance.rb
|
20
|
+
* bin/check-consul-quorum.rb
|
21
|
+
* bin/check-consul-stale-peers.rb
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
28
|
+
|
29
|
+
## Notes
|
@@ -0,0 +1,103 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# OUTPUT:
|
6
|
+
# plain text
|
7
|
+
#
|
8
|
+
# PLATFORMS:
|
9
|
+
# Linux
|
10
|
+
#
|
11
|
+
# DEPENDENCIES:
|
12
|
+
# gem: sensu-plugin
|
13
|
+
# gem: rest-client
|
14
|
+
#
|
15
|
+
# Consul returns the numerical values for consul members state, which the
|
16
|
+
# numbers used are defined in : https://github.com/hashicorp/serf/blob/master/serf/serf.go
|
17
|
+
#
|
18
|
+
# StatusNone MemberStatus = iota (0, "none")
|
19
|
+
# StatusAlive (1, "alive")
|
20
|
+
# StatusLeaving (2, "leaving")
|
21
|
+
# StatusLeft (3, "left")
|
22
|
+
# StatusFailed (4, "failed")
|
23
|
+
#
|
24
|
+
|
25
|
+
require 'sensu-plugin/check/cli'
|
26
|
+
require 'rest-client'
|
27
|
+
require 'json'
|
28
|
+
|
29
|
+
class ConsulStatus < Sensu::Plugin::Check::CLI
|
30
|
+
option :server,
|
31
|
+
description: 'consul server',
|
32
|
+
short: '-s SERVER',
|
33
|
+
long: '--server SERVER',
|
34
|
+
default: '127.0.0.1'
|
35
|
+
|
36
|
+
option :port,
|
37
|
+
description: 'consul http port',
|
38
|
+
short: '-p PORT',
|
39
|
+
long: '--port PORT',
|
40
|
+
default: '8500'
|
41
|
+
|
42
|
+
option :scheme,
|
43
|
+
description: 'consul listener scheme',
|
44
|
+
short: '-S SCHEME',
|
45
|
+
long: '--scheme SCHEME',
|
46
|
+
default: 'http'
|
47
|
+
|
48
|
+
option :keep_failures,
|
49
|
+
description: 'do not remove failing nodes',
|
50
|
+
short: '-k',
|
51
|
+
long: '--keep-failures',
|
52
|
+
boolean: true,
|
53
|
+
default: false
|
54
|
+
|
55
|
+
option :critical,
|
56
|
+
description: 'set state to critical',
|
57
|
+
short: '-c',
|
58
|
+
long: '--critical',
|
59
|
+
boolean: true,
|
60
|
+
default: false
|
61
|
+
|
62
|
+
option :token,
|
63
|
+
description: 'ACL token',
|
64
|
+
long: '--token ACL_TOKEN'
|
65
|
+
|
66
|
+
def run
|
67
|
+
r = RestClient::Resource.new(
|
68
|
+
"#{config[:scheme]}://#{config[:server]}:#{config[:port]}/v1/agent/members",
|
69
|
+
timeout: 5,
|
70
|
+
headers: { 'X-Consul-Token' => config[:token] }
|
71
|
+
).get
|
72
|
+
if r.code == 200
|
73
|
+
failing_nodes = JSON.parse(r).find_all { |node| node['Status'] == 4 }
|
74
|
+
if !failing_nodes.nil? && !failing_nodes.empty?
|
75
|
+
nodes_names = []
|
76
|
+
failing_nodes.each_entry do |node|
|
77
|
+
nodes_names.push(node['Name'])
|
78
|
+
next if config[:keep_failures]
|
79
|
+
puts "Removing failed node: #{node['Name']}"
|
80
|
+
RestClient::Resource.new(
|
81
|
+
"#{config[:scheme]}://#{config[:server]}:#{config[:port]}/v1/agent/force-leave/#{node['Name']}",
|
82
|
+
timeout: 5,
|
83
|
+
headers: { 'X-Consul-Token' => config[:token] }
|
84
|
+
).put
|
85
|
+
nodes_names.delete(node['Name'])
|
86
|
+
end
|
87
|
+
ok 'All clear' if nodes_names.empty?
|
88
|
+
critical "Found failed nodes: #{nodes_names}" if config[:critical]
|
89
|
+
warning "Found failed nodes: #{nodes_names}"
|
90
|
+
else
|
91
|
+
ok 'All nodes are alive'
|
92
|
+
end
|
93
|
+
else
|
94
|
+
critical 'Consul is not responding'
|
95
|
+
end
|
96
|
+
rescue Errno::ECONNREFUSED
|
97
|
+
critical 'Consul is not responding'
|
98
|
+
rescue RestClient::RequestTimeout
|
99
|
+
critical 'Consul Connection timed out'
|
100
|
+
rescue RestClient::Exception => e
|
101
|
+
unknown "Consul returned: #{e}"
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# check-consul-kv-ttl
|
6
|
+
#
|
7
|
+
# DESCRIPTION:
|
8
|
+
# This plugin assists in checking a Consul KV namespace for timed out global operations
|
9
|
+
#
|
10
|
+
# OUTPUT:
|
11
|
+
# plain text
|
12
|
+
#
|
13
|
+
# PLATFORMS:
|
14
|
+
# Linux
|
15
|
+
#
|
16
|
+
# DEPENDENCIES:
|
17
|
+
# gem: sensu-plugin
|
18
|
+
# gem: diplomat
|
19
|
+
#
|
20
|
+
# USAGE:
|
21
|
+
# ./check-consul-kv-ttl -kv 'ttl/service/tag' -w 30 -c 60
|
22
|
+
# ./check-consul-kv-ttl -kv 'ttl/service/tag' -w 30 -c 60 -j -t 'date'
|
23
|
+
# ./check-consul-kv-ttl -kv 'ttl/service/tag' -w 30 -c 60 -j -t 'date' -s 'status'
|
24
|
+
#
|
25
|
+
# NOTES:
|
26
|
+
#
|
27
|
+
# LICENSE:
|
28
|
+
# Copyright 2015 Yieldbot, Inc. <devops@yieldbot.com>
|
29
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
30
|
+
# for details.
|
31
|
+
#
|
32
|
+
|
33
|
+
require 'sensu-plugin/check/cli'
|
34
|
+
require 'diplomat'
|
35
|
+
require 'json'
|
36
|
+
require 'time'
|
37
|
+
|
38
|
+
class Hash
|
39
|
+
def dig(dotted_path)
|
40
|
+
parts = dotted_path.split '.', 2
|
41
|
+
match = self[parts[0]]
|
42
|
+
if !parts[1] || match.nil? # rubocop:disable Style/GuardClause
|
43
|
+
return match
|
44
|
+
else
|
45
|
+
return match.dig(parts[1])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Service Status
|
52
|
+
#
|
53
|
+
class CheckConsulKvTTL < Sensu::Plugin::Check::CLI
|
54
|
+
option :consul,
|
55
|
+
description: 'consul server',
|
56
|
+
long: '--consul SERVER',
|
57
|
+
default: 'http://localhost:8500'
|
58
|
+
|
59
|
+
option :kv,
|
60
|
+
description: 'kv namespace to pull data from',
|
61
|
+
short: '-k NAMESPACE',
|
62
|
+
long: '--kv NAMESPACE',
|
63
|
+
required: true
|
64
|
+
|
65
|
+
option :json,
|
66
|
+
description: 'Process the value as JSON',
|
67
|
+
short: '-j',
|
68
|
+
long: '--json',
|
69
|
+
default: true
|
70
|
+
|
71
|
+
option :timestamp_key,
|
72
|
+
description: 'Use the given dotted path to alert based on the time(ISO8601), if processing as JSON',
|
73
|
+
short: '-t PATH',
|
74
|
+
long: '--timestamp PATH',
|
75
|
+
default: nil
|
76
|
+
|
77
|
+
option :status_key,
|
78
|
+
description: 'Use the given dotted path to alert based on the status, if processing as JSON',
|
79
|
+
short: '-s PATH',
|
80
|
+
long: '--status PATH',
|
81
|
+
default: nil
|
82
|
+
|
83
|
+
option :warning,
|
84
|
+
description: 'Warning TTL Threshold',
|
85
|
+
short: '-w THRESHOLD',
|
86
|
+
long: '--warning THRESHOLD',
|
87
|
+
proc: proc { |a| a.to_i },
|
88
|
+
default: 30
|
89
|
+
|
90
|
+
option :critical,
|
91
|
+
description: 'Critical TTL Threshold',
|
92
|
+
short: '-c THRESHOLD',
|
93
|
+
long: '--critical THRESHOLD',
|
94
|
+
proc: proc { |a| a.to_i },
|
95
|
+
default: 60
|
96
|
+
|
97
|
+
option :token,
|
98
|
+
description: 'ACL token',
|
99
|
+
long: '--token ACL_TOKEN'
|
100
|
+
|
101
|
+
# Do work
|
102
|
+
def run
|
103
|
+
Diplomat.configure do |dip|
|
104
|
+
dip.url = config[:consul]
|
105
|
+
dip.acl_token = config[:token]
|
106
|
+
end
|
107
|
+
|
108
|
+
begin
|
109
|
+
# Retrieve the kv
|
110
|
+
data = Diplomat::Kv.get(config[:kv])
|
111
|
+
rescue Faraday::ResourceNotFound, Diplomat::KeyNotFound
|
112
|
+
critical %(Key/value pair "#{config[:kv]}" does not exist in Consul.)
|
113
|
+
rescue Diplomat::UnknownStatus => e
|
114
|
+
if e.message.include?('403')
|
115
|
+
critical %(ACL token is not authorized to access "#{config[:kv]}")
|
116
|
+
else
|
117
|
+
critical "Unhandled exception(#{e.class}) -- #{e.message}"
|
118
|
+
end
|
119
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
120
|
+
critical "Unhandled exception(#{e.class}) -- #{e.message}"
|
121
|
+
end
|
122
|
+
|
123
|
+
# Check if the data is JSON or a timestamp
|
124
|
+
if config[:json]
|
125
|
+
begin
|
126
|
+
# Convert the data to JSON
|
127
|
+
json_data = JSON.parse(data)
|
128
|
+
|
129
|
+
# If the status is set add that to the processing chain
|
130
|
+
if config[:status_key]
|
131
|
+
# Dig to the status
|
132
|
+
kv_status = json_data.dig(config[:status_key])
|
133
|
+
|
134
|
+
# Critical if we can not retrieve the status
|
135
|
+
critical "Unable to retrieve status from JSON data: #{data}" if kv_status.nil?
|
136
|
+
|
137
|
+
# Downcase to ease integration
|
138
|
+
kv_status = kv_status.downcase
|
139
|
+
|
140
|
+
# Flag based off of status
|
141
|
+
warning 'Warning status detected!' if %w[warning].include? kv_status
|
142
|
+
critical 'Critical status detected!' if %w[critical unknown].include? kv_status
|
143
|
+
end
|
144
|
+
|
145
|
+
# Dig to the time
|
146
|
+
kv_time = json_data.dig(config[:timestamp_key])
|
147
|
+
|
148
|
+
# Critical if we can not retrieve the time
|
149
|
+
critical "Unable to retrieve time from JSON data: #{data}" if kv_time.nil?
|
150
|
+
rescue JSON::ParserError => e # rubocop:disable Lint/UselessAssignment
|
151
|
+
critical "Unable to parse JSON data: #{data}"
|
152
|
+
end
|
153
|
+
else
|
154
|
+
kv_time = data
|
155
|
+
end
|
156
|
+
|
157
|
+
# Timestamp calculation
|
158
|
+
begin
|
159
|
+
# Convert the time into ISO8601 DateTime object
|
160
|
+
start_time = Time.iso8601(kv_time)
|
161
|
+
|
162
|
+
# Get the current time UTC
|
163
|
+
end_time = Time.now.utc
|
164
|
+
|
165
|
+
# Get diff in seconds between start and end time
|
166
|
+
elapsed_seconds = (end_time - start_time).to_i
|
167
|
+
|
168
|
+
critical "TTL calculation issue -- check date formats -- elapsed seconds is negative(#{elapsed_seconds})" if elapsed_seconds <= -1
|
169
|
+
critical "TTL Expired! Elapsed Time: #{elapsed_seconds}" if elapsed_seconds > config[:critical]
|
170
|
+
warning "TTL Expiration Approaching! Elapsed Time: #{elapsed_seconds}" if elapsed_seconds > config[:warning]
|
171
|
+
ok
|
172
|
+
rescue StandardError
|
173
|
+
critical 'Unable to process DateTime objects!'
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|