-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseops2.rb
60 lines (53 loc) · 1.66 KB
/
parseops2.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/ruby -I ./lib
require 'ldapreplay/parsers/openldap'
require 'ldapreplay/ldapoperation'
require 'pp'
require 'yaml'
parser = LdapReplay::Parsers::OpenLDAP.new( *ARGV )
conn_hsh = {}
conn_ary = []
op_hsh = Hash.new { |hh, kk| hh[kk] = [] }
parser.emit { |args|
begin
op_time, op_conn, op_id, op_type, op_args = *args
# puts "args: #{args.join(' ')}"
unless op_type == 'RESULT'
if conn_hsh.has_key?(op_conn)
connection = conn_hsh[op_conn]
if connection.has_key?(op_id)
connection[op_id].add_args(op_args)
else
new_op = LdapReplay::LdapOperation.new(*args)
connection[op_id] = new_op
unless new_op.op_type == 'ACCEPT'
op_hsh[new_op.op_time].push(new_op)
end
end
else
conn_hsh[op_conn] = {op_id => LdapReplay::LdapOperation.new(*args)}
end
if op_type == 'closed'
conn_ary.push conn_hsh.delete op_conn
# puts "--------------------"
# puts "conn_hsh: %s" % conn_hsh.pretty_inspect
# puts "===================="
# puts "op_hsh: %s" % op_hsh.pretty_inspect
# puts "conn_ary: %s" % conn_ary.pretty_inspect
# # puts "conn_ary: #{conn_ary}"
# puts "^^^^^^^^^^^^^^^^^^^^"
end
end
rescue Errno::EPIPE
break
end
}
ckeys = conn_hsh.keys
ckeys.each {|kk| conn_ary.push conn_hsh.delete kk}
# puts "--------------------"
# puts "conn_hsh: %s" % conn_hsh.pretty_inspect
# puts "===================="
# puts "conn_ary: %s" % conn_ary.pretty_inspect
# # puts "conn_ary: #{conn_ary}"
# puts "^^^^^^^^^^^^^^^^^^^^"
# puts YAML.dump conn_ary
puts "op_hsh: %s" % op_hsh.pretty_inspect