Skip to content

Commit 2e97c6d

Browse files
committed
[CVE-2017-8418] - updating rubocop dependency.
Breaking Changes: - removed ruby `< 2.1` support Misc: - appeased the cops Signed-off-by: Ben Abrams <[email protected]>
1 parent 9d0d00c commit 2e97c6d

30 files changed

+109
-52
lines changed

.rubocop.yml

+9
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@ RegexpLiteral:
2828

2929
Style/Documentation:
3030
Enabled: false
31+
32+
# .match?() was added in ruby 2.4
33+
Performance/RegexpMatch:
34+
Enabled: false
35+
36+
## slow testing is oK
37+
Metrics/BlockLength:
38+
Exclude:
39+
- 'test/**/*'

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ cache:
44
install:
55
- bundle install
66
rvm:
7-
- 2.0
87
- 2.1
98
- 2.2
109
- 2.3.0
@@ -28,7 +27,6 @@ deploy:
2827
on:
2928
tags: true
3029
all_branches: true
31-
rvm: 2.0
3230
rvm: 2.1
3331
rvm: 2.2
3432
rvm: 2.3.0

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
55

66
## [Unreleased]
77

8+
### Security
9+
- updated rubocop dependency to `~> 0.51.0` per: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-8418. (@majormoses)
10+
11+
### Breaking Changes
12+
- removed ruby `< 2.1` support (@majormoses)
13+
14+
### Changed
15+
- appeased the cops (@majormoses)
16+
817
## [3.6.0] - 2017-10-04
918
### Added
1019
- check-rabbitmq-queues-synchronised.rb: added new check if all mirrored queues are synchronised (@cyrilgdn)

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
# Specify your gem's dependencies in sensu-plugins-rabbitmq.gemspec

Rakefile

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'bundler/gem_tasks'
24
require 'github/markup'
35
require 'redcarpet'
@@ -7,9 +9,9 @@ require 'yard'
79
require 'yard/rake/yardoc_task'
810

911
YARD::Rake::YardocTask.new do |t|
10-
OTHER_PATHS = %w().freeze
12+
OTHER_PATHS = %w[].freeze
1113
t.files = ['lib/**/*.rb', 'bin/**/*.rb', OTHER_PATHS]
12-
t.options = %w(--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md)
14+
t.options = %w[--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md]
1315
end
1416

1517
RuboCop::RakeTask.new
@@ -35,4 +37,4 @@ task :check_binstubs do
3537
end
3638
end
3739

38-
task default: [:spec, :make_bin_executable, :yard, :rubocop, :check_binstubs]
40+
task default: %i[spec make_bin_executable yard rubocop check_binstubs]

bin/check-rabbitmq-alive.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
34
#
45
# RabbitMQ check alive plugin
56
# ===
@@ -115,7 +116,7 @@ def vhost_alive?
115116
{ 'status' => 'ok', 'message' => 'RabbitMQ server is alive' }
116117
rescue Errno::ECONNREFUSED => e
117118
{ 'status' => 'critical', 'message' => e.message }
118-
rescue => e
119+
rescue StandardError => e
119120
{ 'status' => 'unknown', 'message' => e.message }
120121
end
121122
end

bin/check-rabbitmq-amqp-alive.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
34
#
45
# RabbitMQ check amqp alive plugin
56
# ===
@@ -142,7 +143,7 @@ def vhost_alive?
142143
{ 'status' => 'critical', 'message' => 'Possible authentication failure' }
143144
rescue Bunny::TCPConnectionFailed
144145
{ 'status' => 'critical', 'message' => 'TCP connection refused' }
145-
rescue => e
146+
rescue StandardError => e
146147
{ 'status' => 'unknown', 'message' => e.message }
147148
end
148149
end

bin/check-rabbitmq-cluster-health.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
34
#
45
# RabbitMQ check cluster nodes health plugin
56
# ===
@@ -161,7 +162,7 @@ def cluster_healthy?
161162
{ 'status' => status, 'message' => message }
162163
rescue Errno::ECONNREFUSED => e
163164
{ 'status' => 'critical', 'message' => e.message }
164-
rescue => e
165+
rescue StandardError => e
165166
{ 'status' => 'unknown', 'message' => e.message }
166167
end
167168
end

bin/check-rabbitmq-consumers.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
33

44
# Check RabbitMQ consumers
55
# ===
@@ -109,19 +109,19 @@ def rabbit
109109
password: password,
110110
ssl: config[:ssl]
111111
)
112-
rescue
112+
rescue StandardError
113113
warning 'could not connect to rabbitmq'
114114
end
115115
connection
116116
end
117117

118118
def return_condition(missing, critical, warning)
119-
if critical.count > 0 || missing.count > 0
119+
if critical.count.positive? || missing.count.positive?
120120
message = ''
121-
message << "Queues in critical state: #{critical.join(', ')}. " if critical.count > 0
122-
message << "Queues missing: #{missing.join(', ')}" if missing.count > 0
121+
message << "Queues in critical state: #{critical.join(', ')}. " if critical.count.positive?
122+
message << "Queues missing: #{missing.join(', ')}" if missing.count.positive?
123123
critical(message)
124-
elsif warning.count > 0
124+
elsif warning.count.positive?
125125
warning("Queues in warning state: #{warning.join(', ')}")
126126
else
127127
ok
@@ -154,7 +154,7 @@ def run
154154
critical.push(queue['name']) if consumers <= config[:critical]
155155
warn.push(queue['name']) if consumers <= config[:warn]
156156
end
157-
rescue
157+
rescue StandardError
158158
critical 'Could not find any queue, check rabbitmq server'
159159
end
160160
return_condition(missing, critical, warn)

bin/check-rabbitmq-messages.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
34
#
45
# Check RabbitMQ Messages
56
# ===
@@ -112,7 +113,7 @@ def acquire_rabbitmq_info
112113
password: password,
113114
ssl: config[:ssl]
114115
)
115-
rescue
116+
rescue StandardError
116117
warning 'Could not connect to rabbitmq'
117118
end
118119
rabbitmq_info

bin/check-rabbitmq-network-partitions.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
34
#
45
# RabbitMQ Network Partitions Check
56
# ===
@@ -68,7 +69,7 @@ def run
6869
ok 'no network partition detected'
6970
rescue Errno::ECONNREFUSED => e
7071
critical e.message
71-
rescue => e
72+
rescue StandardError => e
7273
unknown e.message
7374
end
7475

bin/check-rabbitmq-node-health.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
34
#
45
# RabbitMQ check node health plugin
56
# ===
@@ -215,7 +216,7 @@ def node_healthy?
215216
{ 'status' => status, 'message' => message }
216217
rescue Errno::ECONNREFUSED => e
217218
{ 'status' => 'critical', 'message' => e.message }
218-
rescue => e
219+
rescue StandardError => e
219220
{ 'status' => 'unknown', 'message' => e.message }
220221
end
221222
end

bin/check-rabbitmq-node-usage.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby -W0
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
34
#
45
# RabbitMQ check node health plugin
56
# ===
@@ -72,7 +73,7 @@ class CheckRabbitMQNodeUsage < Sensu::Plugin::Check::CLI
7273
description: 'Resource type',
7374
required: true,
7475
long: '--type TYPE',
75-
in: %w(mem socket fd proc disk)
76+
in: %w[mem socket fd proc disk]
7677

7778
option :memwarn,
7879
description: 'Warning % of mem usage vs high watermark',
@@ -179,7 +180,7 @@ def node_healthy?
179180
end
180181

181182
{ 'status' => output[:status], 'message' => output[:message] }
182-
rescue => e
183+
rescue StandardError => e
183184
{ 'status' => 'unknown', 'message' => e.message }
184185
end
185186

bin/check-rabbitmq-queue-drain-time.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
34
#
45
# RabbitMQ Queue Drain Time
56
# ===
@@ -106,7 +107,7 @@ def acquire_rabbitmq_queues
106107
password: password,
107108
ssl: config[:ssl]
108109
)
109-
rescue
110+
rescue StandardError
110111
warning 'could not get rabbitmq queue info'
111112
end
112113

@@ -125,10 +126,10 @@ def run
125126

126127
acquire_rabbitmq_queues.each do |queue|
127128
# we don't care about empty queues and they'll have an infinite drain time so skip them
128-
next if queue['messages'] == 0 || queue['messages'].nil?
129+
next if queue['messages'].zero? || queue['messages'].nil?
129130

130131
# handle rate of zero which is an infinite time until empty
131-
if queue['backing_queue_status']['avg_egress_rate'].to_f == 0
132+
if queue['backing_queue_status']['avg_egress_rate'].to_f.zero?
132133
crit_queues[queue['name']] = 'Infinite (drain rate = 0)'
133134
next
134135
end

bin/check-rabbitmq-queue.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: false
3+
34
#
45
# Check RabbitMQ Queue Messages
56
# ===
@@ -22,13 +23,15 @@
2223
# for details.
2324

2425
require 'sensu-plugins-rabbitmq'
26+
require 'sensu-plugin/check/cli'
2527

2628
# main plugin class
27-
class CheckRabbitMQMessages < Sensu::Plugin::RabbitMQ::Check
29+
class CheckRabbitMQQueue < Sensu::Plugin::Check::CLI
2830
option :queue,
2931
description: 'RabbitMQ queue to monitor',
3032
long: '--queue queue_names',
3133
required: true,
34+
# not sure if there is a better way to handle frozen strings
3235
proc: proc { |a| a.split(',') }
3336

3437
option :warn,

bin/check-rabbitmq-queues-synchronised.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
34
#
45
# Check RabbitMQ Queues Synchronised
56
# ===
@@ -55,7 +56,7 @@ def run
5556
end
5657
rescue Errno::ECONNREFUSED => e
5758
critical e.message
58-
rescue => e
59+
rescue StandardError => e
5960
unknown e.message
6061
end
6162

bin/check-rabbitmq-stomp-alive.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
34
#
45
# RabbitMQ check alive plugin
56
# ===
@@ -118,7 +119,7 @@ def vhost_alive?
118119
{ 'status' => 'critical', 'message' => 'TCP connection refused' }
119120
rescue Stomp::Error::BrokerException => e
120121
{ 'status' => 'critical', 'message' => "Error from broker. Check auth details? #{e.message}" }
121-
rescue => e
122+
rescue StandardError => e
122123
{ 'status' => 'unknown', 'message' => "#{e.class}: #{e.message}" }
123124
end
124125
end

bin/metrics-rabbitmq-exchange.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
34
#
45
# RabbitMQ Exchange Metrics
56
# ===

bin/metrics-rabbitmq-overview.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
34
#
45
# RabbitMQ Overview Metrics
56
# ===
@@ -99,7 +100,7 @@ def acquire_rabbitmq_info
99100
password: password,
100101
ssl: config[:ssl]
101102
)
102-
rescue
103+
rescue StandardError
103104
warning 'could not get rabbitmq info'
104105
end
105106
rabbitmq_info

bin/metrics-rabbitmq-queue.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
34
#
45
# RabbitMQ Queue Metrics
56
# ===

lib/sensu-plugins-rabbitmq.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'ruby_dig'
24

35
require 'sensu-plugins-rabbitmq/version'

lib/sensu-plugins-rabbitmq/check.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: false
2+
13
require 'sensu-plugin/check/cli'
24
require 'sensu-plugins-rabbitmq/rabbitmq'
35

lib/sensu-plugins-rabbitmq/metrics.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'sensu-plugin/metric/cli'
24
require 'socket'
35
require 'sensu-plugins-rabbitmq/rabbitmq'

lib/sensu-plugins-rabbitmq/rabbitmq.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: false
2+
13
require 'carrot-top'
24
require 'inifile'
35

@@ -66,7 +68,7 @@ def acquire_rabbitmq_info(property = nil)
6668
password: password,
6769
ssl: config[:ssl]
6870
)
69-
rescue
71+
rescue StandardError
7072
warning 'could not get rabbitmq info'
7173
end
7274

0 commit comments

Comments
 (0)