Class: CheckHostIp

Inherits:
Object
  • Object
show all
Defined in:
lib/check_host/check_host_ip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, ip) ⇒ CheckHostIp

Returns a new instance of CheckHostIp.



7
8
9
10
# File 'lib/check_host/check_host_ip.rb', line 7

def initialize(host, ip)
  @host = host
  @ip   = ip
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/check_host/check_host_ip.rb', line 5

def host
  @host
end

#ipObject

Returns the value of attribute ip.



5
6
7
# File 'lib/check_host/check_host_ip.rb', line 5

def ip
  @ip
end

Instance Method Details

#cmdObject

Runs the host cmd and returns just the A record example: “fawazalhokairfashion.com has address 91.109.13.176n”

Returns:

  • String



15
16
17
# File 'lib/check_host/check_host_ip.rb', line 15

def cmd
  `host -t A #{host}`
end

#notifyObject

Sends an email if result? is true If result? is true then SendMail

Returns:

  • Boolean



28
29
30
31
32
33
34
35
# File 'lib/check_host/check_host_ip.rb', line 28

def notify
  if result?
    SendMail.new
    true
  else
    false
  end
end

#result?Boolean

Checks whether a string contains the ip address

Returns:

  • (Boolean)

    Boolean



21
22
23
# File 'lib/check_host/check_host_ip.rb', line 21

def result?
  !cmd.include? ip
end