class Fluent::Plugin::HttpPullInput
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_http_pull.rb, line 25 def initialize super end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_http_pull.rb, line 87 def configure(conf) compat_parameters_convert(conf, :parser) super @parser = parser_create unless @status_only @_request_headers = { "Content-Type" => "application/x-www-form-urlencoded", "User-Agent" => @agent }.merge(@request_headers.map do |section| header = section["header"] value = section["value"] [header.to_sym, value] end.to_h) @http_method = :head if @status_only end
on_timer()
click to toggle source
# File lib/fluent/plugin/in_http_pull.rb, line 111 def on_timer body = nil record = nil begin res = RestClient::Request.execute request_options record, body = get_record(res) rescue StandardError => err record = { "url" => @url, "error" => err.message } if err.respond_to? :http_code record["status"] = err.http_code || 0 else record["status"] = 0 end end record_time = Engine.now record = parse(record, body) router.emit(@tag, record_time, record) end
shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_http_pull.rb, line 133 def shutdown super end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_http_pull.rb, line 105 def start super timer_execute(:in_http_pull, @interval, &method(:on_timer)) end
Private Instance Methods
get_record(response)
click to toggle source
# File lib/fluent/plugin/in_http_pull.rb, line 154 def get_record(response) body = response.body record = { "url" => @url, "status" => response.code } record["header"] = {} unless @response_headers.empty? @response_headers.each do |section| name = section["header"] symbolize_name = name.downcase.gsub(/-/, '_').to_sym record["header"][name] = response.headers[symbolize_name] end return record, body end
parse(record, body)
click to toggle source
# File lib/fluent/plugin/in_http_pull.rb, line 168 def parse(record, body) if !@status_only && body != nil @parser.parse(body) do |time, message| record["message"] = message record_time = time end end return record end
request_options()
click to toggle source
# File lib/fluent/plugin/in_http_pull.rb, line 138 def request_options options = { method: @http_method, url: @url, timeout: @timeout, headers: @_request_headers } options[:proxy] = @proxy if @proxy options[:user] = @user if @user options[:password] = @password if @password options[:verify_ssl] = @verify_ssl if @verify_ssl and @ca_path and @ca_file options[:ssl_ca_path] = @ca_path options[:ssl_ca_file] = @ca_file end return options end