Class: Checkson::Check::DNS
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(opts = {}) ⇒ DNS
constructor
A new instance of DNS.
Methods inherited from Base
Constructor Details
#initialize(opts = {}) ⇒ DNS
Returns a new instance of DNS.
6 7 8 9 10 11 |
# File 'lib/checkson/checks/dns.rb', line 6 def initialize(opts = {}) @opts = { domain: 'heise.de', timeout: 1, host: 'localhost' }.merge(opts) super() end |
Instance Method Details
#check ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/checkson/checks/dns.rb', line 13 def check require 'resolv' resolver = Resolv::DNS.new(nameserver: [@opts[:host]]) resolver.timeouts = @opts[:timeout] begin resolver.getaddress(@opts[:domain]) rescue Resolv::ResolvTimeout failed! log("Resolving #{@opts[:domain]} timed out") rescue Resolv::ResolvError failed! log("Could not resolve #{@opts[:domain]}") end end |