diff options
Diffstat (limited to 'lib/ohai')
-rw-r--r-- | lib/ohai/plugins/elixir.rb | 26 | ||||
-rw-r--r-- | lib/ohai/plugins/filesystem.rb | 20 | ||||
-rw-r--r-- | lib/ohai/plugins/go.rb | 22 | ||||
-rw-r--r-- | lib/ohai/plugins/groovy.rb | 24 | ||||
-rw-r--r-- | lib/ohai/plugins/lua.rb | 26 | ||||
-rw-r--r-- | lib/ohai/plugins/mono.rb | 46 | ||||
-rw-r--r-- | lib/ohai/plugins/nodejs.rb | 26 | ||||
-rw-r--r-- | lib/ohai/plugins/perl.rb | 34 | ||||
-rw-r--r-- | lib/ohai/plugins/php.rb | 44 | ||||
-rw-r--r-- | lib/ohai/plugins/powershell.rb | 60 | ||||
-rw-r--r-- | lib/ohai/plugins/python.rb | 30 | ||||
-rw-r--r-- | lib/ohai/plugins/rust.rb | 22 | ||||
-rw-r--r-- | lib/ohai/plugins/virtualbox.rb | 42 |
13 files changed, 211 insertions, 211 deletions
diff --git a/lib/ohai/plugins/elixir.rb b/lib/ohai/plugins/elixir.rb index 73bd60a9..233a9b9d 100644 --- a/lib/ohai/plugins/elixir.rb +++ b/lib/ohai/plugins/elixir.rb @@ -18,19 +18,19 @@ Ohai.plugin(:Elixir) do depends "languages" collect_data do - begin - so = shell_out("elixir -v") - # Sample output: - # Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace] - # - # Elixir 1.2.4 - if so.exitstatus == 0 && so.stdout =~ /^Elixir (\S*)/ - elixir = Mash.new - elixir[:version] = $1 - languages[:elixir] = elixir - end - rescue Ohai::Exceptions::Exec - logger.trace('Plugin Elixir: Could not shell_out "elixir -v". Skipping plugin') + + so = shell_out("elixir -v") + # Sample output: + # Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace] + # + # Elixir 1.2.4 + if so.exitstatus == 0 && so.stdout =~ /^Elixir (\S*)/ + elixir = Mash.new + elixir[:version] = $1 + languages[:elixir] = elixir end + rescue Ohai::Exceptions::Exec + logger.trace('Plugin Elixir: Could not shell_out "elixir -v". Skipping plugin') + end end diff --git a/lib/ohai/plugins/filesystem.rb b/lib/ohai/plugins/filesystem.rb index 1a823f8b..76ab8ed9 100644 --- a/lib/ohai/plugins/filesystem.rb +++ b/lib/ohai/plugins/filesystem.rb @@ -250,16 +250,16 @@ Ohai.plugin(:Filesystem) do # we have to non-block read dev files. Ew. f = File.open("/proc/mounts") loop do - begin - data = f.read_nonblock(4096) - mounts << data - # We should just catch EOFError, but the kernel had a period of - # bugginess with reading virtual files, so we're being extra - # cautious here, catching all exceptions, and then we'll read - # whatever data we might have - rescue Exception - break - end + + data = f.read_nonblock(4096) + mounts << data + # We should just catch EOFError, but the kernel had a period of + # bugginess with reading virtual files, so we're being extra + # cautious here, catching all exceptions, and then we'll read + # whatever data we might have + rescue Exception + break + end f.close mounts.each_line do |line| diff --git a/lib/ohai/plugins/go.rb b/lib/ohai/plugins/go.rb index 7cfa132d..65eb23c8 100644 --- a/lib/ohai/plugins/go.rb +++ b/lib/ohai/plugins/go.rb @@ -18,17 +18,17 @@ Ohai.plugin(:Go) do depends "languages" collect_data do - begin - so = shell_out("go version") - # Sample output: - # go version go1.6.1 darwin/amd64 - if so.exitstatus == 0 && so.stdout =~ /go(\S+)/ - go = Mash.new - go[:version] = $1 - languages[:go] = go - end - rescue Ohai::Exceptions::Exec - logger.trace('Plugin Go: Could not shell_out "go version". Skipping plugin') + + so = shell_out("go version") + # Sample output: + # go version go1.6.1 darwin/amd64 + if so.exitstatus == 0 && so.stdout =~ /go(\S+)/ + go = Mash.new + go[:version] = $1 + languages[:go] = go end + rescue Ohai::Exceptions::Exec + logger.trace('Plugin Go: Could not shell_out "go version". Skipping plugin') + end end diff --git a/lib/ohai/plugins/groovy.rb b/lib/ohai/plugins/groovy.rb index db49be6d..7b4134ff 100644 --- a/lib/ohai/plugins/groovy.rb +++ b/lib/ohai/plugins/groovy.rb @@ -21,18 +21,18 @@ Ohai.plugin(:Groovy) do depends "languages" collect_data do - begin - so = shell_out("groovy -v") - # Sample output: - # Groovy Version: 2.4.6 JVM: 1.8.0_60 Vendor: Oracle Corporation OS: Mac OS X - if so.exitstatus == 0 && so.stdout =~ /Groovy Version: (\S+).*JVM: (\S+)/ - groovy = Mash.new - groovy[:version] = $1 - groovy[:jvm] = $2 - languages[:groovy] = groovy - end - rescue Ohai::Exceptions::Exec - logger.trace('Plugin Groovy: Could not shell_out "groovy -v". Skipping plugin') + + so = shell_out("groovy -v") + # Sample output: + # Groovy Version: 2.4.6 JVM: 1.8.0_60 Vendor: Oracle Corporation OS: Mac OS X + if so.exitstatus == 0 && so.stdout =~ /Groovy Version: (\S+).*JVM: (\S+)/ + groovy = Mash.new + groovy[:version] = $1 + groovy[:jvm] = $2 + languages[:groovy] = groovy end + rescue Ohai::Exceptions::Exec + logger.trace('Plugin Groovy: Could not shell_out "groovy -v". Skipping plugin') + end end diff --git a/lib/ohai/plugins/lua.rb b/lib/ohai/plugins/lua.rb index 0e984f16..94379ba0 100644 --- a/lib/ohai/plugins/lua.rb +++ b/lib/ohai/plugins/lua.rb @@ -21,19 +21,19 @@ Ohai.plugin(:Lua) do depends "languages" collect_data do - begin - so = shell_out("lua -v") - # Sample output: - # Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio - if so.exitstatus == 0 - lua = Mash.new - # at some point in lua's history they went from outputting the version - # on stderr to doing it on stdout. This handles old / new versions - lua[:version] = so.stdout.empty? ? so.stderr.split[1] : so.stdout.split[1] - languages[:lua] = lua if lua[:version] - end - rescue Ohai::Exceptions::Exec - logger.trace('Plugin Lua: Could not shell_out "lua -v". Skipping plugin') + + so = shell_out("lua -v") + # Sample output: + # Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio + if so.exitstatus == 0 + lua = Mash.new + # at some point in lua's history they went from outputting the version + # on stderr to doing it on stdout. This handles old / new versions + lua[:version] = so.stdout.empty? ? so.stderr.split[1] : so.stdout.split[1] + languages[:lua] = lua if lua[:version] end + rescue Ohai::Exceptions::Exec + logger.trace('Plugin Lua: Could not shell_out "lua -v". Skipping plugin') + end end diff --git a/lib/ohai/plugins/mono.rb b/lib/ohai/plugins/mono.rb index 48d64e93..e7b2483b 100644 --- a/lib/ohai/plugins/mono.rb +++ b/lib/ohai/plugins/mono.rb @@ -21,30 +21,30 @@ Ohai.plugin(:Mono) do depends "languages" collect_data do - begin - so = shell_out("mono -V") - # Sample output: - # Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 30 13:57:48 PDT 2016) - # Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com - # TLS: normal - # SIGSEGV: altstack - # Notification: kqueue - # Architecture: amd64 - # Disabled: none - # Misc: softtrace - # LLVM: supported, not enabled. - # GC: sgen - if so.exitstatus == 0 - mono = Mash.new - output = so.stdout.split - mono[:version] = output[4] unless output[4].nil? - if output.length >= 12 - mono[:builddate] = "%s %s %s %s %s %s" % [output[7], output[8], output[9], output[10], output[11], output[12].delete!(")")] - end - languages[:mono] = mono unless mono.empty? + + so = shell_out("mono -V") + # Sample output: + # Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 30 13:57:48 PDT 2016) + # Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com + # TLS: normal + # SIGSEGV: altstack + # Notification: kqueue + # Architecture: amd64 + # Disabled: none + # Misc: softtrace + # LLVM: supported, not enabled. + # GC: sgen + if so.exitstatus == 0 + mono = Mash.new + output = so.stdout.split + mono[:version] = output[4] unless output[4].nil? + if output.length >= 12 + mono[:builddate] = "%s %s %s %s %s %s" % [output[7], output[8], output[9], output[10], output[11], output[12].delete!(")")] end - rescue Ohai::Exceptions::Exec - logger.trace('Plugin Mono: Could not shell_out "mono -V". Skipping plugin') + languages[:mono] = mono unless mono.empty? end + rescue Ohai::Exceptions::Exec + logger.trace('Plugin Mono: Could not shell_out "mono -V". Skipping plugin') + end end diff --git a/lib/ohai/plugins/nodejs.rb b/lib/ohai/plugins/nodejs.rb index 684e6b47..a24a0454 100644 --- a/lib/ohai/plugins/nodejs.rb +++ b/lib/ohai/plugins/nodejs.rb @@ -21,20 +21,20 @@ Ohai.plugin(:Nodejs) do depends "languages" collect_data do - begin - so = shell_out("node -v") - # Sample output: - # v5.10.1 - if so.exitstatus == 0 - nodejs = Mash.new - output = so.stdout.split - if output.length >= 1 - nodejs[:version] = output[0][1..output[0].length] - end - languages[:nodejs] = nodejs if nodejs[:version] + + so = shell_out("node -v") + # Sample output: + # v5.10.1 + if so.exitstatus == 0 + nodejs = Mash.new + output = so.stdout.split + if output.length >= 1 + nodejs[:version] = output[0][1..output[0].length] end - rescue Ohai::Exceptions::Exec - logger.trace('Plugin Nodejs: Could not shell_out "node -v". Skipping plugin') + languages[:nodejs] = nodejs if nodejs[:version] end + rescue Ohai::Exceptions::Exec + logger.trace('Plugin Nodejs: Could not shell_out "node -v". Skipping plugin') + end end diff --git a/lib/ohai/plugins/perl.rb b/lib/ohai/plugins/perl.rb index f86dc026..b3594148 100644 --- a/lib/ohai/plugins/perl.rb +++ b/lib/ohai/plugins/perl.rb @@ -21,25 +21,25 @@ Ohai.plugin(:Perl) do depends "languages" collect_data do - begin - so = shell_out("perl -V:version -V:archname") - # Sample output: - # version='5.18.2'; - # archname='darwin-thread-multi-2level'; - if so.exitstatus == 0 - perl = Mash.new - so.stdout.split(/\r?\n/).each do |line| - case line - when /^version=\'(.+)\';$/ - perl[:version] = $1 - when /^archname=\'(.+)\';$/ - perl[:archname] = $1 - end + + so = shell_out("perl -V:version -V:archname") + # Sample output: + # version='5.18.2'; + # archname='darwin-thread-multi-2level'; + if so.exitstatus == 0 + perl = Mash.new + so.stdout.split(/\r?\n/).each do |line| + case line + when /^version=\'(.+)\';$/ + perl[:version] = $1 + when /^archname=\'(.+)\';$/ + perl[:archname] = $1 end - languages[:perl] = perl unless perl.empty? end - rescue Ohai::Exceptions::Exec - logger.trace('Plugin Perl: Could not shell_out "perl -V:version -V:archname". Skipping plugin') + languages[:perl] = perl unless perl.empty? end + rescue Ohai::Exceptions::Exec + logger.trace('Plugin Perl: Could not shell_out "perl -V:version -V:archname". Skipping plugin') + end end diff --git a/lib/ohai/plugins/php.rb b/lib/ohai/plugins/php.rb index d9efacd6..f9ecf917 100644 --- a/lib/ohai/plugins/php.rb +++ b/lib/ohai/plugins/php.rb @@ -23,30 +23,30 @@ Ohai.plugin(:PHP) do depends "languages" collect_data do - begin - so = shell_out("php -v") - # Sample output: - # PHP 5.5.31 (cli) (built: Feb 20 2016 20:33:10) - # Copyright (c) 1997-2015 The PHP Group - # Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies - if so.exitstatus == 0 - php = Mash.new - so.stdout.each_line do |line| - case line - when /^PHP (\S+)(?:.*built: ([^)]+))?/ - php[:version] = $1 - php[:builddate] = $2 - when /Zend Engine v([^\s]+),/ - php[:zend_engine_version] = $1 - when /Zend OPcache v([^\s]+),/ - php[:zend_opcache_version] = $1 - end - end - languages[:php] = php unless php.empty? + so = shell_out("php -v") + # Sample output: + # PHP 5.5.31 (cli) (built: Feb 20 2016 20:33:10) + # Copyright (c) 1997-2015 The PHP Group + # Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies + if so.exitstatus == 0 + php = Mash.new + so.stdout.each_line do |line| + case line + when /^PHP (\S+)(?:.*built: ([^)]+))?/ + php[:version] = $1 + php[:builddate] = $2 + when /Zend Engine v([^\s]+),/ + php[:zend_engine_version] = $1 + when /Zend OPcache v([^\s]+),/ + php[:zend_opcache_version] = $1 + end end - rescue Ohai::Exceptions::Exec - logger.trace('Plugin Php: Could not shell_out "php -v". Skipping plugin') + + languages[:php] = php unless php.empty? end + rescue Ohai::Exceptions::Exec + logger.trace('Plugin Php: Could not shell_out "php -v". Skipping plugin') + end end diff --git a/lib/ohai/plugins/powershell.rb b/lib/ohai/plugins/powershell.rb index 52dc8f6f..728e5b11 100644 --- a/lib/ohai/plugins/powershell.rb +++ b/lib/ohai/plugins/powershell.rb @@ -20,39 +20,39 @@ Ohai.plugin(:Powershell) do depends "languages" collect_data(:windows) do - begin - 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 - powershell = Mash.new - 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 - powershell[:remoting_protocol_version] = version_info["PSRemotingProtocolVersion"] - languages[:powershell] = powershell unless powershell.empty? + 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 + powershell = Mash.new + 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 - rescue Ohai::Exceptions::Exec - logger.trace('Plugin Powershell: Could not shell_out "powershell.exe -NoLogo -NonInteractive -NoProfile -command $PSVersionTable". Skipping plugin') + 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 + powershell[:remoting_protocol_version] = version_info["PSRemotingProtocolVersion"] + languages[:powershell] = powershell unless powershell.empty? end + rescue Ohai::Exceptions::Exec + logger.trace('Plugin Powershell: Could not shell_out "powershell.exe -NoLogo -NonInteractive -NoProfile -command $PSVersionTable". Skipping plugin') + end def version_command diff --git a/lib/ohai/plugins/python.rb b/lib/ohai/plugins/python.rb index 9aea8430..55601f79 100644 --- a/lib/ohai/plugins/python.rb +++ b/lib/ohai/plugins/python.rb @@ -22,22 +22,22 @@ Ohai.plugin(:Python) do depends "languages" collect_data do - begin - so = shell_out("python -c \"import sys; print (sys.version)\"") - # Sample output: - # 2.7.11 (default, Dec 26 2015, 17:47:53) - # [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] - if so.exitstatus == 0 - python = Mash.new - output = so.stdout.split - python[:version] = output[0] - if output.length >= 6 - python[:builddate] = "%s %s %s %s" % [output[2], output[3], output[4], output[5].delete!(")")] - end - languages[:python] = python unless python.empty? + + so = shell_out("python -c \"import sys; print (sys.version)\"") + # Sample output: + # 2.7.11 (default, Dec 26 2015, 17:47:53) + # [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] + if so.exitstatus == 0 + python = Mash.new + output = so.stdout.split + python[:version] = output[0] + if output.length >= 6 + python[:builddate] = "%s %s %s %s" % [output[2], output[3], output[4], output[5].delete!(")")] end - rescue Ohai::Exceptions::Exec - logger.trace('Plugin Python: Could not shell_out "python -c "import sys; print (sys.version)"". Skipping plugin') + languages[:python] = python unless python.empty? end + rescue Ohai::Exceptions::Exec + logger.trace('Plugin Python: Could not shell_out "python -c "import sys; print (sys.version)"". Skipping plugin') + end end diff --git a/lib/ohai/plugins/rust.rb b/lib/ohai/plugins/rust.rb index ee62af17..6cd70d78 100644 --- a/lib/ohai/plugins/rust.rb +++ b/lib/ohai/plugins/rust.rb @@ -18,17 +18,17 @@ Ohai.plugin(:Rust) do depends "languages" collect_data do - begin - so = shell_out("rustc --version") - # Sample output: - # rustc 1.7.0 - if so.exitstatus == 0 - rust = Mash.new - rust[:version] = so.stdout.split[1] - languages[:rust] = rust if rust[:version] - end - rescue Ohai::Exceptions::Exec - logger.trace('Plugin Rust: Could not shell_out "rustc --version". Skipping plugin') + + so = shell_out("rustc --version") + # Sample output: + # rustc 1.7.0 + if so.exitstatus == 0 + rust = Mash.new + rust[:version] = so.stdout.split[1] + languages[:rust] = rust if rust[:version] end + rescue Ohai::Exceptions::Exec + logger.trace('Plugin Rust: Could not shell_out "rustc --version". Skipping plugin') + end end diff --git a/lib/ohai/plugins/virtualbox.rb b/lib/ohai/plugins/virtualbox.rb index b93d3e2a..80e73c86 100644 --- a/lib/ohai/plugins/virtualbox.rb +++ b/lib/ohai/plugins/virtualbox.rb @@ -20,30 +20,30 @@ Ohai.plugin(:Virtualbox) do provides "virtualbox" collect_data do - 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 + 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 - rescue Ohai::Exceptions::Exec - logger.trace('Plugin Virtualbox: Could not execute "VBoxControl guestproperty enumerate". Skipping data') end + rescue Ohai::Exceptions::Exec + logger.trace('Plugin Virtualbox: Could not execute "VBoxControl guestproperty enumerate". Skipping data') + end end |