fluent-plugin-http-pull 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56348b6b227f806a70821eaed3fafddcdc94ee6c
4
- data.tar.gz: 34e8e11a24b5b2dac781f4556f0e534b08e403fc
3
+ metadata.gz: 4431d08247cac9ded691561df1f37e0ca301812c
4
+ data.tar.gz: 34533a363fe85ac8a9e8fe6f7732d25cebe0ea43
5
5
  SHA512:
6
- metadata.gz: 0b5aeea895ccc1cfaf7923f8c21c9bdb54328677d384e66c508c289b0da9f8a7ab23778eb8097323e18822f493a7f1ad491544750d1230e2597910620d90e129
7
- data.tar.gz: b0b8ced808f05bdb9c0804af5dad1c7b171c6f6e096d5eab29d840ad6305ec079276692eea1a45b875629ed26cb82650be4462c7912c8831eb96145b222fb9d5
6
+ metadata.gz: 3ab0a2aad719fb68cda02595b9b7df31c5d8f611534898aee88323c325358ba0915c7937deff0b317ca51ebea4d3fa535ebc929f08d8783cb4932022d514c55c
7
+ data.tar.gz: c8ed089e7978a0ae4dc7dea11ac71e5b5b819def2d2136cc9e43f1111c4ddf8cf5d694ebc0b2d9f22707bcecbf2b53677670794153f509bd59c8e19ee84b1d51
data/README.md CHANGED
@@ -34,6 +34,8 @@ $ bundle
34
34
 
35
35
  ## Example
36
36
 
37
+ You can found more examples in `test/plugin/test_in_http_pull.rb`
38
+
37
39
  ### Monitoring http status code only
38
40
  ```
39
41
  <source>
@@ -133,7 +135,17 @@ for more detail.
133
135
 
134
136
  ### status_only (bool) (optional, default: false)
135
137
 
136
- If status_only is true, body is not parsed.
138
+ If `status_only` is true, body is not parsed.
139
+
140
+ ### http_method (enum) (optional, default: :get)
141
+
142
+ The http request method for each requests. Avaliable options are listed below.
143
+
144
+ * `get`
145
+ * `post`
146
+ * `delete`
147
+
148
+ If `status_only` is true, `http_method` was override to `head`
137
149
 
138
150
  ### timeout (time) (optional, default: 10s)
139
151
 
@@ -151,6 +163,14 @@ The user for basic auth
151
163
 
152
164
  The password for basic auth
153
165
 
166
+ ### response_header (section) (optional, default: nil)
167
+
168
+ The name of response header for capture.
169
+
170
+ ### request_header (section) (optional, default: nil)
171
+
172
+ The name, value pair of custom reuqest header.
173
+
154
174
  ## In case of remote error
155
175
 
156
176
  ### Can receive response from remote
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-http-pull"
6
- spec.version = "0.5.0"
6
+ spec.version = "0.6.0"
7
7
  spec.authors = ["filepang"]
8
8
  spec.email = ["filepang@gmail.com"]
9
9
 
@@ -20,7 +20,6 @@ module Fluent
20
20
  module Plugin
21
21
  class HttpPullInput < Fluent::Plugin::Input
22
22
  Fluent::Plugin.register_input("http_pull", self)
23
-
24
23
  helpers :timer, :parser, :compat_parameters
25
24
 
26
25
  def initialize
@@ -29,19 +28,28 @@ module Fluent
29
28
 
30
29
  desc 'The tag of the event.'
31
30
  config_param :tag, :string
31
+
32
32
  desc 'The url of monitoring target'
33
33
  config_param :url, :string
34
+
34
35
  desc 'The interval time between periodic request'
35
36
  config_param :interval, :time
37
+
36
38
  desc 'status_only'
37
39
  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'
39
45
  config_param :timeout, :time, default: 10
46
+
40
47
  desc 'The HTTP proxy URL to use for each requests'
41
48
  config_param :proxy, :string, default: nil
42
49
 
43
50
  desc 'user of basic auth'
44
51
  config_param :user, :string, default: nil
52
+
45
53
  desc 'password of basic auth'
46
54
  config_param :password, :string, default: nil
47
55
 
@@ -69,6 +77,8 @@ module Fluent
69
77
 
70
78
  [header.to_sym, value]
71
79
  end.to_h
80
+
81
+ @http_method = :head if @status_only
72
82
  end
73
83
 
74
84
  def start
@@ -81,7 +91,7 @@ module Fluent
81
91
  record = { "url" => @url }
82
92
 
83
93
  begin
84
- request_options = { method: :get, url: @url, timeout: @timeout }
94
+ request_options = { method: @http_method, url: @url, timeout: @timeout }
85
95
 
86
96
  request_options[:proxy] = @proxy if @proxy
87
97
  request_options[:user] = @user if @user
@@ -1,5 +1,17 @@
1
1
  require 'webrick'
2
2
 
3
+ class DeleteService < WEBrick::HTTPServlet::AbstractServlet
4
+ def service(req, res)
5
+ if req.request_method != "DELETE"
6
+ res.status = 405
7
+ else
8
+ res.status = 200
9
+ res['Content-Type'] = 'application/json'
10
+ res.body = '{ "status": "OK" }'
11
+ end
12
+ end
13
+ end
14
+
3
15
  class StubServer
4
16
  def initialize
5
17
  create_server
@@ -12,6 +24,9 @@ class StubServer
12
24
  @server.mount_proc '/redirect', &method(:redirect)
13
25
  @server.mount_proc '/protected', &method(:protected)
14
26
  @server.mount_proc '/custom_header', &method(:custom_header)
27
+
28
+ @server.mount_proc '/method_post', &method(:method_post)
29
+ @server.mount '/method_delete', DeleteService
15
30
  end
16
31
 
17
32
  def start
@@ -90,4 +105,15 @@ class StubServer
90
105
  res['Content-Type'] = 'application/json'
91
106
  res.body = '{ "status": "OK" }'
92
107
  end
108
+
109
+ def method_post(req, res)
110
+ if req.request_method != "POST"
111
+ res.status = 405
112
+ else
113
+ res.status = 200
114
+ res['Content-Type'] = 'application/json'
115
+ res.body = '{ "status": "OK" }'
116
+ end
117
+ end
93
118
  end
119
+
@@ -58,6 +58,13 @@ class HttpPullInputTest < Test::Unit::TestCase
58
58
 
59
59
  assert_equal(nil, d.instance.proxy)
60
60
  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
61
68
  end
62
69
 
63
70
  sub_test_case "success case" do
@@ -556,6 +563,62 @@ class HttpPullInputTest < Test::Unit::TestCase
556
563
  end
557
564
  end
558
565
 
566
+ sub_test_case "request method" do
567
+ TEST_INTERVAL_3_POST = %[
568
+ tag test
569
+ url http://127.0.0.1:3939/method_post
570
+
571
+ interval 3s
572
+ format json
573
+ http_method post
574
+ ]
575
+
576
+ TEST_INTERVAL_3_DELETE = %[
577
+ tag test
578
+ url http://127.0.0.1:3939/method_delete
579
+
580
+ interval 3s
581
+ format json
582
+ http_method delete
583
+ ]
584
+
585
+ test 'interval 3 with :post' do
586
+ d = create_driver TEST_INTERVAL_3_POST
587
+ assert_equal("test", d.instance.tag)
588
+ assert_equal(3, d.instance.interval)
589
+
590
+ d.run(timeout: 8) do
591
+ sleep 7
592
+ end
593
+ assert_equal(2, d.events.size)
594
+
595
+ d.events.each do |tag, time, record|
596
+ assert_equal("test", tag)
597
+
598
+ assert_equal({"url"=>"http://127.0.0.1:3939/method_post","status"=>200, "message"=>{"status"=>"OK"}}, record)
599
+ assert(time.is_a?(Fluent::EventTime))
600
+ end
601
+ end
602
+
603
+ test 'interval 3 with :delete' do
604
+ d = create_driver TEST_INTERVAL_3_DELETE
605
+ assert_equal("test", d.instance.tag)
606
+ assert_equal(3, d.instance.interval)
607
+
608
+ d.run(timeout: 8) do
609
+ sleep 7
610
+ end
611
+ assert_equal(2, d.events.size)
612
+
613
+ d.events.each do |tag, time, record|
614
+ assert_equal("test", tag)
615
+
616
+ assert_equal({"url"=>"http://127.0.0.1:3939/method_delete","status"=>200, "message"=>{"status"=>"OK"}}, record)
617
+ assert(time.is_a?(Fluent::EventTime))
618
+ end
619
+ end
620
+ end
621
+
559
622
  private
560
623
 
561
624
  def create_driver(conf)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-http-pull
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - filepang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-08 00:00:00.000000000 Z
11
+ date: 2017-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  version: '0'
168
168
  requirements: []
169
169
  rubyforge_project:
170
- rubygems_version: 2.6.13
170
+ rubygems_version: 2.5.2
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: fluent-plugin-http-pull