Skip to content

Commit 8bc363a

Browse files
add support of request method
1 parent 5595b4f commit 8bc363a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/fluent/plugin/in_http_pull.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module Fluent
2020
module Plugin
2121
class HttpPullInput < Fluent::Plugin::Input
2222
Fluent::Plugin.register_input("http_pull", self)
23-
2423
helpers :timer, :parser, :compat_parameters
2524

2625
def initialize
@@ -29,19 +28,28 @@ def initialize
2928

3029
desc 'The tag of the event.'
3130
config_param :tag, :string
31+
3232
desc 'The url of monitoring target'
3333
config_param :url, :string
34+
3435
desc 'The interval time between periodic request'
3536
config_param :interval, :time
37+
3638
desc 'status_only'
3739
config_param :status_only, :bool, default: false
38-
desc 'The timeout stime of each request'
40+
41+
desc 'The http method for each request'
42+
config_param :http_method, :enum, list: [:get, :post, :delete], default: :get
43+
44+
desc 'The timeout second of each request'
3945
config_param :timeout, :time, default: 10
46+
4047
desc 'The HTTP proxy URL to use for each requests'
4148
config_param :proxy, :string, default: nil
4249

4350
desc 'user of basic auth'
4451
config_param :user, :string, default: nil
52+
4553
desc 'password of basic auth'
4654
config_param :password, :string, default: nil
4755

@@ -69,6 +77,8 @@ def configure(conf)
6977

7078
[header.to_sym, value]
7179
end.to_h
80+
81+
@http_method = :head if @status_only
7282
end
7383

7484
def start
@@ -81,7 +91,7 @@ def on_timer
8191
record = { "url" => @url }
8292

8393
begin
84-
request_options = { method: :get, url: @url, timeout: @timeout }
94+
request_options = { method: @http_method, url: @url, timeout: @timeout }
8595

8696
request_options[:proxy] = @proxy if @proxy
8797
request_options[:user] = @user if @user

test/plugin/test_in_http_pull.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ class HttpPullInputTest < Test::Unit::TestCase
5858

5959
assert_equal(nil, d.instance.proxy)
6060
end
61+
62+
test 'http_method' do
63+
d = create_driver TEST_DEFAULT_VALUE_CONFIG
64+
assert_equal("test", d.instance.tag)
65+
66+
assert_equal(:get, d.instance.http_method)
67+
end
6168
end
6269

6370
sub_test_case "success case" do

0 commit comments

Comments
 (0)