Class: ExtendedAPI
- Inherits:
-
Object
- Object
- ExtendedAPI
- Defined in:
- lib/extended-api.rb
Overview
Extends the base API functionality by combining common API commands to produce a simplified user command.
Constant Summary collapse
- @@connected =
false
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#nexpose_api ⇒ Object
Returns the value of attribute nexpose_api.
-
#password ⇒ Object
Returns the value of attribute password.
-
#scan_manager ⇒ Object
Returns the value of attribute scan_manager.
-
#user_name ⇒ Object
Returns the value of attribute user_name.
Instance Method Summary collapse
-
#do_login ⇒ Object
——————————————————————- Logs in to NeXpose and sets a session key on the connector object.
- #do_logout ⇒ Object
-
#initialize(user_name, password, host) ⇒ ExtendedAPI
constructor
A new instance of ExtendedAPI.
-
#print_asset_group_info(group_id) ⇒ Object
—————————————————— Prints all asset group information in tabular format: | site_id | device_id | address | riskfactor | ——————————————————.
-
#print_asset_groups ⇒ Object
—————————————————————- Prints asset group configuration information in tabular format: | site_id | device_id | address | riskfactor | —————————————————————-.
- #start_excluded_scan(scan_info) ⇒ Object
Constructor Details
#initialize(user_name, password, host) ⇒ ExtendedAPI
Returns a new instance of ExtendedAPI.
16 17 18 19 20 21 |
# File 'lib/extended-api.rb', line 16 def initialize user_name, password, host @user_name = user_name @password = password @host = host @nexpose_api = Nexpose::Connection.new @host, @user_name, @password end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
13 14 15 |
# File 'lib/extended-api.rb', line 13 def host @host end |
#nexpose_api ⇒ Object
Returns the value of attribute nexpose_api.
13 14 15 |
# File 'lib/extended-api.rb', line 13 def nexpose_api @nexpose_api end |
#password ⇒ Object
Returns the value of attribute password.
13 14 15 |
# File 'lib/extended-api.rb', line 13 def password @password end |
#scan_manager ⇒ Object
Returns the value of attribute scan_manager.
13 14 15 |
# File 'lib/extended-api.rb', line 13 def scan_manager @scan_manager end |
#user_name ⇒ Object
Returns the value of attribute user_name.
13 14 15 |
# File 'lib/extended-api.rb', line 13 def user_name @user_name end |
Instance Method Details
#do_login ⇒ Object
Logs in to NeXpose and sets a session key on the connector object.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/extended-api.rb', line 26 def do_login if not @@connected begin if @nexpose_api.login @@connected = true end rescue Exception => e puts e. end end end |
#do_logout ⇒ Object
113 114 115 |
# File 'lib/extended-api.rb', line 113 def do_logout @nexpose_api.logout end |
#print_asset_group_info(group_id) ⇒ Object
Prints all asset group information in tabular format: | site_id | device_id | address | riskfactor |
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/extended-api.rb', line 42 def print_asset_group_info group_id group_configs = @nexpose_api.asset_group_config group_id puts "\nASSET GROUP INFO (id: #{group_id})" puts Hirb::Helpers::AutoTable.render group_configs, :fields => [:site_id, :device_id, :address, :riskfactor] rescue Exception => e if e. =~ /Invalid groupID/ puts 'Group ID does not exist' else puts e. end end |
#print_asset_groups ⇒ Object
Prints asset group configuration information in tabular format: | site_id | device_id | address | riskfactor |
58 59 60 61 62 |
# File 'lib/extended-api.rb', line 58 def print_asset_groups res = @nexpose_api.asset_groups_listing puts "\nASSET GROUPS:" puts Hirb::Helpers::AutoTable.render res, :fields => [:asset_group_id, :name, :description, :risk_score] end |
#start_excluded_scan(scan_info) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/extended-api.rb', line 67 def start_excluded_scan scan_info # Parse the scan_info object to get site # to be scanned and the asset group(s) to exclude parsed_string = scan_info.to_s.split ',' site_id = parsed_string[0] unless Util.is_number? site_id raise ArgumentError.new 'The site-id must be a number' end # Get all the device_ids for the site device_listing_hash = @nexpose_api.site_device_listing site_id device_ids = [] device_listing_hash.each do |device_listing| device_ids << device_listing[:device_id].to_i end # Get all the devices associated with the group(s) device_ids_excluded = [] parsed_string.delete_at(0) parsed_string.each do |group_id| group_infos = @nexpose_api.asset_group_config group_id group_infos.each do |group_info| device_ids_excluded << group_info[:device_id].to_i end end # Remove all the devices in the group devices_to_scan = device_ids - device_ids_excluded # Hopefully this is not an empty set if not devices_to_scan or devices_to_scan.empty? raise "There are no devices left to scan after devices in groups: #{parsed_string.inspect} are removed from site: #{site_id}" end # Start an ad-hoc scan. res = @nexpose_api.site_device_scan_start site_id, devices_to_scan, nil if res puts "Scan started scan ID: #{res[:scan_id]}, on engine ID: #{res[:engine_id]}" else put "Scan start failed for site #{site}" end end |