sensu-plugins-rabbitmq-temp 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +102 -0
- data/LICENSE +22 -0
- data/README.md +31 -0
- data/bin/check-rabbitmq-alive.rb +109 -0
- data/bin/check-rabbitmq-amqp-alive.rb +119 -0
- data/bin/check-rabbitmq-cluster-health.rb +155 -0
- data/bin/check-rabbitmq-consumers.rb +131 -0
- data/bin/check-rabbitmq-messages.rb +135 -0
- data/bin/check-rabbitmq-network-partitions.rb +82 -0
- data/bin/check-rabbitmq-node-health.rb +204 -0
- data/bin/check-rabbitmq-queue-drain-time.rb +138 -0
- data/bin/check-rabbitmq-queue.rb +131 -0
- data/bin/check-rabbitmq-stomp-alive.rb +109 -0
- data/bin/metrics-rabbitmq-overview.rb +142 -0
- data/bin/metrics-rabbitmq-queue.rb +119 -0
- data/lib/sensu-plugins-rabbitmq.rb +1 -0
- data/lib/sensu-plugins-rabbitmq/version.rb +9 -0
- metadata +306 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8a42ed18facbfdcc6048222e3fdfb447b511fc5f
|
4
|
+
data.tar.gz: f06c0a1e7bf4c37f47fe466e7e3f52a065440a75
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02ec6fb3850b3aa1c5fc41db31ba51fe1727c3b4ec9e876d4015794b5bcbfda08f942a6906006817aa74bf99971633c72d882befcca72bc43cd34ef03ae5f5d8
|
7
|
+
data.tar.gz: deef308af374489b19f9db5ad5e95be3860450a1144bf646e8976b556db2eb12f2a364dff17015fe6eb250ab0ddb9fb307ed0350de1587b29f02a2d534cdddc8
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
#Change Log
|
2
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
3
|
+
|
4
|
+
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
|
+
|
6
|
+
## [Unreleased]
|
7
|
+
|
8
|
+
## [1.4.0] - 2016-07-24
|
9
|
+
### Changed
|
10
|
+
- bump bunny version to 2.5.0
|
11
|
+
- bump amq-protocol version to 2.0.1
|
12
|
+
- drop ruby v1.9.3 support
|
13
|
+
|
14
|
+
## [1.3.0] - 2016-04-13
|
15
|
+
### Added
|
16
|
+
- check-rabbitmq-cluster-health.rb: Added option to provide SSL CA certificate
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
- set dep on sensu-plugin gem to be more relaxed
|
20
|
+
|
21
|
+
## [1.2.0] - 2016-04-13
|
22
|
+
### Added
|
23
|
+
- check-rabbitmq-amqp-alive.rb: Added support for TLS authentication
|
24
|
+
- metrics-rabbitmq-queue.rb: Added option to filter vhost with regular expression
|
25
|
+
- Added option to skip SSL cert checking
|
26
|
+
|
27
|
+
### Fixed
|
28
|
+
- check-rabbitmq-queue.rb: Fix default vhost
|
29
|
+
- check-rabbitmq-queue-drain-time.rb: Fix logging output and filter
|
30
|
+
|
31
|
+
### Changed
|
32
|
+
- Update to rubocop 0.37
|
33
|
+
|
34
|
+
## [1.1.0] - 2015-12-30
|
35
|
+
### Added
|
36
|
+
- check-rabbitmq-queue-drain-time.rb: Added option to filter vhost with regular expression
|
37
|
+
|
38
|
+
## [1.0.0] - 2015-12-01
|
39
|
+
### Fixed
|
40
|
+
- check-rabbitmq-node-health.rb: Fix messages for file descriptor alerts
|
41
|
+
- check-rabbitmq-node-health.rb: Make options unique
|
42
|
+
|
43
|
+
NOTE: this release changes the option flags in check-rabbitmq-node-health.rb to be unique.
|
44
|
+
|
45
|
+
## [0.1.0] - 2015-11-19
|
46
|
+
### Changed
|
47
|
+
- Upgrade to rubocop 0.32.1 and cleanup
|
48
|
+
|
49
|
+
### Added
|
50
|
+
- check-rabbitmq-queue.rb: Added option to ignore non-existent queues
|
51
|
+
- check-rabbitmq-queue.rb: Added vhost support
|
52
|
+
- Added SSL support to check-rabbitmq-cluster-health.rb and check-rabbitmq-node-health.rb
|
53
|
+
|
54
|
+
### Fixed
|
55
|
+
- metrics-rabbitmq-queue.rb: Fix error when queue['messages'] is missing
|
56
|
+
|
57
|
+
## [0.0.4] - 2015-08-18
|
58
|
+
### Changed
|
59
|
+
- pinned amq-protocol
|
60
|
+
|
61
|
+
## [0.0.3] - 2015-07-14
|
62
|
+
### Changed
|
63
|
+
- updated sensu-plugin gem to 1.2.0
|
64
|
+
|
65
|
+
## 0.0.1 - 2015-05-30
|
66
|
+
### Added
|
67
|
+
- Add the ability to monitor all queues in the consumer count plugin
|
68
|
+
- Add ability to exclude specific queues in the consumer count plugin
|
69
|
+
- Added Ruby 2.2.0 to Travis
|
70
|
+
- Added additional node health checks to the check-rabbitmq-node-health.rb plugin
|
71
|
+
- Added development tasks to the Rakefile
|
72
|
+
- Added a Gemfile
|
73
|
+
- Added egress rate to the metrics-rabbitmq-queue.rb plugin
|
74
|
+
- Added encoding comment to each plugin
|
75
|
+
- Added check-rabbitmq-queue-drain-time.rb plugin
|
76
|
+
- Added queue drain time and the number of consumers to the metrics-rabbitmq-queue.rb plugin
|
77
|
+
- Added check-rabbitmq-network-partitions plugin
|
78
|
+
- Added the ability to monitor message count per queue and exclude specific queues in check-rabbitmq-messages.rb
|
79
|
+
|
80
|
+
### Fixed
|
81
|
+
- Nil queue values should be treated as a 0 in the queue drain time plugin
|
82
|
+
- Fixed the critical and warning values to alert when <= not < in check-rabbitmq-consumers.rb
|
83
|
+
|
84
|
+
### Changed
|
85
|
+
- Updated Rubocop to 0.30 and resolved all warnings
|
86
|
+
- Updated the headers to match and use the new template for additional information
|
87
|
+
- Updated class names to match plugin names for better alert messaging
|
88
|
+
- Made all plugins executable
|
89
|
+
|
90
|
+
### Removed
|
91
|
+
- Remove copy paste errors in the Readme
|
92
|
+
- Removed Rubygems require Ruby 1.8.7 backwards compatibility from all plugins
|
93
|
+
|
94
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-rabbitmq/compare/1.3.0...HEAD
|
95
|
+
[1.3.0]: https://github.com/sensu-plugins/sensu-plugins-rabbitmq/compare/1.2.0...1.3.0
|
96
|
+
[1.2.0]: https://github.com/sensu-plugins/sensu-plugins-rabbitmq/compare/1.1.0...1.2.0
|
97
|
+
[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-rabbitmq/compare/1.0.0...1.1.0
|
98
|
+
[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-rabbitmq/compare/0.1.0...1.0.0
|
99
|
+
[0.1.0]: https://github.com/sensu-plugins/sensu-plugins-rabbitmq/compare/0.0.4...0.1.0
|
100
|
+
[0.0.4]: https://github.com/sensu-plugins/sensu-plugins-rabbitmq/compare/0.0.3...0.0.4
|
101
|
+
[0.0.3]: https://github.com/sensu-plugins/sensu-plugins-rabbitmq/compare/0.0.1...0.0.3
|
102
|
+
[0.0.3]: https://github.com/sensu-plugins/sensu-plugins-rabbitmq/compare/0.0.1...0.0.3
|
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,31 @@
|
|
1
|
+
## Sensu-Plugins-rabbitmq
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-rabbitmq.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-rabbitmq)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/sensu-plugins-rabbitmq.svg)](http://badge.fury.io/rb/sensu-plugins-rabbitmq)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-rabbitmq/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-rabbitmq)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-rabbitmq/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-rabbitmq)
|
7
|
+
[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-rabbitmq.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-rabbitmq)
|
8
|
+
|
9
|
+
## Functionality
|
10
|
+
|
11
|
+
## Files
|
12
|
+
* bin/check-rabbitmq-alive.rb
|
13
|
+
* bin/check-rabbitmq-amqp-alive.rb
|
14
|
+
* bin/check-rabbitmq-cluster-health.rb
|
15
|
+
* bin/check-rabbitmq-consumers.rb
|
16
|
+
* bin/check-rabbitmq-messages.rb
|
17
|
+
* bin/check-rabbitmq-network-partitions.rb
|
18
|
+
* bin/check-rabbitmq-node-health.rb
|
19
|
+
* bin/check-rabbitmq-queue-drain-time.rb
|
20
|
+
* bin/check-rabbitmq-queue.rb
|
21
|
+
* bin/check-rabbitmq-stomp-alive.rb
|
22
|
+
* bin/metrics-rabbitmq-overview.rb
|
23
|
+
* bin/metrics-rabbitmq-queue.rb
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
30
|
+
|
31
|
+
## Notes
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# RabbitMQ check alive plugin
|
5
|
+
# ===
|
6
|
+
#
|
7
|
+
# DESCRIPTION:
|
8
|
+
# This plugin checks if RabbitMQ server is alive using the REST API
|
9
|
+
#
|
10
|
+
# PLATFORMS:
|
11
|
+
# Linux, Windows, BSD, Solaris
|
12
|
+
#
|
13
|
+
# DEPENDENCIES:
|
14
|
+
# RabbitMQ rabbitmq_management plugin
|
15
|
+
# gem: sensu-plugin
|
16
|
+
# gem: rest-client
|
17
|
+
#
|
18
|
+
# LICENSE:
|
19
|
+
# Copyright 2012 Abhijith G <abhi@runa.com> and Runa Inc.
|
20
|
+
#
|
21
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
22
|
+
# for details.
|
23
|
+
|
24
|
+
require 'sensu-plugin/check/cli'
|
25
|
+
require 'json'
|
26
|
+
require 'rest_client'
|
27
|
+
|
28
|
+
# main plugin class
|
29
|
+
class CheckRabbitMQAlive < Sensu::Plugin::Check::CLI
|
30
|
+
option :host,
|
31
|
+
description: 'RabbitMQ host',
|
32
|
+
short: '-w',
|
33
|
+
long: '--host HOST',
|
34
|
+
default: 'localhost'
|
35
|
+
|
36
|
+
option :vhost,
|
37
|
+
description: 'RabbitMQ vhost',
|
38
|
+
short: '-v',
|
39
|
+
long: '--vhost VHOST',
|
40
|
+
default: '%2F'
|
41
|
+
|
42
|
+
option :username,
|
43
|
+
description: 'RabbitMQ username',
|
44
|
+
short: '-u',
|
45
|
+
long: '--username USERNAME',
|
46
|
+
default: 'guest'
|
47
|
+
|
48
|
+
option :password,
|
49
|
+
description: 'RabbitMQ password',
|
50
|
+
short: '-p',
|
51
|
+
long: '--password PASSWORD',
|
52
|
+
default: 'guest'
|
53
|
+
|
54
|
+
option :port,
|
55
|
+
description: 'RabbitMQ API port',
|
56
|
+
short: '-P',
|
57
|
+
long: '--port PORT',
|
58
|
+
default: '15672'
|
59
|
+
|
60
|
+
option :ssl,
|
61
|
+
description: 'Enable SSL for connection to RabbitMQ',
|
62
|
+
long: '--ssl',
|
63
|
+
boolean: true,
|
64
|
+
default: false
|
65
|
+
|
66
|
+
option :verify_ssl_off,
|
67
|
+
description: 'Do not check validity of SSL cert. Use for self-signed certs, etc (insecure)',
|
68
|
+
long: '--verify_ssl_off',
|
69
|
+
boolean: true,
|
70
|
+
default: false
|
71
|
+
|
72
|
+
def run
|
73
|
+
res = vhost_alive?
|
74
|
+
|
75
|
+
if res['status'] == 'ok'
|
76
|
+
ok res['message']
|
77
|
+
elsif res['status'] == 'critical'
|
78
|
+
critical res['message']
|
79
|
+
else
|
80
|
+
unknown res['message']
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def vhost_alive?
|
85
|
+
host = config[:host]
|
86
|
+
port = config[:port]
|
87
|
+
username = config[:username]
|
88
|
+
password = config[:password]
|
89
|
+
vhost = config[:vhost]
|
90
|
+
ssl = config[:ssl]
|
91
|
+
verify_ssl = config[:verify_ssl_off]
|
92
|
+
|
93
|
+
begin
|
94
|
+
resource = RestClient::Resource.new(
|
95
|
+
"http#{ssl ? 's' : ''}://#{host}:#{port}/api/aliveness-test/#{vhost}",
|
96
|
+
user: username,
|
97
|
+
password: password,
|
98
|
+
verify_ssl: !verify_ssl
|
99
|
+
)
|
100
|
+
# Attempt to parse response (just to trigger parse exception)
|
101
|
+
_response = JSON.parse(resource.get) == { 'status' => 'ok' }
|
102
|
+
{ 'status' => 'ok', 'message' => 'RabbitMQ server is alive' }
|
103
|
+
rescue Errno::ECONNREFUSED => e
|
104
|
+
{ 'status' => 'critical', 'message' => e.message }
|
105
|
+
rescue => e
|
106
|
+
{ 'status' => 'unknown', 'message' => e.message }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# RabbitMQ check amqp alive plugin
|
5
|
+
# ===
|
6
|
+
#
|
7
|
+
# DESCRIPTION:
|
8
|
+
# This plugin checks if RabbitMQ server is alive using AMQP
|
9
|
+
#
|
10
|
+
# PLATFORMS:
|
11
|
+
# Linux, BSD, Solaris
|
12
|
+
#
|
13
|
+
# DEPENDENCIES:
|
14
|
+
# gem: sensu-plugin
|
15
|
+
# gem: bunny
|
16
|
+
#
|
17
|
+
# LICENSE:
|
18
|
+
# Copyright 2013 Milos Gajdos
|
19
|
+
#
|
20
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
21
|
+
# for details.
|
22
|
+
|
23
|
+
require 'sensu-plugin/check/cli'
|
24
|
+
require 'bunny'
|
25
|
+
|
26
|
+
# main plugin class
|
27
|
+
class CheckRabbitAMQPAlive < Sensu::Plugin::Check::CLI
|
28
|
+
option :host,
|
29
|
+
description: 'RabbitMQ host',
|
30
|
+
short: '-w',
|
31
|
+
long: '--host HOST',
|
32
|
+
default: 'localhost'
|
33
|
+
|
34
|
+
option :vhost,
|
35
|
+
description: 'RabbitMQ vhost',
|
36
|
+
short: '-v',
|
37
|
+
long: '--vhost VHOST',
|
38
|
+
default: '%2F'
|
39
|
+
|
40
|
+
option :username,
|
41
|
+
description: 'RabbitMQ username',
|
42
|
+
short: '-u',
|
43
|
+
long: '--username USERNAME',
|
44
|
+
default: 'guest'
|
45
|
+
|
46
|
+
option :password,
|
47
|
+
description: 'RabbitMQ password',
|
48
|
+
short: '-p',
|
49
|
+
long: '--password PASSWORD',
|
50
|
+
default: 'guest'
|
51
|
+
|
52
|
+
option :port,
|
53
|
+
description: 'RabbitMQ AMQP port',
|
54
|
+
short: '-P',
|
55
|
+
long: '--port PORT',
|
56
|
+
default: '5672'
|
57
|
+
|
58
|
+
option :ssl,
|
59
|
+
description: 'Enable SSL for connection to RabbitMQ',
|
60
|
+
long: '--ssl',
|
61
|
+
boolean: true,
|
62
|
+
default: false
|
63
|
+
|
64
|
+
option :tls_cert,
|
65
|
+
description: 'TLS Certificate to use when connecting',
|
66
|
+
long: '--tls-cert CERT',
|
67
|
+
default: nil
|
68
|
+
|
69
|
+
option :tls_key,
|
70
|
+
description: 'TLS Private Key to use when connecting',
|
71
|
+
long: '--tls-key KEY',
|
72
|
+
default: nil
|
73
|
+
|
74
|
+
option :no_verify_peer,
|
75
|
+
description: 'Disable peer verification',
|
76
|
+
long: '--no-verify-peer',
|
77
|
+
boolean: true,
|
78
|
+
default: true
|
79
|
+
|
80
|
+
def run
|
81
|
+
res = vhost_alive?
|
82
|
+
|
83
|
+
if res['status'] == 'ok'
|
84
|
+
ok res['message']
|
85
|
+
elsif res['status'] == 'critical'
|
86
|
+
critical res['message']
|
87
|
+
else
|
88
|
+
unknown res['message']
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def vhost_alive?
|
93
|
+
host = config[:host]
|
94
|
+
port = config[:port]
|
95
|
+
username = config[:username]
|
96
|
+
password = config[:password]
|
97
|
+
vhost = config[:vhost]
|
98
|
+
ssl = config[:ssl]
|
99
|
+
tls_cert = config[:tls_cert]
|
100
|
+
tls_key = config[:tls_key]
|
101
|
+
no_verify_peer = config[:no_verify_peer]
|
102
|
+
|
103
|
+
begin
|
104
|
+
conn = Bunny.new("amqp#{ssl ? 's' : ''}://#{username}:#{password}@#{host}:#{port}/#{vhost}",
|
105
|
+
tls_cert: tls_cert,
|
106
|
+
tls_key: tls_key,
|
107
|
+
verify_peer: no_verify_peer)
|
108
|
+
conn.start
|
109
|
+
conn.close if conn.connected?
|
110
|
+
{ 'status' => 'ok', 'message' => 'RabbitMQ server is alive' }
|
111
|
+
rescue Bunny::PossibleAuthenticationFailureError
|
112
|
+
{ 'status' => 'critical', 'message' => 'Possible authentication failure' }
|
113
|
+
rescue Bunny::TCPConnectionFailed
|
114
|
+
{ 'status' => 'critical', 'message' => 'TCP connection refused' }
|
115
|
+
rescue => e
|
116
|
+
{ 'status' => 'unknown', 'message' => e.message }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# RabbitMQ check cluster nodes health plugin
|
5
|
+
# ===
|
6
|
+
#
|
7
|
+
# DESCRIPTION:
|
8
|
+
# This plugin checks if RabbitMQ server's cluster nodes are in a running state.
|
9
|
+
# It also accepts and optional list of nodes and verifies that those nodes are
|
10
|
+
# present in the cluster.
|
11
|
+
# The plugin is based on the RabbitMQ alive plugin by Abhijith G.
|
12
|
+
#
|
13
|
+
# PLATFORMS:
|
14
|
+
# Linux, Windows, BSD, Solaris
|
15
|
+
#
|
16
|
+
# DEPENDENCIES:
|
17
|
+
# RabbitMQ rabbitmq_management plugin
|
18
|
+
# gem: sensu-plugin
|
19
|
+
# gem: rest-client
|
20
|
+
#
|
21
|
+
# LICENSE:
|
22
|
+
# Copyright 2012 Abhijith G <abhi@runa.com> and Runa Inc.
|
23
|
+
# Copyright 2014 Tim Smith <tim@cozy.co> and Cozy Services Ltd.
|
24
|
+
#
|
25
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
26
|
+
# for details.
|
27
|
+
|
28
|
+
require 'sensu-plugin/check/cli'
|
29
|
+
require 'json'
|
30
|
+
require 'rest_client'
|
31
|
+
|
32
|
+
# main plugin class
|
33
|
+
class CheckRabbitMQCluster < Sensu::Plugin::Check::CLI
|
34
|
+
option :host,
|
35
|
+
description: 'RabbitMQ host',
|
36
|
+
short: '-w',
|
37
|
+
long: '--host HOST',
|
38
|
+
default: 'localhost'
|
39
|
+
|
40
|
+
option :username,
|
41
|
+
description: 'RabbitMQ username',
|
42
|
+
short: '-u',
|
43
|
+
long: '--username USERNAME',
|
44
|
+
default: 'guest'
|
45
|
+
|
46
|
+
option :password,
|
47
|
+
description: 'RabbitMQ password',
|
48
|
+
short: '-p',
|
49
|
+
long: '--password PASSWORD',
|
50
|
+
default: 'guest'
|
51
|
+
|
52
|
+
option :port,
|
53
|
+
description: 'RabbitMQ API port',
|
54
|
+
short: '-P',
|
55
|
+
long: '--port PORT',
|
56
|
+
default: '15672'
|
57
|
+
|
58
|
+
option :nodes,
|
59
|
+
description: 'Optional comma separated list of expected nodes in the cluster',
|
60
|
+
short: '-n',
|
61
|
+
long: '--nodes NODE1,NODE2',
|
62
|
+
default: ''
|
63
|
+
|
64
|
+
option :ssl,
|
65
|
+
description: 'Enable SSL for connection to the API',
|
66
|
+
long: '--ssl',
|
67
|
+
boolean: true,
|
68
|
+
default: false
|
69
|
+
|
70
|
+
option :verify_ssl_off,
|
71
|
+
description: 'Do not check validity of SSL cert. Use for self-signed certs, etc (insecure)',
|
72
|
+
long: '--verify_ssl_off',
|
73
|
+
boolean: true,
|
74
|
+
default: false
|
75
|
+
|
76
|
+
option :ssl_ca_file,
|
77
|
+
description: 'Path to SSL CA .crt',
|
78
|
+
long: '--ssl_ca_file CA_PATH',
|
79
|
+
default: ''
|
80
|
+
|
81
|
+
def run
|
82
|
+
res = cluster_healthy?
|
83
|
+
|
84
|
+
if res['status'] == 'ok'
|
85
|
+
ok res['message']
|
86
|
+
elsif res['status'] == 'critical'
|
87
|
+
critical res['message']
|
88
|
+
else
|
89
|
+
unknown res['message']
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def missing_nodes?(nodes, servers_status)
|
94
|
+
missing = []
|
95
|
+
if nodes.empty?
|
96
|
+
missing
|
97
|
+
else
|
98
|
+
nodes.reject { |x| servers_status.keys.include?(x) }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def failed_nodes?(servers_status)
|
103
|
+
failed_nodes = []
|
104
|
+
servers_status.each { |sv, stat| failed_nodes << sv unless stat == true }
|
105
|
+
failed_nodes
|
106
|
+
end
|
107
|
+
|
108
|
+
def cluster_healthy?
|
109
|
+
host = config[:host]
|
110
|
+
port = config[:port]
|
111
|
+
username = config[:username]
|
112
|
+
password = config[:password]
|
113
|
+
ssl = config[:ssl]
|
114
|
+
verify_ssl = config[:verify_ssl_off]
|
115
|
+
nodes = config[:nodes].split(',')
|
116
|
+
ssl_ca_file = config[:ssl_ca_file]
|
117
|
+
|
118
|
+
begin
|
119
|
+
url_prefix = ssl ? 'https' : 'http'
|
120
|
+
options = {
|
121
|
+
user: username,
|
122
|
+
password: password,
|
123
|
+
verify_ssl: !verify_ssl
|
124
|
+
}
|
125
|
+
options[:ssl_ca_file] = ssl_ca_file unless ssl_ca_file.empty?
|
126
|
+
|
127
|
+
resource = RestClient::Resource.new(
|
128
|
+
"#{url_prefix}://#{host}:#{port}/api/nodes",
|
129
|
+
options
|
130
|
+
)
|
131
|
+
# create a hash of the server names and their running state
|
132
|
+
servers_status = Hash[JSON.parse(resource.get).map { |server| [server['name'], server['running']] }]
|
133
|
+
|
134
|
+
# true or false for health of the nodes
|
135
|
+
missing_nodes = missing_nodes?(nodes, servers_status)
|
136
|
+
|
137
|
+
# array of nodes that are not running
|
138
|
+
failed_nodes = failed_nodes?(servers_status)
|
139
|
+
|
140
|
+
# build status and message
|
141
|
+
status = failed_nodes.empty? && missing_nodes.empty? ? 'ok' : 'critical'
|
142
|
+
message = if failed_nodes.empty?
|
143
|
+
"#{servers_status.keys.count} healthy cluster nodes"
|
144
|
+
else
|
145
|
+
"#{failed_nodes.count} failed cluster node: #{failed_nodes.sort.join(',')}"
|
146
|
+
end
|
147
|
+
message.prepend("#{missing_nodes.count} node(s) not found: #{missing_nodes.join(',')}. ") unless missing_nodes.empty?
|
148
|
+
{ 'status' => status, 'message' => message }
|
149
|
+
rescue Errno::ECONNREFUSED => e
|
150
|
+
{ 'status' => 'critical', 'message' => e.message }
|
151
|
+
rescue => e
|
152
|
+
{ 'status' => 'unknown', 'message' => e.message }
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|