bin/check-dns.rb in sensu-plugins-dns-1.3.0 vs bin/check-dns.rb in sensu-plugins-dns-1.4.0

- old
+ new

@@ -52,11 +52,11 @@ short: '-c CLASS', long: '--class CLASS', default: 'IN' option :server, - description: 'Server to use for resolution', + description: 'A comma-separated list of servers to use for resolution', short: '-s SERVER', long: '--server SERVER' option :port, description: 'Port to use for resolution', @@ -116,13 +116,14 @@ short: '-T TIMEOUT', long: '--timeout TIMEOUT', proc: proc(&:to_i), default: 5 - def resolve_domain + def resolve_domain(server) dnsruby_config = {} - dnsruby_config[:nameserver] = [config[:server]] unless config[:server].nil? + + dnsruby_config[:nameserver] = server unless server.nil? dnsruby_config[:port] = config[:port] unless config[:port].nil? dnsruby_config[:use_tcp] = config[:use_tcp] unless config[:use_tcp].nil? resolv = Dnsruby::Resolver.new(dnsruby_config) resolv.do_validation = true if config[:validate] @@ -227,13 +228,22 @@ def run unknown 'No domain specified' if config[:domain].nil? unknown 'Count must be 1 or more' if config[:request_count] < 1 - entries = resolve_domain - errors, success = check_results(entries) + success = [] + errors = [] - percent = success.count.to_f / config[:request_count] * 100 + ns = config[:server].nil? ? [nil] : config[:server].split(',') + ns.each do |server| + entries = resolve_domain(server) + e, s = check_results(entries) + + success += s + errors += e + end + + percent = success.count.to_f / (config[:request_count] * ns.count) * 100 if percent < config[:threshold] output = "#{percent.to_i}% of tests succeeded: #{errors.uniq.join(', ')}" config[:warn_only] ? warning(output) : critical(output) else ok(success.uniq.join(', '))