Class: NexposeSCCM::DataSource::Helpers::NexposeHelper::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose_sccm/helpers/nexpose_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Connection

Returns a new instance of Connection.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/nexpose_sccm/helpers/nexpose_helper.rb', line 9

def initialize(settings)
  nexpose_ip = settings[:host]
  nexpose_un = settings[:user]
  nexpose_pw = settings[:pass]
  nexpose_pt = settings[:port]
  nexpose_silo = settings[:silo]
  nexpose_timeout = settings[:timeout]
  @nexpose_query_timeout = settings[:query_timeout]

  ## New Nexpose Connection -> Requirements are Device IP, Username, Password, Port with optional Silo ID
  @nsc = Nexpose::Connection.new(nexpose_ip, nexpose_un, nexpose_pw, nexpose_pt, nexpose_silo)
  (nexpose_timeout)
  register_metrics(nexpose_ip, nexpose_pt, {})
end

Instance Method Details

#get_data(query) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/nexpose_sccm/helpers/nexpose_helper.rb', line 43

def get_data(query)
  report_config = Nexpose::AdhocReportConfig.new(nil, 'sql')
  report_config.add_filter('version', '2.3.0')
  report_config.add_filter('query', query)

  NexposeSCCM.logger.info("Running SQL report for a list of windows vulnerabilities.")
  report_output = report_config.generate(@nsc, @nexpose_query_timeout)

  CSV.parse(report_output.chomp, {:headers => :first_row})
end

#login(timeout = 120) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nexpose_sccm/helpers/nexpose_helper.rb', line 24

def (timeout=120)
  @nsc.

  # Check for a valid session.
  unless @nsc.session_id
    NexposeSCCM.logger.error("Login Failed")
    exit 1
  end

  at_exit do
    NexposeSCCM.logger.debug("Logging out")
    @nsc.logout if @nsc.session_id
  end

  ## Set the http read timeout.
  NexposeSCCM.logger.info("Setting the web session timeout to #{timeout}")
  @nsc.timeout = timeout.to_i
end

#register_metrics(hostname, port, payload) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/nexpose_sccm/helpers/nexpose_helper.rb', line 54

def register_metrics(hostname, port, payload)
  NexposeSCCM.logger.debug("Sending_Stats")
  NexposeSCCM.logger.on_connect(hostname,
                                port,
                                @nsc.session_id,
                                payload)
end