Sha256: 17e6f07f798db883a66ddc909d376622d13a440ad63aabbc2db2a7eb8cdf0611

Contents?: true

Size: 1.89 KB

Versions: 14

Compression:

Stored size: 1.89 KB

Contents

#!/usr/bin/env ruby
#  encoding: UTF-8
#
# RabbitMQ Network Partitions Check
# ===
#
# DESCRIPTION:
# This plugin checks if a RabbitMQ network partition has occured.
# https://www.rabbitmq.com/partitions.html
#
# PLATFORMS:
#   Linux, BSD, Solaris
#
# DEPENDENCIES:
#   RabbitMQ rabbitmq_management plugin
#   gem: sensu-plugin
#   gem: carrot-top
#
# LICENSE:
# Copyright 2015 Ed Robinson <ed@reevoo.com> and Reevoo LTD.
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.

require 'sensu-plugin/check/cli'
require 'carrot-top'

# main plugin class
class CheckRabbitMQPartitions < Sensu::Plugin::Check::CLI
  option :host,
         description: 'RabbitMQ management API host',
         short: '-w',
         long: '--host HOST',
         default: 'localhost'

  option :port,
         description: 'RabbitMQ management API port',
         long: '--port PORT',
         proc: proc(&:to_i),
         default: 15_672

  option :username,
         description: 'RabbitMQ management API user',
         short: '-u',
         long: '--username USERNAME',
         default: 'guest'

  option :password,
         description: 'RabbitMQ management API password',
         short: '-p',
         long: '--password PASSWORD',
         default: 'guest'

  option :ssl,
         description: 'Enable SSL for connection to the API',
         long: '--ssl',
         boolean: true,
         default: false

  def run
    critical 'network partition detected' if partition?
    ok 'no network partition detected'
  rescue Errno::ECONNREFUSED => e
    critical e.message
  rescue => e
    unknown e.message
  end

  def partition?
    rabbitmq_management.nodes.map { |node| node['partitions'] }.any?(&:any?)
  end

  def rabbitmq_management
    CarrotTop.new(
      host: config[:host],
      port: config[:port],
      user: config[:username],
      password: config[:password],
      ssl: config[:ssl]
    )
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
sensu-plugins-rabbitmq-2.3.0 bin/check-rabbitmq-network-partitions.rb
sensu-plugins-rabbitmq-2.2.0 bin/check-rabbitmq-network-partitions.rb
sensu-plugins-rabbitmq-2.1.0 bin/check-rabbitmq-network-partitions.rb
sensu-plugins-rabbitmq-2.0.0 bin/check-rabbitmq-network-partitions.rb
sensu-plugins-rabbitmq-temp-1.4.0 bin/check-rabbitmq-network-partitions.rb
sensu-plugins-rabbitmq-1.3.1 bin/check-rabbitmq-network-partitions.rb
sensu-plugins-rabbitmq-1.2.0 bin/check-rabbitmq-network-partitions.rb
sensu-plugins-rabbitmq-1.1.0 bin/check-rabbitmq-network-partitions.rb
sensu-plugins-rabbitmq-1.0.0 bin/check-rabbitmq-network-partitions.rb
sensu-plugins-rabbitmq-0.1.0 bin/check-rabbitmq-network-partitions.rb
sensu-plugins-rabbitmq-0.0.4 bin/check-rabbitmq-network-partitions.rb
sensu-plugins-rabbitmq-0.0.3 bin/check-rabbitmq-network-partitions.rb
sensu-plugins-rabbitmq-0.0.2 bin/check-rabbitmq-network-partitions.rb
sensu-plugins-rabbitmq-0.0.1 bin/check-rabbitmq-network-partitions.rb