Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for site_device_search_by_address in site.rb #35

Closed
frozen352 opened this issue Jul 25, 2013 · 5 comments
Closed

Request for site_device_search_by_address in site.rb #35

frozen352 opened this issue Jul 25, 2013 · 5 comments

Comments

@frozen352
Copy link

As you are working the asset.rb search feature, would you consider this as a temporary solution in site.rb:

def site_device_by_address(site_id = nil, address)
  r = execute(make_xml('SiteDeviceListingRequest', {'site-id' => site_id}))

  if r.success
    r.res.elements.each('SiteDeviceListingResponse/SiteDevices') do |site|
      site_id = site.attributes['site-id'].to_i
      site.elements.each('device') do |device|
         if device.attributes['address'] == address
            return device
         end
      end
    end
  end
  return nil
end

Please keep in mind that I would hope to have future changes made to eliminate the requirement to pull all site devices via the site_device_listing, especially for really large sites. We have a site with 200k devices. It would be great to pass the address filter all the way up through to the where clause in the sql select.

@frozen352
Copy link
Author

It then allows for:

device = nsc.site_device_by_address( 32, scan_asset_address)

@mdaines-r7
Copy link
Contributor

Might be faster to write it as an XPath. One question, what are you looking to be returned? As it stands, it would return an XML object. Would returning a parsed Nexpose::Device be good? (like what the device listing returns.) Or are you just looking for the device ID? I'm inclined to return a Device object, just to make it more generally useful.

@mdaines-r7
Copy link
Contributor

Here's a prototype that seems to be working:

def find_device_by_address(address, site_id = nil)
  r = execute(make_xml('SiteDeviceListingRequest', {'site-id' => site_id}))
  if r.success
    device = REXML::XPath.first(r.res, "SiteDeviceListingResponse/SiteDevices/device@['#{address}']")
    return Device.new(device.attributes['id'].to_i,
                      device.attributes['address'],
                      site_id,
                      device.attributes['riskfactor'].to_f,
                      device.attributes['riskscore'].to_f)
  end
  nil
end

@frozen352
Copy link
Author

Agreed a Device object would be very useful.


From: Michael Daines notifications@github.com
To: rapid7/nexpose-client nexpose-client@noreply.github.com
Cc: Gomez frozen@pobox.com
Sent: Thursday, July 25, 2013 7:42 PM
Subject: Re: [nexpose-client] Request for site_device_search_by_address in site.rb (#35)

Might be faster to write it as an XPath. One question, what are you looking to be returned? As it stands, it would return an XML object. Would returning a parsed Nexpose::Device be good? (like what the device listing returns.) Or are you just looking for the device ID? I'm inclined to return a Device object, just to make it more generally useful.

Reply to this email directly or view it on GitHub.

@mdaines-r7
Copy link
Contributor

There was a bug in my XPath. I fixed it and also made sure that the site ID is correctly reported if not provided. Pushed in version 0.2.8 of the gem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants