bin/check-dns.rb in sensu-plugins-dns-1.2.2 vs bin/check-dns.rb in sensu-plugins-dns-1.3.0
- old
+ new
@@ -63,11 +63,11 @@
short: '-p PORT',
long: '--port PORT',
proc: proc(&:to_i)
option :result,
- description: 'A positive result entry',
+ description: 'A list of positive result entries (comma separated list)',
short: '-r RESULT',
long: '--result RESULT'
option :regex,
description: 'Compare results to a regular expression',
@@ -160,11 +160,12 @@
def check_results(entries)
errors = []
success = []
- entries.each do |entry|
+ # TODO: come back and refactor
+ entries.each do |entry| # rubocop:disable Metrics/BlockLength
if entry.class == Dnsruby::NXDomain
errors << "Could not resolve #{config[:domain]} #{config[:type]} record"
next
elsif entry.class == Dnsruby::ResolvTimeout
errors << "Could not resolve #{config[:domain]}: Query timed out"
@@ -188,11 +189,11 @@
b = if entry.answer.count > 1
entry.answer.rrsets(config[:type].to_s).to_s
else
entry.answer.first.to_s
end
- if b.include?(config[:result])
+ if config[:result].split(',').any? { |r| b.include?(r) }
success << "Resolved #{entry.security_level} #{config[:domain]} #{config[:type]} included #{config[:result]}"
else
errors << "Resolved #{config[:domain]} #{config[:type]} did not include #{config[:result]}"
end
end
@@ -211,11 +212,14 @@
[errors, success]
end
def check_ips(entries)
ips = entries.first.answer.rrsets(config[:type]).flat_map(&:rrs).map(&:address).map(&:to_s)
- result = IPAddr.new config[:result]
- if ips.any? { |ip| (IPAddr.new ip) == result }
+ results = config[:result].split(',').map { |r| IPAddr.new(r) }
+ found = results.any? do |result|
+ ips.any? { |ip| IPAddr.new(ip) == result }
+ end
+ if found
ok "Resolved #{entries.first.security_level} #{config[:domain]} #{config[:type]} included #{config[:result]}"
else
critical "Resolved #{config[:domain]} #{config[:type]} did not include #{config[:result]}"
end
end