Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to define charset #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)

## [Unreleased]
### Added
- Option to define default charset in following scripts:
- `check-mysql-alive.rb`
- `check-mysql-connections.rb`
- `check-mysql-replication-status.rb`
- `check-mysql-select-count.rb`

## [3.2.0] - 2020-08-26
### Changed
Expand Down
11 changes: 10 additions & 1 deletion bin/check-mysql-alive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class CheckMySQL < Sensu::Plugin::Check::CLI
short: '-s SOCKET',
long: '--socket SOCKET'

option :default_charset,
short: '-D',
long: '--default_charset=VALUE',
description: 'Provide custom charset for connection'

def run
if config[:ini]
ini = IniFile.load(config[:ini])
Expand All @@ -92,7 +97,11 @@ def run
end

begin
db = Mysql.real_connect(config[:hostname], db_user, db_pass, config[:database], config[:port].to_i, config[:socket])
db = Mysql.init
if config[:default_charset]
db.options Mysql::SET_CHARSET_NAME, config[:default_charset]
end
db.real_connect(config[:hostname], db_user, db_pass, config[:database], config[:port].to_i, config[:socket])
info = db.get_server_info
ok "Server version: #{info}"
rescue Mysql::Error => e
Expand Down
11 changes: 10 additions & 1 deletion bin/check-mysql-connections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class CheckMySQLHealth < Sensu::Plugin::Check::CLI
long: '--percentage',
default: false

option :default_charset,
short: '-D',
long: '--default_charset=VALUE',
description: 'Provide custom charset for connection'

def run
if config[:ini]
ini = IniFile.load(config[:ini])
Expand All @@ -83,7 +88,11 @@ def run
db_user = config[:user]
db_pass = config[:password]
end
db = Mysql.real_connect(config[:hostname], db_user, db_pass, config[:database], config[:port].to_i, config[:socket])
db = Mysql.init
if config[:default_charset]
db.options Mysql::SET_CHARSET_NAME, config[:default_charset]
end
db.real_connect(config[:hostname], db_user, db_pass, config[:database], config[:port].to_i, config[:socket])
max_con = db
.query("SHOW VARIABLES LIKE 'max_connections'")
.fetch_hash
Expand Down
11 changes: 10 additions & 1 deletion bin/check-mysql-replication-status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class CheckMysqlReplicationStatus < Sensu::Plugin::Check::CLI
long: '--master-connection=VALUE',
description: 'Replication master connection name'

option :default_charset,
short: '-D',
long: '--default_charset=VALUE',
description: 'Provide custom charset for connection'

option :ini,
short: '-i',
long: '--ini VALUE',
Expand Down Expand Up @@ -131,7 +136,11 @@ def run
end

begin
db = Mysql.new(db_host, db_user, db_pass, nil, config[:port], config[:socket])
db = Mysql.init
if config[:default_charset]
db.options Mysql::SET_CHARSET_NAME, config[:default_charset]
end
db.real_connect(db_host, db_user, db_pass, nil, config[:port], config[:socket])

results = if db_conn.nil?
db.query 'SHOW SLAVE STATUS'
Expand Down
11 changes: 10 additions & 1 deletion bin/check-mysql-select-count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class MysqlSelectCountCheck < Sensu::Plugin::Check::CLI
description: 'Query to execute',
required: true

option :default_charset,
short: '-D',
long: '--default_charset=VALUE',
description: 'Provide custom charset for connection'

def run
if config[:ini]
ini = IniFile.load(config[:ini])
Expand All @@ -94,7 +99,11 @@ def run
end
raise 'Please specify hostname using -h or in mysql.cnf file' unless config[:host]

db = Mysql.real_connect(config[:host], db_user, db_pass, config[:database], config[:port], config[:socket])
db = Mysql.init
if config[:default_charset]
db.options Mysql::SET_CHARSET_NAME, config[:default_charset]
end
db.real_connect(config[:hostname], db_user, db_pass, config[:database], config[:port].to_i, config[:socket])

count = db.query(config[:query]).fetch_row[0].to_i
if count >= config[:crit]
Expand Down