Sha256: c78e55954fbdfd4d14c42bb455b396c33dbdfdc263ec04fad2772b129be2bc29

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

module PxnxJruby
  class EpsBroker
    require 'java'
    require 'jruby/core_ext'
    java_import org.slf4j.Logger
    java_import org.slf4j.LoggerFactory

   attr_accessor :grid_connection, :eps, :ip

    # Takes a GridConnection object.
    def initialize(grid)
      @grid = grid
      # Doc says this is an instance method, but it isn't.
      @eps_factory = Java::com.cisco.pxgrid.stub.eps.EPSClientStub.new
      @eps = @eps_factory.createEPSQuery(@grid)
      @log = LoggerFactory.getLogger(EpsBroker.become_java!)
    end

    # Sends an IP or an Array of IPs (Strings) to quarantine.
    def quarantine_ip(ip)
      @ip = ip.is_a?(Array) ? ip : Array.new(1, ip)
      @ip.each do |single_ip|
        @log.info("Quarantine on <#{single_ip}>")
        begin
          @eps.quarantineByIP(single_ip)
          return true
        rescue Java::com.cisco.pxgrid.TimeoutException => e
          @log.error("Could not quarantine <#{single_ip}> the error was <#{e.message}>.")
          return false
        end
      end
    end

    # Unquarantines an IP or an Array of IPs (Strings)
    def unquarantine_ip(ip)
      @ip = ip.is_a?(Array) ? ip : Array.new(1, ip)
      @ip.each do |single_ip|
        @log.info("Removing quarantine on <#{single_ip}>.")
        begin
          @eps.unquarantineByIP(single_ip)
            true
        rescue Java::com.cisco.pxgrid.TimeoutException => e
          @log.error("Could not unquarantine <#{single_ip}> the error was <#{e.message}>.")
          return false
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nexpose_pxgrid-0.1.6-java lib/pxnx_jruby/eps_broker.rb
nexpose_pxgrid-0.1.5-java lib/pxnx_jruby/eps_broker.rb
nexpose_pxgrid-0.1.4-java lib/pxnx_jruby/eps_broker.rb
nexpose_pxgrid-0.1.2-java lib/pxnx_jruby/eps_broker.rb