-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmoveEngineToPool.rb
62 lines (46 loc) · 1.75 KB
/
moveEngineToPool.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby
# Brian W. Gray
# 04.09.2015
## Script performs the following tasks
## 1.) Stop all scans assigned sites assigned to a specified scan engine.
## 2.) Stop all scans running on the engine to be removed.
## 3.) Assign the listed sites from one scan engine to a new scan engine.
## 4.) TODO: efficiency improvements.
## This script was primarily meant to be used for moving sites from engines to scan pools.
require 'yaml'
require 'nexpose'
include Nexpose
engineID = 3 # engine id to move from
newEngineID = 6 # engine id to move to
# Default Values from yaml file
config_path = File.expand_path("../conf/nexpose.yaml", __FILE__)
config = YAML.load_file(config_path)
@host = config["hostname"]
@userid = config["username"]
@password = config["passwordkey"]
@port = config["port"]
@nexposeAjaxTimeout = config["nexposeajaxtimeout"]
nsc = Nexpose::Connection.new(@host, @userid, @password, @port)
begin
nsc.login
rescue ::Nexpose::APIError => err
$stderr.puts("Connection failed: #{err.reason}")
exit(1)
end
at_exit { nsc.logout }
engineInfo = Nexpose::Engine.load(nsc, engineID)
engineInfo.sites.each do |engineSites|
begin
puts "Moving Site ID: #{engineSites.id}, Site Name: #{engineSites.name} from EngineID: #{engineID} to EngineID #{newEngineID}"
begin
siteModify = Nexpose::Site.load(nsc,engineSites.id)
siteModify.engine_id = newEngineID
siteModify.save(nsc)
rescue ::Nexpose::APIError => err
puts "Error during site modify function: #{err.reason}"
end
rescue ::Nexpose::APIError => err
puts "Error modifying Site ID: #{engineSites.id}, Site Name: #{engineSites.name}'s scan engine: #{err.reason}"
end
end
exit