sensu-plugins-rabbitmq-temp 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # Check RabbitMQ Messages
5
+ # ===
6
+ #
7
+ # DESCRIPTION:
8
+ # This plugin checks the total number of messages queued 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 2012 Evan Hazlett <ejhazlett@gmail.com>
20
+ # Copyright 2015 Tim Smith <tim@cozy.co> and Cozy Services Ltd.
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 'socket'
27
+ require 'carrot-top'
28
+
29
+ # main plugin class
30
+ class CheckRabbitMQMessages < Sensu::Plugin::Check::CLI
31
+ option :host,
32
+ description: 'RabbitMQ management API host',
33
+ long: '--host HOST',
34
+ default: 'localhost'
35
+
36
+ option :port,
37
+ description: 'RabbitMQ management API port',
38
+ long: '--port PORT',
39
+ proc: proc(&:to_i),
40
+ default: 15_672
41
+
42
+ option :user,
43
+ description: 'RabbitMQ management API user',
44
+ long: '--user USER',
45
+ default: 'guest'
46
+
47
+ option :password,
48
+ description: 'RabbitMQ management API password',
49
+ long: '--password PASSWORD',
50
+ default: 'guest'
51
+
52
+ option :ssl,
53
+ description: 'Enable SSL for connection to the API',
54
+ long: '--ssl',
55
+ boolean: true,
56
+ default: false
57
+
58
+ option :warn,
59
+ short: '-w NUM_MESSAGES',
60
+ long: '--warn NUM_MESSAGES',
61
+ description: 'WARNING message count threshold',
62
+ default: 250
63
+
64
+ option :critical,
65
+ short: '-c NUM_MESSAGES',
66
+ long: '--critical NUM_MESSAGES',
67
+ description: 'CRITICAL message count threshold',
68
+ default: 500
69
+
70
+ option :queuelevel,
71
+ short: '-q',
72
+ long: '--queuelevel',
73
+ description: 'Monitors that no individual queue is above the thresholds specified'
74
+
75
+ option :excluded,
76
+ short: '-e queue_name',
77
+ long: '--excludedqueues queue_name',
78
+ description: 'Comma separated list of queues to exclude when using queue level monitoring',
79
+ proc: proc { |q| q.split(',') },
80
+ default: []
81
+
82
+ def generate_message(status_hash)
83
+ message = []
84
+ status_hash.each_pair do |k, v|
85
+ message << "#{k}: #{v}"
86
+ end
87
+ message.join(', ')
88
+ end
89
+
90
+ def acquire_rabbitmq_info
91
+ begin
92
+ rabbitmq_info = CarrotTop.new(
93
+ host: config[:host],
94
+ port: config[:port],
95
+ user: config[:user],
96
+ password: config[:password],
97
+ ssl: config[:ssl]
98
+ )
99
+ rescue
100
+ warning 'Could not connect to rabbitmq'
101
+ end
102
+ rabbitmq_info
103
+ end
104
+
105
+ def run
106
+ rabbitmq = acquire_rabbitmq_info
107
+
108
+ # monitor counts in each queue or monitor the total number of messages in the system
109
+ if config[:queuelevel]
110
+ warn_queues = {}
111
+ crit_queues = {}
112
+ rabbitmq.queues.each do |queue|
113
+ next if config[:excluded].include?(queue['name'])
114
+ queue['messages'] ||= 0
115
+ if queue['messages'] >= config[:critical].to_i
116
+ crit_queues[(queue['name']).to_s] = queue['messages']
117
+ next
118
+ end
119
+ if queue['messages'] >= config[:warn].to_i
120
+ warn_queues[(queue['name']).to_s] = queue['messages']
121
+ next
122
+ end
123
+ end
124
+ message crit_queues.empty? ? generate_message(warn_queues) : generate_message(crit_queues)
125
+ critical unless crit_queues.empty?
126
+ warning unless warn_queues.empty?
127
+ else
128
+ total = rabbitmq.overview['queue_totals']['messages']
129
+ message total.to_s
130
+ critical if total > config[:critical].to_i
131
+ warning if total > config[:warn].to_i
132
+ end
133
+ ok
134
+ end
135
+ end
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # RabbitMQ Network Partitions Check
5
+ # ===
6
+ #
7
+ # DESCRIPTION:
8
+ # This plugin checks if a RabbitMQ network partition has occured.
9
+ # https://www.rabbitmq.com/partitions.html
10
+ #
11
+ # PLATFORMS:
12
+ # Linux, BSD, Solaris
13
+ #
14
+ # DEPENDENCIES:
15
+ # RabbitMQ rabbitmq_management plugin
16
+ # gem: sensu-plugin
17
+ # gem: carrot-top
18
+ #
19
+ # LICENSE:
20
+ # Copyright 2015 Ed Robinson <ed@reevoo.com> and Reevoo LTD.
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 CheckRabbitMQPartitions < Sensu::Plugin::Check::CLI
30
+ option :host,
31
+ description: 'RabbitMQ management API host',
32
+ short: '-w',
33
+ long: '--host HOST',
34
+ default: 'localhost'
35
+
36
+ option :port,
37
+ description: 'RabbitMQ management API port',
38
+ long: '--port PORT',
39
+ proc: proc(&:to_i),
40
+ default: 15_672
41
+
42
+ option :username,
43
+ description: 'RabbitMQ management API user',
44
+ short: '-u',
45
+ long: '--username USERNAME',
46
+ default: 'guest'
47
+
48
+ option :password,
49
+ description: 'RabbitMQ management API password',
50
+ short: '-p',
51
+ long: '--password PASSWORD',
52
+ default: 'guest'
53
+
54
+ option :ssl,
55
+ description: 'Enable SSL for connection to the API',
56
+ long: '--ssl',
57
+ boolean: true,
58
+ default: false
59
+
60
+ def run
61
+ critical 'network partition detected' if partition?
62
+ ok 'no network partition detected'
63
+ rescue Errno::ECONNREFUSED => e
64
+ critical e.message
65
+ rescue => e
66
+ unknown e.message
67
+ end
68
+
69
+ def partition?
70
+ rabbitmq_management.nodes.map { |node| node['partitions'] }.any?(&:any?)
71
+ end
72
+
73
+ def rabbitmq_management
74
+ CarrotTop.new(
75
+ host: config[:host],
76
+ port: config[:port],
77
+ user: config[:username],
78
+ password: config[:password],
79
+ ssl: config[:ssl]
80
+ )
81
+ end
82
+ end
@@ -0,0 +1,204 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ #
4
+ # RabbitMQ check node health plugin
5
+ # ===
6
+ #
7
+ # DESCRIPTION:
8
+ # This plugin checks if RabbitMQ server node is in a running state.
9
+ #
10
+ # The plugin is based on the RabbitMQ cluster node health plugin by Tim Smith
11
+ #
12
+ # PLATFORMS:
13
+ # Linux, Windows, BSD, Solaris
14
+ #
15
+ # DEPENDENCIES:
16
+ # RabbitMQ rabbitmq_management plugin
17
+ # gem: sensu-plugin
18
+ # gem: rest-client
19
+ #
20
+ # LICENSE:
21
+ # Copyright 2012 Abhijith G <abhi@runa.com> and Runa Inc.
22
+ # Copyright 2014 Tim Smith <tim@cozy.co> and Cozy Services Ltd.
23
+ # Copyright 2015 Edward McLain <ed@edmclain.com> and Daxko, LLC.
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 CheckRabbitMQNodeHealth < 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 :ssl,
59
+ description: 'Enable SSL for connection to the API',
60
+ long: '--ssl',
61
+ boolean: true,
62
+ default: false
63
+
64
+ option :verify_ssl_off,
65
+ description: 'Do not check validity of SSL cert. Use for self-signed certs, etc (insecure)',
66
+ long: '--verify_ssl_off',
67
+ boolean: true,
68
+ default: false
69
+
70
+ option :memwarn,
71
+ description: 'Warning % of mem usage vs high watermark',
72
+ short: '-m',
73
+ long: '--mwarn PERCENT',
74
+ proc: proc(&:to_f),
75
+ default: 80
76
+
77
+ option :memcrit,
78
+ description: 'Critical % of mem usage vs high watermark',
79
+ short: '-c',
80
+ long: '--mcrit PERCENT',
81
+ proc: proc(&:to_f),
82
+ default: 90
83
+
84
+ option :fdwarn,
85
+ description: 'Warning % of file descriptor usage vs high watermark',
86
+ short: '-f',
87
+ long: '--fwarn PERCENT',
88
+ proc: proc(&:to_f),
89
+ default: 80
90
+
91
+ option :fdcrit,
92
+ description: 'Critical % of file descriptor usage vs high watermark',
93
+ short: '-F',
94
+ long: '--fcrit PERCENT',
95
+ proc: proc(&:to_f),
96
+ default: 90
97
+
98
+ option :socketwarn,
99
+ description: 'Warning % of socket usage vs high watermark',
100
+ short: '-s',
101
+ long: '--swarn PERCENT',
102
+ proc: proc(&:to_f),
103
+ default: 80
104
+
105
+ option :socketcrit,
106
+ description: 'Critical % of socket usage vs high watermark',
107
+ short: '-S',
108
+ long: '--scrit PERCENT',
109
+ proc: proc(&:to_f),
110
+ default: 90
111
+
112
+ option :watchalarms,
113
+ description: 'Sound critical if one or more alarms are triggered',
114
+ short: '-a BOOLEAN',
115
+ long: '--alarms BOOLEAN',
116
+ default: 'true'
117
+
118
+ def run
119
+ res = node_healthy?
120
+
121
+ if res['status'] == 'ok'
122
+ ok res['message']
123
+ elsif res['status'] == 'warning'
124
+ warning res['message']
125
+ elsif res['status'] == 'critical'
126
+ critical res['message']
127
+ else
128
+ unknown res['message']
129
+ end
130
+ end
131
+
132
+ def node_healthy?
133
+ host = config[:host]
134
+ port = config[:port]
135
+ username = config[:username]
136
+ password = config[:password]
137
+ ssl = config[:ssl]
138
+ verify_ssl = config[:verify_ssl_off]
139
+
140
+ begin
141
+ url_prefix = ssl ? 'https' : 'http'
142
+ resource = RestClient::Resource.new(
143
+ "#{url_prefix}://#{host}:#{port}/api/nodes",
144
+ user: username,
145
+ password: password,
146
+ verify_ssl: !verify_ssl
147
+ )
148
+ # Parse our json data
149
+ nodeinfo = JSON.parse(resource.get)[0]
150
+
151
+ # Determine % memory consumed
152
+ pmem = format('%.2f', nodeinfo['mem_used'].fdiv(nodeinfo['mem_limit']) * 100)
153
+ # Determine % sockets consumed
154
+ psocket = format('%.2f', nodeinfo['sockets_used'].fdiv(nodeinfo['sockets_total']) * 100)
155
+ # Determine % file descriptors consumed
156
+ pfd = format('%.2f', nodeinfo['fd_used'].fdiv(nodeinfo['fd_total']) * 100)
157
+
158
+ # build status and message
159
+ status = 'ok'
160
+ message = 'Server is healthy'
161
+
162
+ # criticals
163
+ if pmem.to_f >= config[:memcrit]
164
+ message = "Memory usage is critical: #{pmem}%"
165
+ status = 'critical'
166
+ elsif psocket.to_f >= config[:socketcrit]
167
+ message = "Socket usage is critical: #{psocket}%"
168
+ status = 'critical'
169
+ elsif pfd.to_f >= config[:fdcrit]
170
+ message = "File Descriptor usage is critical: #{pfd}%"
171
+ status = 'critical'
172
+ # warnings
173
+ elsif pmem.to_f >= config[:memwarn]
174
+ message = "Memory usage is at warning: #{pmem}%"
175
+ status = 'warning'
176
+ elsif psocket.to_f >= config[:socketwarn]
177
+ message = "Socket usage is at warning: #{psocket}%"
178
+ status = 'warning'
179
+ elsif pfd.to_f >= config[:fdwarn]
180
+ message = "File Descriptor usage is at warning: #{pfd}%"
181
+ status = 'warning'
182
+ end
183
+
184
+ # If we are set to watch alarms then watch those and set status and messages accordingly
185
+ if config[:watchalarms] == 'true'
186
+ if nodeinfo['mem_alarm'] == true
187
+ status = 'critical'
188
+ message += ' Memory Alarm ON'
189
+ end
190
+
191
+ if nodeinfo['disk_free_alarm'] == true
192
+ status = 'critical'
193
+ message += ' Disk Alarm ON'
194
+ end
195
+ end
196
+
197
+ { 'status' => status, 'message' => message }
198
+ rescue Errno::ECONNREFUSED => e
199
+ { 'status' => 'critical', 'message' => e.message }
200
+ rescue => e
201
+ { 'status' => 'unknown', 'message' => e.message }
202
+ end
203
+ end
204
+ end