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
data/README ADDED
@@ -0,0 +1,29 @@
1
+ GNMS - Gnome Network Monitoring System
2
+
3
+
4
+ Introduction
5
+ ---------------
6
+
7
+ GNMS tries to bring a tool to monitor network elements.
8
+ This tool is written in Ruby with Gtk bindings, and use
9
+ some command tools for finding, scanning nodes.
10
+
11
+
12
+ How to test
13
+ --------------
14
+
15
+ Run as root the following command in a shell
16
+ from the project dir:
17
+
18
+ # gem build gnms.gemspec
19
+ # gem install gnms-*.gem
20
+ # gnms
21
+
22
+ Btw, you will need some development files to compile gtk
23
+ bindings and other libraries. And you should at least
24
+ install nmap package which is used to remotely scan hosts.
25
+
26
+ This package is provided as is with no warranty.
27
+ See http://gnms.rubyforge.org/ to get some more help.
28
+
29
+ David Maciejak
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # gnms launcher
4
+ # David Maciejak
5
+ #
6
+
7
+ file = __FILE__
8
+ file = File.readlink(file) while File.symlink?(file)
9
+ $LOAD_PATH.unshift File.expand_path('../../lib', file)
10
+
11
+ require 'gnms'
@@ -0,0 +1,70 @@
1
+ #gnms gemspec
2
+
3
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
4
+ require 'version'
5
+
6
+ class GnmsGemspecHelper
7
+ def self.remove_gitignored_files(filelist)
8
+ gitignore_file = File.expand_path("../.gitignore", __FILE__)
9
+ if File.exist?(gitignore_file)
10
+ ignores = File.readlines(gitignore_file)
11
+ ignores = ignores.select {|ignore| ignore.chomp.strip != "" and ignore !~ /^#/}
12
+ ignores = ignores.map {|ignore| Regexp.new(ignore.chomp.gsub(".", "\\.").gsub("*", ".*"))}
13
+ r = filelist.select {|fn| not ignores.any? {|ignore| fn =~ ignore }}
14
+ r.select {|fn| fn !~ /\.git/ }
15
+ else
16
+ filelist
17
+ end
18
+ end
19
+
20
+ def self.remove_matching_files(list, string)
21
+ list.reject {|entry| entry.include?(string)}
22
+ end
23
+
24
+ def self.gem_manifest
25
+ r = %w(LICENSE README gnms.gemspec) +
26
+ Dir.glob("bin/gnms") +
27
+ Dir.glob("pixmap/**/*") +
28
+ Dir.glob("sound/*") +
29
+ remove_gitignored_files(Dir.glob("lib/**/*")) +
30
+ remove_gitignored_files(Dir.glob("plugins/**/*"))
31
+ end
32
+ end
33
+
34
+ Gem::Specification.new do |s|
35
+ s.name = "gnms"
36
+ #s.version = GNMSVERSION
37
+ s.version = "#{GNMSVERSION}.rc1"
38
+ s.platform = Gem::Platform::RUBY
39
+ s.required_ruby_version = '>= 1.8.6'
40
+ s.authors = ["David Maciejak"]
41
+ s.email = ["david.maciejak@gmail.com"]
42
+ s.homepage = "http://gnms.rubyforge.org/"
43
+ s.rubyforge_project = "gnms"
44
+ s.summary = "Gnome Network Management System"
45
+ s.description = "GNMS is a graphical tool used to monitor state of network elements"
46
+
47
+ s.files = GnmsGemspecHelper.gem_manifest
48
+ s.has_rdoc = false
49
+ s.test_files = (s.files & Dir['test/*'])
50
+ s.license = "GPL-2.1"
51
+
52
+ s.executables = ["gnms"]
53
+ s.require_path = 'lib'
54
+
55
+ s.add_dependency("facter")
56
+ s.add_dependency("goocanvas")
57
+ s.add_dependency("gdk_pixbuf2", "~> 1.1.7")
58
+ s.add_dependency("glib2", "~> 1.1.7")
59
+ s.add_dependency("gtk2", "~> 1.1.7")
60
+ s.add_dependency("net-ssh")
61
+ s.add_dependency("snmp")
62
+ s.add_dependency("xmpp4r")
63
+ s.add_dependency("sqlite3")
64
+ s.add_dependency("pcaprub", "~>0.11.3")
65
+ s.add_dependency("packetfu")
66
+ s.add_dependency("gruff")
67
+ # s.add_dependency("ruby-ldap")
68
+ # s.add_dependency("gstreamer")
69
+ end
70
+
@@ -0,0 +1,747 @@
1
+ require "#{GNMSLIB}"+'/ipcalc'
2
+ require 'net/http'
3
+
4
+ #
5
+ #get system information
6
+ #
7
+ def get_system_infor()
8
+ sysinfor = Hash.new()
9
+ sysinfor["cpu" => "","Memory" =>"","hostname" => "","OS" => ""]
10
+ value=`cat /proc/cpuinfo | grep 'model name'`
11
+ value=value.match(/\:\s+(\w+.*)/)
12
+ if value != nil
13
+ sysinfor["cpu"]=value[1]
14
+ end
15
+ value=`cat /proc/meminfo | grep 'MemTotal'`
16
+ value=value.match(/\:\s+(\d+)\s+(\w+)/)
17
+ if value !=nil
18
+ if (value[2] == "kB") and isInteger(value[1])
19
+ if value[1].to_f >= 1024
20
+ val = value[1].to_f / 1024 / 1024
21
+ sysinfor["Memory"]="#{sprintf "%.1f",val} G"
22
+ else
23
+ val = value[1].to_f / 1024
24
+ sysinfor["Memory"]="#{sprintf "%.1f",val} M"
25
+ end
26
+ else
27
+ sysinfor["Memory"]=sprintf "%.1f",value[1]
28
+ end
29
+ end
30
+ value=`hostname`
31
+ sysinfor["hostname"]=value.chomp
32
+
33
+ value=`cat /proc/version`
34
+ sysinfor["OS"]=value.chomp
35
+
36
+ value=`df -h`
37
+ disk_size=0
38
+ flag=false
39
+ #parsing the output of command "df -h"
40
+ value.each_line{|s|
41
+ temp=s.match(/\/dev\//)
42
+ if temp !=nil
43
+ flag=true
44
+ end
45
+ temp=s.match(/\s+(\d+[\w])\s+\w+\.?\w*\s+\w+\.?\w*\s+\d+\.?\d*\%/)
46
+ if temp !=nil && flag
47
+ if temp[1].gsub!(/M/){|s|}!=nil
48
+ temp1=temp[1].gsub("M","")
49
+ temp2=temp1.to_f
50
+ temp2=temp2/1024
51
+ else
52
+ temp1=temp[1].gsub("M","")
53
+ temp2=temp1.to_f
54
+ end
55
+ disk_size=disk_size+temp2
56
+ flag=false
57
+ end
58
+ }
59
+ sysinfor["Disk Size"]="#{sprintf "%.1f",disk_size} G"
60
+ return sysinfor
61
+ end
62
+
63
+ #
64
+ # download mac manufacturer list
65
+ #
66
+ def get_mac_manufacturer_list()
67
+ puts "in get_mac_manufacturer_list"
68
+ if ! mac_manufacturer_list_exist?()
69
+ ieee_addr="standards.ieee.org"
70
+ ieee_url="/develop/regauth/oui/oui.txt"
71
+ local_file_path="#{CONF_DIR}"
72
+ local_file_name="oui.txt"
73
+ Net::HTTP.version_1_1
74
+ tf=Tempfile.new(local_file_name)
75
+ begin
76
+ Net::HTTP.start(ieee_addr, 80) do |http|
77
+ response,=http.get(ieee_url)
78
+ response.body.each do |str|
79
+ str.chomp
80
+ if str.match('base\s16')
81
+ #line syntax is 'XXXXXX (base 16) name'
82
+ str.scan(/(\w+)\s+\([^)]+\)\s+(.+)/) do |mac,manufacturer|
83
+ tf.write "#{mac}\t#{manufacturer}\n"
84
+ end
85
+ end
86
+ end
87
+ end
88
+ rescue Exception => msg
89
+ print #{msg.backtrace.join("\n")},"\n"
90
+ tf.close(true)
91
+ return -1
92
+ end
93
+ end
94
+ tf.close
95
+ FileUtils.move(tf.path, "#{local_file_path}/#{local_file_name}")
96
+ return 0
97
+ end
98
+
99
+ #
100
+ # return if mac manufacturer list exist
101
+ #
102
+ def mac_manufacturer_list_exist?()
103
+ return FileTest.exist?("#{CONF_DIR}/oui.txt")
104
+ end
105
+
106
+ #
107
+ # Return nic manufacturer based on OUI
108
+ #
109
+ def find_manufacturer (mac)
110
+ if FileTest.exist?("#{CONF_DIR}/oui.txt")
111
+
112
+ if defined?($mac_manufacturer)
113
+ if $mac_manufacturer[mac] != ""
114
+ return $mac_manufacturer[mac]
115
+ end
116
+ else
117
+ $mac_manufacturer=Hash.new
118
+ end
119
+
120
+ manufacturer_name="unknown"
121
+ f=File.open("#{CONF_DIR}/oui.txt","r")
122
+ begin
123
+ while (line = f.readline)
124
+ line.chomp
125
+ if line.match("^#{mac}")
126
+ result_t=line.split(/\s+/)
127
+ manufacturer_name=result_t[1]
128
+ end
129
+ end
130
+ rescue EOFError
131
+ f.close
132
+ end
133
+ $mac_manufacturer[mac]=manufacturer_name
134
+ return manufacturer_name
135
+ else
136
+ $log.warn("you need to download OUIs list, see pref")
137
+ return nil
138
+ end
139
+ end
140
+
141
+ #
142
+ #list port with nmap
143
+ #
144
+ def listport(ip)
145
+ lp=""
146
+ nmap_version = $config.nmap_vers.to_f()
147
+ if nmap_version >= 6.0
148
+ lp=`#{$config.nmap_path} -sU -sT #{ip} --host_timeout 60 2>/dev/null| grep open | grep "^[0-9]"`
149
+ else
150
+ lp=`#{$config.nmap_path} -sU -sT #{ip} --host_timeout 60000 2>/dev/null| grep open | grep "^[0-9]"`
151
+ end
152
+ $_=lp
153
+ gsub("/"," ")
154
+ gsub("open","")
155
+ gsub("|filtered","")
156
+ gsub("\ +"," ")
157
+ return $_
158
+ end
159
+
160
+ #
161
+ #get nmap version
162
+ #
163
+ def nmap_version()
164
+ if $config.nmap_path != ""
165
+ regx=Regexp.new('Nmap version ([\d.]+) \(')
166
+ if $config.nmap_path
167
+ ret=`#{$config.nmap_path} -V|grep Nmap`
168
+ ret.scan(regx) do |val|
169
+ return val[0]
170
+ end
171
+ end
172
+ return nil
173
+ end
174
+ end
175
+
176
+ #
177
+ # Return mac adress of the ip if in local arp table
178
+ #
179
+ def mac_tablelocal(ip)
180
+ `ping -c 1 -W 1 #{ip}`
181
+ lp=`arp -n #{ip} | grep #{ip} | awk '{print $3;}'`
182
+ #there is no entry
183
+ if lp.chomp == "--"
184
+ lp=""
185
+ end
186
+ return lp
187
+ end
188
+
189
+ #
190
+ # Return interface info of local machine
191
+ # format is an array of array of elements
192
+ # ipv4 mask ipv6 mac_addr interface_name
193
+ def local_interface()
194
+ result = Array.new
195
+ Facter::Util::IP.get_interfaces.each do |interface|
196
+ tmp= Array.new
197
+ %w{ipaddress netmask ipaddress6 macaddress}.each do |label|
198
+ tmp.push Facter::Util::IP.get_interface_value(interface, label)
199
+ end
200
+ #tmp.push interface
201
+ #check if ip is not empty
202
+ if !tmp[0].nil? and !tmp[0].empty?
203
+ result.push tmp
204
+ end
205
+ end
206
+ return result
207
+ end
208
+
209
+ #
210
+ # Return netmask adress of local machine
211
+ #
212
+ def local_mask()
213
+ Facter::Util::IP.get_interfaces.each do |interface|
214
+ return Facter::Util::IP.get_interface_value(interface, "netmask") if interface != "lo"
215
+ end
216
+ return nil
217
+ end
218
+
219
+ #
220
+ #ping broadcast
221
+ #
222
+ def broadcast_ping
223
+ ipbroadcast=`#{$config.ping_path} 255.255.255.255 -b -c 2 -n 2>&1 | grep ^64 | awk '{ print $4 }'`
224
+ ipbroadcast.gsub!(":","")
225
+ iptab=ipbroadcast.split(/\n/)
226
+ return iptab
227
+ end
228
+
229
+ #
230
+ # To know if an host is up, we use here ping perhaps in a near future nmap
231
+ #
232
+ def ping (ip)
233
+ pip=`#{$config.ping_path} #{ip} -c 1 -n -W 4 2>/dev/null | grep ^64`
234
+ return pip!=""
235
+ end
236
+
237
+
238
+ #
239
+ # verify by custom monitoring
240
+ #
241
+ def test_monitored_custom(ip)
242
+ $log.debug "cmd_parse test_monitored_custom #{ip}"
243
+ if $host[ip].custom_monitoring.size() > 0
244
+ max_severity=UNKNOWN
245
+ max_severity_description=nil
246
+ $host[ip].custom_monitoring.each_value {|custom_mon|
247
+ if custom_mon.active?()
248
+ $log.debug("running custom #{custom_mon.name}")
249
+ begin
250
+ result_tmp=(eval custom_mon.name).new($host[ip])
251
+ while (result_tmp.get_event_state_raw()==nil) do
252
+ sleep(5)
253
+ end
254
+
255
+ if $status_value[result_tmp.get_event_state_raw()] > max_severity
256
+ max_severity=$status_value[result_tmp.get_event_state_raw()]
257
+ max_severity_description=result_tmp.get_event_description()
258
+ end
259
+ if result_tmp.get_event_description() != nil
260
+ #if severity is unknown and we have a description; this should be an error report
261
+ if result_tmp.get_event_state_raw() == $status.size()-1
262
+ $event_win.add_event(EventWindow::CUSTOM_EVENT_TYPE, "ERR", $host[ip], "#{result_tmp.get_event_description()}")
263
+ else
264
+ $event_win.add_event(EventWindow::CUSTOM_EVENT_TYPE, get_level_from_status($status[result_tmp.get_event_state_raw()]), $host[ip], "#{result_tmp.get_event_description()}")
265
+ end
266
+ end
267
+ rescue
268
+ raise
269
+ end
270
+ end
271
+ }
272
+ #at this point max_severity contains the severity max found for all custom monitor enabled for this host
273
+ $host[ip].set_custom_severity(max_severity)
274
+ elsif $host[ip].custom_sev > UNMANAGED
275
+ #no custom monitoring for this host
276
+ $host[ip].set_custom_severity(UNMANAGED)
277
+ end
278
+ end
279
+
280
+ #
281
+ # verify if oid ref threshold value is ok
282
+ #
283
+ def test_monitored_snmp(ip)
284
+ $log.info "cmd_parse test_monitored_snmp #{ip}"
285
+ if $host[ip] && ($host[ip].snmp_monitoring.size() > 0)
286
+ max_severity=UNKNOWN
287
+
288
+ if $host[ip].get_account_id("snmp")
289
+ community_pub, community_priv = $host[ip].get_account_id("snmp")
290
+ begin
291
+
292
+ SNMP::Manager.open(:Host => ip, :Community => community_pub, :Version => get_snmp_version($host[ip].get_default_inherit_snmp_version()), :Port => $host[ip].get_default_inherit_snmp_port().to_i, :Timeout => $host[ip].get_default_inherit_snmp_timeout().to_i, :Retries => $host[ip].get_default_inherit_snmp_retry().to_i) do |manager|
293
+ $host[ip].snmp_monitoring.each_value {|snmp_mon|
294
+ if snmp_mon.active?()
295
+ snmp_oper="#{snmp_mon.oper()}"
296
+ if "#{snmp_mon.oper()}" == "="
297
+ snmp_oper="=="
298
+ end
299
+ begin
300
+
301
+ snmp_direct_value="#{snmp_mon.value(manager,$host[ip])}"
302
+ #here snmp_direct_value can be a string and not an operation
303
+ #check if a OID value in not known by the agent
304
+ if !snmp_direct_value.include?("Null")
305
+ expr_test=""
306
+ if snmp_direct_value.match('^[\d.+*/ -]+$')
307
+ expr_test="#{snmp_direct_value} #{snmp_oper} #{snmp_mon.threshold}"
308
+ else
309
+ expr_test="'#{snmp_direct_value}' #{snmp_oper} '#{snmp_mon.threshold}'"
310
+ end
311
+ if eval(expr_test)
312
+ if $status_value[snmp_mon.raw_severity] > max_severity
313
+ max_severity=$status_value[snmp_mon.raw_severity]
314
+ end
315
+ $event_win.add_event(EventWindow::SNMP_EVENT_TYPE, get_level_from_status($status[$status_value.index(max_severity)]), $host[ip], "Monitoring #{snmp_mon.oidref} matched")
316
+ end
317
+ else
318
+ $log.error("Problem in SNMP request on #{ip}, seems OID used is unknown on remote agent")
319
+ $event_win.add_event(EventWindow::SNMP_EVENT_TYPE, "ERR", $host[ip], "OID #{snmp_mon.oidref} used is unknown on remote agent")
320
+ end
321
+ rescue
322
+ $log.error("Problem in SNMP request on #{ip}, validate #{snmp_mon.oidref} OID Reference")
323
+ $event_win.add_event(EventWindow::SNMP_EVENT_TYPE, "ERR", $host[ip], "Problem validate #{snmp_mon.oidref} OID Reference")
324
+ return
325
+ end
326
+ end
327
+ }
328
+ #set the snmp severity to max find for this host
329
+ if max_severity > $host[ip].snmp_sev
330
+ $host[ip].set_snmp_severity(max_severity)
331
+ end
332
+
333
+ end #manager
334
+ rescue Exception => msg
335
+ $log.error("Exception in test_monitored_snmp for #{ip}: #{msg}")
336
+ end
337
+ else
338
+ $log.error("snmp account not set for host #{ip}")
339
+ $event_win.add_event(EventWindow::SNMP_EVENT_TYPE, "ERR", $host[ip], "snmp account not set")
340
+ end
341
+ else
342
+ if $host[ip]
343
+ $host[ip].set_snmp_severity(UNMANAGED)
344
+ end
345
+ end
346
+ end
347
+
348
+ #
349
+ # verify if wmi ref threshold value is ok
350
+ #
351
+ def test_monitored_wmi(ip)
352
+ $log.debug "cmd_parse test_monitored_wmi #{ip}"
353
+ if $host[ip] && ($host[ip].wmi_monitoring.size() > 0)
354
+ max_severity=UNKNOWN
355
+ begin
356
+ $host[ip].wmi_monitoring.each_value {|wmi_mon|
357
+ if wmi_mon.active?()
358
+ wmi_oper="#{wmi_mon.oper()}"
359
+ if "#{wmi_mon.oper()}" == "="
360
+ wmi_oper="=="
361
+ end
362
+ begin
363
+ #wml request can return multiple entries
364
+ wmi_direct_table=wmi_mon.request($host[ip])
365
+ if wmi_direct_table
366
+ max_severity_set=0
367
+ if wmi_oper == "Contain"
368
+ if wmi_direct_table.include?(wmi_mon.value)
369
+ if $status_value[wmi_mon.raw_severity] > max_severity
370
+ max_severity=$status_value[wmi_mon.raw_severity]
371
+ max_severity_set=1
372
+ end
373
+ end
374
+ elsif wmi_oper == "Not contain"
375
+ if !wmi_direct_table.include?(wmi_mon.value)
376
+ if $status_value[wmi_mon.raw_severity] > max_severity
377
+ max_severity=$status_value[wmi_mon.raw_severity]
378
+ max_severity_set=1
379
+ end
380
+ end
381
+ end
382
+ if max_severity_set == 1
383
+ $event_win.add_event(EventWindow::WMI_EVENT_TYPE, get_level_from_status($status[$status_value.index(max_severity)]), $host[ip], "Monitoring '#{wmi_mon.wmiref}' matched for #{wmi_mon.value}")
384
+ end
385
+ else
386
+ $log.error("Problem in WMI request on #{ip}, seems WML used is unknown on remote agent")
387
+ $event_win.add_event(EventWindow::WMI_EVENT_TYPE, "ERR", $host[ip], "WML used is unknown on remote agent")
388
+ end
389
+ rescue Exception => msg
390
+ $log.error("Problem in WMI request on #{ip}, validate '#{wmi_mon.wmiref}' WMI Reference")
391
+ return
392
+ end
393
+ end
394
+ }
395
+ #set the wmi severity to max find for this host
396
+ if max_severity > $host[ip].wmi_sev
397
+ $host[ip].set_wmi_severity(max_severity)
398
+ end
399
+ rescue Exception => msg
400
+ $log.error("Exception in test_monitored_wmi for #{ip}: #{msg}")
401
+ end
402
+ else
403
+ if $host[ip]
404
+ $host[ip].set_wmi_severity(UNMANAGED)
405
+ end
406
+ end
407
+ end
408
+
409
+ #
410
+ # wmi request using external wmic command
411
+ #
412
+ def wmi_request(login, password, host, wml)
413
+ if ($config.wmic_path != nil) && ($config.wmic_path != "")
414
+ rs=`#{$config.wmic_path} -U #{login}%#{password} //#{host} "#{wml}" 2>/dev/null`
415
+ return rs.split(/\n/)
416
+ end
417
+ return Array.new
418
+ end
419
+
420
+ #
421
+ # verify if jmx ref threshold value is ok
422
+ #
423
+ def test_monitored_jmx(ip)
424
+ $log.error "cmd_parse test_monitored_jmx #{ip}"
425
+ if $host[ip] && ($host[ip].jmx_monitoring.size() > 0)
426
+ max_severity=UNKNOWN
427
+ begin
428
+ $host[ip].jmx_monitoring.each_value {|jmx_mon|
429
+ if jmx_mon.active?()
430
+ begin
431
+ #jmx can return multiple entries
432
+ jmx_direct_table=""
433
+ if jmx_mon.get_auth() == "None"
434
+ jmx_direct_table=jmx_request($host[ip], jmx_mon.get_port(), "", "", jmx_mon.get_ref(), jmx_mon.get_attributes().keys.join(" "))
435
+ else
436
+ username, password = $host[ip].get_account_id(jmx_mon.get_auth())
437
+ jmx_direct_table=jmx_request($host[ip], jmx_mon.get_port(), username, password, jmx_mon.get_ref(), jmx_mon.get_attributes().keys.join(" "))
438
+ end
439
+ if jmx_direct_table[0] && !jmx_direct_table[0].match("^error|such file")
440
+ max_severity_set=0
441
+ jmx_mon.get_attributes().each_pair { |attr, attrmon|
442
+ ind=-1
443
+ fnd=false
444
+ jmx_direct_table.each {|entr|
445
+ ind+=1
446
+ if entr.match("^#{attr}")
447
+ fnd=true
448
+ break
449
+ end
450
+ }
451
+
452
+ if fnd
453
+ if ind
454
+ val=jmx_direct_table[ind].gsub(attr+": ","")
455
+ jmx_oper="#{JmxAttributeMonitoring::TESTOP[attrmon.operator]}"
456
+ if "#{jmx_oper}" == "="
457
+ jmx_oper="=="
458
+ end
459
+ expr_test="#{val} #{jmx_oper} #{attrmon.value}"
460
+ if eval(expr_test)
461
+ print $status_value[attrmon.raw_severity()]," ", max_severity, "\n"
462
+ if $status_value[attrmon.raw_severity()] > max_severity
463
+ max_severity=$status_value[attrmon.raw_severity()]
464
+ max_severity_set=1
465
+ end
466
+ end
467
+ end
468
+ end
469
+ }
470
+ if max_severity_set == 1
471
+ $event_win.add_event(EventWindow::JMX_EVENT_TYPE, get_level_from_status($status[$status_value.index(max_severity)]), $host[ip], "Monitoring '#{jmx_mon.get_ref()}' matched")
472
+ end
473
+ else
474
+ $log.error("Problem in JMX request on #{ip}, #{jmx_direct_table[0]}")
475
+ $event_win.add_event(EventWindow::JMX_EVENT_TYPE, "ERR", $host[ip], "#{jmx_direct_table}")
476
+ end
477
+ rescue Exception => msg
478
+ $log.error("Problem in JMX request on #{ip}, validate '#{jmx_mon.get_ref()}' JMX Reference #{msg}")
479
+ return
480
+ end
481
+ end
482
+ }
483
+ #set the jmx severity to max find for this host
484
+ if max_severity > $host[ip].jmx_sev
485
+ $host[ip].set_jmx_severity(max_severity)
486
+ end
487
+ rescue Exception => msg
488
+ $log.error("Exception in test_monitored_jmx for #{ip}: #{msg}")
489
+ end
490
+ else
491
+ if $host[ip]
492
+ $host[ip].set_jmx_severity(UNMANAGED)
493
+ end
494
+ end
495
+ end
496
+
497
+ def jmx_request(host, port, user, pass, object_name, attr_names)
498
+ rs=`#{GNMSLIB}/external/jjmx.rb #{host.ip} #{port} "#{user}" "#{pass}" #{$jmx_refs[object_name].mbean} "#{attr_names}" 2>&1`
499
+ return rs.split(/\n/)
500
+ end
501
+
502
+ #
503
+ # verify if monitored ports are always open
504
+ # return -1 if ok
505
+ # or return the severity as constant
506
+ def test_monitored_ports(ip)
507
+ $log.debug "cmd_parse test_monitored_ports #{ip}"
508
+ #we assume here $host[ip].port is not nil
509
+ if $host[ip].service.size() == 0
510
+ return -1
511
+ end
512
+
513
+ #puts "monitored ports for #{ip}"
514
+ ip_port=""
515
+ $host[ip].service.each_value{|serv|
516
+ if serv.monitor.to_i() == 1
517
+ proto="U"
518
+ if serv.protocol == "tcp"
519
+ proto="T"
520
+ end
521
+ ip_port+="#{proto}:#{serv.port},"
522
+ end
523
+ }
524
+ ip_port.chop!()
525
+ if ip_port == ""
526
+ #we dont monitor ports for this node
527
+ return -1
528
+ end
529
+ ports = ip_port.split(/,/).dup
530
+ lp=""
531
+ nmap_version = $config.nmap_vers.to_f()
532
+
533
+ if nmap_version >= 6.0
534
+ lp=`#{$config.nmap_path} -sT -sU #{ip} --host_timeout 60 -p #{ip_port} 2>/dev/null | grep "^[0-9]"`
535
+ else
536
+ lp=`#{$config.nmap_path} -sT -sU #{ip} --host_timeout 60000 -p #{ip_port} 2>/dev/null | grep "^[0-9]"`
537
+ end
538
+
539
+ $log.error("Issue running scan command: #{$config.nmap_path} -sT -sU #{ip} -p #{ip_port}") if lp == ""
540
+ llp=lp.split(/\n/)
541
+ for pt in llp
542
+ ptlign=pt.split(/\s+/)
543
+ portprotocol=ptlign[0]
544
+ portstate=ptlign[1]
545
+ if portstate.match("^open")
546
+ ptt = portprotocol.split(/\//)
547
+ if ptt[1] == "tcp"
548
+ pt="T:#{ptt[0]}"
549
+ else
550
+ pt="U:#{ptt[0]}"
551
+ end
552
+ i=0
553
+ for ptlo in ports
554
+ if ptlo == pt
555
+ ports.delete ptlo
556
+ break
557
+ end
558
+ i+=1
559
+ end
560
+ end
561
+ end
562
+
563
+ if ports.size != 0 #we have port which dont respond
564
+
565
+ #identify worst sev from down port(s)
566
+ bad_sev = $status.size
567
+ str_port = ports.join(" ")
568
+ ports.each {|str|
569
+ sev_spe = $status.size
570
+ if str.gsub!(/T:/,"")
571
+ sev_spe = $host[ip].get_service_sev("tcp", str)
572
+ else
573
+ sev_spe = $host[ip].get_service_sev("udp", str)
574
+ end
575
+ bad_sev = sev_spe if sev_spe < bad_sev
576
+ }
577
+ if bad_sev == $status.size
578
+ $log.error("Service monitoring severity can't be found, setting critical")
579
+ bad_sev = 0
580
+ end
581
+
582
+ #nmap protocol/port syntax to human easy readable!
583
+ str_port.gsub!(/T:/,"tcp/")
584
+ str_port.gsub!(/U:/,"udp/")
585
+ $event_win.add_event(EventWindow::PORT_EVENT_TYPE, get_level_from_status($status[bad_sev]), $host[ip], "#{str_port} not responding")
586
+
587
+ return $status_value[bad_sev]
588
+ end
589
+
590
+ return -1
591
+ end
592
+
593
+ #
594
+ # Return all host seems to be up (responding to icmp) from a given network (class c)
595
+ # netmork submitted as 0.0.0.0/24
596
+ def broadcast_remote_ping(network, mask)
597
+ $log.debug "cmd_parse broadcast_remote_ping #{network} #{mask}"
598
+ puts "cmd_parse broadcast_remote_ping #{network} #{mask}"
599
+ result=[]
600
+ if $config.nmap_path == ""
601
+ return result
602
+ end
603
+ res=nil
604
+ nmap_version = $config.nmap_vers.to_f()
605
+ case
606
+ when nmap_version >= 6.0 then
607
+ res=`#{$config.nmap_path} --send-ip -PE -sP -n "#{network}/#{mask}" 2>/dev/null| grep "^Nmap scan report.*$" | awk '{print $5}'`
608
+ when nmap_version >= 4.0 then
609
+ res=`#{$config.nmap_path} --send-ip -PE -sP -n "#{network}/#{mask}" 2>/dev/null| grep "^H.*appears.*$" | awk '{print $2}'`
610
+ else
611
+ res=`#{$config.nmap_path} -PE -sP -n "#{network}/#{mask}" 2>/dev/null| grep "^H.*$" | awk '{print $2}'`
612
+ end
613
+ if res
614
+ lres=res.split(/\n/)
615
+ for ip in lres
616
+ result.push ip unless ip == network
617
+ end
618
+ end
619
+ return result
620
+ end
621
+
622
+ #
623
+ # Return all host seems to be up (responding to icmp) from a given range IP addr
624
+ def range_remote_ping(ip_begin, ip_end)
625
+ puts "in range_remote_ping"
626
+ result=[]
627
+ if $config.nmap_path == ""
628
+ return result
629
+ end
630
+ res=nil
631
+ if $config.nmap_vers.to_f() >= 4
632
+ res=`#{$config.nmap_path} --send-ip -sP -n "#{ip_begin}-#{ip_end}" 2>/dev/null| grep "^H.*$" | awk '{print $2}'`
633
+ else
634
+ res=`#{$config.nmap_path} -sP -n "#{ip_begin}-#{ip_end}" 2>/dev/null| grep "^H.*$" | awk '{print $2}'`
635
+ end
636
+
637
+ lres=res.split(/\n/)
638
+ for ip in lres
639
+ result.push ip
640
+ end
641
+ return result
642
+ end
643
+
644
+ #
645
+ # OS Fingerprint
646
+ #
647
+ def osfingerprint(ip)
648
+
649
+ $log.debug "cmd_parse osfingerprint #{ip}"
650
+
651
+ if $config.xprobe_path != ""
652
+ #with xprobe version 1
653
+ #res=`#{$config.xprobe_path} #{ip} 2>&1 | grep "FINAL"`
654
+ #with xprobe version 2
655
+ res=`#{$config.xprobe_path} -c /etc/xprobe2/xprobe2.conf -m 1 #{ip} 2>&1 | grep "Running OS"`
656
+ # seems xprobe2 get a segfault when he can't find the interface to contact the ip
657
+
658
+ if (res == "")
659
+ nmap_version = $config.nmap_vers.to_f()
660
+ if nmap_version >= 6.0
661
+ res=`#{$config.nmap_path} -O #{ip} --host_timeout 10 2>&1 | grep "Running: "`
662
+ else
663
+ res=`#{$config.nmap_path} -O #{ip} --host_timeout 10000 2>&1 | grep "Running: "`
664
+ end
665
+ end
666
+
667
+ if (res!="")
668
+ if (res.index("Linux")!=nil)
669
+ res="linux"
670
+ return res
671
+ end
672
+ if (res.index("Win")!=nil)
673
+ res="windows"
674
+ return res
675
+ end
676
+ if (res.index("HPUX")!=nil)
677
+ res="hp"
678
+ return res
679
+ end
680
+ if (res.index("3Com")!=nil)
681
+ res="3com"
682
+ $host[ip].type="switch"
683
+ return res
684
+ end
685
+ if (res.index("Cisco")!=nil)
686
+ res="cisco"
687
+ $host[ip].type="router"
688
+ return res
689
+ end
690
+ if (res.index("BSD")!=nil)
691
+ res="freebsd"
692
+ return res
693
+ end
694
+ end
695
+ end
696
+ return ""
697
+ end
698
+
699
+ #
700
+ # Return the service name associate to the port give in argument
701
+ # first is protocol, second is port
702
+ def service_name(protocol,port)
703
+ sn = `cat /etc/services | awk '{print $2, $1;}' | grep "^#{port}/#{protocol}" | awk '{print $2;}'`
704
+ return sn.chomp
705
+ end
706
+
707
+ #
708
+ # find netbios name
709
+ #
710
+ def ip2netbiosname(ip)
711
+ if $config.nmblookup_path == ""
712
+ return nil
713
+ end
714
+ res=`#{$config.nmblookup_path} -A "#{ip}" | grep ACTIVE | awk '{print $1;}'`
715
+ rest=res.split(/\n/)
716
+ return rest[0]
717
+ end
718
+
719
+ #
720
+ # convert bitmask address to netmask address
721
+ #
722
+ def bit2netmask(int)
723
+ if int==0
724
+ return "0.0.0.0"
725
+ end
726
+ return IPCalc.bits_to_netmask(int)
727
+ end
728
+
729
+ #
730
+ # convert netmask address to bitmask address
731
+ #
732
+ def net2bitmask(netmask)
733
+ if netmask =="0.0.0.0"
734
+ return 0
735
+ end
736
+ return IPCalc.netmask_to_bits(netmask)
737
+ end
738
+
739
+ #
740
+ # return network address and compress mask class
741
+ #
742
+ def getnetwork_and_mask(ip)
743
+ if ip == "" || ip == nil
744
+ return nil
745
+ end
746
+ return IPCalc.get_network_and_mask(ip)
747
+ end