Class: PxnxJruby::EpsBroker

Inherits:
Object
  • Object
show all
Defined in:
lib/pxnx_jruby/eps_broker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grid) ⇒ EpsBroker

Takes a GridConnection object.



11
12
13
14
15
16
17
# File 'lib/pxnx_jruby/eps_broker.rb', line 11

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

Instance Attribute Details

#epsObject

Returns the value of attribute eps.



8
9
10
# File 'lib/pxnx_jruby/eps_broker.rb', line 8

def eps
  @eps
end

#grid_connectionObject

Returns the value of attribute grid_connection.



8
9
10
# File 'lib/pxnx_jruby/eps_broker.rb', line 8

def grid_connection
  @grid_connection
end

#ipObject

Returns the value of attribute ip.



8
9
10
# File 'lib/pxnx_jruby/eps_broker.rb', line 8

def ip
  @ip
end

Instance Method Details

#quarantine_ip(ip) ⇒ Object

Sends an IP or an Array of IPs (Strings) to quarantine.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pxnx_jruby/eps_broker.rb', line 20

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

#unquarantine_ip(ip) ⇒ Object

Unquarantines an IP or an Array of IPs (Strings)



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pxnx_jruby/eps_broker.rb', line 35

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