bin/check-mesos.rb in sensu-plugins-mesos-0.1.1 vs bin/check-mesos.rb in sensu-plugins-mesos-1.0.0

- old
+ new

@@ -27,65 +27,55 @@ # 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'.freeze -SLAVE_DEFAULT_PORT = '5051'.freeze - class MesosNodeStatus < Sensu::Plugin::Check::CLI option :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)", + description: 'port (default 5050, use 5051 for slaves)', short: '-p PORT', long: '--port PORT', + default: 5050, required: false + option :uri, + description: 'Endpoint URI', + short: '-u URI', + long: '--uri URI', + default: '/health' + option :timeout, description: 'timeout in seconds', short: '-t TIMEOUT', long: '--timeout TIMEOUT', proc: proc(&:to_i), default: 5 def run - mode = config[:mode] servers = config[:server] - case mode - when 'master' - port = config[:port] || MASTER_DEFAULT_PORT - uri = '/master/health' - when 'slave' - port = config[:port] || SLAVE_DEFAULT_PORT - uri = '/slave(1)/health' - end + uri = config[:uri] + port = config[:port] 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" + failures << "Mesos on #{server} is not responding" end rescue Errno::ECONNREFUSED, RestClient::ResourceNotFound, SocketError - failures << "Mesos #{mode} on #{server} is not responding" + failures << "Mesos on #{server} is not responding" rescue RestClient::RequestTimeout - failures << "Mesos #{mode} on #{server} connection timed out" + failures << "Mesos on #{server} connection timed out" end end if failures.empty? - ok "Mesos #{mode} is running on #{servers}" + ok "Mesos is running on #{servers}" else critical failures.join("\n") end end end