Class: DDis

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(range, unassigned, verbose = nil) ⇒ DDis

Returns a new instance of DDis.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ddis.rb', line 15

def initialize range, unassigned, verbose=nil
  @verbose  = true if verbose

  @unass    = unassigned
  @resolv   = Resolv.new
  @ping     = Net::Ping::ICMP.new nil, nil, 1

  ip_range  = NetAddr::CIDR.create range
  @base     = ip_range.base
  @size     = ip_range.size
  @iterator = Iterator.new @base, @size
  @db       = StoreIPs.new

end

Instance Attribute Details

#iteratorObject

Returns the value of attribute iterator.



13
14
15
# File 'lib/ddis.rb', line 13

def iterator
  @iterator
end

Instance Method Details

#read_dbObject



55
56
57
# File 'lib/ddis.rb', line 55

def read_db
  @db.dump
end

#saveObject



59
60
61
# File 'lib/ddis.rb', line 59

def save
  @db.save
end

#test_ip(ip) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ddis.rb', line 30

def test_ip ip
  begin
    hostname = @resolv.getname( ip )
  rescue
    hostname = nil
  end

  begin
    @ping.host = ip
    up = @ping.ping?
  rescue
    warn "Can't ping #{ip}" if @verbose
  end

  if up and ( hostname =~ /#{@unass}/ or hostname.nil? )
    warn "#{ip} is up yet has an invalid hostname" if @verbose
    @db.up_no_dns( ip )
  end

  if not up and ( hostname !~ /#{@unass}/ and ! hostname.nil? )
    warn "#{ip} is down yet has a hostname set" if @verbose
    @db.down_with_dns( ip )
  end
end