Class: LogStash::Inputs::HTTP_Poller

Inherits:
Base
  • Object
show all
Includes:
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

#register ⇒ Object



42
43
44
45
46
47
48
# File 'lib/logstash/inputs/http_poller.rb', line 42

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

  @logger.info("Registering http_poller Input", :type => @type, :schedule => @schedule, :timeout => @timeout)

  setup_requests!
end

#run(queue) ⇒ Object



121
122
123
# File 'lib/logstash/inputs/http_poller.rb', line 121

def run(queue)
  setup_schedule(queue)
end

#run_once(queue) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/logstash/inputs/http_poller.rb', line 141

def run_once(queue)
  @requests.each do |name, request|
    request_async(queue, name, request)
  end

  client.execute!
end

#setup_schedule(queue) ⇒ Object

Raises:

  • (Logstash::ConfigurationError)


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/logstash/inputs/http_poller.rb', line 125

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)
  #as of v3.0.9, :first_in => :now doesn't work. Use the following workaround instead
  opts = schedule_type == "every" ? { :first_in => 0.01 } : {} 
  @scheduler.send(schedule_type, schedule_value, opts) { run_once(queue) }
  @scheduler.join
end

#stop ⇒ Object



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

def stop
  Stud.stop!(@interval_thread) if @interval_thread
  @scheduler.stop if @scheduler
end