Class: EventWindow

Inherits:
Object
  • Object
show all
Defined in:
lib/gui/event_window.rb

Constant Summary collapse

EVENT_WINDOW_TITLE =
"Event Browser"
CORE_EVENT_TYPE =

event type

"core"
PORT_EVENT_TYPE =
"port"
AVAIL_EVENT_TYPE =
"interface"
TRAP_EVENT_TYPE =
"trap"
CUSTOM_EVENT_TYPE =
"custom"
SNMP_EVENT_TYPE =
"snmp"
WMI_EVENT_TYPE =
"wmi"
JMX_EVENT_TYPE =
"jmx"
SYSLOG_EVENT_TYPE =
"syslog"
HTTP_EVENT_TYPE =
"http"

Instance Method Summary collapse

Constructor Details

#initializeEventWindow

Returns a new instance of EventWindow.



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/gui/event_window.rb', line 241

def initialize()

  @statusbar=nil
  @in_statusbar = Mutex.new
  @list=nil
  clean()
  
  #################################################
  #create thread to handle new events
  #
  @buff=MsgBuffer.new(1)
  @event_analyzer_thread_status = 1
  @event_analyzer_thread = Thread.start do
        while (@event_analyzer_thread_status)
      	   analyze_event if @buff.full?
      	   sleep(1)
	   Thread.pass
   	end
        $log.debug("end of EventAnalyzer thread")
    end

  #################################################
  #GUI part
  #
  @window=Gtk::Window.new
  @window.signal_connect("delete_event") do
		self.hide()
  end

  @window.signal_connect("key_press_event") {|w,e|
    if e.keyval == Gdk::Keyval::GDK_Escape
		self.hide()
    end
  }

  @window.set_size_request(600, 100)
  @window.set_title(EVENT_WINDOW_TITLE)
  @window.set_icon("#{PIXMAP_PATH}/logo_icon.png")

  box1 = Gtk::VBox.new(false, 0)
  @window.add(box1)

  box1.show
  box11 = Gtk::VBox.new(false, 0)
  box11.show

#------------begin scrolledbar--------------------------------------
  scrolled_window = Gtk::ScrolledWindow.new(nil, nil)
  scrolled_window.border_width=0
  scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC,
                             Gtk::POLICY_AUTOMATIC)
  # scrolled_window.vscrollbar.unset_flag(Gtk::CAN_FOCUS)
  box1.pack_start(scrolled_window, true, true, 0)
  
  scrolled_window.add_with_viewport(box11)
  box11.set_focus_vadjustment(scrolled_window.vadjustment)
  scrolled_window.show
#----------------end scrolledbar-----------------------------------


@list = Gtk::CList::new(["Event ID", "Level", "Module","Timestamp", "Node", "Summary" ])
@list.set_sort_column(1,4)
#@list.selection.set_mode(Gtk::SELECTION_MULTIPLE)
# Create a popup menu
menu = Gtk::Menu.new

item_ack = Gtk::MenuItem.new("Acknowledge event")
item_ack.signal_connect("activate") { acknowledge_event() }
menu.append(item_ack)

item_clear = Gtk::MenuItem.new("Clear display")
item_clear.signal_connect("activate") { @list.clear() }
menu.append(item_clear)

item_remove_filter = Gtk::MenuItem.new("Remove src filter")
item_remove_filter.signal_connect("activate") { filter_by_node() }
menu.append(item_remove_filter)


map_menu_severity=Gtk::MenuItem.new("Severity threshold")
map_menu_severity_list=Gtk::Menu.new
radio_menu_grp=nil
for level in $LEVEL
	rmi=Gtk::RadioMenuItem.new(radio_menu_grp,"#{level}")
	if level == $level_view
		rmi.set_active(true)
	end
   rmi.signal_connect("activate") do |widget|
			if widget.active?
		       filter_by_sev(widget.child.label)
			end
    end
	radio_menu_grp=rmi.group
	map_menu_severity_list.append(rmi)
end
map_menu_severity.set_submenu(map_menu_severity_list)
menu.append(map_menu_severity)

menu.show_all

@list.signal_connect("cursor-changed") do |widget, event|
	iter=widget.selection.selected
	ip=widget.get_value(iter,5)

	if ip != nil
		  if $network.has_key?(ip)
			  set_map($network[ip].map)
			  $network[ip].node_view.select()
		  else
			  #verify that node exist
			  if $host[ip] != nil
			  	 set_map($host[ip].map)
				 $host[ip].node_view.select()
			  end
		  end
	end
end

@list.signal_connect("button_press_event") do |widget, event|
  if event.kind_of? Gdk::EventButton  and event.button == 3
		if @list.nb_event > 0
			item_clear.set_sensitive(true)
		else
			item_clear.set_sensitive(false)
		end
		if @filter_active
			item_remove_filter.set_sensitive(true)
		else
			item_remove_filter.set_sensitive(false)
		end
	    menu.popup(nil, nil, event.button, event.time)

  end
end

@list.signal_connect("key_press_event") {|w, e| 
  if (e.keyval == Gdk::Keyval::GDK_Delete) || (e.keyval == Gdk::Keyval::GDK_d)
    hide_event()
  end
}

 @list.show
 box11.add @list

#---------------------begin statusbar---------

    @statusbar = Gtk::Statusbar.new
    
    vvbox = Gtk::VButtonBox.new
    vvbox.border_width=0
    vvbox.set_layout_style(Gtk::ButtonBox::END)
    vvbox.set_spacing(0)
    vvbox.set_size_request(200, 20)
    vvbox.show

    box1.pack_start(@statusbar,false,false,0)
    
    @statusbar.show
    @statusbar.signal_connect("text_popped") do |o, mid, text|
      popped(mid,text)
    end
    @statusbar.signal_connect("text_pushed") do |o, mid, text|
      pushed(mid,text)
    end

#---------------------end status bar----------

end

Instance Method Details

#acknowledge_eventObject



215
216
217
# File 'lib/gui/event_window.rb', line 215

def acknowledge_event()
	hide_event()
end

#add_event(src_module, category, node, summary, datetime = nil, state = 'N') ⇒ Object

add event in list state can be normal N or acknowledge A



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/gui/event_window.rb', line 128

def add_event(src_module, category, node, summary, datetime=nil, state='N')
  if node
    ip_str = node.ip
    #puts "in add_event #{ip_str} #{summary}"
    text = []
    index_pos=@event_strings.length()+1
    text.push index_pos.to_s
    text.push category
    text.push src_module
    if datetime == nil
      datetime=Time.new.to_s
    end
    text.push datetime
    text.push ip_str
    text.push summary

    if filter_on_node(ip_str) || @filter_active == false
      if $LEVEL.index(category)>=$LEVEL.index($level_view)
        @buff.put Marshal.load(Marshal.dump(text))
      end
    end
    text.push state
    #in event_strings there is one more column: state
    @event_strings.push(text)

    alarm_handle(src_module, category, ip_str, summary, datetime)
    update_node_notification(get_status_from_level(category), ip_str)
    update_statusbar()
  end
end

#analyze_eventObject



227
228
229
230
231
232
233
# File 'lib/gui/event_window.rb', line 227

def analyze_event()
   while @buff.has_more?     
      event=@buff.get
      #puts "in analyze_event: #{@buff.has_more?} #{event}"
      @list.prepend(event)      
   end
end

#cleanObject



235
236
237
238
239
# File 'lib/gui/event_window.rb', line 235

def clean()
  @event_strings=[]
  @filter_active=false
  @filter_node=nil
end

#filter_by_node(node = nil) ⇒ Object

show logs for this specific node, node=nil to show all logs



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/gui/event_window.rb', line 69

def filter_by_node(node=nil)
	@list.clear()
	if node
	  @filter_active=true
	  @filter_node=node
	  @event_strings.each {|pos, category, src_module, time, ip, summary, state|
		if state != "A"
		  if filter_on_node(ip) && ($LEVEL.index(category)>=$LEVEL.index($level_view))
			 text = []
   		 text.push pos
   		 text.push category
   		 text.push src_module
   		 text.push time
   		 text.push ip
   		 text.push summary
			 @list.prepend(text)
		  end
		end
	  }
	  @window.set_title(EVENT_WINDOW_TITLE + " filter #{$level_view} from #{node.ip}")
	else
	  @filter_active=false
	  @filter_node=nil
	  @event_strings.each {|pos, category, src_module, time, ip, summary, state|
		if state != "A"
		  if ($LEVEL.index(category)>=$LEVEL.index($level_view))
			  text = []
   		  text.push pos
   		  text.push category
   		  text.push src_module
   		  text.push time
   		  text.push ip
   		  text.push summary
			  @list.prepend(text)
		  end
		end
	  }
	  @window.set_title(EVENT_WINDOW_TITLE)
	end
end

#filter_by_sev(sev) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/gui/event_window.rb', line 57

def filter_by_sev(sev)
	$level_view = sev
	if @filter_node
		filter_by_node(@filter_node)
	else
		filter_by_node()
	end
end

#filter_on_node(ip_str) ⇒ Object

define if ip is part of the filter tag



113
114
115
116
117
118
119
120
121
122
# File 'lib/gui/event_window.rb', line 113

def filter_on_node(ip_str)
	if @filter_node == nil
		return false
	end
	if exist_network(@filter_node.ip)
		#we want to retrieve events from all a network
		return $network[@filter_node.ip].contain_host(ip_str)		
	end
	return ip_str == @filter_node.ip
end

#hideObject

hide the window



49
50
51
52
53
54
55
# File 'lib/gui/event_window.rb', line 49

def hide()
	if $canvas.fullscreen?()
	  @window.set_modal(false)
	  @window.set_transient_for(nil)
	end
	return @window.hide()
end

#hide_eventObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/gui/event_window.rb', line 159

def hide_event()
	iter = @list.selection.selected
	if iter != nil
	  #set state to aknowledge
  	  list_id=@list.get_value(iter,1)
	  event_id=list_id.to_i()-1
     if @event_strings[event_id] != nil
		@event_strings[event_id][6]='A'
		#real time events sev need to be caught
		if @event_strings[event_id][2] != CORE_EVENT_TYPE
		  event_type=@event_strings[event_id][2]
		  max_lev=nil
		  @event_strings.each {|pos, category, src_module, time, ip, summary, state|
			if (src_module == event_type) && (state != "A")
				if (max_lev != nil)
					if ($LEVEL.index(category) > $LEVEL.index(max_lev))
						max_lev=category
					end
				else
					max_lev=category
				end
			end
		  }
			if max_lev != nil
				max_lev_status=get_status_from_level(max_lev)
				if $host[@event_strings[event_id][4]] != nil
					$host[@event_strings[event_id][4]].set_severity(event_type, $status.index(max_lev_status))
				end
			else
				if $host[@event_strings[event_id][4]] != nil
					$host[@event_strings[event_id][4]].set_severity(event_type, $status.index("UNMANAGED"))
				end				
			end
		end
		#update notification icon
		print "in hide_event #{@event_strings[event_id][4]} #{$status_value[$status.index(get_status_from_level(@event_strings[event_id][1]))]}\n"
		ip = @event_strings[event_id][4]
		if $host[ip] and $host[ip].node_view
		   sev=$status_value[$status.index(get_status_from_level(@event_strings[event_id][1]))]
		   if sev > NORMAL
		      $host[ip].node_view.del_notification(sev)
		   end
		end
		#remove from gui
		@list.remove(iter) unless iter == nil
	  end
	end
end

#popped(mid, text) ⇒ Object



470
471
# File 'lib/gui/event_window.rb', line 470

def popped(mid,text)
end

#pushed(mid, text) ⇒ Object



467
468
# File 'lib/gui/event_window.rb', line 467

def pushed(mid,text)
end

#save_eventObject



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/gui/event_window.rb', line 443

def save_event()
	iter_zero=@list.model.get_iter("0")
	if iter_zero != nil
	  #we extract the timestamp of the first entry
	  bbeg= @list.get_value(iter_zero,4)
	  vall=@list.nb_event-1
	  #we extract the timestamp of the last entry
	  bend=@list.get_value(@list.model.get_iter("#{vall}"),4)
	
	  #filename is base on the timestamp of the first and last entry
	  begin
		  filepath="#{LOG_DIR}/#{bend}-#{bbeg}"
		  $log.info("Saving log to #{filepath}")
		  fic = File.new(filepath,'w')
		  for row in 0..@list.nb_event-1
	   	  	fic.puts(@list.get_value(@list.model.get_iter("#{row}"),4)+"\t"+@list.get_value(@list.model.get_iter("#{row}"),3)+"\t"+@list.get_value(@list.model.get_iter("#{row}"),2)+"\t"+@list.get_value(@list.model.get_iter("#{row}"),5)+"\t"+@list.get_value(@list.model.get_iter("#{row}"),6))
		  end
		  fic.close
	 rescue
	 	$log.error("Can't write log to #{LOG_DIR}")
	 end
	end
end

#showObject

show the window



37
38
39
40
41
42
43
44
# File 'lib/gui/event_window.rb', line 37

def show()
	if $canvas.fullscreen?()
	  @window.set_modal(true)
	  @window.set_transient_for($win)
	end
	@window.deiconify()
	return @window.show()
end

#stop_analyzerObject



219
220
221
222
223
224
# File 'lib/gui/event_window.rb', line 219

def stop_analyzer()
	 if @event_analyzer_thread.alive?
		 @event_analyzer_thread_status = 0
		 Thread.kill(@event_analyzer_thread)
	 end
end

#update_node_notification(sev, ip) ⇒ Object



208
209
210
211
212
213
# File 'lib/gui/event_window.rb', line 208

def update_node_notification(sev, ip)
   sev_value = $status_value[$status.index(sev)]
   if sev_value > NORMAL
   	$host[ip].node_view.add_notification(sev_value)
   end
end

#update_statusbarObject

update status bar (active host) / (total host) also update the statusicon if exists



414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'lib/gui/event_window.rb', line 414

def update_statusbar()
  @in_statusbar.synchronize {
    hup=0
    hdown=0
    if @statusbar != nil
      begin
	$host.each_key {|ip|
          if $host[ip] && ($host[ip].status == NORMAL)
            hup=hup+1
          else
            hdown=hdown+1
          end
	}
      rescue Exception => msg
	$log.error(msg)
      end
      str="Active Host" + ($host.size<2?" ":"s ") + "#{hup}/#{$host.size}"
      @statusbar.push(1, str)
      if $icon && $icon.embedded?
	$icon.set_tooltip(str)
      end
    end
  }
end

#updating_statusbar?Boolean

Returns:

  • (Boolean)


439
440
441
# File 'lib/gui/event_window.rb', line 439

def updating_statusbar?()
   @in_statusbar.locked?
end

#visible?Boolean

end event type

return if window is visible

Returns:

  • (Boolean)


30
31
32
# File 'lib/gui/event_window.rb', line 30

def visible?()
	return @window.visible?()
end