sensu-plugins-rabbitmq 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3938fc8f1c33be6ee3f1ced513960928dc62e09
4
+ data.tar.gz: 17e8e359a42996896ff54693c34d6c8ccc21498e
5
+ SHA512:
6
+ metadata.gz: dc59629127f1d646280538bca55bd3cbf6a0299eaab77fbd4153bfbcbd9b3751a04bc27a930a0a13e6b0c536c93e6e3682e09967ee3ff8c55433bf8b75af869d
7
+ data.tar.gz: d793e6f461d8dc98380d47e1e748e2feadea26df87386e456759ac19215b21cc2b733953a3bc53638de393166e9bbdbd51a64f3dfa397bdd8e6e0262e744c315
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ X��W8��)~,�&F99%�1P:� �������i[%�^��o�;>%J��nߟm9��}&��sW8H%�t�M~b�Ҩ���N��*I����-�
data/CHANGELOG.md ADDED
@@ -0,0 +1,35 @@
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][unreleased]
7
+
8
+ ## 0.0.1 - 2015-05-30
9
+
10
+ ### Added
11
+ - Add the ability to monitor all queues in the consumer count plugin
12
+ - Add ability to exclude specific queues in the consumer count plugin
13
+ - Added Ruby 2.2.0 to Travis
14
+ - Added additional node health checks to the check-rabbitmq-node-health.rb plugin
15
+ - Added development tasks to the Rakefile
16
+ - Added a Gemfile
17
+ - Added egress rate to the metrics-rabbitmq-queue.rb plugin
18
+ - Added encoding comment to each plugin
19
+ - Added check-rabbitmq-queue-drain-time.rb plugin
20
+ - Added queue drain time and the number of consumers to the metrics-rabbitmq-queue.rb plugin
21
+ - Added check-rabbitmq-network-partitions plugin
22
+ - Added the ability to monitor message count per queue and exclude specific queues in check-rabbitmq-messages.rb
23
+
24
+ ### Fixed
25
+ - Fixed the critical and warning values to alert when <= not < in check-rabbitmq-consumers.rb
26
+
27
+ ### Changed
28
+ - Updated Rubocop to 0.30 and resolved all warnings
29
+ - Updated the headers to match and use the new template for additional information
30
+ - Updated class names to match plugin names for better alert messaging
31
+ - Made all plugins executable
32
+
33
+ ### Removed
34
+ - Remove copy paste errors in the Readme
35
+ - Removed Rubygems require Ruby 1.8.7 backwards compatibility from all plugins
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,32 @@
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
+ [![Codeship Status for sensu-plugins/sensu-plugins-rabbitmq](https://codeship.com/projects/524c57f0-e89b-0132-b373-0e94167ad564/status?branch=master)](https://codeship.com/projects/82842)
9
+
10
+ ## Functionality
11
+
12
+ ## Files
13
+ * bin/check-rabbitmq-alive.rb
14
+ * bin/check-rabbitmq-amqp-alive.rb
15
+ * bin/check-rabbitmq-cluster-health.rb
16
+ * bin/check-rabbitmq-consumers.rb
17
+ * bin/check-rabbitmq-messages.rb
18
+ * bin/check-rabbitmq-network-partitions.rb
19
+ * bin/check-rabbitmq-node-health.rb
20
+ * bin/check-rabbitmq-queue-drain-time.rb
21
+ * bin/check-rabbitmq-queue.rb
22
+ * bin/check-rabbitmq-stomp-alive.rb
23
+ * bin/metrics-rabbitmq-overview.rb
24
+ * bin/metrics-rabbitmq-queue.rb
25
+
26
+ ## Usage
27
+
28
+ ## Installation
29
+
30
+ [Installation and Setup](https://github.com/sensu-plugins/documentation/blob/master/user_docs/installation_instructions.md)
31
+
32
+ ## Notes
@@ -0,0 +1,97 @@
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
+ def run
67
+ res = vhost_alive?
68
+
69
+ if res['status'] == 'ok'
70
+ ok res['message']
71
+ elsif res['status'] == 'critical'
72
+ critical res['message']
73
+ else
74
+ unknown res['message']
75
+ end
76
+ end
77
+
78
+ def vhost_alive?
79
+ host = config[:host]
80
+ port = config[:port]
81
+ username = config[:username]
82
+ password = config[:password]
83
+ vhost = config[:vhost]
84
+ ssl = config[:ssl]
85
+
86
+ begin
87
+ resource = RestClient::Resource.new "http#{ssl ? 's' : ''}://#{host}:#{port}/api/aliveness-test/#{vhost}", username, password
88
+ # Attempt to parse response (just to trigger parse exception)
89
+ _response = JSON.parse(resource.get) == { 'status' => 'ok' }
90
+ { 'status' => 'ok', 'message' => 'RabbitMQ server is alive' }
91
+ rescue Errno::ECONNREFUSED => e
92
+ { 'status' => 'critical', 'message' => e.message }
93
+ rescue => e
94
+ { 'status' => 'unknown', 'message' => e.message }
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,97 @@
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 the REST API
9
+ #
10
+ # PLATFORMS:
11
+ # Linux, BSD, Solaris
12
+ #
13
+ # DEPENDENCIES:
14
+ # RabbitMQ rabbitmq_management plugin
15
+ # gem: sensu-plugin
16
+ # gem: bunny
17
+ #
18
+ # LICENSE:
19
+ # Copyright 2013 Milos Gajdos
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 'bunny'
26
+
27
+ # main plugin class
28
+ class CheckRabbitAMQPAlive < Sensu::Plugin::Check::CLI
29
+ option :host,
30
+ description: 'RabbitMQ host',
31
+ short: '-w',
32
+ long: '--host HOST',
33
+ default: 'localhost'
34
+
35
+ option :vhost,
36
+ description: 'RabbitMQ vhost',
37
+ short: '-v',
38
+ long: '--vhost VHOST',
39
+ default: '%2F'
40
+
41
+ option :username,
42
+ description: 'RabbitMQ username',
43
+ short: '-u',
44
+ long: '--username USERNAME',
45
+ default: 'guest'
46
+
47
+ option :password,
48
+ description: 'RabbitMQ password',
49
+ short: '-p',
50
+ long: '--password PASSWORD',
51
+ default: 'guest'
52
+
53
+ option :port,
54
+ description: 'RabbitMQ AMQP port',
55
+ short: '-P',
56
+ long: '--port PORT',
57
+ default: '5672'
58
+
59
+ option :ssl,
60
+ description: 'Enable SSL for connection to RabbitMQ',
61
+ long: '--ssl',
62
+ boolean: true,
63
+ default: false
64
+
65
+ def run
66
+ res = vhost_alive?
67
+
68
+ if res['status'] == 'ok'
69
+ ok res['message']
70
+ elsif res['status'] == 'critical'
71
+ critical res['message']
72
+ else
73
+ unknown res['message']
74
+ end
75
+ end
76
+
77
+ def vhost_alive?
78
+ host = config[:host]
79
+ port = config[:port]
80
+ username = config[:username]
81
+ password = config[:password]
82
+ vhost = config[:vhost]
83
+ ssl = config[:ssl]
84
+
85
+ begin
86
+ conn = Bunny.new("amqp#{ssl ? 's' : ''}://#{username}:#{password}@#{host}:#{port}/#{vhost}")
87
+ conn.start
88
+ { 'status' => 'ok', 'message' => 'RabbitMQ server is alive' }
89
+ rescue Bunny::PossibleAuthenticationFailureError
90
+ { 'status' => 'critical', 'message' => 'Possible authentication failure' }
91
+ rescue Bunny::TCPConnectionFailed
92
+ { 'status' => 'critical', 'message' => 'TCP connection refused' }
93
+ rescue => e
94
+ { 'status' => 'unknown', 'message' => e.message }
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,124 @@
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
+ def run
65
+ res = cluster_healthy?
66
+
67
+ if res['status'] == 'ok'
68
+ ok res['message']
69
+ elsif res['status'] == 'critical'
70
+ critical res['message']
71
+ else
72
+ unknown res['message']
73
+ end
74
+ end
75
+
76
+ def missing_nodes?(nodes, servers_status)
77
+ missing = []
78
+ if nodes.empty?
79
+ missing
80
+ else
81
+ nodes.reject { |x| servers_status.keys.include?(x) }
82
+ end
83
+ end
84
+
85
+ def failed_nodes?(servers_status)
86
+ failed_nodes = []
87
+ servers_status.each { |sv, stat| failed_nodes << sv unless stat == true }
88
+ failed_nodes
89
+ end
90
+
91
+ def cluster_healthy?
92
+ host = config[:host]
93
+ port = config[:port]
94
+ username = config[:username]
95
+ password = config[:password]
96
+ nodes = config[:nodes].split(',')
97
+
98
+ begin
99
+ resource = RestClient::Resource.new "http://#{host}:#{port}/api/nodes", username, password
100
+ # create a hash of the server names and their running state
101
+ servers_status = Hash[JSON.parse(resource.get).map { |server| [server['name'], server['running']] }]
102
+
103
+ # true or false for health of the nodes
104
+ missing_nodes = missing_nodes?(nodes, servers_status)
105
+
106
+ # array of nodes that are not running
107
+ failed_nodes = failed_nodes?(servers_status)
108
+
109
+ # build status and message
110
+ status = failed_nodes.empty? && missing_nodes.empty? ? 'ok' : 'critical'
111
+ if failed_nodes.empty?
112
+ message = "#{servers_status.keys.count} healthy cluster nodes"
113
+ else
114
+ message = "#{failed_nodes.count} failed cluster node: #{failed_nodes.sort.join(',')}"
115
+ end
116
+ message.prepend("#{missing_nodes.count } node(s) not found: #{missing_nodes.join(',')}. ") unless missing_nodes.empty?
117
+ { 'status' => status, 'message' => message }
118
+ rescue Errno::ECONNREFUSED => e
119
+ { 'status' => 'critical', 'message' => e.message }
120
+ rescue => e
121
+ { 'status' => 'unknown', 'message' => e.message }
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # Check RabbitMQ consumers
5
+ # ===
6
+ #
7
+ # DESCRIPTION:
8
+ # This plugin checks the number of consumers on the RabbitMQ server
9
+ #
10
+ # PLATFORMS:
11
+ # Linux, BSD, Solaris
12
+ #
13
+ # DEPENDENCIES:
14
+ # RabbitMQ rabbitmq_management plugin
15
+ # gem: sensu-plugin
16
+ # gem: carrot-top
17
+ #
18
+ # LICENSE:
19
+ # Copyright 2014 Daniel Kerwin <d.kerwin@gini.net>
20
+ # Copyright 2014 Tim Smith <tim@cozy.co>
21
+ #
22
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
23
+ # for details.
24
+
25
+ require 'sensu-plugin/check/cli'
26
+ require 'carrot-top'
27
+
28
+ # main plugin class
29
+ class CheckRabbitMQConsumers < Sensu::Plugin::Check::CLI
30
+ option :host,
31
+ description: 'RabbitMQ management API host',
32
+ long: '--host HOST',
33
+ default: 'localhost'
34
+
35
+ option :port,
36
+ description: 'RabbitMQ management API port',
37
+ long: '--port PORT',
38
+ proc: proc(&:to_i),
39
+ default: 15_672
40
+
41
+ option :ssl,
42
+ description: 'Enable SSL for connection to the API',
43
+ long: '--ssl',
44
+ boolean: true,
45
+ default: false
46
+
47
+ option :user,
48
+ description: 'RabbitMQ management API user',
49
+ long: '--user USER',
50
+ default: 'guest'
51
+
52
+ option :password,
53
+ description: 'RabbitMQ management API password',
54
+ long: '--password PASSWORD',
55
+ default: 'guest'
56
+
57
+ option :queue,
58
+ description: 'Comma separated list of RabbitMQ queues to monitor.',
59
+ long: '--queue queue_name',
60
+ proc: proc { |q| q.split(',') }
61
+
62
+ option :exclude,
63
+ description: 'Comma separated list of RabbitMQ queues to NOT monitor. All others will be monitored.',
64
+ long: '--exclude queue_name',
65
+ proc: proc { |q| q.split(',') }
66
+
67
+ option :warn,
68
+ short: '-w NUM_CONSUMERS',
69
+ long: '--warn NUM_CONSUMERS',
70
+ proc: proc(&:to_i),
71
+ description: 'WARNING consumer count threshold',
72
+ default: 5
73
+
74
+ option :critical,
75
+ short: '-c NUM_CONSUMERS',
76
+ long: '--critical NUM_CONSUMERS',
77
+ description: 'CRITICAL consumer count threshold',
78
+ proc: proc(&:to_i),
79
+ default: 2
80
+
81
+ def rabbit
82
+ begin
83
+ connection = CarrotTop.new(
84
+ host: config[:host],
85
+ port: config[:port],
86
+ user: config[:user],
87
+ password: config[:password],
88
+ ssl: config[:ssl]
89
+ )
90
+ rescue
91
+ warning 'could not connect to rabbitmq'
92
+ end
93
+ connection
94
+ end
95
+
96
+ def return_condition(missing, critical, warning)
97
+ if critical.count > 0 || missing.count > 0
98
+ message = ''
99
+ message << "Queues in critical state: #{critical.join(', ')}. " if critical.count > 0
100
+ message << "Queues missing: #{missing.join(', ')}" if missing.count > 0
101
+ critical(message)
102
+ elsif warning.count > 0
103
+ warning("Queues in warning state: #{warning.join(', ')}")
104
+ else
105
+ ok
106
+ end
107
+ end
108
+
109
+ def run
110
+ # create arrays to hold failures
111
+ missing = config[:queue] || []
112
+ critical = []
113
+ warn = []
114
+
115
+ rabbit.queues.each do |queue|
116
+ # if specific queues were passed only monitor those.
117
+ # if specific queues to exclude were passed then skip those
118
+ if config[:queue]
119
+ next unless config[:queue].include?(queue['name'])
120
+ elsif config[:exclude]
121
+ next if config[:exclude].include?(queue['name'])
122
+ end
123
+ missing.delete(queue['name'])
124
+ consumers = queue['consumers']
125
+ critical.push(queue['name']) if consumers <= config[:critical]
126
+ warn.push(queue['name']) if consumers <= config[:warn]
127
+ end
128
+
129
+ return_condition(missing, critical, warn)
130
+ end
131
+ end