diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ohai/application.rb | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/azure.rb | 10 | ||||
-rw-r--r-- | lib/ohai/plugins/c.rb | 164 | ||||
-rw-r--r-- | lib/ohai/plugins/cloud.rb | 1 | ||||
-rw-r--r-- | lib/ohai/plugins/dmi.rb | 10 | ||||
-rw-r--r-- | lib/ohai/plugins/groovy.rb | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/haskell.rb | 8 | ||||
-rw-r--r-- | lib/ohai/plugins/hostname.rb | 12 | ||||
-rw-r--r-- | lib/ohai/plugins/ip_scopes.rb | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/linux/network.rb | 30 | ||||
-rw-r--r-- | lib/ohai/plugins/linux/sessions.rb | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/linux/virtualization.rb | 18 | ||||
-rw-r--r-- | lib/ohai/plugins/lua.rb | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/network.rb | 20 | ||||
-rw-r--r-- | lib/ohai/plugins/scala.rb | 4 | ||||
-rw-r--r-- | lib/ohai/plugins/solaris2/dmi.rb | 10 | ||||
-rw-r--r-- | lib/ohai/plugins/virtualbox.rb | 39 | ||||
-rw-r--r-- | lib/ohai/plugins/vmware.rb | 4 | ||||
-rw-r--r-- | lib/ohai/system.rb | 4 | ||||
-rw-r--r-- | lib/ohai/util/file_helper.rb | 4 | ||||
-rw-r--r-- | lib/ohai/version.rb | 2 |
21 files changed, 223 insertions, 127 deletions
diff --git a/lib/ohai/application.rb b/lib/ohai/application.rb index 0b0327e7..9f1c400f 100644 --- a/lib/ohai/application.rb +++ b/lib/ohai/application.rb @@ -83,6 +83,8 @@ class Ohai::Application @attributes = nil if @attributes.empty? load_workstation_config + + Ohai::Log.init(Ohai.config[:log_location]) end def run_application diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb index 8bc29964..8d984083 100644 --- a/lib/ohai/plugins/azure.rb +++ b/lib/ohai/plugins/azure.rb @@ -24,14 +24,14 @@ Ohai.plugin(:Azure) do # project for details azure_metadata_from_hints = hint?("azure") if azure_metadata_from_hints - Ohai::Log.debug("azure plugin: azure_metadata_from_hints is present.") + Ohai::Log.debug("Plugin Azure: azure_metadata_from_hints is present.") azure Mash.new azure_metadata_from_hints.each { |k, v| azure[k] = v } elsif has_waagent? || has_dhcp_option_245? - Ohai::Log.debug("azure plugin: No hints present, but system appears to be on azure.") + Ohai::Log.debug("Plugin Azure: No hints present, but system appears to be on azure.") azure Mash.new else - Ohai::Log.debug("azure plugin: No hints present for azure and doesn't appear to be azure.") + Ohai::Log.debug("Plugin Azure: No hints present for azure and doesn't appear to be azure.") false end end @@ -40,7 +40,7 @@ Ohai.plugin(:Azure) do # http://blog.mszcool.com/index.php/2015/04/detecting-if-a-virtual-machine-runs-in-microsoft-azure-linux-windows-to-protect-your-software-when-distributed-via-the-azure-marketplace/ def has_waagent? if File.exist?("/usr/sbin/waagent") || Dir.exist?('C:\WindowsAzure') - Ohai::Log.debug("azure plugin: Found waagent used by MS Azure.") + Ohai::Log.debug("Plugin Azure: Found waagent used by MS Azure.") return true end end @@ -50,7 +50,7 @@ Ohai.plugin(:Azure) do if File.exist?("/var/lib/dhcp/dhclient.eth0.leases") File.open("/var/lib/dhcp/dhclient.eth0.leases").each do |line| if line =~ /unknown-245/ - Ohai::Log.debug("azure plugin: Found unknown-245 DHCP option used by MS Azure.") + Ohai::Log.debug("Plugin Azure: Found unknown-245 DHCP option used by MS Azure.") has_245 = true break end diff --git a/lib/ohai/plugins/c.rb b/lib/ohai/plugins/c.rb index e5107cdc..61b20cc6 100644 --- a/lib/ohai/plugins/c.rb +++ b/lib/ohai/plugins/c.rb @@ -16,11 +16,8 @@ # limitations under the License. # -require "rbconfig" - Ohai.plugin(:C) do provides "languages/c" - depends "languages" def collect(cmd, &block) @@ -28,100 +25,175 @@ Ohai.plugin(:C) do if so.exitstatus == 0 yield(so) else - Ohai::Log.debug("Plugin C '#{cmd}' failed. Skipping data.") + Ohai::Log.debug("Plugin C: '#{cmd}' failed. Skipping data.") end rescue Ohai::Exceptions::Exec - Ohai::Log.debug("Plugin C '#{cmd}' binary could not be found. Skipping data.") + Ohai::Log.debug("Plugin C: '#{cmd}' binary could not be found. Skipping data.") end - collect_data do - c = Mash.new + def xcode_installed? + Ohai::Log.debug("Plugin C: Checking for Xcode Command Line Tools.") + so = shell_out("/usr/bin/xcode-select -p") + if so.exitstatus == 0 + Ohai::Log.debug("Plugin C: Xcode Command Line Tools found.") + return true + else + Ohai::Log.debug("Plugin C: Xcode Command Line Tools not found.") + return false + end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug("Plugin C: xcode-select binary could not be found. Skipping data.") + end - #gcc + def collect_gcc + # gcc + # Sample output on os x: + # Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 + # Apple LLVM version 7.3.0 (clang-703.0.29) + # Target: x86_64-apple-darwin15.4.0 + # Thread model: posix + # InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin + # + # + # Sample output on Linux: + # Using built-in specs. + # COLLECT_GCC=gcc + # COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper + # Target: x86_64-linux-gnu + # Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu + # Thread model: posix + # gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) + gcc = Mash.new collect("gcc -v") do |so| - # Sample output: - # Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 - # Apple LLVM version 7.3.0 (clang-703.0.29) - # Target: x86_64-apple-darwin15.4.0 - # Thread model: posix - # InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin - description = so.stderr.split($/).last - output = description.split - if output.length >= 3 - c[:gcc] = Mash.new - c[:gcc][:version] = output[2] - c[:gcc][:description] = description + so.stderr.each_line do |line| + case line + when /^(.*version\s(\S*).*)/ + gcc[:description] = $1 + gcc[:version] = $2 + when /^Target:\s(.*)/ + gcc[:target] = $1 + when /^Configured with:\s(.*)/ + gcc[:configured_with] = $1 + when /^Thread model:\s(.*)/ + gcc[:thread_model] = $1 + end end end + @c[:gcc] = gcc unless gcc.empty? + end - #glibc + def collect_glibc + # glibc ["/lib/libc.so.6", "/lib64/libc.so.6"].each do |glibc| collect( Ohai.abs_path( glibc )) do |so| description = so.stdout.split($/).first if description =~ /(\d+\.\d+\.?\d*)/ - c[:glibc] = Mash.new - c[:glibc][:version] = $1 - c[:glibc][:description] = description + @c[:glibc] = Mash.new + @c[:glibc][:version] = $1 + @c[:glibc][:description] = description end - end unless c[:glibc] || ::RbConfig::CONFIG["host_os"] =~ /mswin|mingw32|windows/ + end end + end - #ms cl + def check_for_cl + # ms cl collect("cl /?") do |so| description = so.stderr.lines.first.chomp if description =~ /Compiler Version ([\d\.]+)/ - c[:cl] = Mash.new - c[:cl][:version] = $1 - c[:cl][:description] = description + @c[:cl] = Mash.new + @c[:cl][:version] = $1 + @c[:cl][:description] = description end end + end - #ms vs + def check_for_devenv + # ms vs collect("devenv.com /?") do |so| lines = so.stdout.split($/) description = lines[0].length == 0 ? lines[1] : lines[0] if description =~ /Visual Studio Version ([\d\.]+)/ - c[:vs] = Mash.new - c[:vs][:version] = $1.chop - c[:vs][:description] = description + @c[:vs] = Mash.new + @c[:vs][:version] = $1.chop + @c[:vs][:description] = description end end + end - #ibm xlc + def collect_xlc + # ibm xlc begin so = shell_out("xlc -qversion") if so.exitstatus == 0 || (so.exitstatus >> 8) == 249 description = so.stdout.split($/).first if description =~ /V(\d+\.\d+)/ - c[:xlc] = Mash.new - c[:xlc][:version] = $1 - c[:xlc][:description] = description.strip + @c[:xlc] = Mash.new + @c[:xlc][:version] = $1 + @c[:xlc][:description] = description.strip end end rescue Ohai::Exceptions::Exec end + end - #sun pro + def collect_sunpro + # sun pro collect("cc -V -flags") do |so| output = so.stderr.split if so.stderr =~ /^cc: Sun C/ && output.size >= 4 - c[:sunpro] = Mash.new - c[:sunpro][:version] = output[3] - c[:sunpro][:description] = so.stderr.chomp + @c[:sunpro] = Mash.new + @c[:sunpro][:version] = output[3] + @c[:sunpro][:description] = so.stderr.chomp end end + end - #hpux cc + def collect_hpux_cc + # hpux cc collect("what /opt/ansic/bin/cc") do |so| description = so.stdout.split($/).select { |line| line =~ /HP C Compiler/ }.first if description output = description.split - c[:hpcc] = Mash.new - c[:hpcc][:version] = output[1] if output.size >= 1 - c[:hpcc][:description] = description.strip + @c[:hpcc] = Mash.new + @c[:hpcc][:version] = output[1] if output.size >= 1 + @c[:hpcc][:description] = description.strip end end + end + + collect_data(:aix) do + @c = Mash.new + collect_xlc + collect_gcc + languages[:c] = @c unless @c.empty? + end + + collect_data(:darwin) do + @c = Mash.new + collect_gcc if xcode_installed? + languages[:c] = @c unless @c.empty? + end + + collect_data(:windows) do + @c = Mash.new + check_for_cl + check_for_devenv + languages[:c] = @c unless @c.empty? + end + + collect_data(:hpux) do + @c = Mash.new + collect_gcc + collect_hpux_cc + languages[:c] = @c unless @c.empty? + end - languages[:c] = c unless c.empty? + collect_data(:default) do + @c = Mash.new + collect_gcc + collect_glibc + collect_sunpro + languages[:c] = @c unless @c.empty? end end diff --git a/lib/ohai/plugins/cloud.rb b/lib/ohai/plugins/cloud.rb index 23084631..c204f292 100644 --- a/lib/ohai/plugins/cloud.rb +++ b/lib/ohai/plugins/cloud.rb @@ -208,6 +208,7 @@ Ohai.plugin(:Cloud) do # Fill cloud hash with azure values def get_azure_values cloud[:vm_name] = azure["vm_name"] + cloud[:private_ips] << azure["private_ip"] cloud[:public_ips] << azure["public_ip"] cloud[:public_ipv4] = azure["public_ip"] cloud[:public_fqdn] = azure["public_fqdn"] diff --git a/lib/ohai/plugins/dmi.rb b/lib/ohai/plugins/dmi.rb index bcda1c4a..6acf7feb 100644 --- a/lib/ohai/plugins/dmi.rb +++ b/lib/ohai/plugins/dmi.rb @@ -92,14 +92,14 @@ Ohai.plugin(:DMI) do elsif type = type_line.match(line) if dmi_record == nil - Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}") + Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}") next end dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:application_identifier] = type[1] elsif data = data_line.match(line) if dmi_record == nil - Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}") + Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}") next end dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2] @@ -107,11 +107,11 @@ Ohai.plugin(:DMI) do elsif extended_data = extended_data_line.match(line) if dmi_record == nil - Ohai::Log.debug("unexpected extended data line found before header; discarding:\n#{line}") + Ohai::Log.debug("Plugin DMI: unexpected extended data line found before header; discarding:\n#{line}") next end if field == nil - Ohai::Log.debug("unexpected extended data line found outside data section; discarding:\n#{line}") + Ohai::Log.debug("Plugin DMI: unexpected extended data line found outside data section; discarding:\n#{line}") next end # overwrite "raw" value with a new Mash @@ -119,7 +119,7 @@ Ohai.plugin(:DMI) do dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = nil else - Ohai::Log.debug("unrecognized output line; discarding:\n#{line}") + Ohai::Log.debug("Plugin DMI: unrecognized output line; discarding:\n#{line}") end end diff --git a/lib/ohai/plugins/groovy.rb b/lib/ohai/plugins/groovy.rb index 7edbb67c..431a9dab 100644 --- a/lib/ohai/plugins/groovy.rb +++ b/lib/ohai/plugins/groovy.rb @@ -32,7 +32,7 @@ Ohai.plugin(:Groovy) do languages[:groovy] = groovy end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Groovy plugin: Could not shell_out "groovy -v". Skipping plugin') + Ohai::Log.debug('Plugin Groovy: Could not shell_out "groovy -v". Skipping plugin') end end end diff --git a/lib/ohai/plugins/haskell.rb b/lib/ohai/plugins/haskell.rb index d3070e04..07132581 100644 --- a/lib/ohai/plugins/haskell.rb +++ b/lib/ohai/plugins/haskell.rb @@ -39,7 +39,7 @@ Ohai.plugin(:Haskell) do haskell[:ghc][:description] = so.stdout.chomp end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Haskell plugin: Could not shell_out "ghc --version". Skipping data') + Ohai::Log.debug('Plugin Haskell: Could not shell_out "ghc --version". Skipping data') end # Check for ghci @@ -54,7 +54,7 @@ Ohai.plugin(:Haskell) do haskell[:ghci][:description] = so.stdout.chomp end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Haskell plugin: Could not shell_out "ghci --version". Skipping data') + Ohai::Log.debug('Plugin Haskell: Could not shell_out "ghci --version". Skipping data') end # Check for cabal @@ -70,7 +70,7 @@ Ohai.plugin(:Haskell) do haskell[:cabal][:description] = so.stdout.split("\n")[0].chomp end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Haskell plugin: Could not shell_out "cabal --version". Skipping data') + Ohai::Log.debug('Plugin Haskell: Could not shell_out "cabal --version". Skipping data') end # Check for stack @@ -87,7 +87,7 @@ Ohai.plugin(:Haskell) do haskell[:stack][:description] = so.stdout.chomp end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Haskell plugin: Could not shell_out "stack --version". Skipping data') + Ohai::Log.debug('Plugin Haskell: Could not shell_out "stack --version". Skipping data') end languages[:haskell] = haskell unless haskell.empty? diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb index 6b744461..29df8813 100644 --- a/lib/ohai/plugins/hostname.rb +++ b/lib/ohai/plugins/hostname.rb @@ -105,19 +105,19 @@ Ohai.plugin(:Hostname) do # Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely # returns a blank string. WTF. if ourfqdn.nil? || ourfqdn.empty? - Ohai::Log.debug("hostname returned an empty string, retrying once.") + Ohai::Log.debug("Plugin Hostname: hostname returned an empty string, retrying once.") ourfqdn = resolve_fqdn end if ourfqdn.nil? || ourfqdn.empty? - Ohai::Log.debug("hostname returned an empty string twice and will" + + Ohai::Log.debug("Plugin Hostname: hostname returned an empty string twice and will" + "not be set.") else fqdn ourfqdn end rescue Ohai::Log.debug( - "hostname returned an error, probably no domain set") + "Plugin Hostname: hostname returned an error, probably no domain set") end domain collect_domain end @@ -137,20 +137,20 @@ Ohai.plugin(:Hostname) do # 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 " + + Ohai::Log.debug("Plugin Hostname: 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 " + + Ohai::Log.debug("Plugin Hostname: 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") + "Plugin Hostname: hostname --fqdn returned an error, probably no domain set") end domain collect_domain end diff --git a/lib/ohai/plugins/ip_scopes.rb b/lib/ohai/plugins/ip_scopes.rb index e9367762..5ef5474e 100644 --- a/lib/ohai/plugins/ip_scopes.rb +++ b/lib/ohai/plugins/ip_scopes.rb @@ -43,7 +43,7 @@ Ohai.plugin(:IpScopes) do rescue LoadError => e # our favourite gem is not installed. Boohoo. - Ohai::Log.debug("Plugin ip_scopes: cannot load gem, plugin disabled: #{e}") + Ohai::Log.debug("Plugin IpScopes: cannot load gem, plugin disabled: #{e}") end end diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb index 98c95245..5d9c2952 100644 --- a/lib/ohai/plugins/linux/network.rb +++ b/lib/ohai/plugins/linux/network.rb @@ -80,7 +80,7 @@ Ohai.plugin(:Network) do so = shell_out("ip -o -f #{family[:name]} route show table #{default_route_table}") so.stdout.lines do |line| line.strip! - Ohai::Log.debug("Parsing #{line}") + Ohai::Log.debug("Plugin Network: Parsing #{line}") if line =~ /\\/ parts = line.split('\\') route_dest = parts.shift.strip @@ -95,13 +95,13 @@ Ohai.plugin(:Network) do if route_ending =~ /\bdev\s+([^\s]+)\b/ route_int = $1 else - Ohai::Log.debug("Skipping route entry without a device: '#{line}'") + Ohai::Log.debug("Plugin Network: Skipping route entry without a device: '#{line}'") next end route_int = "venet0:0" if is_openvz? && !is_openvz_host? && route_int == "venet0" && iface["venet0:0"] unless iface[route_int] - Ohai::Log.debug("Skipping previously unseen interface from 'ip route show': #{route_int}") + Ohai::Log.debug("Plugin Network: Skipping previously unseen interface from 'ip route show': #{route_int}") next end @@ -118,7 +118,7 @@ Ohai.plugin(:Network) do addr = iface[route_int][:addresses] unless addr.nil? || addr.has_key?(route_entry[:src]) || addr.values.all? { |a| a["family"] != family[:name] } - Ohai::Log.debug("Skipping route entry whose src does not match the interface IP") + Ohai::Log.debug("Plugin Network: Skipping route entry whose src does not match the interface IP") next end end @@ -156,7 +156,7 @@ Ohai.plugin(:Network) do so = shell_out("#{ethtool_binary} #{tmp_int}") so.stdout.lines do |line| line.chomp! - Ohai::Log.debug("Parsing ethtool output: #{line}") + Ohai::Log.debug("Plugin Network: Parsing ethtool output: #{line}") line.lstrip! k, v = line.split(": ") next unless keys.include? k @@ -177,7 +177,7 @@ Ohai.plugin(:Network) do iface.each_key do |tmp_int| next unless iface[tmp_int][:encapsulation] == "Ethernet" so = shell_out("#{ethtool_binary} -g #{tmp_int}") - Ohai::Log.debug("Parsing ethtool output: #{so.stdout}") + Ohai::Log.debug("Plugin Network: Parsing ethtool output: #{so.stdout}") type = nil iface[tmp_int]["ring_params"] = {} so.stdout.lines.each do |line| @@ -462,7 +462,7 @@ Ohai.plugin(:Network) do else default_route_table = configuration(:default_route_table) end - Ohai::Log.debug("default route table is '#{default_route_table}'") + Ohai::Log.debug("Plugin Network: default route table is '#{default_route_table}'") # Match the lead line for an interface from iproute2 # 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP @@ -507,14 +507,14 @@ Ohai.plugin(:Network) do else "default_#{family[:name]}_interface" end - Ohai::Log.debug("Unable to determine '#{attribute_name}' as no default routes were found for that interface family") + Ohai::Log.debug("Plugin Network: Unable to determine '#{attribute_name}' as no default routes were found for that interface family") else network["#{default_prefix}_interface"] = default_route[:dev] - Ohai::Log.debug("#{default_prefix}_interface set to #{default_route[:dev]}") + Ohai::Log.debug("Plugin Network: #{default_prefix}_interface set to #{default_route[:dev]}") # setting gateway to 0.0.0.0 or :: if the default route is a link level one network["#{default_prefix}_gateway"] = default_route[:via] ? default_route[:via] : family[:default_route].chomp("/0") - Ohai::Log.debug("#{default_prefix}_gateway set to #{network["#{default_prefix}_gateway"]}") + Ohai::Log.debug("Plugin Network: #{default_prefix}_gateway set to #{network["#{default_prefix}_gateway"]}") # deduce the default route the user most likely cares about to pick {ip,mac,ip6}address below favored_route = favored_default_route(routes, iface, default_route, family) @@ -527,20 +527,20 @@ Ohai.plugin(:Network) do if family[:name] == "inet" ipaddress favored_route[:src] m = get_mac_for_interface(iface, favored_route[:dev]) - Ohai::Log.debug("Overwriting macaddress #{macaddress} with #{m} from interface #{favored_route[:dev]}") if macaddress + Ohai::Log.debug("Plugin Network: Overwriting macaddress #{macaddress} with #{m} from interface #{favored_route[:dev]}") if macaddress macaddress m elsif family[:name] == "inet6" # this rarely does anything since we rarely have src for ipv6, so this usually falls back on the network plugin ip6address favored_route[:src] if macaddress - Ohai::Log.debug("Not setting macaddress from ipv6 interface #{favored_route[:dev]} because macaddress is already set") + Ohai::Log.debug("Plugin Network: Not setting macaddress from ipv6 interface #{favored_route[:dev]} because macaddress is already set") else macaddress get_mac_for_interface(iface, favored_route[:dev]) end end else - Ohai::Log.debug("the linux/network plugin was unable to deduce the favored default route for family '#{family[:name]}' despite finding a default route, and is not setting ipaddress/ip6address/macaddress. the network plugin may provide fallbacks.") - Ohai::Log.debug("this potential default route was excluded: #{default_route}") + Ohai::Log.debug("Plugin Network: Unable to deduce the favored default route for family '#{family[:name]}' despite finding a default route, and is not setting ipaddress/ip6address/macaddress. the network plugin may provide fallbacks.") + Ohai::Log.debug("Plugin Network: This potential default route was excluded: #{default_route}") end end end # end families.each @@ -550,7 +550,7 @@ Ohai.plugin(:Network) do route_result = so.stdout.split($/).grep( /^0.0.0.0/ )[0].split( /[ \t]+/ ) network[:default_gateway], network[:default_interface] = route_result.values_at(1, 7) rescue Ohai::Exceptions::Exec - Ohai::Log.debug("Unable to determine default interface") + Ohai::Log.debug("Plugin Network: Unable to determine default interface") end so = shell_out("ifconfig -a") diff --git a/lib/ohai/plugins/linux/sessions.rb b/lib/ohai/plugins/linux/sessions.rb index a2a3a09b..7fb2b5ae 100644 --- a/lib/ohai/plugins/linux/sessions.rb +++ b/lib/ohai/plugins/linux/sessions.rb @@ -45,6 +45,8 @@ Ohai.plugin(:Sessions) do sessions[:by_user][user] = [s] end end + else + Ohai::Log.debug("Plugin Sessions: Could not find loginctl. Skipping plugin.") end end end diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb index ec101314..a0409472 100644 --- a/lib/ohai/plugins/linux/virtualization.rb +++ b/lib/ohai/plugins/linux/virtualization.rb @@ -49,6 +49,7 @@ Ohai.plugin(:Virtualization) do # This file should exist on most Xen systems, normally empty for guests if File.exist?("/proc/xen/capabilities") if File.read("/proc/xen/capabilities") =~ /control_d/i + Ohai::Log.debug("Plugin Virtualization: /proc/xen/capabilities contains control_d. Detecting as Xen host") virtualization[:role] = "host" virtualization[:systems][:xen] = "host" end @@ -65,10 +66,12 @@ Ohai.plugin(:Virtualization) do if File.exist?("/proc/modules") modules = File.read("/proc/modules") if modules =~ /^vboxdrv/ + Ohai::Log.debug("Plugin Virtualization: /proc/modules contains vboxdrv. Detecting as vbox host") virtualization[:system] = "vbox" virtualization[:role] = "host" virtualization[:systems][:vbox] = "host" elsif modules =~ /^vboxguest/ + Ohai::Log.debug("Plugin Virtualization: /proc/modules contains vboxguest. Detecting as vbox guest") virtualization[:system] = "vbox" virtualization[:role] = "guest" virtualization[:systems][:vbox] = "guest" @@ -77,6 +80,7 @@ Ohai.plugin(:Virtualization) do # if nova binary is present we're on an openstack host if nova_exists? + Ohai::Log.debug("Plugin Virtualization: nova command exists. Detecting as openstack host") virtualization[:system] = "openstack" virtualization[:role] = "host" virtualization[:systems][:openstack] = "host" @@ -85,6 +89,7 @@ Ohai.plugin(:Virtualization) do # Detect paravirt KVM/QEMU from cpuinfo, report as KVM if File.exist?("/proc/cpuinfo") if File.read("/proc/cpuinfo") =~ /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/ + Ohai::Log.debug("Plugin Virtualization: /proc/cpuinfo lists a KVM paravirt CPU string. Detecting as kvm guest") virtualization[:system] = "kvm" virtualization[:role] = "guest" virtualization[:systems][:kvm] = "guest" @@ -96,9 +101,11 @@ Ohai.plugin(:Virtualization) do if File.exist?("/sys/devices/virtual/misc/kvm") virtualization[:system] = "kvm" if File.read("/proc/cpuinfo") =~ /hypervisor/ + Ohai::Log.debug("Plugin Virtualization: /sys/devices/virtual/misc/kvm present and /proc/cpuinfo lists the hypervisor feature. Detecting as kvm guest") virtualization[:role] = "guest" virtualization[:systems][:kvm] = "guest" else + Ohai::Log.debug("Plugin Virtualization: /sys/devices/virtual/misc/kvm present and /proc/cpuinfo does not list the hypervisor feature. Detecting as kvm host") virtualization[:role] = "host" virtualization[:systems][:kvm] = "host" end @@ -107,10 +114,12 @@ Ohai.plugin(:Virtualization) do # Detect OpenVZ / Virtuozzo. # http://wiki.openvz.org/BC_proc_entries if File.exist?("/proc/bc/0") + Ohai::Log.debug("Plugin Virtualization: /proc/bc/0 exists. Detecting as openvz host") virtualization[:system] = "openvz" virtualization[:role] = "host" virtualization[:systems][:openvz] = "host" elsif File.exist?("/proc/vz") + Ohai::Log.debug("Plugin Virtualization: /proc/vz exists. Detecting as openvz guest") virtualization[:system] = "openvz" virtualization[:role] = "guest" virtualization[:systems][:openvz] = "guest" @@ -119,6 +128,7 @@ Ohai.plugin(:Virtualization) do # Detect Parallels virtual machine from pci devices if File.exist?("/proc/bus/pci/devices") if File.read("/proc/bus/pci/devices") =~ /1ab84000/ + Ohai::Log.debug("Plugin Virtualization: /proc/bus/pci/devices contains '1ab84000' pci device. Detecting as parallels guest") virtualization[:system] = "parallels" virtualization[:role] = "guest" virtualization[:systems][:parallels] = "guest" @@ -129,6 +139,7 @@ Ohai.plugin(:Virtualization) do if File.exist?("/usr/sbin/dmidecode") guest = guest_from_dmi(shell_out("dmidecode").stdout) if guest + Ohai::Log.debug("Plugin Virtualization: dmidecode contains string indicating #{guest} guest") virtualization[:system] = guest virtualization[:role] = "guest" virtualization[:systems][guest.to_sym] = "guest" @@ -142,9 +153,11 @@ Ohai.plugin(:Virtualization) do if vxid && vxid[2] virtualization[:system] = "linux-vserver" if vxid[2] == "0" + Ohai::Log.debug("Plugin Virtualization: /proc/self/status contains 's_context' or 'VxID' with a value of 0. Detecting as linux-vserver host") virtualization[:role] = "host" virtualization[:systems]["linux-vserver"] = "host" else + Ohai::Log.debug("Plugin Virtualization: /proc/self/status contains 's_context' or 'VxID' with a non-0 value. Detecting as linux-vserver guest") virtualization[:role] = "guest" virtualization[:systems]["linux-vserver"] = "guest" end @@ -173,6 +186,7 @@ Ohai.plugin(:Virtualization) do cgroup_content = File.read("/proc/self/cgroup") if cgroup_content =~ %r{^\d+:[^:]+:/(lxc|docker)/.+$} || cgroup_content =~ %r{^\d+:[^:]+:/[^/]+/(lxc|docker)-.+$} + Ohai::Log.debug("Plugin Virtualization: /proc/self/cgroup indicates #{$1} container. Detecting as #{$1} guest") virtualization[:system] = $1 virtualization[:role] = "guest" virtualization[:systems][$1.to_sym] = "guest" @@ -181,6 +195,7 @@ Ohai.plugin(:Virtualization) do # Even so, it is likely we are on an LXC capable host that is not being used as such # So we're cautious here to not overwrite other existing values (OHAI-573) unless virtualization[:system] && virtualization[:role] + Ohai::Log.debug("Plugin Virtualization: /proc/self/cgroup and lxc-version command exist. Detecting as lxc host") virtualization[:system] = "lxc" virtualization[:role] = "host" end @@ -190,6 +205,7 @@ Ohai.plugin(:Virtualization) do virtualization[:systems][:lxc] = "host" end elsif File.exist?("/.dockerenv") || File.exist?("/.dockerinit") + Ohai::Log.debug("Plugin Virtualization: .dockerenv or .dockerinit exist. Detecting as docker guest") virtualization[:system] = "docker" virtualization[:role] = "guest" virtualization[:systems][:docker] = "guest" @@ -198,9 +214,11 @@ Ohai.plugin(:Virtualization) do # Detect LXD # See https://github.com/lxc/lxd/blob/master/doc/dev-lxd.md if File.exist?("/dev/lxd/sock") + Ohai::Log.debug("Plugin Virtualization: /dev/lxd/sock exists. Detecting as lxd guest") virtualization[:system] = "lxd" virtualization[:role] = "guest" elsif File.exist?("/var/lib/lxd/devlxd") + Ohai::Log.debug("Plugin Virtualization: /var/lib/lxd/devlxd exists. Detecting as lxd host") virtualization[:system] = "lxd" virtualization[:role] = "host" end diff --git a/lib/ohai/plugins/lua.rb b/lib/ohai/plugins/lua.rb index 0a6aaeab..8c1ff496 100644 --- a/lib/ohai/plugins/lua.rb +++ b/lib/ohai/plugins/lua.rb @@ -31,7 +31,7 @@ Ohai.plugin(:Lua) do languages[:lua] = lua if lua[:version] end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Lua plugin: Could not shell_out "lua -v". Skipping plugin') + Ohai::Log.debug('Plugin Lua: Could not shell_out "lua -v". Skipping plugin') end end end diff --git a/lib/ohai/plugins/network.rb b/lib/ohai/plugins/network.rb index 1a1175f5..91547d19 100644 --- a/lib/ohai/plugins/network.rb +++ b/lib/ohai/plugins/network.rb @@ -77,13 +77,13 @@ Ohai.plugin(:NetworkAddresses) do v[:iface] == network[int_attr] end if gw_if_ips.empty? - Ohai::Log.warn("[#{family}] no ip address on #{network[int_attr]}") + Ohai::Log.warn("Plugin Network: [#{family}] no ip address on #{network[int_attr]}") elsif network[gw_attr] && network["interfaces"][network[int_attr]] && network["interfaces"][network[int_attr]]["addresses"] if [ "0.0.0.0", "::", /^fe80:/ ].any? { |pat| pat === network[gw_attr] } # link level default route - Ohai::Log.debug("link level default #{family} route, picking ip from #{network[gw_attr]}") + Ohai::Log.debug("Plugin Network: link level default #{family} route, picking ip from #{network[gw_attr]}") r = gw_if_ips.first else # checking network masks @@ -92,9 +92,9 @@ Ohai.plugin(:NetworkAddresses) do end.first if r.nil? r = gw_if_ips.first - Ohai::Log.debug("[#{family}] no ipaddress/mask on #{network[int_attr]} matching the gateway #{network[gw_attr]}, picking #{r[:ipaddress]}") + Ohai::Log.debug("Plugin Network: [#{family}] no ipaddress/mask on #{network[int_attr]} matching the gateway #{network[gw_attr]}, picking #{r[:ipaddress]}") else - Ohai::Log.debug("[#{family}] Using default interface #{network[int_attr]} and default gateway #{network[gw_attr]} to set the default ip to #{r[:ipaddress]}") + Ohai::Log.debug("Plugin Network: [#{family}] Using default interface #{network[int_attr]} and default gateway #{network[gw_attr]} to set the default ip to #{r[:ipaddress]}") end end else @@ -103,7 +103,7 @@ Ohai.plugin(:NetworkAddresses) do end else r = ips.first - Ohai::Log.debug("[#{family}] no default interface, picking the first ipaddress") + Ohai::Log.debug("Plugin Network: [#{family}] no default interface, picking the first ipaddress") end return [ nil, nil ] if r.nil? || r.empty? @@ -149,13 +149,13 @@ Ohai.plugin(:NetworkAddresses) do # don't overwrite attributes if they've already been set by the "#{os}::network" plugin if (family == "inet") && ipaddress.nil? if r["ip"].nil? - Ohai::Log.warn("unable to detect ipaddress") + Ohai::Log.warn("Plugin Network: unable to detect ipaddress") else ipaddress r["ip"] end elsif (family == "inet6") && ip6address.nil? if r["ip"].nil? - Ohai::Log.debug("unable to detect ip6address") + Ohai::Log.debug("Plugin Network: unable to detect ip6address") else ip6address r["ip"] end @@ -165,10 +165,10 @@ Ohai.plugin(:NetworkAddresses) do # otherwise we set macaddress on a first-found basis (and we started with ipv4) if macaddress.nil? if r["mac"] - Ohai::Log.debug("setting macaddress to '#{r["mac"]}' from interface '#{r["iface"]}' for family '#{family}'") + Ohai::Log.debug("Plugin Network: setting macaddress to '#{r["mac"]}' from interface '#{r["iface"]}' for family '#{family}'") macaddress r["mac"] else - Ohai::Log.debug("unable to detect macaddress for family '#{family}'") + Ohai::Log.debug("Plugin Network: unable to detect macaddress for family '#{family}'") end end @@ -177,7 +177,7 @@ Ohai.plugin(:NetworkAddresses) do if results["inet"]["iface"] && results["inet6"]["iface"] && (results["inet"]["iface"] != results["inet6"]["iface"]) - Ohai::Log.debug("ipaddress and ip6address are set from different interfaces (#{results["inet"]["iface"]} & #{results["inet6"]["iface"]})") + Ohai::Log.debug("Plugin Network: ipaddress and ip6address are set from different interfaces (#{results["inet"]["iface"]} & #{results["inet6"]["iface"]})") end end end diff --git a/lib/ohai/plugins/scala.rb b/lib/ohai/plugins/scala.rb index f847a565..ee905a64 100644 --- a/lib/ohai/plugins/scala.rb +++ b/lib/ohai/plugins/scala.rb @@ -28,7 +28,7 @@ Ohai.plugin(:Scala) do scala[:version] = so.stderr.split[4] end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Scala plugin: Could not shell_out "scala -version". Skipping data') + Ohai::Log.debug('Plugin Scala: Could not shell_out "scala -version". Skipping data') end # Check for sbt @@ -40,7 +40,7 @@ Ohai.plugin(:Scala) do scala[:sbt][:version] = so.stdout.split[3] end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Scala plugin: Could not shell_out "sbt --version". Skipping data') + Ohai::Log.debug('Plugin Scala: Could not shell_out "sbt --version". Skipping data') end languages[:scala] = scala unless scala.empty? diff --git a/lib/ohai/plugins/solaris2/dmi.rb b/lib/ohai/plugins/solaris2/dmi.rb index 3f98dbfe..32f935db 100644 --- a/lib/ohai/plugins/solaris2/dmi.rb +++ b/lib/ohai/plugins/solaris2/dmi.rb @@ -153,7 +153,7 @@ Ohai.plugin(:DMI) do elsif data = data_key_value_line.match(line) if dmi_record == nil - Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}") + Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}") next end dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2] @@ -161,7 +161,7 @@ Ohai.plugin(:DMI) do elsif data = data_key_only_line.match(line) if dmi_record == nil - Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}") + Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}") next end dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = "" @@ -169,11 +169,11 @@ Ohai.plugin(:DMI) do elsif extended_data = extended_data_line.match(line) if dmi_record == nil - Ohai::Log.debug("unexpected extended data line found before header; discarding:\n#{line}") + Ohai::Log.debug("Plugin DMI: unexpected extended data line found before header; discarding:\n#{line}") next end if field == nil - Ohai::Log.debug("unexpected extended data line found outside data section; discarding:\n#{line}") + Ohai::Log.debug("Plugin DMI: unexpected extended data line found outside data section; discarding:\n#{line}") next end # overwrite "raw" value with a new Mash @@ -181,7 +181,7 @@ Ohai.plugin(:DMI) do dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = extended_data[2] else - Ohai::Log.debug("unrecognized output line; discarding:\n#{line}") + Ohai::Log.debug("Plugin DMI: unrecognized output line; discarding:\n#{line}") end end diff --git a/lib/ohai/plugins/virtualbox.rb b/lib/ohai/plugins/virtualbox.rb index 435f649f..36558552 100644 --- a/lib/ohai/plugins/virtualbox.rb +++ b/lib/ohai/plugins/virtualbox.rb @@ -20,25 +20,30 @@ Ohai.plugin(:Virtualbox) do provides "virtualbox" collect_data do - so = shell_out("VBoxControl guestproperty enumerate") - if so.exitstatus == 0 - virtualbox Mash.new - virtualbox[:host] = Mash.new - virtualbox[:guest] = Mash.new - so.stdout.lines.each do |line| - case line - when /LanguageID, value: (\S*),/ - virtualbox[:host][:language] = Regexp.last_match(1) - when /VBoxVer, value: (\S*),/ - virtualbox[:host][:version] = Regexp.last_match(1) - when /VBoxRev, value: (\S*),/ - virtualbox[:host][:revision] = Regexp.last_match(1) - when /GuestAdd\/VersionExt, value: (\S*),/ - virtualbox[:guest][:guest_additions_version] = Regexp.last_match(1) - when /GuestAdd\/Revision, value: (\S*),/ - virtualbox[:guest][:guest_additions_revision] = Regexp.last_match(1) + begin + so = shell_out("VBoxControl guestproperty enumerate") + + if so.exitstatus == 0 + virtualbox Mash.new + virtualbox[:host] = Mash.new + virtualbox[:guest] = Mash.new + so.stdout.lines.each do |line| + case line + when /LanguageID, value: (\S*),/ + virtualbox[:host][:language] = Regexp.last_match(1) + when /VBoxVer, value: (\S*),/ + virtualbox[:host][:version] = Regexp.last_match(1) + when /VBoxRev, value: (\S*),/ + virtualbox[:host][:revision] = Regexp.last_match(1) + when /GuestAdd\/VersionExt, value: (\S*),/ + virtualbox[:guest][:guest_additions_version] = Regexp.last_match(1) + when /GuestAdd\/Revision, value: (\S*),/ + virtualbox[:guest][:guest_additions_revision] = Regexp.last_match(1) + end end end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Plugin Virtualbox: Could not execute "VBoxControl guestproperty enumerate". Skipping data') end end end diff --git a/lib/ohai/plugins/vmware.rb b/lib/ohai/plugins/vmware.rb index 53327e41..73b2505d 100644 --- a/lib/ohai/plugins/vmware.rb +++ b/lib/ohai/plugins/vmware.rb @@ -42,7 +42,7 @@ Ohai.plugin(:VMware) do def get_vm_attributes(vmtools_path) if !File.exist?(vmtools_path) - Ohai::Log.debug("#{vmtools_path} not found") + Ohai::Log.debug("Plugin VMware: #{vmtools_path} not found") else vmware Mash.new begin @@ -62,7 +62,7 @@ Ohai.plugin(:VMware) do vmware[param] = from_cmd("#{vmtools_path} #{param} status") end rescue - Ohai::Log.debug("Error while collecting VMware guest attributes") + Ohai::Log.debug("Plugin VMware: Error while collecting VMware guest attributes") end end end diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb index c55383ca..01ee6463 100644 --- a/lib/ohai/system.rb +++ b/lib/ohai/system.rb @@ -220,10 +220,6 @@ module Ohai end def configure_logging - return if Ohai::Log.configured? - - Ohai::Log.init(Ohai.config[:log_location]) - if Ohai.config[:log_level] == :auto Ohai::Log.level = :info else diff --git a/lib/ohai/util/file_helper.rb b/lib/ohai/util/file_helper.rb index 5b08e2db..eb9a12e9 100644 --- a/lib/ohai/util/file_helper.rb +++ b/lib/ohai/util/file_helper.rb @@ -26,11 +26,11 @@ module Ohai paths.each do |path| filename = File.join(path, cmd) if File.executable?(filename) - Ohai::Log.debug("#{self.name} plugin: found #{cmd} at #{filename}") + Ohai::Log.debug("Plugin #{self.name}: found #{cmd} at #{filename}") return filename end end - Ohai::Log.debug("#{self.name} plugin: did not find #{cmd}") + Ohai::Log.debug("Plugin #{self.name}: did not find #{cmd}") false end end diff --git a/lib/ohai/version.rb b/lib/ohai/version.rb index c2a964c5..235639b0 100644 --- a/lib/ohai/version.rb +++ b/lib/ohai/version.rb @@ -18,5 +18,5 @@ module Ohai OHAI_ROOT = File.expand_path(File.dirname(__FILE__)) - VERSION = "8.22.0" + VERSION = "8.23.0" end |