Class: NodeHostView

Inherits:
NodeView show all
Defined in:
lib/gui/node_host_view.rb

Constant Summary

Constants inherited from NodeView

NodeView::MIN_MOVE, NodeView::NODE_SIZE

Instance Attribute Summary

Attributes inherited from NodeView

#bg_text, #group, #icon, #image, #node, #notification_count, #notification_sev, #selected, #text

Instance Method Summary collapse

Methods inherited from NodeView

#add_notification, #del_notification, #destroy, #get_node_size, #get_size, #get_text, #hide, #hide_link, #hide_selected_node_link, #hide_text, #icon_color, #move, #move_down, #move_left, #move_right, #move_up, #reload_bg_text, #reload_label_colors, #reparent, #reset_notification, #resize, #select, #selected?, #set_image, #set_text, #set_text_color, #show, #show_link, #show_selected_node_link, #show_text, #unlink_node, #unselect

Constructor Details

#initialize(rootcanvas, nd, status, icon_file, label) ⇒ NodeHostView

Returns a new instance of NodeHostView.



263
264
265
266
267
268
269
270
271
272
# File 'lib/gui/node_host_view.rb', line 263

def initialize(rootcanvas, nd, status, icon_file, label)
  @dragging=false
  @size=get_node_size()
  @tooltips=nil
  self.node=nd
  self.selected=false
  reset_notification()

  setup_form(rootcanvas, status, icon_file, label)
end

Instance Method Details

#hide_tooltipsObject



254
255
256
257
258
259
260
261
# File 'lib/gui/node_host_view.rb', line 254

def hide_tooltips()
	if @tooltips != nil
		@tooltips.hide()
		#with this the tooltips is always refreshed
		@tooltips.destroy
		@tooltips=nil
	end
end

#resize_notification_icon(sz) ⇒ Object



113
114
115
116
117
118
# File 'lib/gui/node_host_view.rb', line 113

def resize_notification_icon(sz)
   @notification_text.x = sz/2.0
   @notification_text.y = sz/2.0    
   @notification_bg.width = sz
   @notification_bg.height = sz     
end

#set_type(typ) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gui/node_host_view.rb', line 3

def set_type(typ)
	points=nil
	icon_x = @icon.x
	icon_y = @icon.y
	to_size=get_node_size()
	case typ
	when "printer"
		#hexagone: device
		points = [[to_size/6.0, 0], [5*to_size/6.0, 0], [to_size, to_size/2.0], [5*to_size/6.0, to_size ], [to_size/6.0, to_size], [0, to_size/2.0]]
	when "router" 
		#losange
		points = [[to_size/2.0, 0], [0, to_size/2.0], [to_size/2.0, to_size], [to_size, to_size/2.0] ]
	when "firewall"
		#losange
		points = [[to_size/2.0, 0], [0, to_size/2.0], [to_size/2.0, to_size], [to_size, to_size/2.0] ]
	when "switch"
		#octogone
		points = [[to_size/3.0, 0], [2*to_size/3.0, 0], [to_size, to_size/3.0], [to_size, 2*to_size/3.0], [2*to_size/3, to_size], [to_size/3.0, to_size], [0,2*to_size/3.0], [0, to_size/3.0]]
	end
	@icon.parent.remove_child(@icon)
	if points != nil
                    	@icon=Goo::CanvasPolyline.new(@group, true, points,
		 					:fill_color_rgba => $status_color[$status_value.index(node.status)],
                                                               :stroke_color => "black",
                                                               :line_width => 1.0)
	else
		@icon=Goo::CanvasRect.new(@group, 0, 0,
                                       to_size, to_size,
			        :fill_color_rgba => $status_color[$status_value.index(node.status)],
                                       :stroke_color => "black",
                                       :line_width => 1.0)	
	end
	@icon.x = icon_x
	@icon.y = icon_y
	@icon.lower(nil)
end

#setup_form(root, status, icon_file, label) ⇒ Object



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
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
109
110
111
# File 'lib/gui/node_host_view.rb', line 40

def setup_form(root, status, icon_file, label)

node_size = get_node_size()
@group = Goo::CanvasGroup.new(root,{:x => 0.0,:y => 0.0, :can_focus => true})
	@group.visibility = Goo::CanvasItem::HIDDEN
	@icon=Goo::CanvasRect.new(@group, node.x, node.y,
                                       node_size, node_size,
                                       :fill_color_rgba => status,
                                       :stroke_color => "black",
                                       :line_width => 1.0)

	if (icon_file == nil) || (!FileTest.exist?(icon_file))
icon_file="#{PIXMAP_PATH}/os/unknown.png"
	end
	begin
im=Gdk::Pixbuf.new(icon_file, node_size, node_size)
	rescue Exception => msg
$log.error("Image is corrupted #{msg}")
	end
	@image=Goo::CanvasImage.new(@group, im, @icon.x1, @icon.y1,
                            :width => node_size,
                            :height => node_size,
                            :scale_to_fit => true
)
      @image.width=(node_size)*80/100.0
      @image.height=(node_size)*80/100.0
  
	@image.x = @icon.x1+(node_size/2.0)-@image.width/2.0
	@image.y = @icon.y1+(node_size/2.0)-@image.height/2.0

	if label == nil
label = ""
	end
	#this is the background box for the label
	cl = Integer("0x#{rgb_to_hex_color(Gdk::Color.new($config.label_bg[0],$config.label_bg[1],$config.label_bg[2]))}ff")	
      @bg_text=Goo::CanvasRect.new(@group, @icon.x1-3*label.size/2, @icon.y2+node_size/5-5,
                                       node_size+3*label.size,
                                       node_size/5+5,
		         :fill_color_rgba => cl,
			 :stroke_color_rgba => cl,
                                       :line_width => 1.0)
	
      #this is the label
	@text=Goo::CanvasText.new(@group, label, @icon.x1+node_size/2, @icon.y2+2+node_size/5, 0, 
                         Gtk::ANCHOR_CENTER, 
		  :fill_color_rgba => Integer("0x#{rgb_to_hex_color(Gdk::Color.new($config.label_text[0],$config.label_text[1],$config.label_text[2]))}ff"), 
		  :font => "Sans 8"
		  )

      #this is the notification icon
	circle_size = NODE_SIZE/2.0
      @notification_group = Goo::CanvasGroup.new(@group,{:x => @icon.x+NODE_SIZE-circle_size/2.0,
                                                                                        :y => @icon.y-circle_size/2.0})
	@notification_bg = Goo::CanvasEllipse.new(@notification_group, circle_size/2.0, circle_size/2.0, circle_size/2.0, circle_size/2.0, 
                                                                 :fill_color_rgba => $status_color[$status_value.index(@notification_sev)], 
                                                                 :stroke_color => "white", :line_width => 2.0)
      notification_count_total = @notification_count.inject(0, :+)
	notification_text_label =  notification_count_total >= 10 ? "*" : notification_count_total.to_s
	@notification_text=Goo::CanvasText.new(@notification_group,
                     notification_text_label, circle_size/2.0, circle_size/2.0, 12, Gtk::ANCHOR_CENTER,
                        :fill_color => "white",
	  :font => "Sans 12 Bold"
	  )

      show_notification_icon()
	setup_item(@group)

	#it s easier to change the canvas icon	here based on the node type
	if node.type != "host"
set_type(node.type)
	end
end

#show_notification_iconObject



127
128
129
130
131
132
133
# File 'lib/gui/node_host_view.rb', line 127

def show_notification_icon()
    if (@notification_count.inject(0, :+) < 2) or (@notification_sev < MINOR)
  @notification_group.visibility = Goo::CanvasItem::INVISIBLE
    else
  @notification_group.visibility = Goo::CanvasItem::VISIBLE
    end
end

#show_tooltipsObject

define a tooltip



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/gui/node_host_view.rb', line 137

def show_tooltips()
	if @tooltips==nil
@tooltips=Gtk::Window.new(Gtk::Window::POPUP)
@tooltips.set_decorated(false)
@tooltips.set_size_request(-1,-1)
@tooltips.set_window_position(Gtk::Window::POS_NONE)
@tooltips.border_width=1
x,y=$win.position
@tooltips.move(node.x+x+50, node.y+y+40)
@tooltips.app_paintable=true
@tooltips.realize
drawable=@tooltips.window
gc = Gdk::GC.new(drawable)

#green = Gdk::Color.new(0, 65535, 0)
#colormap = Gdk::Colormap.system
#colormap.alloc_color(green, false, true)

	@tooltips.modify_bg(Gtk::STATE_NORMAL,$light_yellow)
	@tooltips.signal_connect("expose-event") do |win, evt|
	tooltips_width, tooltips_height=@tooltips.size

drawable.draw_rectangle(gc,false, 0, 0, tooltips_width-1, tooltips_height-1)
drawable.draw_rectangle(gc,false, 1, 1, tooltips_width-3, tooltips_height-3)
false

end
vbox=Gtk::VBox.new
 vbox.border_width=5
 ttips_text="<span weight=\"bold\" size=\"small\">IPv4: </span>#{self.node.ipv4}"
ttips_text+="\n<span weight=\"bold\" size=\"small\">NetMask4: </span>#{self.node.netmask4}"
  if !self.node.ipv6.nil?
    ttips_text+="\n<span weight=\"bold\" size=\"small\">IPv6: </span>#{self.node.ipv6}"
  ttips_text+="\n<span weight=\"bold\" size=\"small\">NetMask6: </span>#{self.node.netmask6}"    
  end
  if self.node.dns_name?
    ttips_text+="\n<span weight=\"bold\" size=\"small\">Dns name: </span>#{self.node.dns_name}"
  end
  if self.node.description?() &&( self.node.description != "")
   ttips_text+="\n<span weight=\"bold\" size=\"small\">Description: </span>#{self.node.description}"
  end
 label = Gtk::Label.new.set_markup(ttips_text)
 label.set_alignment(0,0.5)
 vbox.add label

   if self.node.os && (self.node.os != "unknown")
	tos=Gtk::Table.new(1,0,false)
	vbox.add tos
	label_os = Gtk::Label.new.set_markup("<span weight=\"bold\" size=\"small\">OS: </span>")
	label_os.set_alignment(0,0.5)
	label_os.show
	tos.add label_os
	begin
	  pxb = Gdk::Pixbuf.new(PIXMAP_PATH+"/#{find_extension("os/#{self.node.os}")}",20,20)
	  pxb_pixmap,pxb_mask=pxb.render_pixmap_and_mask(128)
	  img=Gtk::Image.new(pxb_pixmap,pxb_mask)
	  img.show
	  tos.attach(img,0,1,0,1, Gtk::FILL)
	  tos.show
	rescue
		#no os image
	end

   end

   if self.node.type
	ttype=Gtk::Table.new(1,0,false)
	vbox.add ttype
	label_type = Gtk::Label.new.set_markup("<span weight=\"bold\" size=\"small\">Type: </span>")
	label_type.set_alignment(0,0.5)
	label_type.show
	ttype.add label_type
	begin
	  pxb = Gdk::Pixbuf.new(PIXMAP_PATH+"/#{find_extension("type/#{self.node.type}")}",20,20)
	  pxb_pixmap,pxb_mask=pxb.render_pixmap_and_mask(128)
	  img=Gtk::Image.new(pxb_pixmap,pxb_mask)
	  img.show
	  ttype.attach(img,0,1,0,1, Gtk::FILL)
	  ttype.show
	rescue
		#no type image
	end

   end
sev_str=$status[$status_value.index(self.node.avail_sev)]
ttips_text_sev="<span weight=\"bold\" size=\"small\">Availability Severity: </span><span color=\"##{rgb_to_hex_color(get_color_from_status(sev_str))}\">#{sev_str}</span>"
sev_str=$status[$status_value.index(self.node.service_sev)]
ttips_text_sev="<span weight=\"bold\" size=\"small\">Service Severity: </span><span color=\"##{rgb_to_hex_color(get_color_from_status(sev_str))}\">#{sev_str}</span>"
sev_str=$status[$status_value.index(self.node.snmp_sev)]
ttips_text_sev+="\n<span weight=\"bold\" size=\"small\">SNMP Severity: </span><span color=\"##{rgb_to_hex_color(get_color_from_status(sev_str))}\">#{sev_str}</span>"
sev_str=$status[$status_value.index(self.node.wmi_sev)]
ttips_text_sev+="\n<span weight=\"bold\" size=\"small\">WMI Severity: </span><span color=\"##{rgb_to_hex_color(get_color_from_status(sev_str))}\">#{sev_str}</span>"
sev_str=$status[$status_value.index(self.node.jmx_sev)]
ttips_text_sev+="\n<span weight=\"bold\" size=\"small\">JMX Severity: </span><span color=\"##{rgb_to_hex_color(get_color_from_status(sev_str))}\">#{sev_str}</span>"
sev_str=$status[$status_value.index(self.node.custom_sev)]	
ttips_text_sev+="\n<span weight=\"bold\" size=\"small\">Custom Severity: </span><span color=\"##{rgb_to_hex_color(get_color_from_status(sev_str))}\">#{sev_str}</span>"
sev_str=$status[$status_value.index(self.node.syslog_sev)]
ttips_text_sev+="\n<span weight=\"bold\" size=\"small\">Syslog Severity: </span><span color=\"##{rgb_to_hex_color(get_color_from_status(sev_str))}\">#{sev_str}</span>"
sev_str=$status[$status_value.index(self.node.trap_sev)]
ttips_text_sev+="\n<span weight=\"bold\" size=\"small\">Trap Severity: </span><span color=\"##{rgb_to_hex_color(get_color_from_status(sev_str))}\">#{sev_str}</span>"

label_sev = Gtk::Label.new.set_markup(ttips_text_sev)
label_sev.set_alignment(0,0.5)
label_sev.show
vbox.add label_sev

 vbox.show
 label.show

 @tooltips.add vbox
	end
	if !@tooltips.visible?
@tooltips.show()
	end

end

#update_notification_iconObject



120
121
122
123
124
125
# File 'lib/gui/node_host_view.rb', line 120

def update_notification_icon()
   notification_count_total = @notification_count.inject(0, :+)
   @notification_text.text =  notification_count_total >= 10 ? "*" : notification_count_total.to_s
   @notification_bg.fill_color_rgba = $status_color[$status_value.index(@notification_sev)]
   show_notification_icon()
end