diff options
-rw-r--r-- | lib/ohai/application.rb | 22 | ||||
-rw-r--r-- | lib/ohai/dsl/plugin/versionvii.rb | 4 | ||||
-rw-r--r-- | lib/ohai/plugins/aix/kernel.rb | 2 | ||||
-rw-r--r-- | lib/ohai/system.rb | 19 |
4 files changed, 46 insertions, 1 deletions
diff --git a/lib/ohai/application.rb b/lib/ohai/application.rb index b1455cab..12acd452 100644 --- a/lib/ohai/application.rb +++ b/lib/ohai/application.rb @@ -56,6 +56,12 @@ class Ohai::Application description: "Set the log file location, defaults to STDOUT - recommended for daemonizing", proc: nil + option :print_plugins, + short: "-p", + long: "--print-plugins", + description: "Print information on each available plugin", + boolean: true + option :help, short: "-h", long: "--help", @@ -79,7 +85,11 @@ class Ohai::Application def run elapsed = Benchmark.measure do configure_ohai - run_application + if config[:print_plugins] + run_print_plugins + else + run_application + end end Ohai::Log.debug("Ohai took #{elapsed.total} total seconds to run.") end @@ -88,6 +98,8 @@ class Ohai::Application # # @return void def configure_ohai + # @attributes receives all the attribute names passed on the CLI and we use + # it later to pass in the list of attributes to filter @attributes = parse_options @attributes = nil if @attributes.empty? @@ -115,6 +127,14 @@ class Ohai::Application end end + def run_print_plugins + config[:invoked_from_cli] = true + config[:logger] = Ohai::Log.with_child + ohai = Ohai::System.new(config) + require 'pry'; binding.pry + ohai.list_plugins(@attributes) + end + class << self # Log a fatal error message to both STDERR and the Logger, exit the application # @param msg [String] the message to log diff --git a/lib/ohai/dsl/plugin/versionvii.rb b/lib/ohai/dsl/plugin/versionvii.rb index 3a8c904e..dc7d5576 100644 --- a/lib/ohai/dsl/plugin/versionvii.rb +++ b/lib/ohai/dsl/plugin/versionvii.rb @@ -101,6 +101,10 @@ module Ohai !!@optional end + def self.description(text) + @description = text + end + # define data collection methodology per platform # # @param platform [Symbol] the platform to collect data for diff --git a/lib/ohai/plugins/aix/kernel.rb b/lib/ohai/plugins/aix/kernel.rb index 39f18c5e..0af4409d 100644 --- a/lib/ohai/plugins/aix/kernel.rb +++ b/lib/ohai/plugins/aix/kernel.rb @@ -20,6 +20,8 @@ Ohai.plugin(:Kernel) do provides "kernel", "kernel/modules" + description "This gathers data on the kernel such as its version and modules" + collect_data(:aix) do kernel Mash.new diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb index 6c920408..6d3c3328 100644 --- a/lib/ohai/system.rb +++ b/lib/ohai/system.rb @@ -130,6 +130,25 @@ module Ohai freeze_strings! end + def list_plugins(attribute_filter = nil) + reset_system + load_plugins + plugins = {} + begin + @provides_map.all_plugins(attribute_filter).each do |plugin| + #require 'pry';binding.pry + plugins[plugin.name] = {} + plugins[plugin.name][:optional] = plugin.optional? + plugins[plugin.name][:dependencies] = plugin.dependencies + plugins[plugin.name][:description] = plugin.description + end + rescue Ohai::Exceptions::AttributeNotFound, Ohai::Exceptions::DependencyCycle => e + logger.error("Encountered error while running plugins: #{e.inspect}") + raise + end + plugins + end + def run_additional_plugins(plugin_path) @loader.load_additional(plugin_path).each do |plugin| logger.trace "Running plugin #{plugin}" |