ruby on rails - Rapid 7 Export Windows Devices to CSV -
i'm trying export windows devices csv rapid 7 using api , ruby.
when run below script throwing error about:
nomethoderror: undefined method 'each' #<nexpose::adhocreportconfig:0x000000 029bf4b8> (irb):232:in block in irb_binding c:/ruby24-x64/lib/ruby/2.4.0/csv.rb:1299:in 'open' (irb):231 c:/ruby24-x64/bin/irb.cmd:19:in '<main>'
the code i'm running is:
require 'nexpose' require 'csv' include nexpose query = " select da.host_name name, dos.description os dim_asset da join dim_operating_system dos using (operating_system_id) join dim_host_type dht using (host_type_id) join dim_site_asset dsa using (asset_id) join dim_site ds using (site_id) (dos.description '%windows%' , da.host_name not null)" @nsc = connection.new('192.168.0.1', 'user', 'pswd') @nsc.login report = nexpose::adhocreportconfig.new(nil, 'sql') report.add_filter('version', '1.1.0') report.add_filter('query', query) @nsc.logout headers = ["name","os"] csv.open('c:\file.csv', 'wb', { force_quotes: true }) |csv| report.each |reports| if csv.tell() == 0 # file empty, write header csv << headers end csv << [report.name, report.os] end end
you can't call .each
on instance of nexpose::adhocreportconfig
try this:
report = nexpose::adhocreportconfig.new(nil, 'sql') report.add_filter('version', '1.1.0') report.add_filter('query', query) report_output = report.generate(@nsc) ... csv.open('c:\file.csv', 'wb', { force_quotes: true }) |csv| report_output.each |reports| ...
see full example here: https://community.rapid7.com/docs/doc-2733
Comments
Post a Comment