Skip to content

Instantly share code, notes, and snippets.

@krobertson
Created August 31, 2011 18:50
Show Gist options
  • Select an option

  • Save krobertson/1184363 to your computer and use it in GitHub Desktop.

Select an option

Save krobertson/1184363 to your computer and use it in GitHub Desktop.

Revisions

  1. krobertson revised this gist Aug 31, 2011. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,9 @@

    # 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 :warning, :kind_of => Fixnum, :default => 20
    attribute :critical, :kind_of => Fixnum, :default => 60
    require_gem 'mysql'

    @@ -13,8 +14,8 @@
    result.free
    connection.close

    critical("We're behind a lot!") if seconds >= warning
    warn("We're behind some") if seconds >= critical
    critical("We're behind a lot!") if seconds >= critical
    warn("We're behind some") if seconds >= warning
    ok
    end
    end
  2. krobertson created this gist Aug 31, 2011.
    38 changes: 38 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    # 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 >= warning
    warn("We're behind some") if seconds >= critical
    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