Created
January 21, 2016 19:02
-
-
Save jjuarez/4ca4d2c0a03b4b38020b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Vertica status Plugin | |
# | |
# This plugin attempts to login to postgres with provided credentials. | |
# | |
# Copyright 2015 tuenti Eng (Javier Juarez jjuarez _AT_ tuenti.com) | |
# | |
# Released under the same terms as Sensu (the MIT license); see LICENSE | |
# for details. | |
# | |
require 'rubygems' if RUBY_VERSION < '1.9.0' | |
require 'sensu-plugin/check/cli' | |
require 'mixlib/shellout' | |
require 'vertica' | |
# | |
# = class: CheckVerticaCluster the sensu check | |
class CheckVerticaCluster < Sensu::Plugin::Check::CLI | |
DEFAULT_HOSTNAME = 'localhost' | |
DEFAULT_PORT = 5433 | |
DEFAULT_QUERY = "SELECT * FROM nodes;".freeze | |
option :hostname, | |
description: 'Vertica Hostname', | |
short: '-h HOST', | |
long: '--hostname HOSTNAME', | |
default: DEFAULT_HOSTNAME | |
option :port, | |
description: 'Vertica port', | |
short: '-P PORT', | |
long: '--port PORT', | |
default: DEFAULT_PORT | |
option :user, | |
description: 'Vertica User', | |
short: '-u USER', | |
long: '--user USER' | |
option :password, | |
description: 'Vertica Password', | |
short: '-p PASSWORD', | |
long: '--password PASSWORD' | |
option :database, | |
description: 'Vertica DB name', | |
short: '-d DATABASE', | |
long: '--database DATABASE' | |
option :warning, | |
description: 'Warning threshold', | |
short: '-w PERCENTAGE', | |
long: '--warning PERCENTAGE' | |
option :critical, | |
description: 'Critical threshold', | |
short: '-c PERCENTAGE', | |
long: '--critical PERCENTAGE' | |
def run | |
unknown("Warning threshold is a mandatory parameter(number of nodes of the cluster)") unless config[:warning] | |
unknown("Critical threshold is a mandatory parameter(number of nodes of the cluster)") unless config[:critical] | |
connection = Vertica.connect({ | |
:host => config[:host], | |
:port => config[:port], | |
:user => config[:user], | |
:password => config[:password], | |
:database => config[:database], | |
:row_style => :array | |
}) | |
nodes = connection.query DEFAULT_QUERY | |
critical("Your cluster has node(s) DOWN") if nodes.rows.any? { |node| node[:node_state] == 'DOWN' } | |
warning("Your cluster has node(s) INITIALIZING or SHUTDOWN") if nodes.rows.any? { |node| node[:node_state] =~ /INITIALIZING|SHUTDOWN/ } | |
ok("Your cluster is working like a charm") if nodes.rows.all? { |node| node[:node_state] == 'UP' } | |
rescue => run_exception | |
unknown "Error: #{run_exception.message}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment