bin/metrics-dns.rb in sensu-plugins-dns-1.0.0 vs bin/metrics-dns.rb in sensu-plugins-dns-1.1.0
- old
+ new
@@ -37,26 +37,41 @@
description: 'Record type to resolve (A, AAAA, TXT, etc) use PTR for reverse lookup',
short: '-t RECORD',
long: '--type RECORD',
default: 'A'
+ option :class,
+ description: 'Record class to resolve (IN, CH, HS, ANY)',
+ short: '-c CLASS',
+ long: '--class CLASS',
+ default: 'IN'
+
option :server,
description: 'Server to use for resolution',
short: '-s SERVER',
long: '--server SERVER'
+ option :port,
+ description: 'Port to use for resolution',
+ short: '-p PORT',
+ long: '--port PORT',
+ proc: proc(&:to_i)
+
option :scheme,
description: 'Metric naming scheme, text to prepend to metric',
short: '-S SCHEME',
long: '--scheme SCHEME',
default: "#{Socket.gethostname}.dns"
def run
unknown 'No domain specified' if config[:domain].nil?
begin
- resolver = config[:server].nil? ? Dnsruby::Resolver.new : Dnsruby::Resolver.new(nameserver: [config[:server]])
- result = Benchmark.realtime { resolver.query(config[:domain], config[:type]) }
+ dnsruby_config = {}
+ dnsruby_config[:nameserver] = [config[:server]] unless config[:server].nil?
+ dnsruby_config[:port] = config[:port] unless config[:port].nil?
+ resolver = Dnsruby::Resolver.new(dnsruby_config)
+ result = Benchmark.realtime { resolver.query(config[:domain], config[:type], config[:class]) }
key_name = config[:domain].to_s.tr('.', '_')
# Response Time stat
output "#{config[:scheme]}.#{config[:type]}.#{key_name}.response_time", result.to_f.round(8)