Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
sensu-plugins-cassandra / bin / check-cassandra-exceptions.rb
Size: Mime:
#! /usr/bin/env ruby
#
# check-cassandra-exceptions
#
# DESCRIPTION:
#   This plugin uses Apache Cassandra's `nodetool` to check to see
#   if any node in the cluster has run into a schema disagreement problem
#
# OUTPUT:
#   plain text
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#   gem: english
#   Cassandra's nodetool
#
# USAGE:
#   # command => check-cassandra-exceptions.rb
#
# NOTES:
#   See http://www.datastax.com/documentation/cassandra/2.0/cassandra/dml/dml_handle_schema_disagree_t.html
#   for more details
#
# LICENSE:
#   Copyright 2014 Sonian, Inc. and contributors. <support@sensuapp.org>
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'sensu-plugin/check/cli'
require 'English'

#
# Check Cassandra Exceptions
#
class CheckCassandraExceptions < Sensu::Plugin::Check::CLI
  option :hostname,
         short: '-h HOSTNAME',
         long: '--host HOSTNAME',
         description: 'cassandra hostname',
         default: 'localhost'

  option :port,
         short: '-P PORT',
         long: '--port PORT',
         description: 'cassandra JMX port',
         default: '7199'

  # execute cassandra's nodetool and return output as string
  def nodetool_cmd(cmd)
    out = `nodetool -h #{config[:hostname]} -p #{config[:port]} #{cmd} 2>&1`
    [out, $CHILD_STATUS]
  end

  def parse_info
    info = nodetool_cmd('info')
    info[0].each_line do |line| # rubocop:disable Metrics/BlockLength
      if (m = line.match(/^Exceptions\s*:\s+([0-9]+)$/))
        output = "Consistency unavailible exceptions", m[1], "instances"
        if output[1].to_i > 0
          warning(output.join(" "))
        end
      end
  end
 end

  def run
    out, rc = nodetool_cmd('describecluster')
    parse_info
    ok
  end
end