Skip to content

Commit eddde67

Browse files
author
Jan Kunzmann
committed
check-mysql-replication-status: address RuboCop findings
1 parent ce47362 commit eddde67

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

bin/check-mysql-replication-status.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class CheckMysqlReplicationStatus < Sensu::Plugin::Check::CLI
103103
option :lag_outlier_threshold,
104104
long: '--lag-outlier-threshold=VALUE',
105105
description: 'Lag threshold to trigger outlier protection',
106-
default: 100000,
106+
default: 100_000,
107107
proc: proc { |s| s.to_i }
108108

109109
option :lag_outlier_sleep,
@@ -117,8 +117,7 @@ class CheckMysqlReplicationStatus < Sensu::Plugin::Check::CLI
117117
description: 'Level to report lag outlier',
118118
default: :ok,
119119
proc: proc(&:to_sym),
120-
in: %i(ok warning critical)
121-
120+
in: %i[ok warning critical]
122121

123122
def detect_replication_status?(row)
124123
%w[
@@ -194,7 +193,7 @@ def ok_slave_message
194193
db_conn = config[:master_connection]
195194

196195
if db_conn.nil?
197-
"slave running: true"
196+
'slave running: true'
198197
else
199198
"master connection: #{db_conn}, slave running: true"
200199
end
@@ -204,7 +203,7 @@ def run
204203
db = open_connection
205204

206205
retries = config[:lag_outlier_retry]
207-
unknown "Invalid value for --lag-outlier-retry" if retries < 0
206+
unknown 'Invalid value for --lag-outlier-retry' if retries < 0
208207

209208
lag_outlier = 0
210209

@@ -234,7 +233,7 @@ def run
234233
critical message if config[:lag_outlier_report] == :critical
235234
warning message if config[:lag_outlier_report] == :warning
236235
else
237-
# TODO (breaking change): Thresholds are exclusive which is not consistent with all other checks
236+
# TODO: (breaking change) Thresholds are exclusive which is not consistent with all other checks
238237
critical message if replication_delay > config[:crit]
239238
warning message if replication_delay > config[:warn]
240239
end

test/check-mysql-replication-status_spec.rb

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
require_relative '../bin/check-mysql-replication-status'
3030
require_relative './spec_helper.rb'
3131

32+
# rubocop:disable Metrics/BlockLength
3233
describe CheckMysqlReplicationStatus do
3334
let(:checker) { described_class.new }
3435
let(:exit_code) { nil }
@@ -48,23 +49,23 @@ def checker.critical(*_args)
4849
end
4950

5051
[
51-
['Yes', 'Yes', 0, 0, 'ok'],
52-
['No', 'Yes', nil, 2, 'critical'],
53-
['Yes', 'No', nil, 2, 'critical'],
54-
['No', 'No', nil, 2, 'critical'],
55-
['Yes', 'Yes', 900, 0, 'ok'],
56-
['Yes', 'Yes', 901, 1, 'warning'],
52+
['Yes', 'Yes', 0, 0, 'ok'],
53+
['No', 'Yes', nil, 2, 'critical'],
54+
['Yes', 'No', nil, 2, 'critical'],
55+
['No', 'No', nil, 2, 'critical'],
56+
['Yes', 'Yes', 900, 0, 'ok'],
57+
['Yes', 'Yes', 901, 1, 'warning'],
5758
['Yes', 'Yes', 1800, 1, 'warning'],
5859
['Yes', 'Yes', 1801, 2, 'critical'],
5960
].each do |testdata|
6061
it "returns #{testdata[4]} for default thresholds" do
6162
slave_status_row = {
62-
"Slave_IO_State" => '',
63-
"Slave_IO_Running" => testdata[0],
64-
"Slave_SQL_Running" => testdata[1],
65-
"Last_IO_Error" => '',
66-
"Last_SQL_Error" => '',
67-
"Seconds_Behind_Master" => testdata[2]
63+
'Slave_IO_State' => '',
64+
'Slave_IO_Running' => testdata[0],
65+
'Slave_SQL_Running' => testdata[1],
66+
'Last_IO_Error' => '',
67+
'Last_SQL_Error' => '',
68+
'Seconds_Behind_Master' => testdata[2]
6869
}
6970
begin
7071
allow(checker).to receive(:open_connection) # do nothing
@@ -78,29 +79,29 @@ def checker.critical(*_args)
7879
end
7980

8081
[
81-
[ 0, 0, 'ok'],
82-
[99999, 2, 'critical'],
82+
[0, 0, 'ok'],
83+
[99_999, 2, 'critical'],
8384
].each do |testdata|
8485
it "sleeps with lag outlier protection and returns #{testdata[2]} for default thresholds" do
8586
checker.config[:lag_outlier_retry] = 1
8687
checker.config[:lag_outlier_sleep] = 10
8788

8889
slave_status_row = [
8990
{
90-
"Slave_IO_State" => '',
91-
"Slave_IO_Running" => 'Yes',
92-
"Slave_SQL_Running" => 'Yes',
93-
"Last_IO_Error" => '',
94-
"Last_SQL_Error" => '',
95-
"Seconds_Behind_Master" => 100000
91+
'Slave_IO_State' => '',
92+
'Slave_IO_Running' => 'Yes',
93+
'Slave_SQL_Running' => 'Yes',
94+
'Last_IO_Error' => '',
95+
'Last_SQL_Error' => '',
96+
'Seconds_Behind_Master' => 100_000
9697
},
9798
{
98-
"Slave_IO_State" => '',
99-
"Slave_IO_Running" => 'Yes',
100-
"Slave_SQL_Running" => 'Yes',
101-
"Last_IO_Error" => '',
102-
"Last_SQL_Error" => '',
103-
"Seconds_Behind_Master" => testdata[0]
99+
'Slave_IO_State' => '',
100+
'Slave_IO_Running' => 'Yes',
101+
'Slave_SQL_Running' => 'Yes',
102+
'Last_IO_Error' => '',
103+
'Last_SQL_Error' => '',
104+
'Seconds_Behind_Master' => testdata[0]
104105
}
105106
]
106107

0 commit comments

Comments
 (0)