bin/check-mesos.rb in sensu-plugins-mesos-0.0.3 vs bin/check-mesos.rb in sensu-plugins-mesos-0.0.4
- old
+ new
@@ -27,48 +27,66 @@
#
require 'sensu-plugin/check/cli'
require 'rest-client'
+# Mesos default ports are defined here: http://mesos.apache.org/documentation/latest/configuration
+MASTER_DEFAULT_PORT = '5050'
+SLAVE_DEFAULT_PORT = '5051'
+
class MesosNodeStatus < Sensu::Plugin::Check::CLI
option :server,
- description: 'Mesos Host',
- short: '-s SERVER',
- long: '--server SERVER',
+ description: 'Mesos servers, comma separated',
+ short: '-s SERVER1,SERVER2,...',
+ long: '--server SERVER1,SERVER2,...',
default: 'localhost'
option :mode,
description: 'master or slave',
short: '-m MODE',
long: '--mode MODE',
required: true
+ option :port,
+ description: "port (default #{MASTER_DEFAULT_PORT} for master, #{SLAVE_DEFAULT_PORT} for slave)",
+ short: '-p PORT',
+ long: '--port PORT',
+ required: false
+
option :timeout,
description: 'timeout in seconds',
short: '-t TIMEOUT',
long: '--timeout TIMEOUT',
proc: proc(&:to_i),
default: 5
def run
- case config[:mode]
+ mode = config[:mode]
+ servers = config[:server]
+ case mode
when 'master'
- port = '5050'
+ port = config[:port] || MASTER_DEFAULT_PORT
uri = '/master/health'
when 'slave'
- port = '5051'
+ port = config[:port] || SLAVE_DEFAULT_PORT
uri = '/slave(1)/health'
end
- begin
- r = RestClient::Resource.new("http://#{config[:server]}:#{port}#{uri}", timeout: config[:timeout]).get
- if r.code == 200
- ok "Mesos #{config[:mode]} is up"
- else
- critical "Mesos #{config[:mode]} is not responding"
+ failures = []
+ servers.split(',').each do |server|
+ begin
+ r = RestClient::Resource.new("http://#{server}:#{port}#{uri}", timeout: config[:timeout]).get
+ if r.code != 200
+ failures << "#{config[:mode]} on #{server} is not responding"
+ end
+ rescue Errno::ECONNREFUSED, RestClient::ResourceNotFound, SocketError
+ failures << "Mesos #{mode} on #{server} is not responding"
+ rescue RestClient::RequestTimeout
+ failures << "Mesos #{mode} on #{server} connection timed out"
end
- rescue Errno::ECONNREFUSED
- critical "Mesos #{config[:mode]} is not responding"
- rescue RestClient::RequestTimeout
- critical "Mesos #{config[:mode]} Connection timed out"
+ end
+ if failures.empty?
+ ok "Mesos #{mode} is running on #{servers}"
+ else
+ critical failures.join("\n")
end
end
end