class Nexpose::Engine

Engine connnection to a Nexpose console.

Attributes

address[RW]

The IP address or DNS name of a scan engine.

id[RW]

Unique numeric identifier for the scan engine, assigned by the console in the order of creation.

name[RW]

A name assigned to the scan engine by the security console.

port[RW]

The port on which the engine listens for requests from the security console.

priority[RW]

Relative priority of a scan engine. One of: very-low, low, normal, high, very-high

scope[RW]

Whether the engine has a global or silo-specific scope.

sites[RW]

Sites to which the scan engine is assigned.

Public Class Methods

load(connection, id) click to toggle source
# File lib/nexpose/engine.rb, line 154
def self.load(connection, id)
  xml = '<EngineConfigRequest session-id="' + connection.session_id + '"'
  xml << %( engine-id="#{id}")
  xml << ' />'
  r = connection.execute(xml, '1.2')

  if r.success
    r.res.elements.each('EngineConfigResponse/EngineConfig') do |config|
      engine = Engine.new(config.attributes['address'],
                          config.attributes['name'],
                          config.attributes['port'])
      engine.id       = config.attributes['id']
      engine.scope    = config.attributes['scope'] if config.attributes['scope']
      engine.priority = config.attributes['priority'] if config.attributes['priority']

      config.elements.each('Site') do |site|
        engine.sites << SiteSummary.new(site.attributes['id'], site.attributes['name'])
      end

      return engine
    end
  end
  nil
end
new(address, name = nil, port = 40814) click to toggle source
# File lib/nexpose/engine.rb, line 144
def initialize(address, name = nil, port = 40814)
  @id      = -1
  @address = address
  @name    = name
  @name  ||= address
  @port    = port
  @scope   = 'silo'
  @sites   = []
end

Public Instance Methods

add_site(site_id) click to toggle source

Assign a site to this scan engine.

@param [Fixnum] site_id Unique numerical ID of the site.

# File lib/nexpose/engine.rb, line 183
def add_site(site_id)
  sites << SiteSummary.new(site_id, nil)
end
delete(connection) click to toggle source

Delete this scan engine configuration from the security console.

@param [Connection] connection Connection to console where site exists.

# File lib/nexpose/engine.rb, line 227
def delete(connection)
  connection.delete_engine(@id, @scope)
end
save(connection) click to toggle source

Save this engine configuration to the security console.

@param [Connection] connection Connection to console where site exists. @return [Fixnum] ID assigned to the scan engine.

# File lib/nexpose/engine.rb, line 210
def save(connection)
  xml = '<EngineSaveRequest session-id="' + connection.session_id + '">'
  xml << to_xml
  xml << '</EngineSaveRequest>'

  r = connection.execute(xml, '1.2')
  if r.success
    r.res.elements.each('EngineSaveResponse/EngineConfig') do |v|
      return @id = v.attributes['id'].to_i
    end
  end
end
to_xml() click to toggle source
# File lib/nexpose/engine.rb, line 189
def to_xml
  xml = '<EngineConfig'
  xml << %( id="#{id}")
  xml << %( address="#{address}")
  xml << %( name="#{replace_entities(name)}")
  xml << %( port="#{port}")
  xml << %( scope="#{scope}") if scope
  xml << %( priority="#{priority}") if priority
  xml << '>'
  sites.each do |site|
    xml << %(<Site id="#{site.id}" />)
  end
  xml << '</EngineConfig>'
  xml
end