Class: ScanManager
Overview
Used to start site device scans where a user is able to specify the maximum amount of scans that
should be running at a time. This class does not guarantee that there will be no more than the
maximum amount of scans specified will be running BUT scans will not be started from this class
until the current amount of scans running is less than or equal to the maximum.
This class can also be used to monitor the state of a running scan.
Instance Attribute Summary collapse
-
#is_poller_thread_running ⇒ Object
Used to determine if the poller thread is running.
-
#period ⇒ Object
readonly
Determines how often the poller thread is executed.
Instance Method Summary collapse
-
#add_cond_scan(conditional_scan) ⇒ Object
Starts device site scans based on a particular condition, for now this is if the max amount of scans specified is greater than the amount of currently running scans.
-
#add_scan_observed(scan_id) ⇒ Object
Adds a scan to be observed scan_id: The ID of the scan to be observed.
-
#initialize(nexpose_conn, poler_exit_on_completion, period) ⇒ ScanManager
constructor
The poller thread used within this class is initialized here.
-
#remover_scan_observed(scan_id) ⇒ Object
Removes a currently observed scan scan_id: The ID of the scan to be removed.
Constructor Details
#initialize(nexpose_conn, poler_exit_on_completion, period) ⇒ ScanManager
The poller thread used within this class is initialized here.
nexpose_conn: The NeXpose API object poler_exit_on_completion: ‘true’, if the poller thread should exit when when there is nothing left to process. period: The frequency at which the poller thread executes
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/scan_manager.rb', line 118 def initialize nexpose_conn, poler_exit_on_completion, period @nexpose_conn = nexpose_conn @period = period @poler_exit_on_completion = poler_exit_on_completion @semaphore = Mutex.new @conditional_device_scans = [] @scans_observed = [] @execution_cycle_started = false start_poller end |
Instance Attribute Details
#is_poller_thread_running ⇒ Object
Used to determine if the poller thread is running
20 21 22 |
# File 'lib/scan_manager.rb', line 20 def is_poller_thread_running @is_poller_thread_running end |
#period ⇒ Object (readonly)
Determines how often the poller thread is executed
23 24 25 |
# File 'lib/scan_manager.rb', line 23 def period @period end |
Instance Method Details
#add_cond_scan(conditional_scan) ⇒ Object
Starts device site scans based on a particular condition, for now this is if the max amount of scans specified is greater than the amount of currently running scans.
conditional_scan: A hash of informations used to start scanning ie : @[0] -> :site_id => 1 :devices => [192.168.1.1] :max_scans => 5 :listeners => [listerner_objects]
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/scan_manager.rb', line 153 def add_cond_scan conditional_scan if conditional_scan.nil? raise ArgumentError 'Condtional scan arguement is null' end @semaphore.synchronize do @conditional_device_scans << conditional_scan if not @execution_cycle_started @execution_cycle_started = true end end end |
#add_scan_observed(scan_id) ⇒ Object
Adds a scan to be observed scan_id: The ID of the scan to be observed.
134 135 136 137 |
# File 'lib/scan_manager.rb', line 134 def add_scan_observed scan_id puts "Obeserving scan #{scan_id}" @scans_observed << scan_id end |
#remover_scan_observed(scan_id) ⇒ Object
Removes a currently observed scan scan_id: The ID of the scan to be removed.
143 144 145 |
# File 'lib/scan_manager.rb', line 143 def remover_scan_observed scan_id @scans_observed.delete scan_id end |