itrp 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ module ITRP
2
+
3
+ class Cmd_metrics_summary < Cmd
4
+ def initialize (e)
5
+ super(e)
6
+ @enabled_in_state = :any
7
+ @attach_cmd = ''
8
+ @trigger = 'metricsum'
9
+ end
10
+
11
+ def enter(cmdline)
12
+
13
+ terms = cmdline.scan( /(\w+)\s*=\s*([\w\-_\.\:,\}\{]+)+/ )
14
+ qparams = terms.inject({}) { |acc,t| acc.store( t[0].to_sym, t[1]);acc}
15
+
16
+
17
+ p qparams
18
+
19
+ req =mk_request(TRP::Message::Command::METRICS_SUMMARY_REQUEST,
20
+ #{:time_interval => appstate( :time_interval) }.merge(qparams) )
21
+ {}.merge(qparams) )
22
+
23
+
24
+ rows = []
25
+ get_response_zmq(@appenv.zmq_endpt,req) do |resp|
26
+ resp.vals.each do |val|
27
+ rows << [Time.at(val.ts.tv_sec) , val.val ]
28
+ end
29
+ end
30
+
31
+ table = Terminal::Table.new(:headings => %w(Time Metric) , :rows => rows )
32
+ puts(table)
33
+
34
+ end
35
+
36
+ end
37
+ end
38
+
@@ -9,7 +9,7 @@ class Cmd_options < Cmd
9
9
  end
10
10
 
11
11
  def completions(patt)
12
- [ "maxitems", "key", "resolve_keys" ].grep( /^#{Regexp.escape(patt)}/i)
12
+ [ "maxitems", "cgkey", "resolve_keys" ].grep( /^#{Regexp.escape(patt)}/i)
13
13
  end
14
14
 
15
15
  def enter(cmdline)
@@ -0,0 +1,41 @@
1
+ module ITRP
2
+
3
+ class Cmd_pcap < Cmd
4
+ def initialize (e)
5
+ super(e)
6
+ @enabled_in_state = :any
7
+ @attach_cmd = ''
8
+ @trigger = 'pcap'
9
+ end
10
+
11
+ def enter(cmdline)
12
+
13
+ patt = cmdline.scan(/pcap\s+([\w=_:\.\-]+)/).flatten.first
14
+
15
+ expr = patt
16
+
17
+ if expr == "usefilter"
18
+ p @appenv
19
+ expr = @appenv.context_data[:filter]
20
+ end
21
+
22
+
23
+ expr.gsub!(/flow=/,"{99A78737-4B41-4387-8F31-8077DB917336}=")
24
+ puts "Using filter " + expr
25
+
26
+ req =TrisulRP::Protocol.mk_request(TRP::Message::Command::PCAP_REQUEST,
27
+ :time_interval => appstate(:time_interval),
28
+ :filter_expression => expr,
29
+ :save_file => "/tmp/kk.pcap")
30
+
31
+ rows = []
32
+ TrisulRP::Protocol.get_response_zmq(@appenv.zmq_endpt,req) do |resp|
33
+
34
+ p resp
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
41
+
@@ -0,0 +1,26 @@
1
+ module ITRP
2
+
3
+ class Cmd_probe < Cmd
4
+ def initialize (e)
5
+ super(e)
6
+ @enabled_in_state = :any
7
+ @attach_cmd = ''
8
+ @trigger = 'probe'
9
+ end
10
+
11
+ def enter(cmdline)
12
+
13
+ req =TrisulRP::Protocol.mk_request(TRP::Message::Command::PROBE_STATS_REQUEST,
14
+ :param => "nothing" )
15
+
16
+ rows = []
17
+ TrisulRP::Protocol.get_response_zmq(@appenv.zmq_endpt,req) do |resp|
18
+
19
+ p resp
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
26
+
@@ -11,8 +11,7 @@ class Cmd_query_flow < Cmd
11
11
  def completions(patt)
12
12
  TRP::QuerySessionsRequest
13
13
  .fields
14
- .values
15
- .collect { |a| a.name }
14
+ .collect { |a| a.name.to_s }
16
15
  .grep( /^#{Regexp.escape(patt)}/i)
17
16
  end
18
17
 
@@ -21,14 +20,6 @@ class Cmd_query_flow < Cmd
21
20
  terms = patt.scan( /(\w+)\s*=\s*([\w\-_\.\:,]+)+/ )
22
21
  qparams = terms.inject({}) { |acc,t| acc.store( t[0].to_sym, t[1]);acc}
23
22
 
24
- [:maxitems].each do |a|
25
- qparams[a] = qparams[a].to_i if qparams.key? a
26
- end
27
-
28
- [:idlist].each do |a|
29
- qparams[a] = qparams[a].split(',') if qparams.key? a
30
- end
31
-
32
23
  p qparams
33
24
 
34
25
  # meter names
@@ -43,16 +34,18 @@ class Cmd_query_flow < Cmd
43
34
 
44
35
  get_response_zmq(@appenv.zmq_endpt,req) do |resp|
45
36
 
46
- resp.sessions.each do | sess |
37
+ resp.sessions.each_with_index do | sess , i |
47
38
 
48
- rows << [ "#{sess.session_id}",
39
+ rows << [ i,
40
+ "#{sess.session_id}",
49
41
  Time.at( sess.time_interval.from.tv_sec).to_s(),
50
42
  sess.time_interval.to.tv_sec - sess.time_interval.from.tv_sec,
43
+ sess.probe_id,
51
44
  sess.protocol.label,
52
45
  sess.key1A.label,
53
46
  sess.key1Z.label,
54
- sess.key2A.label,
55
- sess.key2Z.label,
47
+ sess.key2A.readable,
48
+ sess.key2Z.readable,
56
49
  sess.az_bytes + sess.za_bytes
57
50
  ]
58
51
  end
@@ -60,7 +53,7 @@ class Cmd_query_flow < Cmd
60
53
  end
61
54
 
62
55
  table = Terminal::Table.new(
63
- :headings => %w(ID Time Dur Prot SourceIP DestIP SPort DPort Volume),
56
+ :headings => %w(num ID Time Dur Prb Prot SourceIP DestIP SPort DPort rtr IFin out Volume),
64
57
  :rows => rows)
65
58
  puts(table)
66
59
 
@@ -31,9 +31,9 @@ class Cmd_query_fts < Cmd
31
31
  resp.documents.each do | doc |
32
32
  rows << [ doc.dockey,
33
33
  doc.flows.inject("") do |acc,item|
34
- item.key
34
+ item.key + "( " + item.time.tv_sec.to_s + ")"
35
35
  end,
36
- 'wrap(doc.fullcontent,60)',
36
+ doc.fullcontent.size
37
37
  ]
38
38
  end
39
39
 
@@ -12,20 +12,16 @@ class Cmd_query_resource < Cmd
12
12
  TRP::QueryResourcesRequest
13
13
  .fields
14
14
  .values
15
- .collect { |a| a.name }
15
+ .collect { |a| a.name.to_s }
16
16
  .grep( /^#{Regexp.escape(patt)}/i)
17
17
  end
18
18
 
19
19
  def enter(patt)
20
20
 
21
- terms = patt.scan( /(\w+)\s*=\s*([\w\-_\.\:]+)+/ )
21
+ terms = patt.scan( /(\w+)\s*=\s*([\w\-_\.\:,]+)+/ )
22
22
 
23
23
  qparams = terms.inject({}) { |acc,t| acc.store( t[0].to_sym, t[1]);acc}
24
24
 
25
- [:maxitems].each do |a|
26
- qparams[a] = qparams[a].to_i if qparams.key? a
27
- end
28
-
29
25
  p qparams
30
26
 
31
27
  # meter names
@@ -0,0 +1,61 @@
1
+ module ITRP
2
+
3
+ class Cmd_searchkey < Cmd
4
+ def initialize (e)
5
+ super(e)
6
+ @enabled_in_state = :counter
7
+ @attach_cmd = ''
8
+ @trigger = 'searchkey'
9
+ end
10
+
11
+
12
+ def completions(patt)
13
+ TRP::SearchKeysRequest
14
+ .fields
15
+ .values
16
+ .collect { |a| a.name.to_s }
17
+ .grep( /^#{Regexp.escape(patt)}/i)
18
+ end
19
+
20
+
21
+ def enter(cmdline)
22
+
23
+ terms = cmdline.scan( /(\w+)\s*=\s*([\w\-_\.\:,\]\[]+)+/ )
24
+ qparams = terms.inject({}) { |acc,t| acc.store( t[0].to_sym, t[1]);acc}
25
+
26
+ [:maxitems, :offset ].each do |a|
27
+ qparams[a] = qparams[a].to_i if qparams.key? a
28
+ end
29
+
30
+ [:keys].each do |a|
31
+ qparams[a] = qparams[a].split(',') if qparams.key? a
32
+ end
33
+
34
+ p qparams
35
+ req =mk_request(TRP::Message::Command::SEARCH_KEYS_REQUEST,
36
+ {
37
+ :counter_group => appstate(:cgguid),
38
+ :get_attributes => true
39
+ }.merge( qparams))
40
+
41
+ rows = []
42
+ get_response_zmq(@appenv.zmq_endpt,req) do |resp|
43
+ resp.keys.each do |k|
44
+
45
+ attr = k.attributes.collect do |a|
46
+ "#{a.attr_name}=#{a.attr_value}"
47
+ end
48
+ rows << [ k.key, k.label, k.readable, attr.join(",") ]
49
+
50
+ end
51
+ end
52
+
53
+
54
+ table = Terminal::Table.new( :headings => %w(Key Label Readable Attributes ), :rows => rows)
55
+ puts(table)
56
+
57
+ end
58
+
59
+ end
60
+ end
61
+
@@ -0,0 +1,37 @@
1
+ module ITRP
2
+
3
+ class Cmd_setlabel < Cmd
4
+
5
+ def initialize (e)
6
+ super(e)
7
+ @enabled_in_state = :counter
8
+ @attach_cmd = ''
9
+ @trigger = 'setlabel'
10
+ end
11
+
12
+ def completions(patt)
13
+ %w( key label desc).grep( /^#{Regexp.escape(patt)}/i)
14
+ end
15
+
16
+
17
+ def enter(cmdline)
18
+
19
+ terms = cmdline.scan( /(\w+)\s*=\s*([\w\-_\.\:,]+)+/ )
20
+ qparams = terms.inject({}) { |acc,t| acc.store( t[0].to_sym, t[1]);acc}
21
+
22
+ p qparams
23
+ req =mk_request(TRP::Message::Command::UPDATE_KEY_REQUEST,
24
+ :counter_group => appstate(:cgguid),
25
+ :keys => [ TRP::KeyT.new( qparams ) ] )
26
+
27
+
28
+ get_response_zmq(@appenv.zmq_endpt,req) do |resp|
29
+ p resp
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+
37
+
@@ -10,20 +10,45 @@ class Cmd_timeslices < Cmd
10
10
 
11
11
  def enter(cmdline)
12
12
 
13
- req =mk_request(TRP::Message::Command::TIMESLICES_REQUEST,{:context=>0})
13
+ terms = cmdline.scan( /(\w+)\s*=\s*([\w\-_\.\:,\}\{]+)+/ )
14
+ qparams = terms.inject({}) { |acc,t| acc.store( t[0].to_sym, t[1]);acc}
15
+
16
+
17
+ p qparams
18
+
19
+ req =mk_request(TRP::Message::Command::TIMESLICES_REQUEST,
20
+ { }.merge(qparams) )
14
21
 
15
22
  rows = []
23
+ rows_window = []
16
24
 
17
25
  get_response_zmq(@appenv.zmq_endpt,req) do |resp|
18
- resp.slices.each do | window |
19
- rows << [ Time.at(window.from.tv_sec), Time.at(window.to.tv_sec) ]
26
+ resp.slices.each do | slice |
27
+ rows << [ Time.at(slice.time_interval.from.tv_sec),
28
+ Time.at(slice.time_interval.to.tv_sec) ,
29
+ slice.name , slice.status, slice.disk_size
30
+ ]
31
+ end
32
+
33
+ if resp.total_window
34
+ rows_window << [ Time.at(resp.total_window.from.tv_sec),
35
+ Time.at(resp.total_window.to.tv_sec)]
20
36
  end
21
37
  end
22
38
 
39
+
40
+
41
+ p "Time Slices"
23
42
  table = Terminal::Table.new(
24
- :headings => %w(From To),
43
+ :headings => %w(From To Name Status DiskSz),
25
44
  :rows => rows)
26
45
  puts(table)
46
+
47
+ p "Total Window"
48
+ table = Terminal::Table.new(
49
+ :headings => %w(From To ),
50
+ :rows => rows_window)
51
+ puts(table)
27
52
  end
28
53
 
29
54
  end
@@ -12,10 +12,12 @@ class Cmd_toppers < Cmd
12
12
 
13
13
  patt = cmdline.scan(/toppers ([0-9]+)/).flatten.first
14
14
 
15
- req =TrisulRP::Protocol.mk_request(TRP::Message::Command::COUNTER_GROUP_REQUEST,
15
+ req =TrisulRP::Protocol.mk_request(TRP::Message::Command::COUNTER_GROUP_TOPPER_REQUEST,
16
16
  :counter_group => @appenv.context_data[:cgguid],
17
17
  :meter => patt.to_i,
18
+ :maxitems => 5,
18
19
  :resolve_keys => true,
20
+ :get_key_attributes => true,
19
21
  :time_interval => mk_time_interval(@appenv.context_data[:time_window]))
20
22
 
21
23
  TrisulRP::Protocol.get_response_zmq(@appenv.zmq_endpt,req) do |resp|
@@ -24,10 +26,13 @@ class Cmd_toppers < Cmd
24
26
 
25
27
  rows = []
26
28
  resp.keys.each do |key|
29
+ attr_str = key.attributes.inject( "") do |acc,h|
30
+ acc << "#{h.attr_name}=#{h.attr_value} "
31
+ end
27
32
  rows << [ key.key,
28
33
  key.label,
29
34
  key.readable,
30
- key.metric ]
35
+ key.metric, attr_str ]
31
36
  end
32
37
 
33
38
  table = Terminal::Table.new :headings => ["Key", "Label", "Readable", "Metric"], :rows => rows
@@ -0,0 +1,51 @@
1
+ module ITRP
2
+
3
+ class Cmd_toptrend < Cmd
4
+ def initialize (e)
5
+ super(e)
6
+ @enabled_in_state = :counter
7
+ @attach_cmd = ''
8
+ @trigger = 'toptrend'
9
+ end
10
+
11
+ def enter(cmdline)
12
+
13
+ patt = cmdline.scan(/toptrend ([0-9]+)/).flatten.first
14
+
15
+ req =TrisulRP::Protocol.mk_request(TRP::Message::Command::TOPPER_TREND_REQUEST,
16
+ :counter_group => @appenv.context_data[:cgguid],
17
+ :meter => patt.to_i,
18
+ :maxitems => 10,
19
+ :key_filter => "67.19.2C.01_000002A",
20
+ :time_interval => mk_time_interval(@appenv.context_data[:time_window]))
21
+
22
+ TrisulRP::Protocol.get_response_zmq(@appenv.zmq_endpt,req) do |resp|
23
+ print "Counter Group = #{resp.counter_group}\n"
24
+ print "Meter = #{resp.meter}\n"
25
+
26
+ rows = []
27
+ resp.keytrends.each do |ks|
28
+ print("Trends for key #{ks.key.label}\n")
29
+
30
+ ks.key.attributes.each do |a|
31
+ puts "#{a.attr_name}=#{a.attr_value}"
32
+ end
33
+
34
+ rows = []
35
+ ks.meters.each do |meter|
36
+ meter.values.each do |val|
37
+ rows << [val.ts.tv_sec,val.val]
38
+ end
39
+ end
40
+
41
+ table = Terminal::Table.new(:headings => ["Time", "Value"], :rows => rows )
42
+ puts(table)
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
51
+
@@ -10,13 +10,17 @@ class Cmd_flow_trackers < Cmd
10
10
 
11
11
  def enter(cmdline)
12
12
 
13
- patt = cmdline.scan(/tracker\s+([0-9]+)/).flatten.first
13
+
14
+ terms = cmdline.scan( /(\w+)\s*=\s*([\w\-_\.\:,]+)+/ )
15
+ qparams = terms.inject({}) { |acc,t| acc.store( t[0].to_sym, t[1]);acc}
16
+
17
+ p qparams
14
18
 
15
19
  req =TrisulRP::Protocol.mk_request(TRP::Message::Command::SESSION_TRACKER_REQUEST,
20
+ qparams.merge(
16
21
  :session_group => appstate(:cgguid),
17
22
  :time_interval => appstate(:time_interval),
18
- :resolve_keys => true,
19
- :tracker_id => patt.to_i)
23
+ :resolve_keys => true))
20
24
 
21
25
  rows = []
22
26
  TrisulRP::Protocol.get_response_zmq(@appenv.zmq_endpt,req) do |resp|
@@ -25,11 +29,15 @@ class Cmd_flow_trackers < Cmd
25
29
 
26
30
  rows << [ "#{sess.session_key}",
27
31
  Time.at( sess.time_interval.from.tv_sec).to_s(),
32
+ sess.probe_id,
28
33
  sess.protocol.label,
29
34
  sess.key1A.label,
30
35
  sess.key1Z.label,
31
36
  sess.key2A.label,
32
37
  sess.key2Z.label,
38
+ sess.nf_routerid.nil? ? "": sess.nf_router_id.label,
39
+ sess.nf_ifindex_in.nil? ? "": sess.nf_ifindex_in.label,
40
+ sess.nf_ifindex_out.nil? ? "": sess.nf_ifindex_out.label,
33
41
  sess.tracker_statval
34
42
  ]
35
43
  end
@@ -37,7 +45,7 @@ class Cmd_flow_trackers < Cmd
37
45
  end
38
46
 
39
47
  table = Terminal::Table.new(
40
- :headings => %w(Key Last-Seen Prot SourceIP DestIP SPort DPort TrackerVal),
48
+ :headings => %w(Key Last-Seen ProbeID Prot SourceIP DestIP SPort DPort Rtr IfIn IfOut TrackerVal),
41
49
  :rows => rows)
42
50
  puts(table)
43
51
 
@@ -12,9 +12,11 @@ class Cmd_traffic < Cmd
12
12
 
13
13
  def enter(cmdline)
14
14
 
15
- patt = cmdline.scan(/traffic (.*)/).flatten.first
16
- patt ||= "0"
17
- showmeters = patt.split(',').map(&:to_i)
15
+ patt = cmdline.scan(/traffic\s+(.*)/).flatten
16
+
17
+ p patt
18
+
19
+ use_key = patt.empty? ? appstate(:cgkey) : patt[0]
18
20
 
19
21
  # meter names
20
22
  req =mk_request(TRP::Message::Command::COUNTER_GROUP_INFO_REQUEST,
@@ -25,7 +27,7 @@ class Cmd_traffic < Cmd
25
27
  get_response_zmq(@appenv.zmq_endpt,req) do |resp|
26
28
  resp.group_details.each do |group_detail|
27
29
  group_detail.meters.each do |meter|
28
- colnames << meter.name
30
+ colnames << meter.units
29
31
  end
30
32
  end
31
33
  end
@@ -33,32 +35,45 @@ class Cmd_traffic < Cmd
33
35
 
34
36
  req =TrisulRP::Protocol.mk_request(TRP::Message::Command::COUNTER_ITEM_REQUEST,
35
37
  :counter_group => @appenv.context_data[:cgguid],
36
- :key => @appenv.context_data[:cgkey],
37
- :time_interval => mk_time_interval(@appenv.context_data[:time_window]) )
38
+ :key => use_key,
39
+ :get_key_attributes=>true,
40
+ :time_interval => appstate( :time_interval) )
38
41
 
39
42
  rows = []
40
43
 
44
+ print "Request sent at #{Time.now}\n"
41
45
 
46
+ totals = nil
42
47
  TrisulRP::Protocol.get_response_zmq(@appenv.zmq_endpt,req) do |resp|
43
- print "Counter Group = #{resp.stats.counter_group}\n"
44
- print "Key = #{resp.stats.key}\n"
45
-
46
- tseries = {}
47
- resp.stats.meters.each do |meter|
48
- meter.values.each do |val|
49
- tseries[ val.ts.tv_sec ] ||= []
50
- tseries[ val.ts.tv_sec ] << val.val
51
- end
52
- end
53
-
54
-
55
- rows = []
56
- tseries.each do |ts,valarr|
57
- rows << [ ts, valarr ].flatten
48
+ print "Counter Group = #{resp.counter_group}\n"
49
+ print "Key = #{resp.key.key}\n"
50
+ print "Readable = #{resp.key.readable}\n"
51
+ print "Label = #{resp.key.label}\n"
52
+ print "Description = #{resp.key.description}\n"
53
+ print "Num intervals = #{resp.stats.size}\n"
54
+
55
+ # attribute strings
56
+ attr_str = resp.key.attributes.inject( "") do |acc,h|
57
+ acc << "#{h.attr_name}=#{h.attr_value} "
58
+ end
59
+ print "Attributes = #{attr_str}\n"
60
+
61
+ print "Response at #{Time.now}\n"
62
+
63
+
64
+ resp.stats.each do |tsval|
65
+ if totals.nil?
66
+ totals = tsval.values
67
+ else
68
+ totals = [totals, tsval.values ].transpose.map {|x| x.reduce(:+)}
69
+ end
70
+ rows << [ Time.at(tsval.ts_tv_sec), tsval.values ].flatten
58
71
  end
59
72
 
60
73
  table = Terminal::Table.new(:headings => colnames, :rows => rows )
61
74
  puts(table)
75
+ totalstable = Terminal::Table.new(:headings => colnames, :rows => [totals.unshift(0).collect{|a| a*60}])
76
+ puts(totalstable)
62
77
  end
63
78
 
64
79
  end
@@ -0,0 +1,54 @@
1
+ module ITRP
2
+
3
+ class Cmd_volume < Cmd
4
+ def initialize (e)
5
+ super(e)
6
+ @enabled_in_state = :counter
7
+ @attach_cmd = ''
8
+ @trigger = 'volume'
9
+ end
10
+
11
+
12
+
13
+ def enter(cmdline)
14
+
15
+ #volume TOTALBW [0]
16
+ patt = cmdline.scan(/volume\s+(\S+)\s*(\d*)/).flatten
17
+
18
+
19
+ use_key = patt.empty? ? appstate(:cgkey) : patt[0]
20
+ use_meter = patt[1].to_i || 0
21
+ if use_key=="SYS:GROUP_TOTALS"
22
+ use_key=TRP::KeyT.new({key:"SYS:GROUP_TOTALS"})
23
+ end
24
+
25
+ req =TrisulRP::Protocol.mk_request(TRP::Message::Command::COUNTER_ITEM_REQUEST,
26
+ :counter_group => @appenv.context_data[:cgguid],
27
+ :key => use_key,
28
+ :volumes_only => 1,
29
+ :get_percentile => 0,
30
+ :time_interval => appstate( :time_interval) )
31
+
32
+ rows = []
33
+
34
+
35
+ print "Request sent at #{Time.now}\n"
36
+
37
+ TrisulRP::Protocol.get_response_zmq(@appenv.zmq_endpt,req) do |resp|
38
+
39
+ total = resp.totals.values[use_meter]
40
+ pct = 0
41
+ if resp.percentiles
42
+ pct = resp.percentiles.values[use_meter]
43
+ end
44
+
45
+ print( "Total = #{total * 60 }\n")
46
+ print( "Percentile = #{pct }\n")
47
+
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
54
+