Skip to content

Commit

Permalink
Added ini and rewrite.
Browse files Browse the repository at this point in the history
  • Loading branch information
jBRNDnl committed Jan 27, 2020
1 parent d9d048d commit 6f9458f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
Empty file added .kitchen/logs/kitchen.log
Empty file.
50 changes: 27 additions & 23 deletions bin/check-wsrep-ready.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,25 @@

require 'sensu-plugin/check/cli'
require 'mysql2'
require 'inifile'

class CheckWsrepReady < Sensu::Plugin::Check::CLI
option :user,
option :hostname,
description: 'Hostname to login to',
short: '-h HOST',
long: '--hostname HOST',
default: 'localhost'

option :username,
description: 'MySQL User',
short: '-u USER',
long: '--user USER',
short: '-u',
long: '--username VALUE',
default: 'root'

option :password,
description: 'MySQL Password',
short: '-p PASS',
long: '--password PASS'
short: '-p',
long: '--password VALUE'

option :ini,
description: 'ini file',
Expand All @@ -54,17 +61,12 @@ class CheckWsrepReady < Sensu::Plugin::Check::CLI
long: '--ini-section VALUE',
default: 'client'

option :hostname,
description: 'Hostname to login to',
short: '-h HOST',
long: '--hostname HOST',
default: 'localhost'

option :port,
description: 'Port to connect to',
short: '-P PORT',
long: '--port PORT',
default: '3306'
proc: proc(&:to_i),
default: 3306

option :socket,
description: 'Socket to use',
Expand All @@ -82,18 +84,20 @@ def run
db_pass = config[:password]
end

db = Mysql2::Client.new(
host: config[:hostname],
username: db_user,
password: db_pass,
port: config[:port].to_i,
socket: config[:socket]
)
wsrep_ready = db.query("SHOW STATUS LIKE 'wsrep_ready';").first['Value']
critical "WSREP Ready is not ON. Is #{wsrep_ready}" if wsrep_ready != 'ON'
ok 'Cluster is OK!' if wsrep_ready == 'ON'
begin
db = Mysql2::Client.new(
host: config[:hostname],
username: db_user,
password: db_pass,
port: config[:port].to_i,
socket: config[:socket]
)
wsrep_ready = db.query("SHOW STATUS LIKE 'wsrep_ready';").first['Value']
critical "WSREP Ready is not ON. Is #{wsrep_ready}" if wsrep_ready != 'ON'
ok 'Cluster is OK!' if wsrep_ready == 'ON'
end
rescue Mysql2::Error => e
critical "Percona MySQL check failed: #{e.error}"
critical "Percona MySQL wsrep ready failed: #{e.error}"
ensure
db&.close
# db.close if db
Expand Down

0 comments on commit 6f9458f

Please sign in to comment.