nexpose_scan_manager 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/doc/user-guide.txt +39 -0
  2. data/lib/scan_manager.rb +16 -16
  3. metadata +9 -7
@@ -0,0 +1,39 @@
1
+ Usage:
2
+
3
+ The Scan Manager can be used to:
4
+
5
+ A. MONITOR A SCAN
6
+
7
+ # Create a NeXpose API Connection
8
+ nexpose_connection = NeXpose::Connection.new host, username, password, port
9
+
10
+ # Initialize the scan manager
11
+ # Poll NeXpose every 5 seconds for the scan status
12
+ poll_time = 5
13
+ scan_manager = ScanManager.new nexpose_connection, false, poll__time
14
+
15
+ # Add your observing class to the scan manager that defines an update method
16
+ # scan_data contains the scan ID, status, and message if any
17
+ class ScanObserver
18
+ def update scan_data, notifier
19
+ <do whatever with scan_data>
20
+ end
21
+ end
22
+
23
+ scan_observer = ScanObserver.new
24
+ scan_manager.add_observer scan_observer
25
+
26
+
27
+ B. START A RESTRICTIVE SCAN
28
+
29
+ # Define the condition
30
+
31
+ conditional_scan =
32
+ {
33
+ :site_id => <site ID>,
34
+ :max_scans => 5, # Only start scan if there are less than 5 scans running
35
+ :devices => <array of devices>, # IPs
36
+ :listeners => listeners # Can be null or an observer as defined in A
37
+ }
38
+
39
+ scan_manager.add_conditional_device_scan conditional_scan
data/lib/scan_manager.rb CHANGED
@@ -4,14 +4,15 @@ require 'thread'
4
4
  require 'observer'
5
5
  require 'nexpose'
6
6
 
7
- #------------------------------------------------------------------------------------------------------
8
- # Used to start site device scans where a user is able to specify the maximum amount of scans that
9
- # should be running at a time. This class does not guarantee that there will be no more than the
10
- # maximum amount of scans specified will be running BUT scans will not be started from this class
11
- # until the current amount of scans running is less than or equal to the maximum.
12
- #
13
- # This class is also used to
14
- #------------------------------------------------------------------------------------------------------
7
+ =begin rdoc
8
+ Used to start site device scans where a user is able to specify the maximum amount of scans that
9
+ should be running at a time. This class does not guarantee that there will be no more than the
10
+ maximum amount of scans specified will be running BUT scans will not be started from this class
11
+ until the current amount of scans running is less than or equal to the maximum.
12
+
13
+ This class can also be used to monitor the state of a running scan.
14
+ =end
15
+
15
16
  class ScanManager
16
17
  include Observable
17
18
 
@@ -106,14 +107,14 @@ class ScanManager
106
107
 
107
108
  public
108
109
 
109
- #------------------------------------------------------------------------------------------------------
110
+ #
110
111
  # The poller thread used within this class is initialized here.
111
112
  #
112
113
  # nexpose_conn: The NeXpose API object
113
114
  # poler_exit_on_completion: 'true', if the poller thread should exit when
114
115
  # when there is nothing left to process.
115
116
  # period: The frequency at which the poller thread executes
116
- #------------------------------------------------------------------------------------------------------
117
+ #
117
118
  def initialize nexpose_conn, poler_exit_on_completion, period
118
119
  @nexpose_conn = nexpose_conn
119
120
  @period = period
@@ -126,30 +127,29 @@ class ScanManager
126
127
  start_poller
127
128
  end
128
129
 
129
- #------------------------------------------------------------------------------------------------------
130
+ #
130
131
  # Adds a scan to be observed
131
132
  # scan_id: The ID of the scan to be observed.
132
- #------------------------------------------------------------------------------------------------------
133
+ #
133
134
  def add_scan_observed scan_id
134
135
  puts "Obeserving scan #{scan_id}"
135
136
  @scans_observed << scan_id
136
137
  end
137
138
 
138
- #------------------------------------------------------------------------------------------------------
139
+ #
139
140
  # Removes a currently observed scan
140
141
  # scan_id: The ID of the scan to be removed.
141
- #------------------------------------------------------------------------------------------------------
142
+ #
142
143
  def remover_scan_observed scan_id
143
144
  @scans_observed.delete scan_id
144
145
  end
145
146
 
146
- #------------------------------------------------------------------------------------------------------
147
+ #
147
148
  # Starts device site scans based on a particular condition, for now this is if the max amount of scans
148
149
  # specified is greater than the amount of currently running scans.
149
150
  #
150
151
  # conditional_scan: A hash of informations used to start scanning
151
152
  # ie : @[0] -> :site_id => 1 :devices => [192.168.1.1] :max_scans => 5 :listeners => [listerner_objects]
152
- #-------------------------------------------------------------------------------------------------------
153
153
  def add_cond_scan conditional_scan
154
154
  if conditional_scan.nil?
155
155
  raise ArgumentError 'Condtional scan arguement is null'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexpose_scan_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nexpose
17
- requirement: &27094380 !ruby/object:Gem::Requirement
17
+ requirement: &27133608 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.0.3
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *27094380
25
+ version_requirements: *27133608
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: eventmachine-eventmachine
28
- requirement: &27093600 !ruby/object:Gem::Requirement
28
+ requirement: &27132696 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,14 +33,16 @@ dependencies:
33
33
  version: 0.12.9
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *27093600
37
- description:
36
+ version_requirements: *27132696
37
+ description: ! "\tUsed for to start a managed scan and monitor their activity\n"
38
38
  email: christopher_lee@rapid7.com
39
39
  executables: []
40
40
  extensions: []
41
- extra_rdoc_files: []
41
+ extra_rdoc_files:
42
+ - doc/user-guide.txt
42
43
  files:
43
44
  - lib/scan_manager.rb
45
+ - doc/user-guide.txt
44
46
  has_rdoc: true
45
47
  homepage:
46
48
  licenses: []