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.



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

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/fluent/plugin/in_http_pull.rb', line 69

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

  @http_method = :head if @status_only
end

#on_timerObject



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
125
126
127
128
129
130
131
132
133
134
# File 'lib/fluent/plugin/in_http_pull.rb', line 90

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

  begin
    request_options = { method: @http_method, 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



136
137
138
# File 'lib/fluent/plugin/in_http_pull.rb', line 136

def shutdown
  super
end

#startObject



84
85
86
87
88
# File 'lib/fluent/plugin/in_http_pull.rb', line 84

def start
  super

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