Class: Checkson::Check::DNS

Inherits:
Base
  • Object
show all
Defined in:
lib/checkson/checks/dns.rb

Instance Attribute Summary

Attributes inherited from Base

#messages, #status

Instance Method Summary collapse

Methods inherited from Base

#failed?, #ok?

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

#checkObject



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