Class: Fluent::Plugin::HttpPullInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_http_pull.rb

Instance Method Summary collapse

Constructor Details

#initializeHttpPullInput

Returns a new instance of HttpPullInput.



26
27
28
# File 'lib/fluent/plugin/in_http_pull.rb', line 26

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fluent/plugin/in_http_pull.rb', line 61

def configure(conf)
  compat_parameters_convert(conf, :parser)
  super

  @parser = parser_create unless @status_only
  @_request_headers = @request_headers.map do |section|
    header = section["header"]
    value = section["value"]

    [header.to_sym, value]
  end.to_h
end

#on_timerObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/fluent/plugin/in_http_pull.rb', line 80

def on_timer
  record = { "url" => @url }

  begin
    request_options = { method: :get, url: @url, timeout: @timeout }

    request_options[:proxy] = @proxy if @proxy
    request_options[:user] = @user if @user
    request_options[:password] = @password if @password
    request_options[:headers] = @_request_headers unless @request_headers.empty?

    res = RestClient::Request.execute request_options

    record["status"] = res.code
    record["body"] = res.body

    record["header"] = {} unless @response_headers.empty?
    @response_headers.each do |section|
      name = section["header"]
      symbolize_name = name.downcase.gsub(/-/, '_').to_sym

      record["header"][name] = res.headers[symbolize_name]
    end
  rescue StandardError => err
    if err.respond_to? :http_code
      record["status"] = err.http_code || 0
    else
      record["status"] = 0
    end

    record["error"] = err.message
  end

  record_time = Engine.now

  if !@status_only && record["body"] != nil
    @parser.parse(record["body"]) do |time, message|
      record["message"] = message
      record_time = time
    end
  end

  record.delete("body")
  router.emit(@tag, record_time, record)
end

#shutdownObject



126
127
128
# File 'lib/fluent/plugin/in_http_pull.rb', line 126

def shutdown
  super
end

#startObject



74
75
76
77
78
# File 'lib/fluent/plugin/in_http_pull.rb', line 74

def start
  super

  timer_execute(:in_http_pull, @interval, &method(:on_timer))
end