bin/check-marathon.rb in sensu-plugins-mesos-0.0.3 vs bin/check-marathon.rb in sensu-plugins-mesos-0.0.4
- old
+ new
@@ -29,30 +29,46 @@
require 'sensu-plugin/check/cli'
require 'rest-client'
class MarathonNodeStatus < Sensu::Plugin::Check::CLI
option :server,
- description: 'Marathon Host',
- short: '-s SERVER',
- long: '--server SERVER',
+ description: 'Marathon servers, comma separated',
+ short: '-s SERVER1,SERVER2,...',
+ long: '--server SERVER1,SERVER2,...',
default: 'localhost'
+ option :port,
+ description: 'Marathon port',
+ short: '-p PORT',
+ long: '--port PORT',
+ required: false,
+ default: '8080'
+
option :timeout,
description: 'timeout in seconds',
short: '-t TIMEOUT',
long: '--timeout TIMEOUT',
proc: proc(&:to_i),
default: 5
def run
- r = RestClient::Resource.new("http://#{config[:server]}:8080/ping", timeout: config[:timeout]).get
- if r.code == 200
- ok 'Marathon Service is up'
+ servers = config[:server]
+ failures = []
+ servers.split(',').each do |server|
+ begin
+ r = RestClient::Resource.new("http://#{server}:#{config[:port]}/ping", timeout: config[:timeout]).get
+ if r.code != 200
+ failures << "Marathon Service on #{server} is not responding"
+ end
+ rescue Errno::ECONNREFUSED, RestClient::ResourceNotFound, SocketError
+ failures << "Marathon Service on #{server} is not responding"
+ rescue RestClient::RequestTimeout
+ failures << "Marathon Service on #{server} connection timed out"
+ end
+ end
+ if failures.empty?
+ ok "Marathon Service is up on #{servers}"
else
- critical 'Marathon Service is not responding'
+ critical failures.join("\n")
end
- rescue Errno::ECONNREFUSED
- critical 'Marathon Service is not responding'
- rescue RestClient::RequestTimeout
- critical 'Marathon Service Connection timed out'
end
end