Class: LogStash::Inputs::HTTP_Poller

Inherits:
Base
  • Object
show all
Extended by:
PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
Includes:
PluginMixins::ECSCompatibilitySupport::TargetCheck, PluginMixins::EventSupport::EventFactoryAdapter, PluginMixins::HttpClient
Defined in:
lib/logstash/inputs/http_poller.rb

Constant Summary collapse

Schedule_types =
%w(cron every at in)

Instance Method Summary collapse

Instance Method Details

#closeObject



62
63
64
# File 'lib/logstash/inputs/http_poller.rb', line 62

def close
  shutdown_scheduler_and_close_client
end

#registerObject



49
50
51
52
53
54
# File 'lib/logstash/inputs/http_poller.rb', line 49

def register
  @host = Socket.gethostname.force_encoding(Encoding::UTF_8)

  setup_ecs_field!
  setup_requests!
end

#run(queue) ⇒ Object



177
178
179
# File 'lib/logstash/inputs/http_poller.rb', line 177

def run(queue)
  setup_schedule(queue)
end

#run_once(queue) ⇒ Object



196
197
198
199
200
201
202
203
204
205
# File 'lib/logstash/inputs/http_poller.rb', line 196

def run_once(queue)
  @requests.each do |name, request|
    # prevent executing a scheduler kick after the plugin has been stop-ed
    # this could easily happen as the scheduler shutdown is not immediate
    return if stop?
    request_async(queue, name, request)
  end

  client.execute! unless stop?
end

#setup_schedule(queue) ⇒ Object

Raises:

  • (Logstash::ConfigurationError)


181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/logstash/inputs/http_poller.rb', line 181

def setup_schedule(queue)
  #schedule hash must contain exactly one of the allowed keys
  msg_invalid_schedule = "Invalid config. schedule hash must contain " +
    "exactly one of the following keys - cron, at, every or in"
  raise Logstash::ConfigurationError, msg_invalid_schedule if @schedule.keys.length != 1
  schedule_type = @schedule.keys.first
  schedule_value = @schedule[schedule_type]
  raise LogStash::ConfigurationError, msg_invalid_schedule unless Schedule_types.include?(schedule_type)

  @scheduler = Rufus::Scheduler.new(:max_work_threads => 1)
  opts = schedule_type == "every" ? { :first_in => 0.01 } : {} 
  @scheduler.send(schedule_type, schedule_value, opts) { run_once(queue) }
  @scheduler.thread.join # due newer rufus (3.8) doing a blocking operation on scheduler.join
end

#stopObject



57
58
59
# File 'lib/logstash/inputs/http_poller.rb', line 57

def stop
  shutdown_scheduler_and_close_client(:wait)
end