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

Add asset_scan_history method #198

Merged
merged 1 commit into from
Dec 10, 2015

Conversation

gschneider-r7
Copy link
Contributor

This is convenient for a small number of assets, but performance does not scale well for many assets. Something like ~25 assets took 30+ seconds to return using the below example. I was inspired by this community discussion: https://community.rapid7.com/thread/7780

Example usage, retrieving the last scan for assets with 'centos' in their hostname:

assets = nsc.filter(Nexpose::Search::Field::ASSET, Nexpose::Search::Operator::CONTAINS, 'centos')

last_scans = []

assets.each { |asset| last_scans << nsc.asset_scan_history(asset.id).first }

last_scans.each { |scan| puts "Asset: #{scan.asset_id}, IP: #{scan.ip}, Name: #{scan.host_name}, Scan: #{scan.scan_id}, Site: #{scan.site_id}, Engine: #{scan.engine_name}" }

Example AssetScan object:

#<AssetScan:0x007f80c338a8b0
 @asset_id=1777,
 @end_time=2015-11-13 15:34:50 -0800,
 @engine_name="Local scan engine",
 @host_name="centos-linux",
 @ip="192.168.1.2",
 @os="Linux 2.6.32-71.el6.x86_64",
 @scan_id=238,
 @site_id=270,
 @site_name="My Linux Site",
 @vulns=12>

@host_name = json['hostname']
@os = json['operatingSystem']
@vulns = json['vulnCount']
@end_time = Time.at(json['completed'].to_i / 1000)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use Time.at without zone. Use one of Time.zone.at, Time.at.current, Time.at.in_time_zone, Time.at.utc, Time.at.getlocal, Time.at.iso8601, Time.at.jisx0301, Time.at.rfc3339, Time.at.to_i, Time.at.to_f instead.

This is convenient for a small number of assets, but performance does
not scale well for many assets.
sgreen-r7 added a commit that referenced this pull request Dec 10, 2015
@sgreen-r7 sgreen-r7 merged commit f21044f into rapid7:master Dec 10, 2015
@gschneider-r7 gschneider-r7 deleted the asset_scan_history branch December 10, 2015 22:32
@gschneider-r7 gschneider-r7 added this to the 3.0 milestone Dec 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants