Class: Nexpose::EnginePool

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

Overview

Engine pool configuration object.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, scope = 'silo', id = -1)) ⇒ EnginePool

Returns a new instance of EnginePool.



76
77
78
79
# File 'lib/nexpose/pool.rb', line 76

def initialize(name, scope = 'silo', id = -1)
  @name, @scope, @id = name, scope, id.to_i
  @engines = []
end

Instance Attribute Details

#enginesObject

Array containing (EngineSummary*) for each engine assigned to the pool.



74
75
76
# File 'lib/nexpose/pool.rb', line 74

def engines
  @engines
end

#idObject

Unique identifier of the engine pool.



68
69
70
# File 'lib/nexpose/pool.rb', line 68

def id
  @id
end

#nameObject

Name of the engine pool.



70
71
72
# File 'lib/nexpose/pool.rb', line 70

def name
  @name
end

#scopeObject

Whether the engine pool has global or silo scope.



72
73
74
# File 'lib/nexpose/pool.rb', line 72

def scope
  @scope
end

Class Method Details

.load(connection, name, scope = 'silo') ⇒ EnginePool

Returns detailed information about a single engine pool.

Parameters:

  • connection (Connection)

    Connection to console where site exists.

  • name (String)

    The name of the engine pool.

  • scope (String) (defaults to: 'silo')

    The silo of the engine pool.

Returns:

  • (EnginePool)

    Engine pool configuration object.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/nexpose/pool.rb', line 99

def self.load(connection, name, scope = 'silo')
  xml = %(<EnginePoolDetailsRequest session-id="#{connection.session_id}">)
  xml << %(<EnginePool name="#{name}" scope="#{scope}"/>)
  xml << '</EnginePoolDetailsRequest>'

  r = connection.execute(xml, '1.2')
  if r.success
    r.res.elements.each('EnginePoolDetailsResponse/EnginePool') do |pool|
      config = EnginePool.new(pool.attributes['name'],
                              pool.attributes['scope'],
                              pool.attributes['id'].to_i)
      r.res.elements.each('EnginePoolDetailsResponse/EnginePool/EngineSummary') do |summary|
        config.engines << EngineSummary.new(summary.attributes['id'].to_i,
                                            summary.attributes['name'],
                                            summary.attributes['address'],
                                            summary.attributes['port'].to_i,
                                            summary.attributes['status'],
                                            summary.attributes['scope'])
      end
      return config
    end
  end
  nil
end

Instance Method Details

#add(engine_name) ⇒ Object

Add an engine to the pool by name (not ID).

EngineSummary objects should just be appended to the pool directly,

e.g., pool.engines << nsc.engines.find { |e| e.name == 'Cleveland' }

Parameters:

  • engine_name (String)

    Name used to identify a paired scan engine.



88
89
90
# File 'lib/nexpose/pool.rb', line 88

def add(engine_name)
  @engines << EngineSummary.new(-1, engine_name, nil, 40814, nil)
end

#delete(connection) ⇒ Object

Deletes an engine pool

Parameters:

  • connection (Connection)

    Connection to console where site exists.



152
153
154
155
156
157
158
159
# File 'lib/nexpose/pool.rb', line 152

def delete(connection)
  xml = %(<EnginePoolDeleteRequest session-id="#{connection.session_id}">)
  xml << %(<EnginePool name="#{@name}" scope="#{@scope}" />)
  xml << '</EnginePoolDeleteRequest>'

  r = connection.execute(xml, '1.2')
  r.success
end

#save(connection) ⇒ Object

Save an engine pool to a security console.

Parameters:

  • connection (Connection)

    Connection to console where site exists.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/nexpose/pool.rb', line 128

def save(connection)
  request = @id > 0 ? 'EnginePoolUpdateRequest' : 'EnginePoolCreateRequest'
  xml = %(<#{request} session-id="#{connection.session_id}">)
  xml << '<EnginePool'
  xml << %( id="#{@id}") if @id > 0
  xml << %( name="#{@name}" scope="#{@scope}">)
  @engines.each do |engine|
    xml << %(<Engine name="#{engine.name}" />)
  end
  xml << '</EnginePool>'
  xml << %(</#{request}>)

  r = connection.execute(xml, '1.2')
  if r.success
    r.res.elements.each(request.gsub('Request', 'Response')) do |v|
      return @id = v.attributes['id'].to_i
    end
  end
end