Class: DNS::Monitor::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/dns/monitor/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Runner

The “Runner” is the back-end for the command-line utility



5
6
7
# File 'lib/dns/monitor/runner.rb', line 5

def initialize(params)
  @params = params
end

Instance Method Details

#checkObject

This is the main action we do with this app - check all of the domains



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dns/monitor/runner.rb', line 10

def check
  begin
    domains = File.read(@params[:domains_path]).split
  rescue Errno::ENOENT 
    STDERR.puts "File #{@params[:domains_path]} does not exist"
    exit 1 
  end

  checks = domains.map do |domain|
    rdap = Net::HTTP.get(URI("#{@params[:rdap_url]}/domain/#{domain}"))
    db.check domain, rdap 
  end

  message = checks.map {|check| check.status}.to_json
  STDOUT.puts message

  if @params[:gchat] 
    # GChat gets every status update
    GChat.new(@params[:gchat]).message(message) 
  end
  if @params[:mandrill_key] && @params[:mandrill_email] && checks.any?(&:changed?)
    # We only email changed domains
    Mandrill.new(@params[:mandrill_key], @params[:mandrill_email]).message(message)
  end
end

#entriesObject

This is an alternative app action - check the history for a particular domain.



37
38
39
# File 'lib/dns/monitor/runner.rb', line 37

def entries
  STDOUT.puts db.entries(@params[:domain]).map{|row| row.to_parsed_h}.to_json
end