class Mdm::Host

A system with an {#address IP address} on the network that has been discovered in some way.

Constants

ARCHITECTURES

Either the CPU architecture for native code or the programming language name for exploits that run code in the programming language's virtual machine.

SEARCH_FIELDS

Fields searched for the search scope

STATES

Valid values for {#state}.

UNKNOWN_ARCHITECTURE

Special {#arch} value to indicate we should look at {#detected_arch} instead

Public Instance Methods

address() click to toggle source

@!attribute [rw] address

The IP address of this host. Necessary to avoid coercion to an `IPAddr` object.

@return [String]
# File app/models/mdm/host.rb, line 72
def address
  self[:address].to_s
end
attribute_locked?(attr) click to toggle source

Returns whether 'host.updated.<attr>' {#notes note} is {Mdm::Note#data locked}.

@return [true] if Mdm::Note with 'host.updated.<attr>' as {Mdm::Note#name} exists and data is `true`. @return [false] otherwise.

# File app/models/mdm/host.rb, line 554
def attribute_locked?(attr)
  n = notes.find_by_ntype("host.updated.#{attr}")
  n && n.data[:locked]
end
ip_address_invalid?() click to toggle source

This is replicated by the IpAddressValidator class. Had to put it here as well to avoid SQL errors when checking address uniqueness.

@return [void]

# File app/models/mdm/host.rb, line 563
def ip_address_invalid?
  begin
    if address.is_a? IPAddr
      potential_ip = address.dup
    else
      potential_ip = IPAddr.new(address)
    end

    return true unless potential_ip.ipv4? || potential_ip.ipv6?
  rescue ArgumentError
    return true
  end
end
is_vm?() click to toggle source

Returns whether this host is a virtual machine.

@return [true] unless {#virtual_host} is `nil`. @return [false] otherwise.

# File app/models/mdm/host.rb, line 581
def is_vm?
  !!self.virtual_host
end

Private Instance Methods

normalize_arch() click to toggle source
# File app/models/mdm/host.rb, line 587
def normalize_arch
  if attribute_present?(:arch) && !ARCHITECTURES.include?(self.arch)
    self.detected_arch = arch
    self.arch = UNKNOWN_ARCHITECTURE
  end
end