Class: LogStash::Inputs::Ngc
- Inherits:
-
Base
- Object
- Base
- LogStash::Inputs::Ngc
- Defined in:
- lib/logstash/inputs/ngc.rb
Overview
Periodically run a shell command and capture the whole output as an event.
Notes:
-
The ‘script` field of this event will be the python script run.
-
The ‘api_key` field of this event will be the key used to access NGC.
Instance Method Summary collapse
-
#execute(queue) ⇒ Object
Execute a given command.
- #register ⇒ Object
-
#run(queue) ⇒ Object
def register.
-
#stop ⇒ Object
def run.
Instance Method Details
#execute(queue) ⇒ Object
Execute a given command
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/logstash/inputs/ngc.rb', line 72 def execute(queue) start = Time.now output = exit_status = nil begin output, exit_status = run_script() rescue StandardError => e @logger.error("Error while running script", :script => @script, :e => e, :backtrace => e.backtrace) rescue Exception => e @logger.error("Exception while running script", :script => @script, :e => e, :backtrace => e.backtrace) end duration = Time.now - start @logger.debug? && @logger.debug("Command completed", :script => @script, :duration => duration) if output @codec.decode(output) do |decoded| @jwt_token = decoded.get("token") decoded.get("values").each do |val| event = LogStash::Event.new(val) decorate(event) event.set("[@metadata][host]", @hostname) event.set("[@metadata][duration]", duration) event.set("[@metadata][exit_status]", exit_status) queue << event end end end duration end |
#register ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/logstash/inputs/ngc.rb', line 39 def register @logger.info("Registering Exec Input", :type => @type, :script => @script, :interval => @interval, :schedule => @schedule) @hostname = Socket.gethostname @io = nil if (@interval.nil? && @schedule.nil?) || (@interval && @schedule) raise LogStash::ConfigurationError, "jdbc input: either 'interval' or 'schedule' option must be defined." end end |
#run(queue) ⇒ Object
def register
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/logstash/inputs/ngc.rb', line 49 def run(queue) if @schedule @scheduler = Rufus::Scheduler.new(:max_work_threads => 1) @scheduler.cron @schedule do execute(queue) end @scheduler.join else while !stop? duration = execute(queue) wait_until_end_of_interval(duration) end # loop end end |
#stop ⇒ Object
def run
64 65 66 67 |
# File 'lib/logstash/inputs/ngc.rb', line 64 def stop close_io() @scheduler.shutdown(:wait) if @scheduler end |