Class: ITRP::Cmd_query_resource

Inherits:
Cmd
  • Object
show all
Defined in:
lib/handlers/query_resource.rb

Instance Attribute Summary

Attributes inherited from Cmd

#attach_cmd, #children, #enabled_in_state, #trigger

Instance Method Summary collapse

Methods inherited from Cmd

#appstate, #find_node, #is_root?, #place_node, #print_state, #set_time_window, #treeprint

Constructor Details

#initialize(e) ⇒ Cmd_query_resource

Returns a new instance of Cmd_query_resource.



4
5
6
7
8
9
# File 'lib/handlers/query_resource.rb', line 4

def initialize (e)
	super(e)
	@enabled_in_state = :resource
	@attach_cmd  = ''
	@trigger = 'query'
end

Instance Method Details

#completions(patt) ⇒ Object



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

def completions(patt)
	TRP::QueryResourcesRequest
	        .fields
			.values
			.collect { |a| a.name.to_s }
			.grep( /^#{Regexp.escape(patt)}/i)
end

#enter(patt) ⇒ Object



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
# File 'lib/handlers/query_resource.rb', line 19

def enter(patt)

		terms = patt.scan( /(\w+)\s*=\s*([\w\-_\.\:,]+)+/ )

		qparams = terms.inject({}) { |acc,t| acc.store( t[0].to_sym, t[1]);acc}

 p qparams 

		# meter names 
		req =mk_request(TRP::Message::Command::QUERY_RESOURCES_REQUEST,
		{
		 :resource_group => appstate(:cgguid),
                     :time_interval => appstate(:time_interval)
		}.merge(qparams))

    rows = [] 

		get_response_zmq(@appenv.zmq_endpt,req) do |resp|

        resp.resources.each do | res |

        rows << [ "#{res.resource_id}",
                  Time.at( res.time.tv_sec).to_s(),
                  res.source_ip.label,
                  res.source_port.label,
                  res.destination_ip.label,
                  res.destination_port.label,
                  wrap(res.uri,50),
                  wrap(res.userlabel,40)
        ]
        end

    end

		table = Terminal::Table.new( 
:headings => %w(ID Time SourceIP Port DestIP Port URI Label ),
:rows => rows)
		puts(table) 

end