Class: Fluent::OhaiInput
- Inherits:
-
Input
- Object
- Input
- Fluent::OhaiInput
- Defined in:
- lib/fluent/plugin/ohai_input.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ OhaiInput
constructor
A new instance of OhaiInput.
- #run ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ OhaiInput
Returns a new instance of OhaiInput.
7 8 9 10 11 |
# File 'lib/fluent/plugin/ohai_input.rb', line 7 def initialize require 'open3' require 'json' super end |
Instance Method Details
#configure(conf) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/fluent/plugin/ohai_input.rb', line 18 def configure(conf) super @ohai_cmd = 'ohai' if @ohai_path @ohai_cmd = File.join(@ohai_path, @ohai_cmd) end @interval = Config.time_value(@interval) end |
#run ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fluent/plugin/ohai_input.rb', line 50 def run loop do begin stdout, stderr, status = Open3.capture3(@ohai_cmd) if status.success? # replace hostname in ohai json if user configured it this way json = JSON.parse(stdout) json['hostname'] = @hostname now = Engine.now log.debug "['#{now}'] Emitting ohai data" Engine.emit("#{@tag}", now, json) else log.error "Command '#{@ohai_cmd}' failed with exit code #{status} and message '#{stderr}'" end rescue StandardError => e log.error "ohai-plugin: failed to run ohai." log.error "error: #{e.}" log.error e.backtrace.join("\n") end sleep @interval end end |
#shutdown ⇒ Object
46 47 48 |
# File 'lib/fluent/plugin/ohai_input.rb', line 46 def shutdown Thread.kill(@thread) end |
#start ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fluent/plugin/ohai_input.rb', line 28 def start # check whether 'ohai' is installed begin stdout, stderr, status = Open3.capture3("#{@ohai_cmd} -v") if !status.success? || /Ohai/.match(stdout).nil? log.error "'ohai' executable does not return desired output. Ignoring plugin ..." end log.debug "stdout for 'ohai -v' test: #{stdout}" log.debug "stderr for 'ohai -v' test: #{stderr}" rescue Errno::ENOENT => e log.error "'ohai' executable not found. Ingoring plugin ..." end @thread = Thread.new(&method(:run)) end |