rapid7 / nexpose-client

DEPRECATED: Rapid7 Nexpose API client library written in Ruby
https://www.rapid7.com/
BSD 3-Clause "New" or "Revised" License
150 stars 103 forks source link

Nexpose timeout does not seem to work #299

Closed pendraggon87 closed 7 years ago

pendraggon87 commented 7 years ago

Expected Behavior

I expect to be able to submit a custom timeout, since when dealing with large asset groups Nexpose will often time out.

Current Behavior

I used the following code, and yet I still see the error below:

nsc = Nexpose::Connection.new(@host, @user, @password, @port)
nsc.timeout = 6000
nsc.open_timeout = 6000
nsc.login

C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/nexpose-7.0.1/lib/nexpose/api_request.rb:148:in `execute': NexposeAPI: Action failed: **Nexpose did not respond within 120 seconds Net::ReadTimeout.** Reference the Wiki for information on setting the different Timeout values. (Nexpose::APIError)
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/nexpose-7.0.1/lib/nexpose/group.rb:162:in `load'
    from C:/Users/XXXX/Desktop/rm_all_assets_from_group.rb:18:in `<main>'

Your Environment

sgreen-r7 commented 7 years ago

Thanks for opening the issue @pendraggon87 --- so I understand, you're seeing that timeout error on nsc.login? or are you running another command?

I need to understand which method is actually hitting the timeout. Thanks again!

pendraggon87 commented 7 years ago

Here is my script (I am trying to delete assets from a LARGE asset group):

#!/usr/bin/env ruby
require 'optparse'
require 'rubygems'
require 'highline/import'
require 'nexpose'

@host = 'XXXX'
@port = 443
@user = 'XXXXX'
@password = 'XXXXXX'
group_id = 375

nsc = Nexpose::Connection.new(@host, @user, @password, @port)
nsc.timeout = 6000
nsc.open_timeout = 6000
nsc.login

Nexpose::AssetGroup.load(nsc, group_id).devices.each do |device|
  if @dry_run
    puts "#{device.address} [ID: #{device.id}] Site: #{device.site_id}"
  else
    puts "#{device.address} [ID: #{device.id}] Site: #{device.site_id}"
    nsc.delete_device(device.id)
  end
end

nsc.logout

Here is the error:

C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/nexpose-7.1.0/lib/nexpose/api_request.rb:
148:in `execute': NexposeAPI: Action failed: Nexpose did not respond within 120
seconds Net::ReadTimeout. Reference the Wiki for information on setting the diff
erent Timeout values. (Nexpose::APIError)
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/nexpose-7.1.0/lib/nexpose/gr
oup.rb:162:in `load'
        from rm_all_assets_from_group.rb:18:in `<main>'
sgreen-r7 commented 7 years ago

This should be fixed now with the newest version of the gem v.7.1.1.

After talking internally with @morozco-r7 I'm going to go ahead and close this issue, and we'll continue working through this outside of github. I personally have some additional thoughts about how to tighten up that script, so look to an email coming from him.