boris 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/LICENSE.md +9 -0
  2. data/README.md +94 -0
  3. data/boris.gemspec +28 -0
  4. data/doc/Array.html +437 -0
  5. data/doc/Boris.html +230 -0
  6. data/doc/Boris/ConnectionAlreadyActive.html +123 -0
  7. data/doc/Boris/ConnectionFailed.html +127 -0
  8. data/doc/Boris/Connector.html +794 -0
  9. data/doc/Boris/InvalidCredentials.html +131 -0
  10. data/doc/Boris/InvalidOption.html +123 -0
  11. data/doc/Boris/InvalidTargetName.html +123 -0
  12. data/doc/Boris/Lumberjack.html +466 -0
  13. data/doc/Boris/MissingCredentials.html +123 -0
  14. data/doc/Boris/NoActiveConnection.html +123 -0
  15. data/doc/Boris/NoProfileDetected.html +123 -0
  16. data/doc/Boris/Options.html +783 -0
  17. data/doc/Boris/Profiles.html +117 -0
  18. data/doc/Boris/Profiles/Linux.html +1151 -0
  19. data/doc/Boris/Profiles/RedHat.html +875 -0
  20. data/doc/Boris/Profiles/Solaris.html +1230 -0
  21. data/doc/Boris/Profiles/Structure.html +2050 -0
  22. data/doc/Boris/Profiles/UNIX.html +893 -0
  23. data/doc/Boris/Profiles/Windows.html +1846 -0
  24. data/doc/Boris/Profiles/Windows/Windows2003.html +304 -0
  25. data/doc/Boris/Profiles/Windows/Windows2008.html +379 -0
  26. data/doc/Boris/Profiles/Windows/Windows2012.html +304 -0
  27. data/doc/Boris/SNMPConnector.html +512 -0
  28. data/doc/Boris/SSHConnector.html +633 -0
  29. data/doc/Boris/Target.html +2002 -0
  30. data/doc/Boris/WMIConnector.html +1134 -0
  31. data/doc/BorisLogger.html +217 -0
  32. data/doc/Hash.html +195 -0
  33. data/doc/String.html +1246 -0
  34. data/doc/_index.html +420 -0
  35. data/doc/class_list.html +53 -0
  36. data/doc/css/common.css +1 -0
  37. data/doc/css/full_list.css +57 -0
  38. data/doc/css/style.css +328 -0
  39. data/doc/file.README.html +183 -0
  40. data/doc/file_list.html +55 -0
  41. data/doc/frames.html +28 -0
  42. data/doc/index.html +183 -0
  43. data/doc/js/app.js +214 -0
  44. data/doc/js/full_list.js +173 -0
  45. data/doc/js/jquery.js +4 -0
  46. data/doc/method_list.html +1468 -0
  47. data/doc/top-level-namespace.html +126 -0
  48. data/lib/boris.rb +30 -0
  49. data/lib/boris/connectors.rb +47 -0
  50. data/lib/boris/connectors/snmp.rb +56 -0
  51. data/lib/boris/connectors/ssh.rb +110 -0
  52. data/lib/boris/connectors/wmi.rb +186 -0
  53. data/lib/boris/errors.rb +17 -0
  54. data/lib/boris/helpers/array.rb +63 -0
  55. data/lib/boris/helpers/constants.rb +20 -0
  56. data/lib/boris/helpers/hash.rb +8 -0
  57. data/lib/boris/helpers/scrubber.rb +51 -0
  58. data/lib/boris/helpers/string.rb +130 -0
  59. data/lib/boris/lumberjack.rb +47 -0
  60. data/lib/boris/options.rb +86 -0
  61. data/lib/boris/profiles/linux/redhat.rb +77 -0
  62. data/lib/boris/profiles/linux_core.rb +216 -0
  63. data/lib/boris/profiles/unix/solaris.rb +307 -0
  64. data/lib/boris/profiles/unix_core.rb +85 -0
  65. data/lib/boris/profiles/windows/windows2003.rb +15 -0
  66. data/lib/boris/profiles/windows/windows2008.rb +23 -0
  67. data/lib/boris/profiles/windows/windows2012.rb +15 -0
  68. data/lib/boris/profiles/windows_core.rb +530 -0
  69. data/lib/boris/structure.rb +167 -0
  70. data/lib/boris/target.rb +340 -0
  71. data/test/connector_tests/test_snmp.rb +35 -0
  72. data/test/connector_tests/test_ssh.rb +51 -0
  73. data/test/connector_tests/test_wmi.rb +129 -0
  74. data/test/helper_tests/test_array.rb +25 -0
  75. data/test/helper_tests/test_hash.rb +10 -0
  76. data/test/helper_tests/test_string.rb +136 -0
  77. data/test/profile_tests/test_core_skeleton +107 -0
  78. data/test/profile_tests/test_linux_core.rb +331 -0
  79. data/test/profile_tests/test_redhat.rb +134 -0
  80. data/test/profile_tests/test_solaris.rb +523 -0
  81. data/test/profile_tests/test_unix_core.rb +117 -0
  82. data/test/profile_tests/test_windows.rb +536 -0
  83. data/test/setup_tests.rb +14 -0
  84. data/test/test_all.rb +8 -0
  85. data/test/test_options.rb +44 -0
  86. data/test/test_structure.rb +136 -0
  87. data/test/test_target.rb +146 -0
  88. metadata +241 -0
@@ -0,0 +1,216 @@
1
+ require 'boris/structure'
2
+
3
+ module Boris; module Profiles
4
+ module Linux
5
+ include Structure
6
+
7
+ def self.connection_type
8
+ Boris::SSHConnector
9
+ end
10
+
11
+ def self.matches_target?(connector)
12
+ return true if connector.value_at('uname -a') =~ /linux/i
13
+ end
14
+
15
+ def get_file_systems
16
+ super
17
+
18
+ file_system_command = %q{df -P -T | grep "^/" | awk '{print $1 "|" $3 / 1024 "|" $5 / 1024 "|" $7}'}
19
+ @connector.values_at(file_system_command).each do |file_system|
20
+ h = file_system_template
21
+ file_system = file_system.split("|")
22
+
23
+ h[:capacity_mb] = file_system[1].to_i
24
+ h[:file_system] = file_system[0]
25
+ h[:mount_point] = file_system[3]
26
+ h[:used_space_mb] = file_system[2].to_i
27
+
28
+ @file_systems << h
29
+ end
30
+ end
31
+
32
+ def get_hardware
33
+ super
34
+
35
+ cpu_arch_data = @connector.value_at('uname -m')
36
+ @hardware[:cpu_architecture] = cpu_arch_data =~ /ia|_(64)/ ? 64 : 32
37
+
38
+ cpu_data = @connector.values_at('cat /proc/cpuinfo | egrep -i "processor|vendor|mhz|name|cores"')
39
+ @hardware[:cpu_physical_count] = cpu_data.grep(/processor/i).last.after_colon.to_i + 1
40
+ @hardware[:cpu_model] = cpu_data.grep(/model name/i)[0].after_colon
41
+ @hardware[:cpu_vendor] = cpu_data.grep(/vendor_id/i)[0].after_colon
42
+ @hardware[:cpu_speed_mhz] = cpu_data.grep(/cpu mhz/i)[0].after_pipe.to_i
43
+
44
+ # cpu cores aren't always displayed via /proc/cpuinfo
45
+ cpu_cores = cpu_data.grep(/cpu cores/i)[0]
46
+ @hardware[:cpu_core_count] = cpu_cores.after_colon.to_i if cpu_cores
47
+
48
+ memory_data = @connector.value_at("cat /proc/meminfo | grep -i memtotal | awk '{print $2 / 1024}'")
49
+ @hardware[:memory_installed_mb] = memory_data.to_i
50
+
51
+ hardware_data = @connector.values_at('/usr/bin/sudo /usr/sbin/dmidecode -t 0,1,4', true)
52
+ if hardware_data.any?
53
+ # grab the cpu speed again (because its value is usually more useful/relevant than that found via /proc/cpuinfo)
54
+ @hardware[:cpu_speed_mhz] = hardware_data.grep(/current speed/i)[0].after_colon.scan(/\d/).join.to_i
55
+ @hardware[:firmware_version] = hardware_data.grep(/version/i)[0].after_colon
56
+ @hardware[:model] = hardware_data.grep(/product name/i)[0].after_colon
57
+ @hardware[:serial] = hardware_data.grep(/serial number/i)[0].after_colon
58
+ @hardware[:vendor] = hardware_data.grep(/manufacturer/i)[0].after_colon
59
+ else
60
+ info 'no hardware information available (give me sudo access for dmidecode!)'
61
+ end
62
+ end
63
+
64
+ def get_hosted_shares; super; end
65
+ def get_installed_applications; super; end
66
+ def get_installed_patches; super; end
67
+ def get_installed_services; super; end
68
+
69
+ def get_local_user_groups
70
+ super
71
+
72
+ user_data = @connector.values_at('cat /etc/passwd | grep -v "^#"')
73
+ group_data = @connector.values_at('cat /etc/group | grep -v "^#"')
74
+
75
+ users = []
76
+ groups = []
77
+
78
+ user_data.each do |x|
79
+ h = {}
80
+ x = x.split(":")
81
+ h[:status] = nil
82
+ h[:primary_group_id] = x[3]
83
+ h[:username] = x[0]
84
+ users << h
85
+ end
86
+
87
+ group_data.each do |group|
88
+ group = group.split(":")
89
+ h = {:members=>[], :name=>group[0]}
90
+
91
+ h[:members] = users.select{|user| (user[:primary_group_id] == group[2])}.collect{|user| user[:username]}
92
+
93
+ @local_user_groups << h
94
+ end
95
+ end
96
+
97
+ def get_network_id
98
+ super
99
+
100
+ hostname = @connector.value_at('hostname').split('.')
101
+ @network_id[:hostname] = hostname.shift
102
+
103
+ domain = @connector.value_at('domainname')
104
+ domain = nil if domain =~ /\(none\)/i
105
+
106
+ @network_id[:domain] = domain.nil? ? hostname.join('.') : domain
107
+ end
108
+
109
+ def get_network_interfaces
110
+ super
111
+
112
+ # grab the make/model/slot info for all ethernet/fc ports
113
+ ports = @connector.values_at('/sbin/lspci -mmv | egrep -i "class:[[:space:]]*(ethernet controller|fibre channel)" -B1 -A5')
114
+
115
+ ## ETHERNET
116
+ # get some basic info that will apply to all ethernet interfaces
117
+ dns_servers = @connector.values_at("cat /etc/resolv.conf | grep ^nameserver | awk '{print $2}'")
118
+
119
+ found_ethernet_interfaces = ports.join("\n").split('--').grep(/ethernet controller/i)
120
+ found_fibre_interfaces = ports.join("\n").split('--').grep(/fibre channel/i)
121
+
122
+ if found_ethernet_interfaces.any?
123
+ # get info on all ethernet interfaces
124
+ ethernet_mapping_data = @connector.values_at(%q{ls /sys/class/net | awk '{cmd="readlink -f /sys/class/net/" $1 "/device/"; cmd | getline link; print $1 "|" link}'})
125
+ link_properties = @connector.values_at(%q{find -L /sys/class/net/ -mindepth 2 -maxdepth 2 2>/dev/null | awk '{cmd = "cat " $0 " 2>/dev/null"; cmd | getline value; print $0 "|" value;}'})
126
+ ip_addr_data = @connector.values_at(%q{/sbin/ip addr | awk '{if($0 ~ /^[0-9]:/) {print "\n" $0} else {print $0}}'})
127
+
128
+ found_ethernet_interfaces.each do |interface|
129
+ interface = interface.split("\n")
130
+
131
+ h = network_interface_template
132
+
133
+ h[:dns_servers] = dns_servers
134
+ h[:type] = 'ethernet'
135
+
136
+ h[:model] = interface.grep(/^.*sdevice:/i)[0].after_colon
137
+ h[:vendor] = interface.grep(/^.*svendor:/i)[0].after_colon
138
+
139
+ pci_slot = interface.grep(/^.*slot:/i)[0].after_colon
140
+
141
+ h[:name] = ethernet_mapping_data.grep(/#{pci_slot}$/)[0].before_pipe
142
+
143
+ interface_config = link_properties.grep(/\/#{h[:name]}\//)
144
+
145
+ h[:mac_address] = interface_config.grep(/\/address\|/)[0].after_pipe.upcase
146
+
147
+ # operstate sometimes gives reports interface as 'unknown' when it is up
148
+ # and working. checking the value of carrier (0 for not plugged in, 1 for
149
+ # plugged in) in conjunction with the 'ip' command output is a good fallback
150
+ wired_connection = interface_config.grep(/\/carrier\|/)[0].after_pipe
151
+
152
+ ip_config = ip_addr_data.join("\n").strip.split(/\n\n/).grep(/^.*:\s#{h[:name]}:/)[0].split(/\n/)
153
+
154
+ h[:status] = (ip_config[0] =~ /,up,/i && wired_connection =~ /1/i) ? 'up' : 'down'
155
+
156
+ if h[:status] == 'up'
157
+ # speed & duplex are not always available (in case of a virtual machine
158
+ # or hardware failure, etc)
159
+ speed = interface_config.grep(/\/speed\|/)[0]
160
+ h[:current_speed_mbps] = speed.after_pipe.to_i if speed
161
+
162
+ duplex = interface_config.grep(/\/duplex\|/)[0]
163
+ h[:duplex] = duplex.after_pipe if duplex
164
+
165
+ h[:mtu] = interface_config.grep(/\/mtu\|/)[0].after_pipe.to_i
166
+
167
+ ip_config.grep(/^.*inet /).each do |ip|
168
+ ip_address = ip.split[1].before_slash
169
+ netmask_bits = ip.split[1].after_slash
170
+ h[:ip_addresses] << {:ip_address=>ip_address, :subnet=>NetAddr.i_to_ip(NetAddr.netmask_to_i(netmask_bits))}
171
+ end
172
+ end
173
+
174
+ @network_interfaces << h
175
+ end
176
+ end
177
+
178
+ if found_fibre_interfaces.any?
179
+ fibre_mapping_data = @connector.values_at("find /sys/devices/pci* -regex '.*fc_host/host[0-9]'")
180
+ interface_config = @connector.values_at(%q{find -L /sys/class/fc_host/ -mindepth 2 -maxdepth 2 | awk '{value=""; "cat " $1 " 2>/dev/null" | getline value; print $1 "|" value;}'})
181
+
182
+ found_fibre_interfaces.each do |interface|
183
+ interface = interface.split("\n")
184
+
185
+ h = network_interface_template
186
+
187
+ h[:type] = 'fibre'
188
+
189
+ h[:model] = interface.grep(/^.*device:/i)[0].after_colon
190
+ h[:vendor] = interface.grep(/^.*vendor:/i)[0].after_colon
191
+
192
+ pci_slot = interface.grep(/^.*slot:/i)[0].split[1]
193
+
194
+ h[:name] = fibre_mapping_data.grep(/0000:#{pci_slot}\//)[0].after_slash
195
+
196
+ interface_config = interface_config.grep(/fc_host\/#{h[:name]}\//)
197
+
198
+ status = interface_config.grep(/\/port_state\|/)[0].after_pipe
199
+ h[:status] = status =~ /online/i ? 'up' : 'down'
200
+
201
+ if h[:status] == 'up'
202
+ speed = interface_config.grep(/\/speed\|/)[0].after_pipe.split
203
+ h[:current_speed_mbps] = speed[0].to_i * 1000
204
+ h[:fabric_name] = interface_config.grep(/\/fabric_name\|/)[0].after_pipe.sub(/^0x/, '')
205
+ h[:node_wwn] = interface_config.grep(/\/node_name\|/)[0].after_pipe.sub(/^0x/, '')
206
+ h[:port_wwn] = interface_config.grep(/\/port_name\|/)[0].after_pipe.sub(/^0x/, '')
207
+ end
208
+
209
+ @network_interfaces << h
210
+ end
211
+ end
212
+ end
213
+
214
+ def get_operating_system; super; end
215
+ end
216
+ end; end
@@ -0,0 +1,307 @@
1
+ require 'boris/profiles/unix_core'
2
+
3
+ module Boris; module Profiles
4
+ module Solaris
5
+ include UNIX
6
+
7
+ SOLARIS_ZONE_MODEL = 'Oracle Virtual Platform'
8
+
9
+ def self.connection_type
10
+ UNIX.connection_type
11
+ end
12
+
13
+ def self.matches_target?(connector)
14
+ return true if connector.value_at('uname') =~ /sunos/i
15
+ end
16
+
17
+ def get_hardware
18
+ super
19
+
20
+ detect_platform if !@platform
21
+ detect_zone if !@zone
22
+
23
+ if @zone == :child
24
+ @hardware[:vendor] = VENDOR_ORACLE
25
+ @hardware[:model] = SOLARIS_ZONE_MODEL
26
+ elsif @platform == :sparc
27
+ @hardware[:vendor] = VENDOR_ORACLE
28
+
29
+ @hardware[:firmware_version] = @connector.value_at(%q{/usr/platform/`uname -m`/sbin/prtdiag -v | egrep -i "^obp" | awk '{print $2}'})
30
+ model_data = @connector.value_at('/usr/sbin/prtconf -b | grep banner-name')
31
+ @hardware[:model] = model_data.after_colon
32
+ else
33
+ @hardware[:firmware_version] = @connector.value_at('/usr/sbin/smbios -t SMB_TYPE_BIOS | grep -i "version string"').after_colon
34
+ model_data = @connector.values_at("/usr/sbin/smbios -t SMB_TYPE_SYSTEM | egrep -i 'manufacturer|product|serial'")
35
+ @hardware[:vendor] = model_data.grep(/manufacturer/i)[0].after_colon
36
+ @hardware[:model] = model_data.grep(/product/i)[0].after_colon
37
+ @hardware[:serial] = model_data.grep(/serial number/i)[0].after_colon
38
+ end
39
+
40
+ memory_data = @connector.value_at("/usr/sbin/prtconf | egrep -i 'memory size' | awk '{print $3}'")
41
+ @hardware[:memory_installed_mb] = memory_data.to_i
42
+
43
+ cpu_arch_data = @connector.values_at("isainfo -v | egrep -i applications | awk '{print $1}'")
44
+ @hardware[:cpu_architecture] = cpu_arch_data.include?('64-bit') ? 64 : 32
45
+
46
+ cpu_data = @connector.values_at(%q{kstat -m cpu_info | nawk '{if(tolower($1)~/^(chip_id|core_id|clock_mhz|vendor_id|brand)/) {sub($1, $1"|"); print $0}}'})
47
+
48
+ @hardware[:cpu_physical_count] = cpu_data.grep(/chip_id/i).uniq.size
49
+ @hardware[:cpu_core_count] = cpu_data.grep(/core_id/i).uniq.size / @hardware[:cpu_physical_count]
50
+ @hardware[:cpu_model] = cpu_data.grep(/brand/i)[0].after_pipe
51
+ @hardware[:cpu_speed_mhz] = cpu_data.grep(/clock_mhz/i)[0].after_pipe.to_i
52
+
53
+ @hardware[:cpu_vendor] = if @platform == :sparc
54
+ VENDOR_ORACLE
55
+ else
56
+ cpu_data.grep(/vendor_id/i)[0].after_pipe
57
+ end
58
+ end
59
+
60
+ def get_hosted_shares
61
+ super
62
+
63
+ share_data = @connector.values_at(%q{nawk '{system("df -k | grep " $2)}' /usr/sbin/shares | nawk '{print $NF "|" $1}'})
64
+ share_data.each do |share|
65
+ h = hosted_share_template
66
+ share = share.split('|')
67
+ h[:name] = share[0]
68
+ h[:path] = share[1]
69
+ @hosted_shares << h
70
+ end
71
+ end
72
+
73
+ def get_installed_applications
74
+ super
75
+
76
+ application_data = @connector.values_at("pkginfo -il -c application | egrep -i '^$|(name|version|basedir|vendor|instdate):'")
77
+ application_data.join("\n").split("\n\n").each do |application|
78
+
79
+ application = application.split("\n")
80
+ h = installed_application_template
81
+
82
+ date_installed = application.grep(/instdate:/i)[0].split(/instdate:/i)[1].strip
83
+ h[:date_installed] = DateTime.strptime(date_installed, '%b %d %Y %H:%M')
84
+ h[:name] = application.grep(/name:/i)[0].after_colon
85
+ h[:version] = application.grep(/version:/i)[0].after_colon
86
+
87
+ # these sometimes don't show up
88
+ install_location = application.grep(/basedir:/i)[0]
89
+ h[:install_location] = install_location.after_colon if install_location
90
+ vendor = application.grep(/vendor:/i)[0]
91
+ h[:vendor] = vendor.after_colon if vendor
92
+
93
+ @installed_applications << h
94
+ end
95
+ end
96
+
97
+ def get_installed_patches
98
+ super
99
+
100
+ # get list of patch install directories and their modified date. this will be our de-facto
101
+ # list of installed patches on a host.
102
+
103
+ patch_directories = @connector.values_at(%q{ls -ego /var/sadm/patch | grep -v '^total' | nawk '{print $NF "|" $4 " " $5 " " $6 " " $7}'})
104
+
105
+ patch_directories.each do |directory|
106
+
107
+ h = installed_patch_template
108
+
109
+ directory = directory.split('|')
110
+
111
+ h[:patch_code] = directory[0]
112
+ h[:date_installed] = DateTime.parse(directory[1])
113
+
114
+ @installed_patches << h
115
+ end
116
+ end
117
+
118
+ def get_installed_services
119
+ super
120
+
121
+ service_data = @connector.values_at("svcs -a | nawk '{print $NF}'")
122
+ service_data.each do |service|
123
+ h = installed_service_template
124
+ h[:name] = service
125
+
126
+ @installed_services << h
127
+ end
128
+ end
129
+
130
+ def get_local_user_groups; super; end
131
+
132
+ def get_network_interfaces
133
+ super
134
+
135
+ detect_platform if !@platform
136
+ detect_zone if !@zone
137
+
138
+ ## ETHERNET
139
+ # first, grab the link properties for all connections via the kstat command
140
+ link_properties = @connector.values_at(%q{/usr/bin/kstat -c net -p | egrep "ifspeed|link_(up|duplex|autoneg)" | nawk '{print $1 "|" $2}'})
141
+
142
+ # now create a definitive list of interfaces found on this host. to do this, we pull
143
+ # the interfaces from the link_properties (kstat cmd) output.
144
+ found_ethernet_interfaces = []
145
+ link_properties.grep(/:ifspeed\|/).each do |i|
146
+ i = i.strip.split(':')
147
+ found_ethernet_interfaces << {:driver=>i[0], :instance=>i[1]}
148
+ end
149
+
150
+ if found_ethernet_interfaces.any?
151
+
152
+ # get some basic info that will apply to all ethernet interfaces
153
+ dns_servers = @connector.values_at("cat /etc/resolv.conf | grep ^nameserver | awk '{print $2}'")
154
+
155
+ # then get ethernet interface config from ifconfig
156
+ interface_configs = @connector.values_at(%q{/sbin/ifconfig -a | egrep 'flags|inet|zone' | nawk '{if($2~/^flags/ && $1!~/^(lo|dman|sppp)/) {current_line=$0; getline; {if($1!~/^zone/) {$1=$1; print current_line "\n" $0 "\n"}}}}'}).join("\n").strip.split(/\n\n/)
157
+
158
+ # now get the macs of active ethernet connections (for backup in cases where we
159
+ # can't get macs from prtpicl)
160
+ mac_mapping = @connector.values_at(%q{/usr/bin/netstat -pn | grep SP | nawk '{print $1 "|" $2 "|" toupper($5)}'})
161
+
162
+ # if this host is in a child zone, drop any interfaces that are not found in the ifconfig
163
+ # command output (since these would likely be picked up when scanning the zone host)
164
+ if @zone == :child
165
+ found_ethernet_interfaces.delete_if{|fi| interface_configs.select{|config| config =~ /^#{fi[:driver]}#{fi[:instance]}/}.count == 0}
166
+ end
167
+
168
+ # now loop through each unique ethernet interface found on this host
169
+ found_ethernet_interfaces.uniq.each do |fi|
170
+ h = network_interface_template
171
+
172
+ h[:dns_servers] = dns_servers
173
+ h[:name] = fi[:driver] + fi[:instance]
174
+
175
+ # set some defaults for this interface
176
+ h[:mac_address] = '00:00:00:00:00:00'
177
+ h[:model] = 'Unknown Ethernet Adapter'
178
+ h[:status] = 'down'
179
+ h[:type] = 'ethernet'
180
+ h[:vendor] = 'Unknown'
181
+
182
+ # grab the ifconfig output matching this interface
183
+ matched_ifconfig_data = interface_configs.grep(/#{h[:name]}:/)
184
+ matched_ifconfig_data.each do |ifconfig_data|
185
+ ifconfig_data = ifconfig_data.split(/\n/)
186
+ interface_line = ifconfig_data[0].split
187
+ inet_line = ifconfig_data[1].split
188
+
189
+ subnet = inet_line[3] ? inet_line[3].hex_to_address : nil
190
+
191
+ h[:status] = 'up' if interface_line[1] =~ /<up/i
192
+
193
+ if h[:status] == 'up'
194
+ h[:mtu] = interface_line[3].to_i unless h[:mtu]
195
+ h[:ip_addresses] << {:ip_address=>inet_line[1], :subnet=>subnet}
196
+ end
197
+ end
198
+
199
+ # for a child zone, set default ethernet interface model/vendor. for zone host,
200
+ # run prtpicl command to grab hardware details
201
+ if @zone == :child
202
+ h[:model] = 'Virtual Ethernet Adapter'
203
+ h[:vendor] = VENDOR_ORACLE
204
+ else
205
+ prtpicl_command = %q{/usr/sbin/prtpicl -c network -v | egrep ':model|:driver-name|:instance|:local-mac-address|:vendor-id|:device-id|\(network' | nawk '{if ($0 ~ /\(network/) print ""; else {first=$1; $1=""; print first "|" $0}}'}
206
+
207
+ prtpicl_command.gsub!(/network/, 'obp-device') if @platform == :x86
208
+
209
+ hardware_details = @connector.values_at(prtpicl_command).join("\n").split(/\n\n/)
210
+
211
+ hardware = hardware_details.grep(/driver-name\|.*#{fi[:driver]}/).grep(/instance\|.*#{fi[:instance]}/)[0].split(/\n/)
212
+
213
+ h[:vendor_id] = hardware.grep(/vendor-id\|/)[0].after_pipe unless hardware.grep(/vendor-id\|/).empty?
214
+ h[:model_id] = hardware.grep(/device-id\|/)[0].after_pipe unless hardware.grep(/device-id\|/).empty?
215
+
216
+ h[:vendor] = hardware.grep(/vendor\|/)[0].after_pipe unless hardware.grep(/vendor\|/).empty?
217
+ h[:model] = hardware.grep(/model\|/)[0].after_pipe unless hardware.grep(/model\|/).empty?
218
+
219
+ # try grabbing the mac from the hardware details (hit or miss if it's there)
220
+ h[:mac_address] = hardware.grep(/local-mac-address\|/)[0].after_pipe.gsub(/\s+/, ':').upcase unless hardware.grep(/local-mac-address\|/).empty?
221
+ end
222
+
223
+ # make another attempt at grabbing the mac, this time checking output from netstat,
224
+ # which would only apply to active connections
225
+ netstat_mac = mac_mapping.select{|mac| mac.strip =~ /^#{fi[:driver]}#{fi[:instance]}\|/}
226
+ h[:mac_address] = netstat_mac[0].after_pipe unless netstat_mac.empty?
227
+
228
+ # grab link properties from the kstat command results
229
+ properties = link_properties.select{|l| l.strip =~ /^#{fi[:driver]}:#{fi[:instance]}/}
230
+
231
+ # override status if the link is down
232
+ h[:status] = 'down' if properties.grep(/:link_up\|/)[0].after_pipe != '1'
233
+
234
+ if h[:status] == 'up'
235
+ speed = properties.grep(/:ifspeed\|/)
236
+ h[:current_speed_mbps] = speed[0].after_pipe.to_i / 1000 / 1000 unless speed.empty?
237
+
238
+ auto_negotiate_setting = properties.grep(/:link_autoneg\|/)
239
+ h[:auto_negotiate] = case auto_negotiate_setting[0].after_pipe.to_i
240
+ when 1; true
241
+ else; false
242
+ end unless auto_negotiate_setting.empty?
243
+
244
+ duplex_setting = properties.grep(/:link_duplex\|/)
245
+ h[:duplex] = case duplex_setting[0].after_pipe
246
+ when '2' || 'full'; 'full'
247
+ when '1' || 'half'; 'half'
248
+ end unless duplex_setting.empty?
249
+
250
+ end
251
+
252
+ @network_interfaces << h
253
+ end
254
+ end
255
+
256
+ ## FIBRE CHANNEL
257
+ found_fibre_interfaces = @connector.values_at(%q{/usr/local/bin/sudo /usr/sbin/fcinfo hba-port | egrep -i "wwn|device name|model|manufacturer|driver name|state|current speed" | nawk '{$1=$1; if(tolower($1) ~ /^node/) print $0 "\n"; else print $0;}'})
258
+ found_fibre_interfaces = found_fibre_interfaces.join("\n").split(/\n\n/)
259
+
260
+ found_fibre_interfaces.each do |hba|
261
+ hba = hba.split(/\n/)
262
+
263
+ h = network_interface_template
264
+
265
+ h[:name] = hba.grep(/os device name/i)[0].after_colon
266
+ h[:node_wwn] = hba.grep(/node wwn/i)[0].after_colon
267
+ h[:port_wwn] = hba.grep(/port wwn/i)[0].after_colon
268
+
269
+ h[:model] = hba.grep(/model/i)[0].after_colon
270
+ h[:vendor] = hba.grep(/manufacturer/i)[0].after_colon
271
+
272
+ h[:status] = hba.grep(/state/i)[0].after_colon =~ /online/i ? 'up' : 'down'
273
+ h[:type] = 'fibre'
274
+
275
+ current_speed = hba.grep(/current speed/i)[0].after_colon
276
+ speed = current_speed.scan(/\d/).join.to_i
277
+ h[:current_speed_mbps] = current_speed =~ /gb/i ? speed * 1000 : speed
278
+
279
+ @network_interfaces << h
280
+ end
281
+ end
282
+
283
+ def get_operating_system
284
+ super
285
+
286
+ install_log_date = @connector.value_at("ls -l /var/sadm/system/logs/install_log | nawk '{print $6" "$7" "$8'}")
287
+ @operating_system[:date_installed] = DateTime.parse(install_log_date)
288
+
289
+ os_data = @connector.value_at('uname -rv').split
290
+ @operating_system[:kernel] = os_data[1]
291
+ @operating_system[:name] = 'Oracle Solaris'
292
+ @operating_system[:version] = os_data[0]
293
+ end
294
+
295
+ private
296
+
297
+ def detect_platform
298
+ platform = @connector.values_at('showrev').grep(/application architecture/i)[0].after_colon
299
+ @platform = platform =~ /sparc/i ? :sparc : :x86
300
+ end
301
+
302
+ def detect_zone
303
+ zone = @connector.values_at('/usr/sbin/zoneadm list')
304
+ @zone = zone.include?('global') ? :global : :child
305
+ end
306
+ end
307
+ end; end