trisulrp 1.2.8 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/trisulrp/protocol.rb +96 -5
- data/lib/trisulrp/utils.rb +4 -5
- data/test/cginfo.rb +33 -0
- data/test/test_alerts.rb +1 -1
- data/test/test_cap.rb +4 -8
- data/test/test_grep.rb +1 -1
- data/test/test_key_flows.rb +2 -2
- data/test/test_resources.rb +2 -3
- data/trisulrp.gemspec +4 -2
- metadata +6 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.9
|
data/lib/trisulrp/protocol.rb
CHANGED
@@ -75,8 +75,8 @@ module TrisulRP::Protocol
|
|
75
75
|
resp =TRP::Message.new
|
76
76
|
resp.parse dataarray
|
77
77
|
raise resp.error_response if resp.trp_command == TRP::Message::Command::ERROR_RESPONSE
|
78
|
-
yield resp if block_given?
|
79
|
-
return resp
|
78
|
+
yield unwrap_response(resp) if block_given?
|
79
|
+
return unwrap_response(resp)
|
80
80
|
end
|
81
81
|
|
82
82
|
|
@@ -105,8 +105,8 @@ module TrisulRP::Protocol
|
|
105
105
|
req=mk_request(TRP::Message::Command::COUNTER_GROUP_INFO_REQUEST,
|
106
106
|
:counter_group => TrisulRP::Guids::CG_AGGREGATE)
|
107
107
|
get_response(conn,req) do |resp|
|
108
|
-
from_tm = Time.at(resp.
|
109
|
-
to_tm = Time.at(resp.
|
108
|
+
from_tm = Time.at(resp.group_details[0].time_interval.from.tv_sec)
|
109
|
+
to_tm = Time.at(resp.group_details[0].time_interval.to.tv_sec)
|
110
110
|
end
|
111
111
|
return [from_tm,to_tm]
|
112
112
|
end
|
@@ -179,7 +179,7 @@ module TrisulRP::Protocol
|
|
179
179
|
when TRP::Message::Command::SEARCH_KEYS_REQUEST
|
180
180
|
req.search_keys_request = TRP::SearchKeysRequest.new(params)
|
181
181
|
when TRP::Message::Command::BULK_COUNTER_ITEM_REQUEST
|
182
|
-
req.bulk_counter_item_request = TRP::
|
182
|
+
req.bulk_counter_item_request = TRP::BulkCounterItemRequest.new(params)
|
183
183
|
when TRP::Message::Command:: CGMONITOR_REQUEST
|
184
184
|
req.cgmonitor_request = TRP::CgmonitorRequest.new(params)
|
185
185
|
when TRP::Message::Command::TOPPER_SNAPSHOT_REQUEST
|
@@ -216,5 +216,96 @@ module TrisulRP::Protocol
|
|
216
216
|
return req
|
217
217
|
end
|
218
218
|
|
219
|
+
# Helper to unwrap a response
|
220
|
+
#
|
221
|
+
# All protobuf messages used in TRP have a wrapper containing a command_id which identifies
|
222
|
+
# the type of encapsulated message. This sometimes gets in the way because you have to write
|
223
|
+
# stuff like
|
224
|
+
#
|
225
|
+
# <code>
|
226
|
+
#
|
227
|
+
# response.counter_group_response.blah_blah
|
228
|
+
#
|
229
|
+
# instead of
|
230
|
+
#
|
231
|
+
# response.blah_blah
|
232
|
+
#
|
233
|
+
# </code>
|
234
|
+
#
|
235
|
+
# Read the TRP documentation wiki for a description of each command.
|
236
|
+
#
|
237
|
+
# [resp] The response
|
238
|
+
#
|
239
|
+
# ==== Typical usage
|
240
|
+
#
|
241
|
+
# <code>
|
242
|
+
#
|
243
|
+
# # create a new command of type KeySessionActivityRequest
|
244
|
+
# req = TrisulRP::Protocol.get_response(...) do |resp|
|
245
|
+
#
|
246
|
+
# # here resp points to the inner response without the wrapper
|
247
|
+
# # this allows you to write resp.xyz instead of resp.hello_response.xyz
|
248
|
+
#
|
249
|
+
#
|
250
|
+
# end
|
251
|
+
#
|
252
|
+
# </code>
|
253
|
+
#
|
254
|
+
#
|
255
|
+
def unwrap_response(resp)
|
256
|
+
case resp.trp_command
|
257
|
+
when TRP::Message::Command::HELLO_RESPONSE
|
258
|
+
resp.hello_response
|
259
|
+
when TRP::Message::Command::COUNTER_GROUP_RESPONSE
|
260
|
+
resp.counter_group_response
|
261
|
+
when TRP::Message::Command::COUNTER_ITEM_RESPONSE
|
262
|
+
resp.counter_item_response
|
263
|
+
when TRP::Message::Command::OK_RESPONSE
|
264
|
+
resp.ok_response
|
265
|
+
when TRP::Message::Command::CONTROLLED_COUNTER_GROUP_RESPONSE
|
266
|
+
resp.controlled_counter_group_response
|
267
|
+
when TRP::Message::Command::FILTERED_DATAGRAMS_RESPONSE
|
268
|
+
resp.filtered_datagram_response
|
269
|
+
when TRP::Message::Command::CONTROLLED_CONTEXT_RESPONSE
|
270
|
+
resp.controlled_context_response
|
271
|
+
when TRP::Message::Command::SEARCH_KEYS_RESPONSE
|
272
|
+
resp.search_keys_response
|
273
|
+
when TRP::Message::Command::BULK_COUNTER_ITEM_RESPONSE
|
274
|
+
resp.bulk_counter_item_response
|
275
|
+
when TRP::Message::Command:: CGMONITOR_RESPONSE
|
276
|
+
resp.cgmonitor_response
|
277
|
+
when TRP::Message::Command::TOPPER_SNAPSHOT_RESPONSE
|
278
|
+
resp.topper_snapshot_response
|
279
|
+
when TRP::Message::Command::UPDATE_KEY_RESPONSE
|
280
|
+
resp.update_key_response
|
281
|
+
when TRP::Message::Command::RING_STATS_RESPONSE
|
282
|
+
resp.ring_stats_response
|
283
|
+
when TRP::Message::Command::SERVER_STATS_RESPONSE
|
284
|
+
resp.server_stats_response
|
285
|
+
when TRP::Message::Command::SESSION_ITEM_RESPONSE
|
286
|
+
resp.session_item_response
|
287
|
+
when TRP::Message::Command::SESSION_GROUP_RESPONSE
|
288
|
+
resp.session_group_response
|
289
|
+
when TRP::Message::Command::ALERT_ITEM_RESPONSE
|
290
|
+
resp.alert_item_response
|
291
|
+
when TRP::Message::Command::ALERT_GROUP_RESPONSE
|
292
|
+
resp.alert_group_response
|
293
|
+
when TRP::Message::Command::RESOURCE_ITEM_RESPONSE
|
294
|
+
resp.resource_item_response
|
295
|
+
when TRP::Message::Command::RESOURCE_GROUP_RESPONSE
|
296
|
+
resp.resource_group_response
|
297
|
+
when TRP::Message::Command::KEY_LOOKUP_RESPONSE
|
298
|
+
resp.key_lookup_response
|
299
|
+
when TRP::Message::Command::COUNTER_GROUP_INFO_RESPONSE
|
300
|
+
resp.counter_group_info_response
|
301
|
+
when TRP::Message::Command::KEY_SESS_ACTIVITY_RESPONSE
|
302
|
+
resp.key_session_activity_response
|
303
|
+
when TRP::Message::Command::GREP_RESPONSE
|
304
|
+
resp.grep_response
|
305
|
+
else
|
306
|
+
raise "Unknown TRP command ID"
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
219
310
|
end
|
220
311
|
|
data/lib/trisulrp/utils.rb
CHANGED
@@ -35,7 +35,7 @@ module TrisulRP::Utils
|
|
35
35
|
:session_ids => all_sids)
|
36
36
|
|
37
37
|
TrisulRP::Protocol.get_response(conn,follow_up) do |resp|
|
38
|
-
resp.
|
38
|
+
resp.items.each do |item|
|
39
39
|
print "#{item.session_id.slice_id},#{item.session_id.session_id} "
|
40
40
|
print "#{Time.at(item.time_interval.from.tv_sec)} "
|
41
41
|
print "#{item.time_interval.to.tv_sec-item.time_interval.from.tv_sec} ".rjust(8)
|
@@ -72,8 +72,8 @@ module TrisulRP::Utils
|
|
72
72
|
|
73
73
|
resp = TrisulRP::Protocol.get_response(conn,req)
|
74
74
|
|
75
|
-
if resp.
|
76
|
-
resp.
|
75
|
+
if resp.found_keys.size > 0
|
76
|
+
resp.found_keys[0].key
|
77
77
|
else
|
78
78
|
str
|
79
79
|
end
|
@@ -106,8 +106,7 @@ module TrisulRP::Utils
|
|
106
106
|
|
107
107
|
|
108
108
|
|
109
|
-
TrisulRP::Protocol.get_response(conn,follow_up) do |
|
110
|
-
resp=resp2.alert_item_response
|
109
|
+
TrisulRP::Protocol.get_response(conn,follow_up) do | resp |
|
111
110
|
resolv_candidates = resp.items.collect { |item| [item.source_ip, item.source_port, item.destination_ip, item.destination_port,item.sigid] }
|
112
111
|
resolv_arr = resolv_candidates.transpose
|
113
112
|
sip_names = TrisulRP::Keys.get_labels_for_keys(conn,TrisulRP::Guids::CG_HOST, resolv_arr[0])
|
data/test/cginfo.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Trisul Remote Protocol TRP Demo script
|
2
|
+
#
|
3
|
+
# Counter Group Info
|
4
|
+
#
|
5
|
+
# Prints information about all supported coutner groups on a trisul instance
|
6
|
+
#
|
7
|
+
require 'trisulrp'
|
8
|
+
|
9
|
+
include TrisulRP::Protocol
|
10
|
+
include TrisulRP::Utils
|
11
|
+
|
12
|
+
|
13
|
+
raise "Usage : cginfo host port" unless ARGV.length==2
|
14
|
+
|
15
|
+
|
16
|
+
TrisulRP::Protocol.connect(ARGV.shift,ARGV.shift,"Demo_Client.crt","Demo_Client.key") do |conn|
|
17
|
+
|
18
|
+
req =TrisulRP::Protocol.mk_request(TRP::Message::Command::COUNTER_GROUP_INFO_REQUEST,
|
19
|
+
:counter_group => "{C51B48D4-7876-479E-B0D9-BD9EFF03CE2E}" )
|
20
|
+
|
21
|
+
TrisulRP::Protocol.get_response(conn,req) do |resp|
|
22
|
+
resp.group_details.each do |group_detail|
|
23
|
+
start_time= Time.at(group_detail.time_interval.from.tv_sec)
|
24
|
+
end_time=Time.at(group_detail.time_interval.to.tv_sec)
|
25
|
+
|
26
|
+
p "Name = " + group_detail.name
|
27
|
+
p "GUID = " + group_detail.guid
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
data/test/test_alerts.rb
CHANGED
@@ -24,7 +24,7 @@ class TestTrisulrp < Test::Unit::TestCase
|
|
24
24
|
:time_interval => mk_time_interval(tm_arr))
|
25
25
|
|
26
26
|
TrisulRP::Protocol.get_response(conn,req) do |resp|
|
27
|
-
print_alert_details(conn,resp.
|
27
|
+
print_alert_details(conn,resp.alerts)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
data/test/test_cap.rb
CHANGED
@@ -26,8 +26,7 @@ class TestCap < Test::Unit::TestCase
|
|
26
26
|
:filter_expression => expr)
|
27
27
|
)
|
28
28
|
|
29
|
-
TrisulRP::Protocol.get_response(conn,req) do |
|
30
|
-
fdr=resp.filtered_datagram_response
|
29
|
+
TrisulRP::Protocol.get_response(conn,req) do |fdr|
|
31
30
|
p "Number of bytes = #{fdr.num_bytes}\n"
|
32
31
|
p "Number of pkts = #{fdr.num_datagrams}\n"
|
33
32
|
p "Hash = #{fdr.sha1}\n"
|
@@ -52,8 +51,7 @@ class TestCap < Test::Unit::TestCase
|
|
52
51
|
:session_id => target_sess)
|
53
52
|
)
|
54
53
|
|
55
|
-
TrisulRP::Protocol.get_response(conn,req) do |
|
56
|
-
fdr=resp.filtered_datagram_response
|
54
|
+
TrisulRP::Protocol.get_response(conn,req) do |fdr|
|
57
55
|
p "Number of bytes = #{fdr.num_bytes}\n"
|
58
56
|
p "Number of pkts = #{fdr.num_datagrams}\n"
|
59
57
|
p "Hash = #{fdr.sha1}\n"
|
@@ -78,8 +76,7 @@ class TestCap < Test::Unit::TestCase
|
|
78
76
|
:alert_id => target_alert)
|
79
77
|
)
|
80
78
|
|
81
|
-
TrisulRP::Protocol.get_response(conn,req) do |
|
82
|
-
fdr=resp.filtered_datagram_response
|
79
|
+
TrisulRP::Protocol.get_response(conn,req) do |fdr|
|
83
80
|
p "Number of bytes = #{fdr.num_bytes}\n"
|
84
81
|
p "Number of pkts = #{fdr.num_datagrams}\n"
|
85
82
|
p "Hash = #{fdr.sha1}\n"
|
@@ -105,8 +102,7 @@ class TestCap < Test::Unit::TestCase
|
|
105
102
|
:resource_id => target)
|
106
103
|
)
|
107
104
|
|
108
|
-
TrisulRP::Protocol.get_response(conn,req) do |
|
109
|
-
fdr=resp.filtered_datagram_response
|
105
|
+
TrisulRP::Protocol.get_response(conn,req) do |fdr|
|
110
106
|
p "Number of bytes = #{fdr.num_bytes}\n"
|
111
107
|
p "Number of pkts = #{fdr.num_datagrams}\n"
|
112
108
|
p "Hash = #{fdr.sha1}\n"
|
data/test/test_grep.rb
CHANGED
data/test/test_key_flows.rb
CHANGED
@@ -26,7 +26,7 @@ class TestTrisulrp < Test::Unit::TestCase
|
|
26
26
|
:time_interval => mk_time_interval(tmarr))
|
27
27
|
|
28
28
|
TrisulRP::Protocol.get_response(@conn,req) do |resp|
|
29
|
-
print_session_details(@conn,resp.
|
29
|
+
print_session_details(@conn,resp.sessions)
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
@@ -45,7 +45,7 @@ class TestTrisulrp < Test::Unit::TestCase
|
|
45
45
|
:time_interval => mk_time_interval(tmarr))
|
46
46
|
|
47
47
|
TrisulRP::Protocol.get_response(@conn,req) do |resp|
|
48
|
-
print_session_details(@conn,resp.
|
48
|
+
print_session_details(@conn,resp.sessions)
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
data/test/test_resources.rb
CHANGED
@@ -25,7 +25,7 @@ class TestTrisulrp < Test::Unit::TestCase
|
|
25
25
|
TrisulRP::Protocol.get_response(conn,req) do |resp|
|
26
26
|
|
27
27
|
# matching resource ids
|
28
|
-
resource_ids = resp.
|
28
|
+
resource_ids = resp.resources.collect do |res|
|
29
29
|
TRP::ResourceID.new(:slice_id => res.slice_id, :resource_id => res.resource_id)
|
30
30
|
end
|
31
31
|
|
@@ -33,8 +33,7 @@ class TestTrisulrp < Test::Unit::TestCase
|
|
33
33
|
:context => 0, :resource_group => TrisulRP::Guids::RG_DNS,
|
34
34
|
:resource_ids => resource_ids)
|
35
35
|
|
36
|
-
TrisulRP::Protocol.get_response(conn,follow_up) do |
|
37
|
-
resp=resp2.resource_item_response
|
36
|
+
TrisulRP::Protocol.get_response(conn,follow_up) do | resp |
|
38
37
|
resp.items.each do |item|
|
39
38
|
print "#{Time.at(item.time.tv_sec)} "
|
40
39
|
print "#{item.source_ip}".ljust(28)
|
data/trisulrp.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{trisulrp}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["vivek"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-03-06}
|
13
13
|
s.description = %q{This gem deals about the trisul remote protocol}
|
14
14
|
s.email = %q{vivek_rajagopal@yahoo.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/trisulrp/utils.rb",
|
34
34
|
"test/Demo_Client.crt",
|
35
35
|
"test/Demo_Client.key",
|
36
|
+
"test/cginfo.rb",
|
36
37
|
"test/helper.rb",
|
37
38
|
"test/test_alerts.rb",
|
38
39
|
"test/test_cap.rb",
|
@@ -50,6 +51,7 @@ Gem::Specification.new do |s|
|
|
50
51
|
s.summary = %q{trisul trp}
|
51
52
|
s.test_files = [
|
52
53
|
"examples/strp.rb",
|
54
|
+
"test/cginfo.rb",
|
53
55
|
"test/helper.rb",
|
54
56
|
"test/test_alerts.rb",
|
55
57
|
"test/test_cap.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 1.2.
|
8
|
+
- 9
|
9
|
+
version: 1.2.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- vivek
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-03-06 00:00:00 +05:30
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- lib/trisulrp/utils.rb
|
130
130
|
- test/Demo_Client.crt
|
131
131
|
- test/Demo_Client.key
|
132
|
+
- test/cginfo.rb
|
132
133
|
- test/helper.rb
|
133
134
|
- test/test_alerts.rb
|
134
135
|
- test/test_cap.rb
|
@@ -152,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
153
|
requirements:
|
153
154
|
- - ">="
|
154
155
|
- !ruby/object:Gem::Version
|
155
|
-
hash:
|
156
|
+
hash: 918382383
|
156
157
|
segments:
|
157
158
|
- 0
|
158
159
|
version: "0"
|
@@ -173,6 +174,7 @@ specification_version: 3
|
|
173
174
|
summary: trisul trp
|
174
175
|
test_files:
|
175
176
|
- examples/strp.rb
|
177
|
+
- test/cginfo.rb
|
176
178
|
- test/helper.rb
|
177
179
|
- test/test_alerts.rb
|
178
180
|
- test/test_cap.rb
|