sensu-plugins / sensu-plugins-dns

This plugin provides native DNS instrumentation for monitoring, including: record resolution
http://sensu-plugins.io
MIT License
5 stars 26 forks source link

check-dns.rb fails with `undefined method answer for #<Array:0x895b73c>` in 1.2.0 #19

Closed grem11n closed 7 years ago

grem11n commented 7 years ago

Encountered an issue with version 1.2.0 of this plugin:

Check results with 1.2.0:

$ruby ./check-dns-1-2-0.rb -s 8.8.8.8 -d google.com -r 74.125.202.100
Check failed to run: undefined method `answer' for #<Array:0x895b73c>, ["/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-dns-1.2.0/bin/check-dns.rb:215:in `check_ips'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-dns-1.2.0/bin/check-dns.rb:185:in `block in check_results'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-dns-1.2.0/bin/check-dns.rb:165:in `each'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-dns-1.2.0/bin/check-dns.rb:165:in `check_results'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-dns-1.2.0/bin/check-dns.rb:229:in `run'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.4.2/lib/sensu-plugin/cli.rb:58:in `block in <class:CLI>'"]

Output of 1.1.0 version of this plugin:

$ruby ./check-dns-1-1-0.rb -s 8.8.8.8 -d google.com -r 74.125.202.100
DNS OK: Resolved UNCHECKED google.com A included 74.125.202.100

Some debug information:

--/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/ipv6.rb:93: `cannot interpret as IPv4 address: "MY_HOSTNAME"' (ArgumentError)
    from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/resolver.rb:513:in `set_config_nameserver'
    from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/resolver.rb:458:in `block in initialize'
    from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/resolver.rb:453:in `each'
    from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/resolver.rb:453:in `initialize'
    from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-dns-1.2.0/bin/check-dns.rb:126:in `new'
    from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-dns-1.2.0/bin/check-dns.rb:126:in `resolve_domain'
    from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-dns-1.2.0/bin/check-dns.rb:228:in `run'
    from /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.4.2/lib/sensu-plugin/cli.rb:58:in `block in <class:CLI>'
/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/ipv6.rb:93:          raise ArgumentError.new("not numeric IPv6 address: " + arg)

I haven't dig into diff between versions 1.1.0 and 1.2.0, though. My environment:

Ruby version:

ruby --version
ruby 2.3.0p0 (2015-12-25 revision 53290) [i686-linux]

Gem version:

gem --version
2.6.6

OS: Ubuntu 12.04 i386 Kernel: 3.2.0-55-virtual

This host is pretty old and support term for 12.04 have already ended. So, if this issue is related to an outdated environment, please, advise and close this issue.

Thanks!

Qsick commented 7 years ago

I'm seeing this same issue on Ubuntu 16.04 and 14.04.

My systems are using sensu embedded Ruby.

Note that taking off the result portion returns success:

$ /opt/sensu/embedded/bin/check-dns.rb -s 8.8.8.8 -d google.com
DNS OK: Resolved google.com A
majormoses commented 7 years ago

Here is the diff of 1.1.0 and 1.2.0: https://github.com/sensu-plugins/sensu-plugins-dns/compare/1.1.0...1.2.0 When I have some time tonight I will try to look into it if someone has not.

majormoses commented 7 years ago

broken by: https://github.com/sensu-plugins/sensu-plugins-dns/pull/15

majormoses commented 7 years ago

released: https://rubygems.org/gems/sensu-plugins-dns/versions/1.2.1

majormoses commented 7 years ago

@grem11n @Qsick can you please validate the hotfix works for you?

Qsick commented 7 years ago

@majormoses 1.2.1 is working properly for my configuration. Thanks for the quick fix.

majormoses commented 7 years ago

no problem, this is why we want to start adding testing to catch these regressions...

grem11n commented 7 years ago

@majormoses I can confirm, that version 1.2.1 works on Ubuntu 12.04 i386 as well Thank you for fixing this bug!