Skip to content

Commit

Permalink
Added ability to use many NS servers
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuri Zubov authored and majormoses committed Mar 22, 2018
1 parent 3535f1c commit 4f4e461
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)

## [Unreleased]
- check-dns.rb: Added ability to use many name servers (@yuri-zubov)

## [1.3.0] - 2017-11-04
### Added
Expand Down
22 changes: 16 additions & 6 deletions bin/check-dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DNS < Sensu::Plugin::Check::CLI
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'

Expand Down Expand Up @@ -118,9 +118,10 @@ class DNS < Sensu::Plugin::Check::CLI
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)
Expand Down Expand Up @@ -229,10 +230,19 @@ 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 = []

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] * 100
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)
Expand Down

0 comments on commit 4f4e461

Please sign in to comment.