Sha256: eb304859d3b6b4e664d336b8edbf283d4ba1a9c2d1934d587e47bf5c1ff5ea31

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

#! /usr/bin/env ruby
#
# check-cassandra-schema
#
# 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
#   Cassandra's nodetool
#
# USAGE:
#   #YELLOW
#
# 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 Schema
#
class CheckCassandraSchema < 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 run # rubocop:disable all
    out, rc = nodetool_cmd('describecluster')
    if rc != 0
      critical(out)
    end

    bad_nodes = []
    # #YELLOW
    out.each_line do |line|  # rubocop:disable Style/Next
      if m = line.match(/\s+UNREACHABLE:\s+(.*)\[(.*)\]\s+$/)# rubocop:disable all
        bad_nodes << m[2]
        next
      end
      if bad_nodes.count > 0
        if m = line.match(/\s+(.*)\[(.*)\]\s+$/)# rubocop:disable all
          bad_nodes << m[2]
        end
      end
    end

    if bad_nodes.count > 0
      critical('nodes ' + bad_nodes.join(', ') + ' are in schema disagreement')
    else
      ok
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sensu-plugins-cassandra-0.0.1 bin/check-cassandra-schema.rb
sensu-plugins-cassandra-0.0.1.alpha.1 bin/check-cassandra-schema.rb