Skip to content

Instantly share code, notes, and snippets.

@krobertson
Created August 31, 2011 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krobertson/1184363 to your computer and use it in GitHub Desktop.
Save krobertson/1184363 to your computer and use it in GitHub Desktop.
# The definition...
define :check_mysql_seconds_behind_master do
attribute :username, :kind_of => String
attribute :password, :kind_of => String
attribute :warning, :kind_of => Fixnum, :default => 20
attribute :critical, :kind_of => Fixnum, :default => 60
require_gem 'mysql'
execute do
connection = Mysql.new(host[:ipaddress], username, password)
result = connection.query('show slave status')
seconds = result.fetch_hash['Seconds_Behind_Master']
result.free
connection.close
critical("We're behind a lot!") if seconds >= critical
warn("We're behind some") if seconds >= warning
ok
end
end
# In the config file, the parameters need to be set. No passing over the network.
# idea for method one
check_mysql_seconds_behind_master do
username "foo"
password "bar"
warning nil
critical 10
end
# idea for method two
configure :check_mysql_seconds_behind_master do
username "foo"
password "bar"
warning nil
critical 10
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment