Class: Nwsdk::Packets

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/nwsdk/packets.rb

Constant Summary

Constants included from Helpers

Helpers::ATTACHMENT_FILENAME, Helpers::MULTIPART_BOUNDARY, Helpers::MULTIPART_END, Helpers::MULTIPART_PROLOGUE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#count_results, #decode_value, #each_multipart_response_entity, #format_timestamp, #get_boundary, #get_sessionids, #response_successful?

Constructor Details

#initialize(*args) ⇒ Packets

Returns a new instance of Packets.



7
8
9
10
11
12
# File 'lib/nwsdk/packets.rb', line 7

def initialize(*args)
  Hash[*args].each {|k,v| self.send("%s="%k, v)}
  @group       ||= 1000
  @file_prefix ||= "pcap"
  @query       ||= Nwsdk::Query.new(keys: %w{ sessionid })
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition.



5
6
7
# File 'lib/nwsdk/packets.rb', line 5

def condition
  @condition
end

#endpointObject

Returns the value of attribute endpoint.



5
6
7
# File 'lib/nwsdk/packets.rb', line 5

def endpoint
  @endpoint
end

#file_prefixObject

Returns the value of attribute file_prefix.



5
6
7
# File 'lib/nwsdk/packets.rb', line 5

def file_prefix
  @file_prefix
end

#groupObject

Returns the value of attribute group.



5
6
7
# File 'lib/nwsdk/packets.rb', line 5

def group
  @group
end

#queryObject

Returns the value of attribute query.



5
6
7
# File 'lib/nwsdk/packets.rb', line 5

def query
  @query
end

Instance Method Details

#build_request(sessions = []) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/nwsdk/packets.rb', line 22

def build_request(sessions=[])
  endpoint.get_request(
    path: 'sdk/packets',
    params: {
      sessions: sessions.join(',')
    }
  )
end

#each_pcap_groupObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/nwsdk/packets.rb', line 35

def each_pcap_group
  sessions=get_sessionids(self)
  sessions_digits=sessions.size.to_s.length
  session_counter=0
  session_stamp=Time.new.to_i
  fformat="%s_%0#{sessions_digits}d-%0#{sessions_digits}d.pcap"
  sessions.each_slice(group) do |slice|
    sstart=session_counter
    ssend = sstart + slice.size - 1
    fname=sprintf(fformat, file_prefix, sstart, ssend)
    data=get_pcap_data(slice)
    yield pcap_group={
      group_start: sstart,
      group_end:   ssend,
      filename:    fname,
      data:        data
    }
    session_counter += slice.size
  end
end

#get_pcap_data(sessions = []) ⇒ Object



31
32
33
# File 'lib/nwsdk/packets.rb', line 31

def get_pcap_data(sessions=[])
  build_request(sessions).execute
end

#requestObject



14
15
16
17
18
19
20
# File 'lib/nwsdk/packets.rb', line 14

def request
  pcaps={}
  each_pcap_group do | group |
    pcaps[group[:filename]]=data
  end
  pcaps
end