sensu-plugins-mysql 2.6.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba2c83d93364ab17b2ff50509b773fd06cf27874b154c812cfd205e24e01fe4a
4
- data.tar.gz: 9354135db5e40d55d8e9ff44c095a6d7bd6287b5d8b5989937deaffa59c62b65
3
+ metadata.gz: f050ecf7e999bf8ff96e3e089c875532184987ad802cfb1c3d41de64a2b65954
4
+ data.tar.gz: f6d603d1a7b63efedb0e936d9aa0a55d4e598cfc02fbffede44619552af44fbf
5
5
  SHA512:
6
- metadata.gz: 15b9d19c2f41c2ff0c7397ff950c7addcacae961e0579a60db86f0238f3608885f0a55b2f3678b7dee94a6094ad5a809a4de286134c5efb90e0f33f3fea9c81c
7
- data.tar.gz: 866bf72082604e8743b58c8eba700ee66be98fba9dc36098b68103b018763b7779c0a44ff30e24968e9d655e1d755fbf06f900959cd37df58a07220bf8d7208c
6
+ metadata.gz: 84049e67a1c9181c8ad6f2e6df7fe9ac8cc4c947fae1b2c779dd6eae409155ea3bfec5a1565185b142dd5c548cf15de44d077f7c7f5897ff53ece963aca0daf0
7
+ data.tar.gz: 45f695cfe8b6400f12b21dcfe6709f9838db5c1dd71b2996e90021b8198a8ea95b23917cbad277aa2ed18b9583cc373d749c9a21c6806e1f6024adcf6b24243e
@@ -5,6 +5,37 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [3.2.0] - 2020-08-26
9
+ ### Changed
10
+ - Bump sensu-plugin dependency from ~> 1.2 to ~> 4.0
11
+ - Updated bundler dependancy to '~> 2.1'
12
+ - Updated rubocop dependency to '~> 0.81.0'
13
+ - Remediated rubocop issues
14
+ - Updated rake dependency to '~> 13.0'
15
+
16
+ ## [3.1.1] - 2019-03-04
17
+ ### Fixed
18
+ - check-mysql-disk.rb: update defaults for float and integer values as a string as the defaults apparently do not execute the proc which would have properly converted it to the appropriate type (@majormoses)
19
+
20
+ ## [3.1.0] - 2018-12-15
21
+ ### Added
22
+ - metrics-mysql-multiple-select-countcript (@nagyt234)
23
+
24
+
25
+ ## [3.0.0] - 2018-12-04
26
+ ### Security
27
+ - updated rubocop dependency to `~> 0.51.0` per: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-8418. (@majormoses)
28
+
29
+ ### Breaking Changes
30
+ - removed < ruby 2.3 support as they are EOL (@majormoses)
31
+
32
+ ### Changed
33
+ - appeased the cops (@majormoses)
34
+
35
+ ## [2.7.0] - 2018-11-25
36
+ ### Added
37
+ - metrics-mysql-select-count.rb script (@nagyt234)
38
+
8
39
  ## [2.6.0] - 2018-11-17
9
40
  ### Added
10
41
  - check-mysql-select-count.rb: fleshed out config hash to read from ini file if specified (@fuzzy-logic-zach)
@@ -137,7 +168,12 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
137
168
  ### Added
138
169
  - initial release
139
170
 
140
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.6.0...HEAD
171
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/3.2.0...HEAD
172
+ [3.2.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/3.1.1...3.2.0
173
+ [3.1.1]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/3.1.0...3.1.1
174
+ [3.1.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/3.0.0...3.1.0
175
+ [3.0.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.7.0...3.0.0
176
+ [2.7.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.6.0...2.7.0
141
177
  [2.6.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.5.1...2.6.0
142
178
  [2.5.1]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.5.0...2.5.1
143
179
  [2.5.0]: https://github.com/sensu-plugins/sensu-plugins-mysql/compare/2.4.0...2.5.0
data/README.md CHANGED
@@ -20,10 +20,12 @@
20
20
  * bin/check-mysql-select-count.rb
21
21
  * bin/check-mysql-msr-replication-status.rb
22
22
  * bin/metrics-mysql-graphite.rb
23
+ * bin/metrics-mysql-multiple-select-count.rb
23
24
  * bin/metrics-mysql-processes.rb
24
25
  * bin/metrics-mysql-raw.rb
25
26
  * bin/metrics-mysql.rb
26
27
  * bin/metrics-mysql-query-result-count.rb
28
+ * bin/metrics-mysql-select-count.rb
27
29
  * bin/mysql-metrics.sql
28
30
 
29
31
  ## Usage
@@ -98,6 +100,15 @@ $ /opt/sensu/embedded/bin/check-mysql-replication-status.rb --host=<SLAVE> --ini
98
100
  /opt/sensu/embedded/bin$ /opt/sensu/embedded/bin/ruby metrics-mysql-query-result-count.rb --host=localhost --port=3306 --user=collectd --pass=tflypass --socket=/data/mysql.sock --query 'SELECT DISTINCT(t.id) FROM table t where t.failed = true'
99
101
  ```
100
102
 
103
+ **metrics-mysql-select-count** example
104
+ ```bash
105
+ /opt/sensu/embedded/bin$ /opt/sensu/embedded/bin/ruby metrics-mysql-select-count.rb --host=localhost --port=3306 --user=collectd --pass=tflypass --socket=/data/mysql.sock --query 'SELECT COUNT(*) FROM table t'
106
+ ```
107
+
108
+ **metrics-mysql-multiple-select-count** example
109
+ ```bash
110
+ /opt/sensu/embedded/bin$ /opt/sensu/embedded/bin/metrics-mysql-multiple-select-count.rb --host=localhost --port=3306 --user=collectd --pass=tflypass --socket=/data/mysql.sock --query '{"t1_count":"SELECT COUNT(*) FROM table t1", "t2_count":"SELECT COUNT(*) FROM table t2"}'
111
+ ```
101
112
  ### Security
102
113
 
103
114
  In keeping with the principle of least privilege you should create a new user with the minimum required permissions. See the table below for minimum permissions for each check.
@@ -117,6 +128,8 @@ In keeping with the principle of least privilege you should create a new user wi
117
128
  | metrics-mysql-graphite.rb | `SELECT` |
118
129
  | metrics-mysql-processes.rb | `SELECT` |
119
130
  | metrics-mysql-query-result-count.rb | depends on query |
131
+ | metrics-mysql-select-count.rb   | depends on query                                         |
132
+ | metrics-mysql-multiple-select-count   | depends on query                                         |
120
133
  | metrics-mysql-raw.rb | `SELECT` |
121
134
  | metrics-mysql.rb | `INSERT` into `sensumetrics.sensu_historic_metrics` |
122
135
 
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
2
4
  #
3
5
  # MySQL Alive Plugin
4
6
  # ===
@@ -96,7 +98,7 @@ class CheckMySQL < Sensu::Plugin::Check::CLI
96
98
  rescue Mysql::Error => e
97
99
  critical "Error message: #{e.error}"
98
100
  ensure
99
- db.close if db
101
+ db&.close
100
102
  end
101
103
  end
102
104
  end
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
2
4
  #
3
5
  # MySQL Health Plugin
4
6
  # ===
@@ -105,6 +107,6 @@ class CheckMySQLHealth < Sensu::Plugin::Check::CLI
105
107
  rescue Mysql::Error => e
106
108
  critical "MySQL check failed: #{e.error}"
107
109
  ensure
108
- db.close if db
110
+ db&.close
109
111
  end
110
112
  end
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
2
4
  #
3
5
  # MySQL Disk Usage Check
4
6
  # ===
@@ -52,21 +54,21 @@ class CheckMysqlDisk < Sensu::Plugin::Check::CLI
52
54
  long: '--warning=VALUE',
53
55
  description: 'Warning threshold',
54
56
  proc: proc(&:to_f),
55
- default: '85'
57
+ default: 85
56
58
 
57
59
  option :crit,
58
60
  short: '-c',
59
61
  long: '--critical=VALUE',
60
62
  description: 'Critical threshold',
61
63
  proc: proc(&:to_f),
62
- default: '95'
64
+ default: 95
63
65
 
64
66
  option :port,
65
67
  description: 'Port to connect to',
66
68
  short: '-P PORT',
67
69
  long: '--port PORT',
68
70
  proc: proc(&:to_i),
69
- default: '3306'
71
+ default: 3306
70
72
 
71
73
  option :socket,
72
74
  description: 'Socket to use',
@@ -97,7 +99,7 @@ class CheckMysqlDisk < Sensu::Plugin::Check::CLI
97
99
  total_size = 0.0
98
100
  db = Mysql.real_connect(config[:host], db_user, db_pass, nil, config[:port], config[:socket])
99
101
 
100
- results = db.query <<-EOSQL
102
+ results = db.query <<-SQL
101
103
  SELECT table_schema,
102
104
  count(*) TABLES,
103
105
  concat(round(sum(table_rows)/1000000,2),'M') rows,
@@ -106,13 +108,11 @@ class CheckMysqlDisk < Sensu::Plugin::Check::CLI
106
108
  round(sum(data_length+index_length)/(1024*1024*1024),2) total_size,
107
109
  round(sum(index_length)/sum(data_length),2) idxfrac
108
110
  FROM information_schema.TABLES group by table_schema
109
- EOSQL
111
+ SQL
110
112
 
111
- unless results.nil?
112
- results.each_hash do |row|
113
- # #YELLOW
114
- total_size = total_size + row['total_size'].to_f # rubocop:disable Style/SelfAssignment
115
- end
113
+ results&.each_hash do |row|
114
+ # #YELLOW
115
+ total_size = total_size + row['total_size'].to_f # rubocop:disable Style/SelfAssignment
116
116
  end
117
117
 
118
118
  disk_use_percentage = total_size / disk_size * 100
@@ -125,16 +125,13 @@ class CheckMysqlDisk < Sensu::Plugin::Check::CLI
125
125
  else
126
126
  ok diskstr
127
127
  end
128
-
129
128
  rescue Mysql::Error => e
130
129
  errstr = "Error code: #{e.errno} Error message: #{e.error}"
131
130
  critical "#{errstr} SQLSTATE: #{e.sqlstate}" if e.respond_to?('sqlstate')
132
-
133
- rescue => e
131
+ rescue StandardError => e
134
132
  critical e
135
-
136
133
  ensure
137
- db.close if db
134
+ db&.close
138
135
  end
139
136
  end
140
137
  end
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
2
4
  #
3
5
  # MySQL InnoDB Lock Check Plugin
4
6
  # ===
@@ -140,10 +142,9 @@ class CheckMySQLInnoDBLock < Sensu::Plugin::Check::CLI
140
142
  else
141
143
  critical "Detected Locks #{lock_info}"
142
144
  end
143
-
144
145
  rescue Mysql::Error => e
145
146
  critical "MySQL check failed: #{e.error}"
146
147
  ensure
147
- db.close if db
148
+ db&.close
148
149
  end
149
150
  end
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
2
4
  #
3
5
  # MySQL Multi-source Replication Status
4
6
  # ===
@@ -74,6 +76,16 @@ class CheckMysqlMSRReplicationStatus < Sensu::Plugin::Check::CLI
74
76
  default: 1800,
75
77
  proc: proc(&:to_i)
76
78
 
79
+ def set_status(io_thread_status, sql_thread_status, seconds_behind_master)
80
+ if io_thread_status == 'No' || sql_thread_status == 'No' || seconds_behind_master > config[:crit]
81
+ 2
82
+ elsif seconds_behind_master > config[:warn] && seconds_behind_master <= config[:crit]
83
+ 1
84
+ else
85
+ 0
86
+ end
87
+ end
88
+
77
89
  def run
78
90
  if config[:ini]
79
91
  ini = IniFile.load(config[:ini])
@@ -106,19 +118,13 @@ class CheckMysqlMSRReplicationStatus < Sensu::Plugin::Check::CLI
106
118
  io_thread_status = row['Slave_IO_Running']
107
119
  sql_thread_status = row['Slave_SQL_Running']
108
120
  seconds_behind_master = row['Seconds_Behind_Master'].to_i
109
- status = 0
110
- if io_thread_status == 'No' || sql_thread_status == 'No' || seconds_behind_master > config[:crit]
111
- status = 2
112
- end
113
- if seconds_behind_master > config[:warn] && seconds_behind_master <= config[:crit]
114
- status = 1
115
- end
121
+ status = set_status
116
122
  message = "#{channel['channel_name']} STATES:"
117
123
  message += " Slave_IO_Running=#{io_thread_status}"
118
124
  message += ", Slave_SQL_Running=#{sql_thread_status}"
119
125
  message += ", Seconds_Behind_Master=#{seconds_behind_master}"
120
126
 
121
- if status.zero?
127
+ if status == 0
122
128
  ok_statuses << message
123
129
  elsif status == 1
124
130
  warn_statuses << message
@@ -147,7 +153,7 @@ class CheckMysqlMSRReplicationStatus < Sensu::Plugin::Check::CLI
147
153
  rescue StandardError => e
148
154
  critical "unhandled exception: #{e}"
149
155
  ensure
150
- db.close if db
156
+ db&.close
151
157
  end
152
158
  end
153
159
  end
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
2
4
  #
3
5
  # MySQL Query Result Count Check
4
6
  #
@@ -99,15 +101,12 @@ class MysqlQueryCountCheck < Sensu::Plugin::Check::CLI
99
101
  else
100
102
  ok 'Result count length is below thresholds'
101
103
  end
102
-
103
104
  rescue Mysql::Error => e
104
105
  errstr = "Error code: #{e.errno} Error message: #{e.error}"
105
106
  critical "#{errstr} SQLSTATE: #{e.sqlstate}" if e.respond_to?('sqlstate')
106
-
107
- rescue => e
107
+ rescue StandardError => e
108
108
  critical e
109
-
110
109
  ensure
111
- db.close if db
110
+ db&.close
112
111
  end
113
112
  end
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
2
4
  #
3
5
  # MySQL Replication Status (modded from disk)
4
6
  # ===
@@ -45,7 +47,7 @@ class CheckMysqlReplicationStatus < Sensu::Plugin::Check::CLI
45
47
  description: 'Database port',
46
48
  default: 3306,
47
49
  # #YELLOW
48
- proc: lambda { |s| s.to_i } # rubocop:disable Lambda
50
+ proc: lambda { |s| s.to_i } # rubocop:disable Style/Lambda
49
51
 
50
52
  option :socket,
51
53
  short: '-s SOCKET',
@@ -83,7 +85,7 @@ class CheckMysqlReplicationStatus < Sensu::Plugin::Check::CLI
83
85
  description: 'Warning threshold for replication lag',
84
86
  default: 900,
85
87
  # #YELLOW
86
- proc: lambda { |s| s.to_i } # rubocop:disable Lambda
88
+ proc: lambda { |s| s.to_i } # rubocop:disable Style/Lambda
87
89
 
88
90
  option :crit,
89
91
  short: '-c',
@@ -91,7 +93,25 @@ class CheckMysqlReplicationStatus < Sensu::Plugin::Check::CLI
91
93
  description: 'Critical threshold for replication lag',
92
94
  default: 1800,
93
95
  # #YELLOW
94
- proc: lambda { |s| s.to_i } # rubocop:disable Lambda
96
+ proc: lambda { |s| s.to_i } # rubocop:disable Style/Lambda
97
+
98
+ def detect_replication_status?(row)
99
+ %w[
100
+ Slave_IO_State
101
+ Slave_IO_Running
102
+ Slave_SQL_Running
103
+ Last_IO_Error
104
+ Last_SQL_Error
105
+ Seconds_Behind_Master
106
+ ].all? { |key| row.key? key }
107
+ end
108
+
109
+ def slave_running?(row)
110
+ %w[
111
+ Slave_IO_Running
112
+ Slave_SQL_Running
113
+ ].all? { |key| row[key] =~ /Yes/ }
114
+ end
95
115
 
96
116
  def run
97
117
  if config[:ini]
@@ -121,14 +141,9 @@ class CheckMysqlReplicationStatus < Sensu::Plugin::Check::CLI
121
141
 
122
142
  unless results.nil?
123
143
  results.each_hash do |row|
124
- warn "couldn't detect replication status" unless
125
- %w(Slave_IO_State Slave_IO_Running Slave_SQL_Running Last_IO_Error Last_SQL_Error Seconds_Behind_Master).all? do |key|
126
- row.key? key
127
- end
144
+ warn "couldn't detect replication status" unless detect_replication_status?(row)
128
145
 
129
- slave_running = %w(Slave_IO_Running Slave_SQL_Running).all? do |key|
130
- row[key] =~ /Yes/
131
- end
146
+ slave_running = slave_running?(row)
132
147
 
133
148
  output = if db_conn.nil?
134
149
  'Slave not running!'
@@ -160,16 +175,13 @@ class CheckMysqlReplicationStatus < Sensu::Plugin::Check::CLI
160
175
  end
161
176
  ok 'show slave status was nil. This server is not a slave.'
162
177
  end
163
-
164
178
  rescue Mysql::Error => e
165
179
  errstr = "Error code: #{e.errno} Error message: #{e.error}"
166
180
  critical "#{errstr} SQLSTATE: #{e.sqlstate}" if e.respond_to?('sqlstate')
167
-
168
- rescue => e
181
+ rescue StandardError => e
169
182
  critical e
170
-
171
183
  ensure
172
- db.close if db
184
+ db&.close
173
185
  end
174
186
  end
175
187
  end
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
2
4
  #
3
5
  # MySQL Select Count Check
4
6
  #
@@ -102,15 +104,12 @@ class MysqlSelectCountCheck < Sensu::Plugin::Check::CLI
102
104
  else
103
105
  ok "Count is below thresholds : #{count} count"
104
106
  end
105
-
106
107
  rescue Mysql::Error => e
107
108
  errstr = "Error code: #{e.errno} Error message: #{e.error}"
108
109
  critical "#{errstr} SQLSTATE: #{e.sqlstate}" if e.respond_to?('sqlstate')
109
-
110
110
  rescue StandardError => e
111
111
  critical "unhandled exception: #{e}"
112
-
113
112
  ensure
114
- db.close if db
113
+ db&.close
115
114
  end
116
115
  end
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
2
4
  #
3
5
  # MySQL Status Plugin
4
6
  # ===
@@ -115,11 +117,13 @@ class CheckMySQLStatus < Sensu::Plugin::Check::CLI
115
117
  section = ini[config[:ini_section]]
116
118
  db_user = section['user']
117
119
  db_pass = section['password']
120
+ # rubocop:disable Style/RedundantCondition
118
121
  db_socket = if config[:socket]
119
122
  config[:socket]
120
123
  else
121
124
  section['socket']
122
125
  end
126
+ # rubocop:enable Style/RedundantCondition
123
127
  else
124
128
  db_user = config[:user]
125
129
  db_pass = config[:password]
@@ -139,7 +143,7 @@ class CheckMySQLStatus < Sensu::Plugin::Check::CLI
139
143
  else
140
144
  critical "Error message: status: #{status}"
141
145
  end
142
- rescue => e
146
+ rescue StandardError => e
143
147
  critical "Error message: status: #{status} | Exception: #{e}"
144
148
  ensure
145
149
  puts ''
@@ -162,14 +166,14 @@ class CheckMySQLStatus < Sensu::Plugin::Check::CLI
162
166
  end
163
167
  dict = []
164
168
  table.keys.to_a.each do |k|
165
- %w(Slave_IO_State Slave_IO_Running Slave_SQL_Running Last_IO_Error Last_SQL_Error Seconds_Behind_Master).each do |key|
169
+ %w[Slave_IO_State Slave_IO_Running Slave_SQL_Running Last_IO_Error Last_SQL_Error Seconds_Behind_Master].each do |key|
166
170
  dict.push(k.strip.to_s) if key.strip == k.strip
167
171
  end
168
172
  end
169
173
  table.each do |attribute, value|
170
174
  puts "#{attribute} : #{value}" if config[:debug]
171
175
  warn "couldn't detect replication status :#{dict.size}" unless dict.size == 6
172
- slave_running = %w(Slave_IO_Running Slave_SQL_Running).all? do |key|
176
+ slave_running = %w[Slave_IO_Running Slave_SQL_Running].all? do |key|
173
177
  table[key].to_s =~ /Yes/
174
178
  end
175
179
  output = 'Slave not running!'
@@ -189,7 +193,7 @@ class CheckMySQLStatus < Sensu::Plugin::Check::CLI
189
193
  end
190
194
  end
191
195
  ok 'show slave status was nil. This server is not a slave.'
192
- rescue => e
196
+ rescue StandardError => e
193
197
  critical "Error message: status: #{status} | Exception: #{e}"
194
198
  end
195
199
  end