Last updated at Wed, 27 Sep 2017 14:19:43 GMT

Here's a walk-through of a Ruby script that uses the nexpose gem to add and configure your Nexpose Scan Engines.

This script configures the Dynamic Scan Pool feature. A Scan Engine pool is a group of shared Scan Engines that can be bound to a site so that the load is distributed evenly across the shared engines. The feature can only be managed through the API.

You'll need familiarity with Ruby to understand the script. I've inserted explanations as comments (marked in blue) in the code below. Values that you'll need to modify for your specific environment are in green. Please note that pairing of engines must still be done manually.

#!/usr/bin/env ruby
require 'rubygems'
require 'nexpose'
include Nexpose
require 'pp'

Wrap the call to catch exceptions.

begin

Create a connection to the Nexpose instance and log in.

  @nsc = Connection.new('nexpose.company.com', 'nxadmin', 'supersecret', 3780)

  @nsc.login

Adds a new Cleveland Engine.

This is only necessary if the engine does not already exist.

  engine = EngineConfig.new(@nsc)
  engine.address = 'cleveland.company.com'
  engine.name = 'Cleveland Engine'
  engine.save()

Define the pool. Can be instantiated with just a name.

  pool = EnginePool.new('Midwest Pool')

Add engines to the pool by name.

  pool.add('Cleveland Engine')

OK to add already existing engines.

  pool.add('Chicago Engine')

Then create the pool on the server with our new configuration.

  pool.create(@nsc)

Get a listing of all engine pools now on the server.

  list = EnginePoolSummary.listing(@nsc)

  list.each do |summary|

Print out the existing pools to the screen.

    puts summary

    puts

This overwrites our pool variable with what's returned.

    pool = EnginePool.new(summary.name, summary.id, summary.scope)
  end

Load in the details from the server.

This pulls the configuration into our pool variable.

  pool.load_details(@nsc)

Print out the configuration to the screen.

  puts 'Pool loaded from server:'

  puts pool

  puts

Adds new St Louis Engine.

  engine = EngineConfig.new(@nsc)

  engine.address = 'stlouis.company.com'

  engine.name = 'St Louis Engine'

  engine.save()

Now update the pool to include the new engine.

  pool.add('St Louis Engine')

  pool.update(@nsc)

Reload the details from the server

  pool.load_details(@nsc)

  puts pool

  puts

Know what? I've changed my mind. Delete the pool.

This only works if you have the ID of the pool correctly set, done in the load_details call above.

  pool.delete(@nsc)

rescue ::Nexpose::APIError => e

  $stderr.puts("Connection failed: #{e.reason}")

  exit(1)

end