fluent-plugin-http-status 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "fluent-plugin-http-status"
7
- gem.version = "0.0.2"
7
+ gem.version = "0.0.3"
8
8
  gem.authors = ["hiro-su"]
9
9
  gem.email = ["h.sugipon@gmail.com"]
10
10
  gem.description = %q{Fluentd input plugin for to get the http status}
@@ -4,6 +4,9 @@ require "net/https"
4
4
  require "uri"
5
5
  require "socket"
6
6
 
7
+ ENV['LC_ALL'] = 'C'
8
+ Encoding.default_external = 'ascii-8bit' if RUBY_VERSION > '1.9'
9
+
7
10
  module Fluent
8
11
  class HttpStatusInput < Input
9
12
  Plugin.register_input('http_status',self)
@@ -15,10 +18,10 @@ module Fluent
15
18
  config_param :proxy_port, :integer, :default => nil
16
19
  config_param :proxy_user, :string, :default => nil
17
20
  config_param :proxy_password, :string, :default => nil
18
- config_param :open_timeout, :integer, :default => 10
21
+ config_param :open_timeout, :integer, :default => 20
19
22
  config_param :read_timeout, :integer, :default => 20
20
23
  config_param :params, :string, :default => nil
21
- config_param :polling_time, :string
24
+ config_param :polling_time, :string, :default => "1m"
22
25
  config_param :basic_user, :string, :default => nil
23
26
  config_param :basic_password, :string, :default => nil
24
27
 
@@ -91,6 +94,13 @@ module Fluent
91
94
  port = uri.port
92
95
  request_uri = uri.request_uri
93
96
 
97
+ hash["url"] = url
98
+ hash["host"] = host
99
+ hash["port"] = port
100
+ hash["request_uri"] = request_uri
101
+ hash["proxy_address"] = @proxy_address if @proxy_address
102
+ hash["proxy_port"] = @proxy_port if @proxy_port
103
+
94
104
  http = Net::HTTP.new(host,port,@proxy_address,@proxy_port,@proxy_user,@proxy_password)
95
105
  http.open_timeout = @open_timeout
96
106
  http.read_timeout = @read_timeout
@@ -105,39 +115,31 @@ module Fluent
105
115
  req.basic_auth @basic_user, @basic_password
106
116
  response = http.request(req)
107
117
 
108
- hash[:url] = url
109
- hash[:host] = host
110
- hash[:port] = port
111
- hash[:request_uri] = request_uri
112
- hash[:proxy_address] = @proxy_address if @proxy_address
113
- hash[:proxy_port] = @proxy_port if @proxy_port
114
- hash[:code] = response.code.to_i
115
- hash[:message] = response.message
116
- hash[:class_name] = response.class.name
118
+ hash["code"] = response.code.to_i
119
+ hash["message"] = response.message
120
+ hash["class_name"] = response.class.name
117
121
  hostent = Socket.gethostbyname(host)
118
- hash[:ipaddress] = hostent[3].unpack("C4").join('.')
119
- hash[:headers] = Hash.new
122
+ hash["ipaddress"] = hostent[3].unpack("C4").join('.')
123
+ hash["headers"] = Hash.new
120
124
 
121
125
  response.each_key{|name|
122
126
  if @params
123
- @params.each{|param| hash[:headers][param] = response[param] =~ /^-?\d+$/ ? response[param].to_i : response[param]}
127
+ @params.each{|param| hash["headers"][param] = response[param] =~ /^-?\d+$/ ? response[param].to_i : response[param]}
124
128
  else
125
- hash[:headers][name] = response[name] =~ /^-?\d+$/ ? response[name].to_i : response[name]
129
+ hash["headers"][name] = response[name] =~ /^-?\d+$/ ? response[name].to_i : response[name]
126
130
  end
127
131
  }
128
132
 
129
- response_time = Time.now - start
130
- hash[:response_time] = response_time * 1000
131
- return hash
132
133
  rescue Timeout::Error => ex
133
- $log.error "Timeout Error : #{ex.message}"
134
- hash[:code] = 408
135
- hash[:message] = ex.message
136
- return hash
134
+ $log.error "Timeout Error : #{url}:#{port}#{request_uri}"
135
+ hash["code"] = 408
136
+ hash["message"] = ex.message
137
137
  rescue => ex
138
- $log.error ex.message
139
- hash[:code] = 000
140
- hash[:message] = ex.message
138
+ $log.error "#{ex.message} : #{url}:#{port}#{request_uri}"
139
+ hash["code"] = 0
140
+ hash["message"] = ex.message
141
+ ensure
142
+ hash["response_time"] = (Time.now - start) * 1000 #msec
141
143
  return hash
142
144
  end
143
145
 
@@ -30,6 +30,22 @@ class HttpStatusInputTest < Test::Unit::TestCase
30
30
  end
31
31
 
32
32
  def test_configure
33
+ assert_raise(Fluent::ConfigError) {
34
+ d = create_driver('')
35
+ }
36
+
37
+ assert_raise(Fluent::ConfigError) {
38
+ d = create_driver %[
39
+ tag http.status
40
+ ]
41
+ }
42
+
43
+ assert_raise(Fluent::ConfigError) {
44
+ d = create_driver %[
45
+ url http://example.com
46
+ ]
47
+ }
48
+
33
49
  d = create_driver
34
50
 
35
51
  assert_equal "http.status", d.instance.tag
@@ -58,7 +74,7 @@ class HttpStatusInputTest < Test::Unit::TestCase
58
74
  }
59
75
 
60
76
  headers = {}
61
- headers[:headers] = {
77
+ headers["headers"] = {
62
78
  "server" => "Apache",
63
79
  "date" => "Sun, 18 Nov 2012 17:12:09 GMT",
64
80
  "last-modified" => "Thu, 15 Nov 2012 02:00:30 GMT",
@@ -71,22 +87,23 @@ class HttpStatusInputTest < Test::Unit::TestCase
71
87
  }
72
88
 
73
89
  Socket.stubs(:gethostbyname).returns(["www.test.ad.jp", [], 0, "\xC0\xA8\x00\x01"])
74
- WebMock.stub_request(:head, "www.test.ad.jp").to_return(:status => 200, :headers => headers[:headers])
90
+ WebMock.stub_request(:head, "www.test.ad.jp").to_return(:status => 200, :headers => headers["headers"])
75
91
  res_data = @obj.__send__(:get_status,@hash,args)
76
- res_data[:response_time] = 0.001239
92
+ res_data["response_time"] = 1.239
77
93
 
78
94
  result_hash = {
79
- :url=>"http://www.test.ad.jp",
80
- :host=>"www.test.ad.jp",
81
- :port=>80, :request_uri=>"/",
82
- :proxy_address=>"proxy.test.jp",
83
- :proxy_port=>8080,
84
- :code=>200,
85
- :message=>"",
86
- :class_name=>"Net::HTTPOK",
87
- :ipaddress=>"192.168.0.1",
88
- :response_time=>0.001239,
89
- :headers=>{
95
+ "url"=>"http://www.test.ad.jp",
96
+ "host"=>"www.test.ad.jp",
97
+ "port"=>80,
98
+ "request_uri"=>"/",
99
+ "proxy_address"=>"proxy.test.jp",
100
+ "proxy_port"=>8080,
101
+ "code"=>200,
102
+ "message"=>"",
103
+ "class_name"=>"Net::HTTPOK",
104
+ "ipaddress"=>"192.168.0.1",
105
+ "response_time"=>1.239,
106
+ "headers"=>{
90
107
  "server"=>"Apache",
91
108
  "date"=>"Sun, 18 Nov 2012 17:12:09 GMT",
92
109
  "last-modified"=>"Thu, 15 Nov 2012 02:00:30 GMT",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-http-status
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-05 00:00:00.000000000 Z
12
+ date: 2012-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd