diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-04-07 14:14:24 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-04-07 14:14:24 -0700 |
commit | 85673a97f0bf224663bb4f5784818038d35ae1c8 (patch) | |
tree | d50998fcb741ff9107cdfb2e1b3813d612fc2b4d | |
parent | 8aea6701b5680b146a3f5a94eb34f9caf5c861b6 (diff) | |
download | ohai-jdm/minimal-no-ole.tar.gz |
Don't rely on win32 ole for ohai minimaljdm/minimal-no-ole
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/hostname.rb | 332 | ||||
-rw-r--r-- | lib/ohai/plugins/kernel.rb | 378 | ||||
-rw-r--r-- | lib/ohai/plugins/powershell.rb | 124 | ||||
-rw-r--r-- | ohai.gemspec | 4 |
5 files changed, 403 insertions, 437 deletions
@@ -9,7 +9,7 @@ gem "rspec_junit_formatter", :git => 'https://github.com/sj26/rspec_junit_format :ref => "147836c41fab23ff7b92806f34122c8e5f2ddcad" group :development do - gem "chef", github: "opscode/chef", branch: "master" + #gem "chef", github: "opscode/chef", branch: "master" gem "sigar", :platform => "ruby" gem 'plist' diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb index 447b255d..fb4aa9e9 100644 --- a/lib/ohai/plugins/hostname.rb +++ b/lib/ohai/plugins/hostname.rb @@ -1,167 +1,165 @@ -# -# Author:: Adam Jacob (<adam@opscode.com>) -# Author:: Benjamin Black (<nostromo@gmail.com>) -# Author:: Bryan McLellan (<btm@loftninjas.org>) -# Author:: Daniel DeLeo (<dan@kallistec.com>) -# Author:: Doug MacEachern (<dougm@vmware.com>) -# Author:: James Gartrell (<jgartrel@gmail.com>) -# Copyright:: Copyright (c) 2008, 2009 Opscode, Inc. -# Copyright:: Copyright (c) 2009 Bryan McLellan -# Copyright:: Copyright (c) 2009 Daniel DeLeo -# Copyright:: Copyright (c) 2010 VMware, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require 'socket' -require 'ipaddr' - -Ohai.plugin(:Hostname) do - provides "domain", "hostname", "fqdn", "machinename" - - # hostname : short hostname - # machinename : output of hostname command (might be short on solaris) - # fqdn : result of canonicalizing hostname using DNS or /etc/hosts - # domain : domain part of FQDN - # - # hostname and machinename should always exist - # fqdn and domain may be broken if DNS is broken on the host - - def from_cmd(cmd) - so = shell_out(cmd) - so.stdout.split($/)[0] - end - - # forward and reverse lookup to canonicalize FQDN (hostname -f equivalent) - # this is ipv6-safe, works on ruby 1.8.7+ - def resolve_fqdn - begin - hostname = from_cmd("hostname") - addrinfo = Socket.getaddrinfo(hostname, nil).first - iaddr = IPAddr.new(addrinfo[3]) - Socket.gethostbyaddr(iaddr.hton)[0] - rescue - nil - end - end - - def collect_domain - # Domain is everything after the first dot - if fqdn - fqdn =~ /.+?\.(.*)/ - domain $1 - end - end - - def collect_hostname - # Hostname is everything before the first dot - if machinename - machinename =~ /(\w+)\.?/ - hostname $1 - elsif fqdn - fqdn =~ /(.+?)\./ - hostname $1 - end - end - - def get_fqdn_from_sigar - require 'sigar' - sigar = Sigar.new - sigar.fqdn - end - - def sigar_is_available? - begin - require 'sigar' - true - rescue LoadError - false - end - end - - collect_data(:aix, :hpux, :default) do - machinename from_cmd("hostname") - fqdn sigar_is_available? ? get_fqdn_from_sigar : resolve_fqdn - collect_hostname - collect_domain - end - - collect_data(:darwin, :netbsd, :openbsd) do - hostname from_cmd("hostname -s") - fqdn resolve_fqdn - machinename from_cmd("hostname") - collect_domain - end - - collect_data(:freebsd) do - hostname from_cmd("hostname -s") - machinename from_cmd("hostname") - fqdn from_cmd("hostname -f") - collect_domain - end - - collect_data(:linux) do - hostname from_cmd("hostname -s") - machinename from_cmd("hostname") - begin - ourfqdn = from_cmd("hostname --fqdn") - # Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely - # returns a blank string. WTF. - if ourfqdn.nil? || ourfqdn.empty? - Ohai::Log.debug("hostname --fqdn returned an empty string, retrying " + - "once.") - ourfqdn = from_cmd("hostname --fqdn") - end - - if ourfqdn.nil? || ourfqdn.empty? - Ohai::Log.debug("hostname --fqdn returned an empty string twice and " + - "will not be set.") - else - fqdn ourfqdn - end - rescue - Ohai::Log.debug( - "hostname --fqdn returned an error, probably no domain set") - end - domain collect_domain - end - - collect_data(:solaris2) do - machinename from_cmd("hostname") - hostname from_cmd("hostname") - fqdn resolve_fqdn - domain collect_domain - end - - collect_data(:windows) do - require 'wmi-lite/wmi' - require 'socket' - - wmi = WmiLite::Wmi.new - host = wmi.first_of('Win32_ComputerSystem') - - hostname "#{host['name']}" - machinename "#{host['name']}" - - info = Socket.gethostbyname(Socket.gethostname) - if info.first =~ /.+?\.(.*)/ - fqdn info.first - else - #host is not in dns. optionally use: - #C:\WINDOWS\system32\drivers\etc\hosts - fqdn Socket.gethostbyaddr(info.last).first - end - domain collect_domain - end -end +#
+# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Benjamin Black (<nostromo@gmail.com>)
+# Author:: Bryan McLellan (<btm@loftninjas.org>)
+# Author:: Daniel DeLeo (<dan@kallistec.com>)
+# Author:: Doug MacEachern (<dougm@vmware.com>)
+# Author:: James Gartrell (<jgartrel@gmail.com>)
+# Copyright:: Copyright (c) 2008, 2009 Opscode, Inc.
+# Copyright:: Copyright (c) 2009 Bryan McLellan
+# Copyright:: Copyright (c) 2009 Daniel DeLeo
+# Copyright:: Copyright (c) 2010 VMware, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'socket'
+require 'ipaddr'
+
+Ohai.plugin(:Hostname) do
+ provides "domain", "hostname", "fqdn", "machinename"
+
+ # hostname : short hostname
+ # machinename : output of hostname command (might be short on solaris)
+ # fqdn : result of canonicalizing hostname using DNS or /etc/hosts
+ # domain : domain part of FQDN
+ #
+ # hostname and machinename should always exist
+ # fqdn and domain may be broken if DNS is broken on the host
+
+ def from_cmd(cmd)
+ so = shell_out(cmd)
+ so.stdout.split($/)[0]
+ end
+
+ # forward and reverse lookup to canonicalize FQDN (hostname -f equivalent)
+ # this is ipv6-safe, works on ruby 1.8.7+
+ def resolve_fqdn
+ begin
+ hostname = from_cmd("hostname")
+ addrinfo = Socket.getaddrinfo(hostname, nil).first
+ iaddr = IPAddr.new(addrinfo[3])
+ Socket.gethostbyaddr(iaddr.hton)[0]
+ rescue
+ nil
+ end
+ end
+
+ def collect_domain
+ # Domain is everything after the first dot
+ if fqdn
+ fqdn =~ /.+?\.(.*)/
+ domain $1
+ end
+ end
+
+ def collect_hostname
+ # Hostname is everything before the first dot
+ if machinename
+ machinename =~ /(\w+)\.?/
+ hostname $1
+ elsif fqdn
+ fqdn =~ /(.+?)\./
+ hostname $1
+ end
+ end
+
+ def get_fqdn_from_sigar
+ require 'sigar'
+ sigar = Sigar.new
+ sigar.fqdn
+ end
+
+ def sigar_is_available?
+ begin
+ require 'sigar'
+ true
+ rescue LoadError
+ false
+ end
+ end
+
+ collect_data(:aix, :hpux, :default) do
+ machinename from_cmd("hostname")
+ fqdn sigar_is_available? ? get_fqdn_from_sigar : resolve_fqdn
+ collect_hostname
+ collect_domain
+ end
+
+ collect_data(:darwin, :netbsd, :openbsd) do
+ hostname from_cmd("hostname -s")
+ fqdn resolve_fqdn
+ machinename from_cmd("hostname")
+ collect_domain
+ end
+
+ collect_data(:freebsd) do
+ hostname from_cmd("hostname -s")
+ machinename from_cmd("hostname")
+ fqdn from_cmd("hostname -f")
+ collect_domain
+ end
+
+ collect_data(:linux) do
+ hostname from_cmd("hostname -s")
+ machinename from_cmd("hostname")
+ begin
+ ourfqdn = from_cmd("hostname --fqdn")
+ # Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely
+ # returns a blank string. WTF.
+ if ourfqdn.nil? || ourfqdn.empty?
+ Ohai::Log.debug("hostname --fqdn returned an empty string, retrying " +
+ "once.")
+ ourfqdn = from_cmd("hostname --fqdn")
+ end
+
+ if ourfqdn.nil? || ourfqdn.empty?
+ Ohai::Log.debug("hostname --fqdn returned an empty string twice and " +
+ "will not be set.")
+ else
+ fqdn ourfqdn
+ end
+ rescue
+ Ohai::Log.debug(
+ "hostname --fqdn returned an error, probably no domain set")
+ end
+ domain collect_domain
+ end
+
+ collect_data(:solaris2) do
+ machinename from_cmd("hostname")
+ hostname from_cmd("hostname")
+ fqdn resolve_fqdn
+ domain collect_domain
+ end
+
+ collect_data(:windows) do
+ require 'socket'
+
+ host = shell_out("hostname").stdout.strip
+
+ hostname host
+ machinename host
+
+ info = Socket.gethostbyname(Socket.gethostname)
+ if info.first =~ /.+?\.(.*)/
+ fqdn info.first
+ else
+ #host is not in dns. optionally use:
+ #C:\WINDOWS\system32\drivers\etc\hosts
+ fqdn Socket.gethostbyaddr(info.last).first
+ end
+ domain collect_domain
+ end
+end
diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb index 337ecd32..3a1b1094 100644 --- a/lib/ohai/plugins/kernel.rb +++ b/lib/ohai/plugins/kernel.rb @@ -1,205 +1,173 @@ -# -# Author:: Adam Jacob (<adam@opscode.com>) -# Author:: Benjamin Black (<nostromo@gmail.com>) -# Author:: Bryan McLellan (<btm@loftninjas.org>) -# Author:: Claire McQuin (<claire@opscode.com>) -# Author:: James Gartrell (<jgartrel@gmail.com>) -# Copyright:: Copyright (c) 2008, 2009, 2013 Opscode, Inc. -# Copyright:: Copyright (c) 2009 Bryan McLellan -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Ohai.plugin(:Kernel) do - provides "kernel", "kernel/modules" - - # common initial kernel attribute values - def init_kernel - kernel Mash.new - [["uname -s", :name], ["uname -r", :release], - ["uname -v", :version], ["uname -m", :machine]].each do |cmd, property| - so = shell_out(cmd) - kernel[property] = so.stdout.split($/)[0] - end - kernel - end - - # common *bsd code for collecting modules data - def bsd_modules(path) - modules = Mash.new - so = shell_out("#{Ohai.abs_path(path)}") - so.stdout.lines do |line| - # 1 7 0xc0400000 97f830 kernel - if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/ - modules[$5] = { :size => $4, :refcount => $2 } - end - end - modules - end - - # windows - def machine_lookup(sys_type) - return "i386" if sys_type.eql?("X86-based PC") - return "x86_64" if sys_type.eql?("x64-based PC") - sys_type - end - - # windows - def os_lookup(sys_type) - return "Unknown" if sys_type.to_s.eql?("0") - return "Other" if sys_type.to_s.eql?("1") - return "MSDOS" if sys_type.to_s.eql?("14") - return "WIN3x" if sys_type.to_s.eql?("15") - return "WIN95" if sys_type.to_s.eql?("16") - return "WIN98" if sys_type.to_s.eql?("17") - return "WINNT" if sys_type.to_s.eql?("18") - return "WINCE" if sys_type.to_s.eql?("19") - return nil - end - - collect_data(:default) do - kernel init_kernel - end - - collect_data(:darwin) do - kernel init_kernel - kernel[:os] = kernel[:name] - - so = shell_out("sysctl -n hw.optional.x86_64") - if so.stdout.split($/)[0].to_i == 1 - kernel[:machine] = 'x86_64' - end - - modules = Mash.new - so = shell_out("kextstat -k -l") - so.stdout.lines do |line| - if line =~ /(\d+)\s+(\d+)\s+0x[0-9a-f]+\s+0x([0-9a-f]+)\s+0x[0-9a-f]+\s+([a-zA-Z0-9\.]+) \(([0-9\.]+)\)/ - modules[$4] = { :version => $5, :size => $3.hex, :index => $1, :refcount => $2 } - end - end - - kernel[:modules] = modules - end - - collect_data(:freebsd) do - kernel init_kernel - kernel[:os] = kernel[:name] - - so = shell_out("uname -i") - kernel[:ident] = so.stdout.split($/)[0] - so = shell_out("sysctl kern.securelevel") - kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ } - - kernel[:modules] = bsd_modules("/sbin/kldstat") - end - - collect_data(:linux) do - kernel init_kernel - - so = shell_out("uname -o") - kernel[:os] = so.stdout.split($/)[0] - - modules = Mash.new - so = shell_out("env lsmod") - so.stdout.lines do |line| - if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/ - modules[$1] = { :size => $2, :refcount => $3 } - end - end - - kernel[:modules] = modules - end - - collect_data(:netbsd, :openbsd) do - kernel init_kernel - kernel[:os] = kernel[:name] - - so = shell_out("sysctl kern.securelevel") - kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel:\ (.+)$/ } - - kernel[:modules] = bsd_modules("/usr/bin/modstat") - end - - collect_data(:solaris2) do - kernel init_kernel - - so = shell_out("uname -s") - kernel[:os] = so.stdout.split($/)[0] - - modules = Mash.new - - so = shell_out("modinfo") - # EXAMPLE: - # Id Loadaddr Size Info Rev Module Name - # 6 1180000 4623 1 1 specfs (filesystem for specfs) - module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/ - so.stdout.lines do |line| - if mod = module_description.match(line) - modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5]} - end - end - - kernel[:modules] = modules - end - - collect_data(:windows) do - require 'win32ole' - require 'wmi-lite/wmi' - - WIN32OLE.codepage = WIN32OLE::CP_UTF8 - - wmi = WmiLite::Wmi.new - - kernel Mash.new - - host = wmi.first_of('Win32_OperatingSystem') - kernel[:os_info] = Mash.new - host.wmi_ole_object.properties_.each do |p| - kernel[:os_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase] - end - - kernel[:name] = "#{kernel[:os_info][:caption]}" - kernel[:release] = "#{kernel[:os_info][:version]}" - kernel[:version] = "#{kernel[:os_info][:version]} #{kernel[:os_info][:csd_version]} Build #{kernel[:os_info][:build_number]}" - kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os] - - host = wmi.first_of('Win32_ComputerSystem') - kernel[:cs_info] = Mash.new - host.wmi_ole_object.properties_.each do |p| - kernel[:cs_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase] - end - - kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}") - - kext = Mash.new - pnp_drivers = Mash.new - - drivers = wmi.instances_of('Win32_PnPSignedDriver') - drivers.each do |driver| - pnp_drivers[driver['deviceid']] = Mash.new - driver.wmi_ole_object.properties_.each do |p| - pnp_drivers[driver['deviceid']][p.name.wmi_underscore.to_sym] = driver[p.name.downcase] - end - if driver['devicename'] - kext[driver['devicename']] = pnp_drivers[driver['deviceid']] - kext[driver['devicename']][:version] = pnp_drivers[driver['deviceid']][:driver_version] - kext[driver['devicename']][:date] = pnp_drivers[driver['deviceid']][:driver_date] ? pnp_drivers[driver['deviceid']][:driver_date].to_s[0..7] : nil - end - end - - kernel[:pnp_drivers] = pnp_drivers - kernel[:modules] = kext - end -end +#
+# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Benjamin Black (<nostromo@gmail.com>)
+# Author:: Bryan McLellan (<btm@loftninjas.org>)
+# Author:: Claire McQuin (<claire@opscode.com>)
+# Author:: James Gartrell (<jgartrel@gmail.com>)
+# Copyright:: Copyright (c) 2008, 2009, 2013 Opscode, Inc.
+# Copyright:: Copyright (c) 2009 Bryan McLellan
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+Ohai.plugin(:Kernel) do
+ provides "kernel", "kernel/modules"
+
+ # common initial kernel attribute values
+ def init_kernel
+ kernel Mash.new
+ [["uname -s", :name], ["uname -r", :release],
+ ["uname -v", :version], ["uname -m", :machine]].each do |cmd, property|
+ so = shell_out(cmd)
+ kernel[property] = so.stdout.split($/)[0]
+ end
+ kernel
+ end
+
+ # common *bsd code for collecting modules data
+ def bsd_modules(path)
+ modules = Mash.new
+ so = shell_out("#{Ohai.abs_path(path)}")
+ so.stdout.lines do |line|
+ # 1 7 0xc0400000 97f830 kernel
+ if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/
+ modules[$5] = { :size => $4, :refcount => $2 }
+ end
+ end
+ modules
+ end
+
+ # windows
+ def machine_lookup(sys_type)
+ return "i386" if sys_type.eql?("X86-based PC")
+ return "x86_64" if sys_type.eql?("x64-based PC")
+ sys_type
+ end
+
+ # windows
+ def os_lookup(sys_type)
+ return "Unknown" if sys_type.to_s.eql?("0")
+ return "Other" if sys_type.to_s.eql?("1")
+ return "MSDOS" if sys_type.to_s.eql?("14")
+ return "WIN3x" if sys_type.to_s.eql?("15")
+ return "WIN95" if sys_type.to_s.eql?("16")
+ return "WIN98" if sys_type.to_s.eql?("17")
+ return "WINNT" if sys_type.to_s.eql?("18")
+ return "WINCE" if sys_type.to_s.eql?("19")
+ return nil
+ end
+
+ collect_data(:default) do
+ kernel init_kernel
+ end
+
+ collect_data(:darwin) do
+ kernel init_kernel
+ kernel[:os] = kernel[:name]
+
+ so = shell_out("sysctl -n hw.optional.x86_64")
+ if so.stdout.split($/)[0].to_i == 1
+ kernel[:machine] = 'x86_64'
+ end
+
+ modules = Mash.new
+ so = shell_out("kextstat -k -l")
+ so.stdout.lines do |line|
+ if line =~ /(\d+)\s+(\d+)\s+0x[0-9a-f]+\s+0x([0-9a-f]+)\s+0x[0-9a-f]+\s+([a-zA-Z0-9\.]+) \(([0-9\.]+)\)/
+ modules[$4] = { :version => $5, :size => $3.hex, :index => $1, :refcount => $2 }
+ end
+ end
+
+ kernel[:modules] = modules
+ end
+
+ collect_data(:freebsd) do
+ kernel init_kernel
+ kernel[:os] = kernel[:name]
+
+ so = shell_out("uname -i")
+ kernel[:ident] = so.stdout.split($/)[0]
+ so = shell_out("sysctl kern.securelevel")
+ kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ }
+
+ kernel[:modules] = bsd_modules("/sbin/kldstat")
+ end
+
+ collect_data(:linux) do
+ kernel init_kernel
+
+ so = shell_out("uname -o")
+ kernel[:os] = so.stdout.split($/)[0]
+
+ modules = Mash.new
+ so = shell_out("env lsmod")
+ so.stdout.lines do |line|
+ if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/
+ modules[$1] = { :size => $2, :refcount => $3 }
+ end
+ end
+
+ kernel[:modules] = modules
+ end
+
+ collect_data(:netbsd, :openbsd) do
+ kernel init_kernel
+ kernel[:os] = kernel[:name]
+
+ so = shell_out("sysctl kern.securelevel")
+ kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel:\ (.+)$/ }
+
+ kernel[:modules] = bsd_modules("/usr/bin/modstat")
+ end
+
+ collect_data(:solaris2) do
+ kernel init_kernel
+
+ so = shell_out("uname -s")
+ kernel[:os] = so.stdout.split($/)[0]
+
+ modules = Mash.new
+
+ so = shell_out("modinfo")
+ # EXAMPLE:
+ # Id Loadaddr Size Info Rev Module Name
+ # 6 1180000 4623 1 1 specfs (filesystem for specfs)
+ module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/
+ so.stdout.lines do |line|
+ if mod = module_description.match(line)
+ modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5]}
+ end
+ end
+
+ kernel[:modules] = modules
+ end
+
+ collect_data(:windows) do
+ properties = {}
+ shell_out("systeminfo").stdout.each_line do |line|
+ kv = line.strip.split(/:\s+/, 2)
+ properties[kv[0]] = kv[1]
+ end
+
+ kernel Mash.new
+
+ kernel[:name] = properties["OS Name"]
+ kernel[:release] = properties["OS Version"].split(' ')[0]
+ kernel[:version] = properties["OS Version"]
+ kernel[:os] = "WINNT"
+ kernel[:machine] = "x86_64"
+
+ end
+end
diff --git a/lib/ohai/plugins/powershell.rb b/lib/ohai/plugins/powershell.rb index 9c67e0f6..a857b182 100644 --- a/lib/ohai/plugins/powershell.rb +++ b/lib/ohai/plugins/powershell.rb @@ -1,62 +1,62 @@ -# -# Copyright:: Copyright (c) 2014 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Ohai.plugin(:Powershell) do - provides "languages/powershell" - depends "languages" - - collect_data(:windows) do - powershell = Mash.new - so = shell_out("powershell.exe -NoLogo -NonInteractive -NoProfile -command $PSVersionTable") - # Sample output: - # - # Name Value - # ---- ----- - # PSVersion 4.0 - # WSManStackVersion 3.0 - # SerializationVersion 1.1.0.1 - # CLRVersion 4.0.30319.34014 - # BuildVersion 6.3.9600.16394 - # PSCompatibleVersions {1.0, 2.0, 3.0, 4.0} - # PSRemotingProtocolVersion 2.2 - - if so.exitstatus == 0 - version_info = {} - so.stdout.strip.each_line do |line| - kv = line.strip.split(/\s+/, 2) - version_info[kv[0]] = kv[1] if kv.length == 2 - end - powershell[:version] = version_info['PSVersion'] - powershell[:ws_man_stack_version] = version_info['WSManStackVersion'] - powershell[:serialization_version] = version_info['SerializationVersion'] - powershell[:clr_version] = version_info['CLRVersion'] - powershell[:build_version] = version_info['BuildVersion'] - powershell[:compatible_versions] = parse_compatible_versions(version_info['PSCompatibleVersions']) - powershell[:remoting_protocol_version] = version_info['PSRemotingProtocolVersion'] - languages[:powershell] = powershell if powershell[:version] - end - end - - def parse_compatible_versions(versions_str) - if versions_str - if versions_str.strip.start_with?('{') && versions_str.end_with?('}') - versions = versions_str.gsub(/[{}\s]+/,'').split(',') - versions if versions.length - end - end - end -end +#
+# Copyright:: Copyright (c) 2014 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+Ohai.plugin(:Powershell) do
+ provides "languages/powershell"
+ depends "languages"
+
+ collect_data(:windows) do
+ powershell = Mash.new
+ so = shell_out("powershell.exe -NoLogo -NonInteractive -NoProfile -command $PSVersionTable")
+ # Sample output:
+ #
+ # Name Value
+ # ---- -----
+ # PSVersion 4.0
+ # WSManStackVersion 3.0
+ # SerializationVersion 1.1.0.1
+ # CLRVersion 4.0.30319.34014
+ # BuildVersion 6.3.9600.16394
+ # PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
+ # PSRemotingProtocolVersion 2.2
+
+ if so.exitstatus == 0
+ version_info = {}
+ so.stdout.strip.each_line do |line|
+ kv = line.strip.split(/\s+/, 2)
+ version_info[kv[0]] = kv[1] if kv.length == 2
+ end
+ powershell[:version] = version_info['PSVersion']
+ powershell[:ws_man_stack_version] = version_info['WSManStackVersion']
+ powershell[:serialization_version] = version_info['SerializationVersion']
+ powershell[:clr_version] = version_info['CLRVersion']
+ powershell[:build_version] = version_info['BuildVersion']
+ powershell[:compatible_versions] = parse_compatible_versions(version_info['PSCompatibleVersions'])
+ powershell[:remoting_protocol_version] = version_info['PSRemotingProtocolVersion']
+ languages[:powershell] = powershell if powershell[:version]
+ end
+ end
+
+ def parse_compatible_versions(versions_str)
+ if versions_str
+ if versions_str.strip.start_with?('{') && versions_str.end_with?('}')
+ versions = versions_str.gsub(/[{}\s]+/,'').split(',')
+ versions if versions.length
+ end
+ end
+ end
+end
diff --git a/ohai.gemspec b/ohai.gemspec index 1f85f7b6..eec2fa10 100644 --- a/ohai.gemspec +++ b/ohai.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.add_dependency "mixlib-log" s.add_dependency "mixlib-shellout", "~> 2.0" s.add_dependency "ipaddress" - s.add_dependency "wmi-lite", "~> 1.0" + #s.add_dependency "wmi-lite", "~> 1.0" s.add_dependency "ffi", "~> 1.9" s.add_dependency "rake", "~> 10.1" @@ -32,7 +32,7 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec-mocks", "~> 3.0" s.add_development_dependency "rspec-collection_matchers", "~> 1.0" # s.add_development_dependency "rspec_junit_formatter" - s.add_development_dependency "chef" + #s.add_development_dependency "chef" s.bindir = "bin" s.executables = %w(ohai) |