<commit_before>module Nexpose
  module NexposeAPI
    include XMLUtils

    # Removes a scan engine from the list of available engines.
    def delete_engine(engine_id)
      xml = make_xml('EngineDeleteRequest', {'engine-id' => engine_id})
      execute(xml, '1.2')
    end

    # Provide a list of current scan activities for a specific Scan Engine.
    #
    # @return [Array[ScanSummary]] Array of ScanSummary objects associated with
    #   each active scan on the engine.
    #
    def engine_activity(engine_id)
      xml = make_xml('EngineActivityRequest', {'engine-id' => engine_id})
      r = execute(xml)
      arr = []
      if r.success
        r.res.elements.each("//ScanSummary") do |scan_event|
          arr << ScanSummary.parse(scan_event)
        end
      end
      arr
    end
  end

  # ==== Description
  # Object that represents a listing of all of the scan engines available on to an NSC.
  class EngineListing
    # true if an error condition exists; false otherwise
    attr_reader :error
    # Error message string
    attr_reader :error_msg
    # The last XML request sent by this object
    attr_reader :connection
    # Array containing (EngineSummary*)
    attr_reader :engines
    # The number of scan engines
    attr_reader :engine_count

    # Constructor
    # EngineListing (connection)
    def initialize(connection)
      @connection = connection
      @engines = []
      @engine_count = 0
      @error = false
      r = @connection.execute('<EngineListingRequest session-id="' + @connection.session_id + '"/>', '1.2')

      if r.success
        r.res.elements.each('EngineListingResponse/EngineSummary') do |v|
          @engines.push(EngineSummary.new(v.attributes['id'], v.attributes['name'], v.attributes['address'],
                                          v.attributes['port'], v.attributes['status']))
        end
      else
        @error = true
        @error_msg = 'EngineListingRequest Parse Error'
      end
      @engine_count = @engines.length
    end
  end

  # ==== Description
  # Object that represents the summary of a scan engine.
  #
  # ==== Examples
  #
  #   # Create a new Nexpose Connection on the default port and Login
  #   nsc = Connection.new("10.1.40.10","nx<PASSWORD>","password")
  #   nsc.login()
  #
  #   # Get the engine listing for the connection
  #   enginelisting = EngineListing.new(nsc)
  #
  #   # Print out the status of the first scan engine
  #   puts enginelisting.engines[0].status
  #
  class EngineSummary
    # A unique ID that identifies this scan engine
    attr_reader :id
    # The name of this scan engine
    attr_reader :name
    # The hostname or IP address of the engine
    attr_reader :address
    # The port there the engine is listening
    attr_reader :port
    # The engine status (active|pending-auth| incompatible|not-responding|unknown)
    attr_reader :status
    # A parameter that specifies whether the engine has a global
    # or silo-specific scope.
    attr_reader :scope

    # Constructor
    # EngineSummary(id, name, address, port, status, scope)
    def initialize(id, name, address, port, status, scope = 'silo')
      @id = id
      @name = name
      @address = address
      @port = port
      @status = status
      @scope = scope
    end

    def to_s
      "Engine: #@name [ID: #@id] #@address:#@port, Status: #@status, Scope: #@scope"
    end
  end

  #-------------------------------------------------------------------------------------------------------------------
  #
  #-------------------------------------------------------------------------------------------------------------------
  class EngineConfig
    attr_accessor :id
    attr_accessor :address<commit_msg>Adds list_engines and engines method.<commit_after>module Nexpose
  module NexposeAPI
    include XMLUtils

    # Removes a scan engine from the list of available engines.
    def delete_engine(engine_id)
      xml = make_xml('EngineDeleteRequest', {'engine-id' => engine_id})
      execute(xml, '1.2')
    end

    # Provide a list of current scan activities for a specific Scan Engine.
    #
    # @return [Array[ScanSummary]] Array of ScanSummary objects associated with
    #   each active scan on the engine.
    #
    def engine_activity(engine_id)
      xml = make_xml('EngineActivityRequest', {'engine-id' => engine_id})
      r = execute(xml)
      arr = []
      if r.success
        r.res.elements.each("//ScanSummary") do |scan_event|
          arr << ScanSummary.parse(scan_event)
        end
      end
      arr
    end

    # Retrieve a list of all Scan Engines managed by the Security Console.
    #
    # @return [Array[EngineSummary]] Array of EngineSummary objects associated with
    #   each engine associated with this security console.
    #
    def list_engines
      response = execute(make_xml('EngineListingRequest'))
      arr = []
      if response.success
        response.res.elements.each("//EngineSummary") do |engine|
          arr << EngineSummary.new(engine.attributes['id'],
                                   engine.attributes['name'],
                                   engine.attributes['address'],
                                   engine.attributes['port'],
                                   engine.attributes['status'])
        end
      end
      arr
    end

    alias_method :engines, :list_engines
  end

  # Object representing the current details of a scan engine attached to the security console.
  #
  class EngineSummary

    # A unique ID that identifies this scan engine.
    attr_reader :id
    # The name of this scan engine.
    attr_reader :name
    # The hostname or IP address of the engine.
    attr_reader :address
    # The port there the engine is listening.
    attr_reader :port
    # The engine status. One of: active|pending-auth|incompatible|not-responding|unknown
    attr_reader :status
    # A parameter that specifies whether the engine has a global
    # or silo-specific scope.
    attr_reader :scope

    def initialize(id, name, address, port, status, scope = 'silo')
      @id = id
      @name = name
      @address = address
      @port = port
      @status = status
      @scope = scope
    end
  end

  # ==== Description
  # Object that represents a listing of all of the scan engines available on to an NSC.
  #
  # ==== Examples
  #
  #   # Create a new Nexpose Connection on the default port and Login
  #   nsc = Connection.new('10.1.40.10', 'nxadmin', 'password')
  #   nsc.login()
  #
  #   # Get the engine listing for the connection
  #   engine_listing = EngineListing.new(nsc)
  #
  #   # Print out the status of the first scan engine
  #   puts engine_listing.engines[0].status
  #
  class EngineListing
    # true if an error condition exists; false otherwise
    attr_reader :error
    # Error message string
    attr_reader :error_msg
    # The last XML request sent by this object
    attr_reader :connection
    # Array containing (EngineSummary*)
    attr_reader :engines
    # The number of scan engines
    attr_reader :engine_count

    # Constructor
    # EngineListing (connection)
    def initialize(connection)
      @connection = connection
      @engines = []
      @engine_count = 0
      @error = false
      r = @connection.execute('<EngineListingRequest session-id="' + @connection.session_id + '"/>', '1.2')

      if r.success
        r.res.elements.each('EngineListingResponse/EngineSummary') do |v|
          @engines.push(EngineSummary.new(v.attributes['id'], v.attributes['name'], v.attributes['address'],
                                          v.attributes['port'], v.attributes['status']))
        end
      else
        @error = true
        @error_msg = 'EngineListingRequest Parse Error'
      end
      @engine_count = @engines.length
    end
  end

  #-------------------------------------------------------------------------------------------------------------------
  #
  #-------------------------------------------------------------------------------------------------------------------
  class EngineConfig
    attr_accessor :id
    attr_accessor :address
{'fraction_non_alphanumeric': 0.14326293689020625, 'fraction_numerical': 0.0032110658268494504, 'mean_word_length': 2.047798268724125, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 13}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7628718', 'n_tokens_mistral': 2195, 'n_tokens_neox': 2137, 'n_words': 683}