gnms 2.1.0.rc1 → 2.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gnms might be problematic. Click here for more details.

@@ -0,0 +1,83 @@
1
+ require File.join(File.dirname(__FILE__), 'ping')
2
+
3
+ # The Net module serves as a namespace only.
4
+ module Net
5
+
6
+ # With a TCP ping simply try to open a connection. If we are successful,
7
+ # assume success. In either case close the connection to be polite.
8
+ #
9
+ class Ping::TCP < Ping
10
+ @@service_check = false
11
+
12
+ # Returns whether or not Errno::ECONNREFUSED is considered a successful
13
+ # ping. The default is false.
14
+ #
15
+ def self.service_check
16
+ @@service_check
17
+ end
18
+
19
+ # Sets whether or not an Errno::ECONNREFUSED should be considered a
20
+ # successful ping.
21
+ #
22
+ def self.service_check=(bool)
23
+ unless bool.kind_of?(TrueClass) || bool.kind_of?(FalseClass)
24
+ raise ArgumentError, 'argument must be true or false'
25
+ end
26
+ @@service_check = bool
27
+ end
28
+
29
+ # This method attempts to ping a host and port using a TCPSocket with
30
+ # the host, port and timeout values passed in the constructor. Returns
31
+ # true if successful, or false otherwise.
32
+ #
33
+ # Note that, by default, an Errno::ECONNREFUSED return result will be
34
+ # considered a failed ping. See the documentation for the
35
+ # Ping::TCP.service_check= method if you wish to change this behavior.
36
+ #
37
+ def ping(host=@host)
38
+ super(host)
39
+
40
+ bool = false
41
+ tcp = nil
42
+ start_time = Time.now
43
+
44
+ begin
45
+ Timeout.timeout(@timeout){
46
+ begin
47
+ tcp = TCPSocket.new(host, @port)
48
+ rescue Errno::ECONNREFUSED => err
49
+ if @@service_check
50
+ bool = true
51
+ else
52
+ @exception = err
53
+ end
54
+ rescue Exception => err
55
+ @exception = err
56
+ else
57
+ bool = true
58
+ end
59
+ }
60
+ rescue Timeout::Error => err
61
+ @exception = err
62
+ ensure
63
+ tcp.close if tcp
64
+ end
65
+
66
+ # There is no duration if the ping failed
67
+ @duration = Time.now - start_time if bool
68
+
69
+ bool
70
+ end
71
+
72
+ alias ping? ping
73
+ alias pingecho ping
74
+
75
+ # Class method aliases. DEPRECATED.
76
+ class << self
77
+ alias econnrefused service_check
78
+ alias econnrefused= service_check=
79
+ alias ecr service_check
80
+ alias ecr= service_check=
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,125 @@
1
+ require File.join(File.dirname(__FILE__), 'ping')
2
+
3
+ # The Net module serves as a namespace only.
4
+ module Net
5
+
6
+ # The Ping::UDP class encapsulates methods for UDP pings.
7
+ class Ping::UDP < Ping
8
+ @@service_check = true
9
+
10
+ # Returns whether or not the connect behavior should enforce remote
11
+ # service availability as well as reachability. The default is true.
12
+ #
13
+ def self.service_check
14
+ @@service_check
15
+ end
16
+
17
+ # Set whether or not the connect behavior should enforce remote
18
+ # service availability as well as reachability. If set to false
19
+ # then Errno::ECONNREFUSED or Errno::ECONNRESET will be considered
20
+ # a successful ping, meaning no actual data handshaking is required.
21
+ # By default, if either of those errors occurs it is considered a failed
22
+ # ping.
23
+ #
24
+ def self.service_check=(bool)
25
+ unless bool.kind_of?(TrueClass) || bool.kind_of?(FalseClass)
26
+ raise ArgumentError, 'argument must be true or false'
27
+ end
28
+ @@service_check = bool
29
+ end
30
+
31
+ # The maximum data size that can be sent in a UDP ping.
32
+ MAX_DATA = 64
33
+
34
+ # The data to send to the remote host. By default this is 'ping'.
35
+ # This should be MAX_DATA size characters or less.
36
+ #
37
+ attr_reader :data
38
+
39
+ # Creates and returns a new Ping::UDP object. This is effectively
40
+ # identical to its superclass constructor.
41
+ #
42
+ def initialize(host=nil, port=nil, timeout=5)
43
+ @data = 'ping'
44
+
45
+ super(host, port, timeout)
46
+
47
+ @bind_host = nil
48
+ @bind_port = nil
49
+ end
50
+
51
+ # Sets the data string sent to the remote host. This value cannot have
52
+ # a size greater than MAX_DATA.
53
+ #
54
+ def data=(string)
55
+ if string.size > MAX_DATA
56
+ err = "cannot set data string larger than #{MAX_DATA} characters"
57
+ raise ArgumentError, err
58
+ end
59
+
60
+ @data = string
61
+ end
62
+
63
+ # Associates the local end of the UDP connection with the given +host+
64
+ # and +port+. This is essentially a wrapper for UDPSocket#bind.
65
+ #
66
+ def bind(host, port)
67
+ @bind_host = host
68
+ @bind_port = port
69
+ end
70
+
71
+ # Sends a simple text string to the host and checks the return string. If
72
+ # the string sent and the string returned are a match then the ping was
73
+ # successful and true is returned. Otherwise, false is returned.
74
+ #
75
+ def ping(host = @host)
76
+ super(host)
77
+
78
+ bool = false
79
+ udp = UDPSocket.open
80
+ array = []
81
+
82
+ if @bind_host
83
+ udp.bind(@bind_host, @bind_port)
84
+ end
85
+
86
+ start_time = Time.now
87
+
88
+ begin
89
+ Timeout.timeout(@timeout){
90
+ udp.connect(host, @port)
91
+ udp.send(@data, 0)
92
+ array = udp.recvfrom(MAX_DATA)
93
+ }
94
+ rescue Errno::ECONNREFUSED, Errno::ECONNRESET => err
95
+ if @@service_check
96
+ @exception = err
97
+ else
98
+ bool = true
99
+ end
100
+ #
101
+ #gnms add this rescue
102
+ #
103
+ #
104
+ rescue Timeout::Error
105
+ bool = true
106
+ rescue Exception => err
107
+ @exception = err
108
+ else
109
+ if array[0] == @data
110
+ bool = true
111
+ end
112
+ ensure
113
+ udp.close if udp
114
+ end
115
+
116
+ # There is no duration if the ping failed
117
+ @duration = Time.now - start_time if bool
118
+
119
+ bool
120
+ end
121
+
122
+ alias ping? ping
123
+ alias pingecho ping
124
+ end
125
+ end
@@ -188,6 +188,7 @@ end
188
188
  #
189
189
  def verify_system_conf()
190
190
  ruby_cmd_version = RUBY_VERSION
191
+ $log.info("Using Ruby version #{RUBY_VERSION}")
191
192
  ruby_version="^1\.[89]"
192
193
  if ruby_cmd_version.match(ruby_version)
193
194
  if (defined? Gtk) and !Gtk.check_version(2,4,0)
@@ -16,7 +16,7 @@ class AboutWindow
16
16
  about.set_title "About GNMS"
17
17
  about.resizable=false
18
18
  about.window_position=Gtk::Window::POS_CENTER
19
- icon_name="./pixmap/logo_icon.png"
19
+ icon_name="#{PIXMAP_PATH}/logo_icon.png"
20
20
  Gtk::Window.set_default_icon(icon_name)
21
21
  about.show
22
22
 
@@ -485,13 +485,13 @@ node_network_icon_radio_actions=[
485
485
  set_map_display_view_user_defined()
486
486
  height=e.height
487
487
  if !$canvas.fullscreen?()
488
- height-=@main_bar.height_request
488
+ height -= @main_bar.height_request
489
489
  else
490
490
  #we need to store $win size!
491
491
  $root_width=$win.window.geometry[2]
492
492
  $root_height=$win.window.geometry[3]
493
493
  end
494
- $canvas.set_size(e.width,height)
494
+ $canvas.set_size(e.width, height)
495
495
  false
496
496
  }
497
497
 
@@ -654,6 +654,8 @@ def new_map()
654
654
  if confirm_initdb_window()
655
655
  thread_stopping()
656
656
  save()
657
+ $event_win.clean
658
+ $event_win.filter_by_node()
657
659
  init_map()
658
660
  thread_starting()
659
661
  end
@@ -21,6 +21,10 @@ class CanvasMap < Gtk::VBox
21
21
  end
22
22
  end
23
23
 
24
+ def bounds()
25
+ return @canvas.bounds
26
+ end
27
+
24
28
  #
25
29
  # set the background image
26
30
  #
@@ -167,17 +171,39 @@ class CanvasMap < Gtk::VBox
167
171
  n.node_view.move_right()
168
172
  }
169
173
  when Gdk::Keyval::GDK_Up
170
- #canvas.y1 = y - 10
171
- #canvas.scroll_to(x, canvas.y1)
172
- when Gdk::Keyval::GDK_Down
173
- #canvas.y1 = y + 10
174
- #canvas.scroll_to(x, canvas.y1)
174
+ #canvas root group scroll_to or translate are pain in the ass to handle
175
+ #so we are just here moving each node one by one ...
176
+ if $map.nil?
177
+ $network[ROOTMAPADDR].node_view.move_up()
178
+ else
179
+ $network[$map].get_node().each_value {|node|
180
+ node.node_view.move_up()
181
+ }
182
+ end
183
+ when Gdk::Keyval::GDK_Down
184
+ if $map.nil?
185
+ $network[ROOTMAPADDR].node_view.move_down()
186
+ else
187
+ $network[$map].get_node().each_value {|node|
188
+ node.node_view.move_down()
189
+ }
190
+ end
175
191
  when Gdk::Keyval::GDK_Left
176
- #canvas.x1 = x - 10
177
- #canvas.scroll_to(canvas.x1, y)
192
+ if $map.nil?
193
+ $network[ROOTMAPADDR].node_view.move_left()
194
+ else
195
+ $network[$map].get_node().each_value {|node|
196
+ node.node_view.move_left()
197
+ }
198
+ end
178
199
  when Gdk::Keyval::GDK_Right
179
- #canvas.x1 = x + 10
180
- #canvas.scroll_to(canvas.x1, y)
200
+ if $map.nil?
201
+ $network[ROOTMAPADDR].node_view.move_right()
202
+ else
203
+ $network[$map].get_node().each_value {|node|
204
+ node.node_view.move_right()
205
+ }
206
+ end
181
207
  when Gdk::Keyval::GDK_Page_Up
182
208
  set_map($network[$map].map) unless $map == nil
183
209
  when Gdk::Keyval::GDK_Page_Down
@@ -226,8 +252,9 @@ end
226
252
  def set_size(w, h)
227
253
  if @bg_image_enable && (@img != nil)
228
254
  @img.width = @canvas.x2 - @canvas.x1
229
- @img.height = @canvas.y2 - @canvas.y1
255
+ @img.height = @canvas.y2 - @canvas.y1
230
256
  end
257
+ @canvas.set_bounds(0, 0, get_map_width(), get_map_height()) if $win
231
258
  end
232
259
 
233
260
  def initialize()
@@ -1,6 +1,7 @@
1
1
  class ConfigWindow
2
2
 
3
3
  def initialize(cfg)
4
+ @window = nil
4
5
  @config=cfg
5
6
  @old_sev_level=@config.level
6
7
  @old_contact=nil
@@ -319,24 +320,25 @@ def ConfigWindow::contact_selection_window(alarm, contact_selected_array, contac
319
320
  contact_window.show
320
321
  end
321
322
 
322
-
323
+ def visible()
324
+ return @window.visible? if @window
325
+ return false
326
+ end
323
327
 
324
328
  #
325
329
  # main config window will all the frames
326
330
  #
327
331
  def show()
328
- window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
329
- window.set_title("Preference")
330
- window.set_size_request(580,560)
331
- window.border_width=0
332
- window.set_modal true
333
- window.resizable=false
334
-
335
- #window.set_allow_shrink true
336
- #window.set_allow_grow false
337
- window.signal_connect("key_press_event") {|w,e|
332
+ @window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
333
+ @window.set_title("Preference")
334
+ @window.set_size_request(580,560)
335
+ @window.border_width=0
336
+ @window.set_modal true
337
+ @window.resizable=false
338
+
339
+ @window.signal_connect("key_press_event") {|w,e|
338
340
  if e.keyval == Gdk::Keyval::GDK_Escape
339
- cancel_action(window)
341
+ cancel_action()
340
342
  end
341
343
  }
342
344
 
@@ -347,7 +349,7 @@ $contact.each_key {|id|
347
349
  } unless !$contact
348
350
 
349
351
  box1 = Gtk::VBox.new(FALSE, 0)
350
- window.add(box1)
352
+ @window.add(box1)
351
353
  box1.show
352
354
 
353
355
  box2 = Gtk::VBox.new(FALSE, 10)
@@ -1109,7 +1111,7 @@ end
1109
1111
  @button_macm.set_sensitive @button_macf.active? unless !mac_manufacturer_list_exist?()
1110
1112
  }
1111
1113
 
1112
- @button_nr = Gtk::CheckButton.new "Node Resolving delay (in s)"
1114
+ @button_nr = Gtk::CheckButton.new "Node resolving delay (in s)"
1113
1115
  @button_nr.set_active @config.node_resolving
1114
1116
  @button_nr.show
1115
1117
 
@@ -1135,12 +1137,8 @@ end
1135
1137
  table.attach(@button_nr,0,1,6,7)
1136
1138
  table.attach(@entry_delay_nr,1,2,6,7)
1137
1139
 
1138
- @button_pm = Gtk::CheckButton.new "Host/Port Monitoring delay (in s)"
1139
- if @config.nmap_path == ""
1140
- @button_pm.set_active false
1141
- else
1142
- @button_pm.set_active @config.port_mon
1143
- end
1140
+ @button_pm = Gtk::CheckButton.new "Host/Port monitoring delay (in s)"
1141
+ @button_pm.set_active @config.port_mon
1144
1142
  @button_pm.show
1145
1143
 
1146
1144
  @entry_delay_pm = Gtk::Entry.new
@@ -1162,9 +1160,7 @@ end
1162
1160
  end
1163
1161
 
1164
1162
  @button_pm.signal_connect("toggled") {
1165
- if @config.nmap_path != ""
1166
- @entry_delay_pm.set_sensitive @button_pm.active?
1167
- end
1163
+ @entry_delay_pm.set_sensitive @button_pm.active?
1168
1164
  }
1169
1165
  table.attach(@button_pm,0,1,8,9)
1170
1166
  table.attach(@entry_delay_pm,1,2,8,9)
@@ -2096,18 +2092,19 @@ button.signal_connect("clicked") do
2096
2092
  $log.info("Thread autosave map already active")
2097
2093
  end
2098
2094
  end
2099
- window.destroy
2095
+ @window.destroy
2096
+ @window = nil
2100
2097
  else
2101
- errorEntry(window, "Bad auto save value need to be greater than 1")
2098
+ errorEntry(@window, "Bad auto save value need to be greater than 1")
2102
2099
  end
2103
2100
  else
2104
- errorEntry(window, "Bad SNMP trap server port")
2101
+ errorEntry(@window, "Bad SNMP trap server port")
2105
2102
  end
2106
2103
  else
2107
- errorEntry(window, "Bad Syslog server port")
2104
+ errorEntry(@window, "Bad Syslog server port")
2108
2105
  end
2109
2106
  else
2110
- errorEntry(window, "Bad delay value")
2107
+ errorEntry(@window, "Bad delay value")
2111
2108
  end
2112
2109
  end
2113
2110
 
@@ -2118,18 +2115,18 @@ button.show
2118
2115
 
2119
2116
  button = Gtk::Button::new(Gtk::Stock::CANCEL)
2120
2117
  button.signal_connect("clicked") do
2121
- cancel_action(window)
2118
+ cancel_action()
2122
2119
  end
2123
2120
  box2.pack_start(button, TRUE, TRUE, 0)
2124
2121
  button.set_flags(Gtk::Widget::CAN_DEFAULT);
2125
2122
  button.grab_default
2126
2123
  button.show
2127
2124
 
2128
- window.show
2125
+ @window.show
2129
2126
 
2130
2127
  end
2131
2128
 
2132
- def cancel_action(win)
2129
+ def cancel_action()
2133
2130
  #restore accounts
2134
2131
  contact_temp=$contact.dup
2135
2132
  $contact.clear
@@ -2144,7 +2141,8 @@ def cancel_action(win)
2144
2141
  }
2145
2142
 
2146
2143
  if FileTest.exist?(GLOBAL_CONF_FILE)
2147
- win.destroy
2144
+ @window.destroy
2145
+ @window = nil
2148
2146
  end
2149
2147
  end
2150
2148