Class: ITRP::Cmd_query_alerts

Inherits:
Cmd
  • Object
show all
Defined in:
lib/handlers/query_alerts.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_alerts

Returns a new instance of Cmd_query_alerts.



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

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

Instance Method Details

#completions(patt) ⇒ Object



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

def completions(patt)
	TRP::QueryAlertsRequest
	        .fields
			.values
			.collect { |a| a.name }
			.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/handlers/query_alerts.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}

		[:maxitems].each do |a|
			qparams[a] = qparams[a].to_i if qparams.key? a
		end

		[:idlist].each do |a|
			qparams[a] = qparams[a].split(',')  if qparams.key? a
		end

 p qparams 


		req =mk_request(TRP::Message::Command::QUERY_ALERTS_REQUEST,
		 { 	:alert_group  => appstate(:cgguid),
                     	:time_interval =>  appstate(:time_interval)
		 }.merge(qparams))


    rows = [] 

		labelfmt = lambda do |fld|
			fld.label.empty? ? fld.key : fld.label
		end

		get_response_zmq(@zmq_endpt,req) do |resp|

        resp.alerts.each do | res |


        rows << [ "#{res.alert_id}",
                  Time.at( res.time.tv_sec).to_s(),
	  res.occurrances, 
                  res.source_ip.label,
                  res.source_port.label,
                  res.destination_ip.label,
                  res.destination_port.label,
                  res.sigid.key,
                  res.priority.key,
                  res.classification.key
        ]
        end

    end

		table = Terminal::Table.new( 
:headings => %w(ID Time Count SourceIP Port DestIP Port SigID Prio Class ),
:rows => rows)
		puts(table) 

end