gnms 2.1.0.rc1

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.

Files changed (140) hide show
  1. data/LICENSE +459 -0
  2. data/README +29 -0
  3. data/bin/gnms +11 -0
  4. data/gnms.gemspec +70 -0
  5. data/lib/cmd_parse.rb +747 -0
  6. data/lib/config_global.rb +414 -0
  7. data/lib/contact.rb +171 -0
  8. data/lib/external/crypt/blowfish-tables.rb +190 -0
  9. data/lib/external/crypt/blowfish.rb +110 -0
  10. data/lib/external/crypt/cbc.rb +123 -0
  11. data/lib/external/crypt/stringxor.rb +27 -0
  12. data/lib/external/fog.rb +41 -0
  13. data/lib/external/jjmx.rb +45 -0
  14. data/lib/external/sms.rb +282 -0
  15. data/lib/external/xmpp4r-simple.rb +497 -0
  16. data/lib/format.rb +85 -0
  17. data/lib/gnms.rb +329 -0
  18. data/lib/gui/about_window.rb +177 -0
  19. data/lib/gui/adddelnode.rb +799 -0
  20. data/lib/gui/base_window.rb +789 -0
  21. data/lib/gui/canvas_map.rb +498 -0
  22. data/lib/gui/charts/gruff.rb +51 -0
  23. data/lib/gui/color_macro.rb +145 -0
  24. data/lib/gui/config_window.rb +2151 -0
  25. data/lib/gui/custom_plugin_window.rb +90 -0
  26. data/lib/gui/debug_window.rb +46 -0
  27. data/lib/gui/event_window.rb +469 -0
  28. data/lib/gui/find_node_window.rb +438 -0
  29. data/lib/gui/help_window.rb +47 -0
  30. data/lib/gui/ipcalculator.rb +147 -0
  31. data/lib/gui/jmx_ref_window.rb +309 -0
  32. data/lib/gui/link_view.rb +46 -0
  33. data/lib/gui/mib_browser.rb +585 -0
  34. data/lib/gui/node_host_property.rb +3712 -0
  35. data/lib/gui/node_host_view.rb +270 -0
  36. data/lib/gui/node_network_property.rb +1059 -0
  37. data/lib/gui/node_network_view.rb +186 -0
  38. data/lib/gui/node_view.rb +672 -0
  39. data/lib/gui/oid_ref_window.rb +288 -0
  40. data/lib/gui/snmptrap_ref_window.rb +288 -0
  41. data/lib/gui/sub/account_frame.rb +196 -0
  42. data/lib/gui/sub/contact_frame.rb +519 -0
  43. data/lib/gui/syslog_ref_window.rb +288 -0
  44. data/lib/gui/treenode_window.rb +320 -0
  45. data/lib/gui/update_window.rb +124 -0
  46. data/lib/gui/widgets.rb +169 -0
  47. data/lib/gui/wmi_ref_window.rb +286 -0
  48. data/lib/interface.rb +16 -0
  49. data/lib/ipcalc.rb +266 -0
  50. data/lib/link.rb +45 -0
  51. data/lib/main.rb +1091 -0
  52. data/lib/monitor/client/custom/custom_monitoring.rb +40 -0
  53. data/lib/monitor/client/jmx/jmx_attr_monitoring.rb +36 -0
  54. data/lib/monitor/client/jmx/jmx_monitoring.rb +83 -0
  55. data/lib/monitor/client/jmx/jmx_ref.rb +114 -0
  56. data/lib/monitor/client/snmp/mibs/SNMPv2-MIB.txt +854 -0
  57. data/lib/monitor/client/snmp/mibs/SNMPv2-SMI.txt +344 -0
  58. data/lib/monitor/client/snmp/oid_ref.rb +141 -0
  59. data/lib/monitor/client/snmp/snmp.rb +178 -0
  60. data/lib/monitor/client/snmp/snmp_monitoring.rb +58 -0
  61. data/lib/monitor/client/wmi/wmi.rb +139 -0
  62. data/lib/monitor/client/wmi/wmi_monitoring.rb +60 -0
  63. data/lib/monitor/client/wmi/wmi_ref.rb +141 -0
  64. data/lib/monitor/custom_plugin.rb +50 -0
  65. data/lib/monitor/server/msg_buffer.rb +39 -0
  66. data/lib/monitor/server/snmp/snmptrap_analyzer.rb +81 -0
  67. data/lib/monitor/server/snmp/snmptrap_capture.rb +26 -0
  68. data/lib/monitor/server/snmp/snmptrap_monitoring.rb +32 -0
  69. data/lib/monitor/server/snmp/snmptrap_ref.rb +135 -0
  70. data/lib/monitor/server/snmp/snmptrap_server.rb +50 -0
  71. data/lib/monitor/server/syslog/syslog_analyzer.rb +141 -0
  72. data/lib/monitor/server/syslog/syslog_capture.rb +28 -0
  73. data/lib/monitor/server/syslog/syslog_monitoring.rb +32 -0
  74. data/lib/monitor/server/syslog/syslog_ref.rb +136 -0
  75. data/lib/monitor/server/syslog/syslog_server.rb +43 -0
  76. data/lib/node.rb +1020 -0
  77. data/lib/node_db.rb +2668 -0
  78. data/lib/node_host.rb +215 -0
  79. data/lib/node_listener.rb +639 -0
  80. data/lib/node_network.rb +269 -0
  81. data/lib/node_property.rb +39 -0
  82. data/lib/notify/alarm.rb +247 -0
  83. data/lib/notify/irc_bot.rb +167 -0
  84. data/lib/notify/xmpp_bot.rb +107 -0
  85. data/lib/service.rb +36 -0
  86. data/lib/version.rb +8 -0
  87. data/pixmap/bg/map_bg.jpg +0 -0
  88. data/pixmap/bg/map_bg2.jpg +0 -0
  89. data/pixmap/logo.jpg +0 -0
  90. data/pixmap/logo_icon.png +0 -0
  91. data/pixmap/os/3com.png +0 -0
  92. data/pixmap/os/aix.gif +0 -0
  93. data/pixmap/os/amiga.png +0 -0
  94. data/pixmap/os/beos.png +0 -0
  95. data/pixmap/os/cisco.png +0 -0
  96. data/pixmap/os/freebsd.png +0 -0
  97. data/pixmap/os/hp.png +0 -0
  98. data/pixmap/os/hurd.gif +0 -0
  99. data/pixmap/os/irix.gif +0 -0
  100. data/pixmap/os/linux.png +0 -0
  101. data/pixmap/os/mac.png +0 -0
  102. data/pixmap/os/netbsd.gif +0 -0
  103. data/pixmap/os/netware.png +0 -0
  104. data/pixmap/os/openbsd.png +0 -0
  105. data/pixmap/os/os2warp.gif +0 -0
  106. data/pixmap/os/qnx.gif +0 -0
  107. data/pixmap/os/sco.gif +0 -0
  108. data/pixmap/os/sgi.xpm +111 -0
  109. data/pixmap/os/solaris.gif +0 -0
  110. data/pixmap/os/unix.gif +0 -0
  111. data/pixmap/os/unknown.png +0 -0
  112. data/pixmap/os/vms.xpm +345 -0
  113. data/pixmap/os/windows.png +0 -0
  114. data/pixmap/type/cloud.png +0 -0
  115. data/pixmap/type/device.png +0 -0
  116. data/pixmap/type/firewall.png +0 -0
  117. data/pixmap/type/gateway.png +0 -0
  118. data/pixmap/type/home.png +0 -0
  119. data/pixmap/type/host.png +0 -0
  120. data/pixmap/type/network.png +0 -0
  121. data/pixmap/type/printer.png +0 -0
  122. data/pixmap/type/router.png +0 -0
  123. data/pixmap/type/server.png +0 -0
  124. data/pixmap/type/switch.png +0 -0
  125. data/pixmap/type/vm.png +0 -0
  126. data/plugins/Defaultme.rb +7 -0
  127. data/plugins/DnsCheck.rb +46 -0
  128. data/plugins/FooMonitor.rb +26 -0
  129. data/plugins/HttpVirtualHostMonitor.rb +43 -0
  130. data/plugins/MysqlShowStatusMonitor.rb +64 -0
  131. data/plugins/PgsqlPercentConnectionMonitor.rb +72 -0
  132. data/plugins/SshCpuLoadMonitor.rb +85 -0
  133. data/plugins/SshDiskMonitor.rb +69 -0
  134. data/plugins/SshFgtAvExpiredMonitor.rb +75 -0
  135. data/plugins/SshPercentUsedRamMonitor.rb +74 -0
  136. data/plugins/TelnetCpuLoadMonitor.rb +69 -0
  137. data/plugins/example1.rb +15 -0
  138. data/plugins/example2.rb +7 -0
  139. data/sound/beep.wav +0 -0
  140. metadata +378 -0
@@ -0,0 +1,269 @@
1
+ class Network < Node
2
+ attr_accessor :name, :dns_domain, :netbios_domain, :host, :network, :node_view, :map_view, :node_size, :map_bg_type, :map_bg_data
3
+
4
+ def initialize (ip="", mask=24, ipv6="", mask6=64, mp=nil, p=nil, s=UNKNOWN, xd=0 ,yd=0, i="", d=NODESCR_PROPERTY, t="network", o="unknown", n=NONAME_PROPERTY, dns_domain=NONAME_PROPERTY, netbios_domain=NONAME_PROPERTY, uuid=create_uuid())
5
+
6
+ super(ip, mask, ipv6, mask6, mp, p, s, xd, yd, i, d, t, o, uuid)
7
+ @name=n
8
+ @dns_domain=NONAME_PROPERTY
9
+ @netbios_domain=NONAME_PROPERTY
10
+ @host=Hash.new
11
+ @network=Hash.new
12
+ @node_view=nil
13
+ @node_size=nil
14
+ @map_bg_type=nil
15
+ @map_bg_data=nil
16
+
17
+ if mp != nil and $network[mp]
18
+ if $network[mp].status == UNMANAGED
19
+ self.status=UNMANAGED
20
+ end
21
+ end
22
+ #create gui view
23
+ create_node()
24
+ #store node in db
25
+ #check from which the call is coming, if it's from db load fct we do nothing
26
+ caller_func = caller[1][/`.*'/][1..-2]
27
+ write_db() unless caller_func == "db_read_node"
28
+ end
29
+
30
+ #
31
+ # h is a node
32
+ #
33
+ def add_host(h)
34
+ if $treenode_win.visible?
35
+ $treenode_win.add_row(h)
36
+ end
37
+ @host[h.ip]=h
38
+ end
39
+
40
+ def add_network(h)
41
+ if $treenode_win.visible?
42
+ $treenode_win.add_row(h)
43
+ end
44
+ @network[h.ip]=h
45
+ end
46
+
47
+ def del_host(hip)
48
+ if $treenode_win.visible?
49
+ $treenode_win.del_row(@host[hip])
50
+ end
51
+ @host.delete hip
52
+ end
53
+
54
+ def del_net(hip)
55
+ if hip == @ip
56
+ $log.error("Can't delete itself ip=#{ip}")
57
+ return
58
+ end
59
+ if $treenode_win.visible?
60
+ $treenode_win.del_row(@network[hip])
61
+ end
62
+ @network.delete hip
63
+ end
64
+
65
+ def contain_host(hip)
66
+ @host.each_value {|node|
67
+ if node.ip == hip
68
+ return true
69
+ end
70
+ }
71
+ return false
72
+ end
73
+
74
+ def contain_network(hip)
75
+ #should be recursive
76
+ @network.each_value {|node|
77
+ if node.ip == hip
78
+ return true
79
+ else
80
+ return node.contain_network(hip)
81
+ end
82
+ }
83
+ return false
84
+ end
85
+
86
+ def get_node()
87
+ return @host.merge(@network)
88
+ end
89
+
90
+ def nb_node()
91
+ return nb_network() + nb_host()
92
+ end
93
+
94
+ def nb_host()
95
+ return @host.size
96
+ end
97
+
98
+ def nb_network()
99
+ return @network.size
100
+ end
101
+
102
+
103
+ def dns_domain?()
104
+ return dns_domain != NONAME_PROPERTY
105
+ end
106
+
107
+ def netbios_domain?()
108
+ return netbios_domain != NONAME_PROPERTY
109
+ end
110
+
111
+ def name?()
112
+ return (@name != nil) && (@name != NONAME_PROPERTY) && (@name != "")
113
+ end
114
+ #
115
+ # method for changing status (color) of the node
116
+ #
117
+ def change_status(st)
118
+ if @status != st
119
+ #status has changed
120
+ @status=st
121
+ @node_view.icon_color($status_color[$status_value.index(st)])
122
+ @links.each {|l|
123
+ l.update_status()
124
+ }
125
+
126
+ if $treenode_win.visible?
127
+ $treenode_win.update_row(self)
128
+ end
129
+
130
+ #propagate status UNMANAGED or UNKNOWN to all nodes includes in this network
131
+ if (st == UNMANAGED) || (st == UNKNOWN)
132
+ get_node().each_value {|node|
133
+ node.change_status(st)
134
+ }
135
+ end
136
+ end
137
+ end
138
+
139
+ #
140
+ # update status depending on node host
141
+ #
142
+ def update_status()
143
+ if @node_view != nil
144
+ total_up=0
145
+ total_other=0
146
+ get_node().each_value{|n|
147
+ if n.status == NORMAL
148
+ total_up+=1
149
+ elsif n.status != UNMANAGED
150
+ total_other+=1
151
+ end
152
+ }
153
+ total_host=total_up+total_other
154
+ if total_host > 0
155
+ percent_status_not_up=(total_other*100)/total_host
156
+ if percent_status_not_up >= 50
157
+ @status=CRITICAL
158
+ @node_view.icon_color($status_color[$status_value.index(CRITICAL)])
159
+ elsif percent_status_not_up == 0
160
+ @status=NORMAL
161
+ @node_view.icon_color($status_color[$status_value.index(NORMAL)])
162
+ elsif percent_status_not_up >= 25
163
+ @status=MAJOR
164
+ @node_view.icon_color($status_color[$status_value.index(MAJOR)])
165
+ else
166
+ @status=MINOR
167
+ @node_view.icon_color($status_color[$status_value.index(MINOR)])
168
+ end
169
+ if $treenode_win.visible?
170
+ $treenode_win.update_row(self)
171
+ end
172
+ #need to propagate to the network upstair
173
+ $network[@map].update_status() unless @map == nil
174
+ else
175
+ @status=UNKNOWN
176
+ @node_view.icon_color($status_color[$status_value.index(UNKNOWN)])
177
+ end
178
+ end
179
+ end
180
+
181
+ #
182
+ # method for changing label of the node
183
+ # lb is nil when we just want a node label refresh
184
+ def change_label(lb=nil)
185
+ if $config.show_label
186
+ if (@old_label != lb) or lb==nil
187
+ @old_label=lb unless lb==nil
188
+ lb=@old_label unless lb!=nil
189
+ if node_view
190
+ node_view.set_text("#{eval lb}") unless ("#{eval lb}" == NODESCR_PROPERTY) || ("#{eval lb}" == NONAME_PROPERTY)
191
+ end
192
+ end
193
+ end
194
+ end
195
+
196
+ def create_node()
197
+ @old_label=""
198
+ #set default label
199
+ label="#{dns_domain}"
200
+ if !dns_domain? && ip != ""
201
+ label="#{ip}"
202
+ if name?
203
+ label="#{@name}"
204
+ end
205
+ end
206
+ @map_view=Goo::CanvasGroup.new($canvas_root,{:x => 0.0,:y => 0.0})
207
+ @map_view.visibility = Goo::CanvasItem::HIDDEN
208
+ @node_view=nil
209
+ if @map == nil
210
+ #its the root network
211
+ @node_view=NodeNetworkView.new($canvas_root, self, $status_color[$status_value.index(status)], "#{PIXMAP_PATH}/#{icon}", label)
212
+ else
213
+ #puts "create_node #{$network[@map]}"
214
+ if $network[@map]
215
+ @node_view=NodeNetworkView.new($network[@map].map_view, self, $status_color[$status_value.index(status)], "#{PIXMAP_PATH}/#{icon}", label)
216
+ end
217
+ end
218
+ change_label($config.network_label_view)
219
+ if @node_view
220
+ if ($config.show_label &&((@map==nil)||(get_map()==@map)))
221
+ @node_view.show_text()
222
+ else
223
+ @node_view.hide_text() unless !@node_view
224
+ end
225
+ end
226
+ end #create_node
227
+
228
+ def delete()
229
+ #first need to destroy the links
230
+ del_all_links()
231
+ if @node_view
232
+ #destroy the tooltips
233
+ @node_view.hide_tooltips()
234
+ #destroy the view
235
+ @node_view.unselect()
236
+ @node_view.destroy()
237
+ end
238
+ @node_view=nil
239
+
240
+ #remove from db
241
+ db_delete_node(NETWORKNODE, ip, netmask)
242
+
243
+ del_network(@ip)
244
+ end
245
+
246
+ #reload pixmap icon to apply changes
247
+ def reload()
248
+ if ($config.network_icon_view=="os")
249
+ @icon="#{find_extension("os/#{@os}")}"
250
+ else
251
+ @icon="#{find_extension("type/#{@type}")}"
252
+ end
253
+ @node_view.set_image(@icon) unless !@node_view
254
+ end
255
+
256
+ #
257
+ # Return a table for the find tool
258
+ #
259
+ def to_t
260
+ tmp=[]
261
+ tmp.push(@ip,$status[$status_value.index(@status)], @name, @dns_domain, @netbios_domain, @description, @type, @os)
262
+ return tmp
263
+ end
264
+
265
+ def write_db()
266
+ return db_insert_node_prp(uuid,NETWORKNODE,ip,netmask,ipv6,netmask6,nil,map,status,avail_sev,snmp_sev,custom_sev,trap_sev, service_sev, wmi_sev, syslog_sev, jmx_sev, x,y,icon,description, snmp_version, snmp_port, snmp_timeout, snmp_retry,type,os,"",nil,dns_domain,nil,netbios_domain,nil,nil,nil)
267
+ end
268
+
269
+ end #class
@@ -0,0 +1,39 @@
1
+ =begin header
2
+
3
+ Property of a node
4
+
5
+ David Maciejak
6
+ 20/01/2003
7
+
8
+ =end
9
+
10
+ require "#{GNMSLIB}"+'/node_listener'
11
+ require "#{GNMSLIB}"+'/monitor/client/snmp/snmp'
12
+ require "#{GNMSLIB}"+'/node'
13
+ require "#{GNMSLIB}"+'/gui/node_host_property'
14
+ require "#{GNMSLIB}"+'/gui/node_network_property'
15
+ require "#{GNMSLIB}"+'/gui/color_macro'
16
+
17
+ if $defined_lib_gruff
18
+ begin
19
+ require 'gruff'
20
+ require "#{GNMSLIB}"+'/gui/charts/gruff'
21
+ rescue LoadError
22
+ $log.error("gruff ruby or rmagick library to display charts is missing, you will not be able to see them")
23
+ $defined_lib_gruff=false
24
+ rescue RuntimeError => $msg
25
+ $log.error($msg)
26
+ $defined_lib_gruff=false
27
+ end
28
+ end
29
+
30
+ def node_property(node)
31
+ if node.status == UNMANAGED
32
+ return
33
+ end
34
+ if node.class == Host
35
+ NodeHostProperty.new(node)
36
+ else
37
+ NodeNetworkProperty.new(node)
38
+ end
39
+ end
@@ -0,0 +1,247 @@
1
+ require "#{GNMSLIB}"+'/notify/xmpp_bot'
2
+ require "#{GNMSLIB}"+'/notify/irc_bot'
3
+
4
+ #
5
+ # alarm module to warn admins
6
+ #
7
+
8
+ require 'net/smtp'
9
+
10
+ def alarm_handle(src_module, category, ip_str, summary, datetime)
11
+ $log.debug("in alarm_handle")
12
+ if $config.level != nil && ($LEVEL.index(category)>=$LEVEL.index($config.level))
13
+ i=0
14
+ level_alert_type=$level_alert_type
15
+ if $host[ip_str] && (!$network[$host[ip_str].map].inherit_from_global)
16
+ level_alert_type=$network[$host[ip_str].map].alert_type_by_level
17
+ end
18
+ level_alert_type[category].each do |alert|
19
+ if alert == true
20
+ case i
21
+ when 0 then #MAIL
22
+ alarm_mail("#{datetime} #{ip_str} #{summary}", ip_str, "#{src_module}", category)
23
+ when 1 then #POPUP
24
+ alarm_popup("#{src_module} #{datetime} #{ip_str} #{summary}")
25
+ when 2 then #BEEP
26
+ if $host[ip_str] && (!$network[$host[ip_str].map].inherit_from_global)
27
+ if $network[$host[ip_str].map].sound_file_path_by_level[category] != nil
28
+ if !$sound_is_played
29
+ Thread.start { alarm_sound($network[$host[ip_str].map].sound_file_path_by_level[category]) }
30
+ end
31
+ else
32
+ alarm_beep()
33
+ end
34
+ else
35
+ if $config.sound_file_path_by_level[category] != nil
36
+ if !$sound_is_played
37
+ Thread.start { alarm_sound($config.sound_file_path_by_level[category]) }
38
+ end
39
+ else
40
+ alarm_beep()
41
+ end
42
+ end
43
+ when 3 then #SYSLOG
44
+ text=sprintf("module='%s', severity='%s', time='%s', src='%s', descr='%s'", src_module, category, datetime, ip_str, summary)
45
+ alarm_syslog(text)
46
+ when 4 then #SMS / PAGER
47
+ if ($config.sms_device != "") && ($config.sms_device != nil)
48
+ if $host[ip_str] && (!$network[$host[ip_str].map].inherit_from_global) && ($network[$host[ip_str].map].sms_num_by_level[category] != "") && ($network[$host[ip_str].map].sms_num_by_level[category] != nil)
49
+ alarm_sms($config.sms_device,$network[$host[ip_str].map].sms_num_by_level[category],"#{src_module} #{datetime} #{ip_str} #{summary}")
50
+ elsif ($config.sms_num_by_level[category] != "") && ($config.sms_num_by_level[category] != nil)
51
+ alarm_sms($config.sms_device,$config.sms_num_by_level[category],"#{src_module} #{datetime} #{ip_str} #{summary}")
52
+ end
53
+ end
54
+ when 5 then #IM
55
+ if $host[ip_str] && (!$network[$host[ip_str].map].inherit_from_global) && ($network[$host[ip_str].map].im_dest_by_level[category] != "") && ($network[$host[ip_str].map].im_dest_by_level[category] != nil)
56
+ alarm_xmpp($network[$host[ip_str].map].im_dest_by_level[category],"#{src_module} #{datetime} #{ip_str} #{summary}")
57
+ elsif ($config.im_dest_by_level[category] != "") && ($config.im_dest_by_level[category] != nil)
58
+ alarm_xmpp($config.im_dest_by_level[category],"#{src_module} #{datetime} #{ip_str} #{summary}")
59
+ end
60
+ when 6 then #SCRIPT EXECUTION
61
+ if $host[ip_str] && (!$network[$host[ip_str].map].inherit_from_global) && ($network[$host[ip_str].map].script_name_by_level[category] != "") && ($network[$host[ip_str].map].script_name_by_level[category] != nil)
62
+ alarm_script($network[$host[ip_str].map].script_name_by_level[category], ip_str)
63
+ elsif ($config.script_name_by_level[category] != "") && ($config.script_name_by_level[category] != nil)
64
+ alarm_script($config.script_name_by_level[category], ip_str)
65
+ else
66
+ $log.error("Invalid script name for #{category}")
67
+ end
68
+ when 7 then #IRC
69
+ alarm_irc("date=#{datetime} src=#{ip_str} descr=#{summary}")
70
+ end
71
+ end
72
+ i+=1
73
+ end
74
+ end
75
+ end
76
+
77
+ def alarm_beep()
78
+ printf "\a"
79
+ end
80
+
81
+ def alarm_sound(sound_file)
82
+ if $sound_is_played
83
+ return
84
+ end
85
+
86
+ if !FileTest.exist?("#{SOUND_DIR}/#{sound_file}")
87
+ $log.error("Sound file not found at #{SOUND_DIR}/#{sound_file}")
88
+ alarm_beep()
89
+ return
90
+ end
91
+
92
+ if $defined_lib_gst
93
+ $sound_is_played = true
94
+ #create the pipeline
95
+ pipeline = Gst::Pipeline.new
96
+ # create a disk reader
97
+ filesrc = Gst::ElementFactory.make("filesrc")
98
+ filesrc.location = "#{SOUND_DIR}/#{sound_file}"
99
+
100
+ decoder = Gst::ElementFactory.make("decodebin")
101
+
102
+ if decoder == nil
103
+ $log.error("gstreamer issue when initializing sound env")
104
+ return
105
+ end
106
+
107
+ audio_convert = Gst::ElementFactory.make("audioconvert")
108
+ audio_resample = Gst::ElementFactory.make("audioresample")
109
+ audio_sink = Gst::ElementFactory.make("autoaudiosink")
110
+ pipeline.add(filesrc, decoder, audio_convert, audio_resample, audio_sink)
111
+
112
+ # link elements
113
+ filesrc >> decoder
114
+ audio_convert >> audio_resample >> audio_sink
115
+
116
+ decoder.signal_connect("new-decoded-pad") do |element, pad|
117
+ sink_pad = audio_convert["sink"]
118
+ pad.link(sink_pad)
119
+ end
120
+
121
+ reading = true
122
+ bus = pipeline.bus
123
+ bus.add_watch do |bus, message|
124
+ case message.type
125
+ when Gst::Message::EOS
126
+ $sound_is_played = false
127
+ reading = false
128
+ when Gst::Message::ERROR
129
+ #p message.parse
130
+ $sound_is_played = false
131
+ reading = false
132
+ end
133
+ true
134
+ end
135
+
136
+ # start playing
137
+ pipeline.play
138
+ while(reading) do
139
+ sleep(1)
140
+ end
141
+ pipeline.stop
142
+ pipeline.set_state(Gst::State::NULL)
143
+ else
144
+ $log.error("Sound can't be played as sound lib gstreamer is not available")
145
+ end
146
+ end
147
+
148
+ def alarm_syslog(text)
149
+ Syslog.log(Syslog::LOG_WARNING, text)
150
+ end
151
+
152
+ def alarm_popup(text)
153
+ if $win.visible?
154
+ dialog = Gtk::MessageDialog.new($win, Gtk::Dialog::MODAL,
155
+ Gtk::MessageDialog::INFO,
156
+ Gtk::MessageDialog::BUTTONS_OK,
157
+ text)
158
+ dialog.signal_connect('response') { dialog.destroy }
159
+ dialog.show
160
+ elsif $icon.embedded?
161
+ #window is hidden and trayicon exists so we just blink the icon
162
+ $icon.set_blinking(true)
163
+ end
164
+ end
165
+
166
+ def alarm_mail(msg, ip, src_module=nil, sev=INFO)
167
+ if src_module != "core"
168
+
169
+ mail_server_addr=$config.mail_server_addr
170
+ mail_server_port=$config.mail_server_port
171
+
172
+ tmail_receipt=$config.mail_by_level[sev]
173
+ if $host[ip] && (!$network[$host[ip].map].inherit_from_global)
174
+ tmail_receipt=$network[$host[ip].map].mail_by_level[sev]
175
+ end
176
+
177
+ Thread.start {
178
+
179
+ tmail_receipt.each{|contact|
180
+ mail_dst=Contact::get_contact_email(contact.firstname, contact.lastname)
181
+ if mail_dst != ""
182
+ begin
183
+ Net::SMTP.start( mail_server_addr, mail_server_port ) {|smtp|
184
+ smtp.send_mail <<EndOfMail, "root@localhost", "#{mail_dst}"
185
+ From: gnms admin <#{ENV["USER"]}@localhost>
186
+ To: gnms contact <#{Contact::get_contact_email(contact.firstname, contact.lastname)}>
187
+ Subject: gnms notification
188
+
189
+ #{msg}
190
+ EndOfMail
191
+
192
+ }
193
+ rescue Exception => msg
194
+ $log.error("Error #{sev} severity level #{msg} when sending mail to '#{mail_dst}' on '#{mail_server_addr}'/'#{mail_server_port}'")
195
+ end
196
+
197
+ else
198
+ $log.error("Mail contact empty for #{contact.firstname} #{contact.lastname}")
199
+ end
200
+ }
201
+ }
202
+
203
+ end
204
+ end
205
+
206
+ def alarm_script(command, ip)
207
+ if !FileTest.exist?("#{SCRIPT_DIR}/#{command}")
208
+ $log.error("Invalid script path name #{SCRIPT_DIR}/#{command}")
209
+ else
210
+ `#{SCRIPT_DIR}/#{command} #{ip}`
211
+ end
212
+ end
213
+
214
+ def alarm_sms(device, tnumber, txt)
215
+ if $defined_lib_sms == false
216
+ $log.error("Can't send SMS, notification type is disabled cause a library is missing")
217
+ else
218
+ Thread.start {
219
+ tnumber.each{|contact|
220
+ sms=Contact::get_contact_mobile(contact.firstname, contact.lastname)
221
+ if sms != ""
222
+ mySMS = SMSController.new(device, sms, txt)
223
+ mySMS.sendSMS
224
+ else
225
+ $log.error("SMS contact empty for #{contact.firstname} #{contact.lastname}")
226
+ end
227
+ }
228
+ }
229
+ end
230
+ end
231
+
232
+ def alarm_xmpp(im_dest_addr, txt)
233
+ if $im_daemon
234
+ im_dest_addr.each{|contact|
235
+ im=Contact::get_contact_im(contact.firstname, contact.lastname)
236
+ if im != ""
237
+ $im_daemon.add_in_queue(im, txt)
238
+ else
239
+ $log.error("IM contact empty for #{contact.firstname} #{contact.lastname}")
240
+ end
241
+ }
242
+ end
243
+ end
244
+
245
+ def alarm_irc(txt)
246
+ $irc_daemon.add_in_queue(txt) if $irc_daemon
247
+ end