fluent-plugin-zoomdata 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +26 -0
- data/Rakefile +10 -0
- data/fluent-plugin-zoomdata.gemspec +22 -0
- data/lib/fluent/plugin/out_zoomdata.rb +78 -0
- data/test/helper.rb +31 -0
- data/test/plugin/test_out_zoomdata.rb +82 -0
- metadata +120 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2013- Jun Ohtani
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# fluent-plugin-zoomdata
|
2
|
+
|
3
|
+
A fluent output plugin for sending json to Zoomdata server
|
4
|
+
|
5
|
+
see [zoomdata][1](zoomdata.com)
|
6
|
+
|
7
|
+
## Configuration
|
8
|
+
|
9
|
+
```
|
10
|
+
<match example.*>
|
11
|
+
type zoomdata
|
12
|
+
endpoint_url https://localhost:443/zoomdata-web/service/upload
|
13
|
+
ssl true
|
14
|
+
sourcename testsource
|
15
|
+
username user
|
16
|
+
password pass
|
17
|
+
</match>
|
18
|
+
```
|
19
|
+
|
20
|
+
## Copyright
|
21
|
+
* Copyright (c) 2013- Jun Ohtani
|
22
|
+
* License
|
23
|
+
* Apache License, Version 2.0
|
24
|
+
|
25
|
+
[1]: http://zoomdata.com
|
26
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "fluent-plugin-zoomdata"
|
5
|
+
gem.version = "0.0.1"
|
6
|
+
gem.authors = ["Jun Ohtani"]
|
7
|
+
gem.email = ["johtani@gmail.com"]
|
8
|
+
gem.description = %q{Fluentd output plugin to post json to zoomdata}
|
9
|
+
gem.summary = %q{see zoomdata http://www.zoomdata.com}
|
10
|
+
gem.homepage = "https://github.com/johtani/fluent-plugin-zoomdata"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($/)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.add_development_dependency "json"
|
18
|
+
gem.add_development_dependency "fluentd"
|
19
|
+
gem.add_development_dependency "webmock"
|
20
|
+
gem.add_runtime_dependency "fluentd"
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class Fluent::ZoomdataOutput < Fluent::Output
|
4
|
+
Fluent::Plugin.register_output('zoomdata', self)
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
require 'net/http'
|
9
|
+
require 'uri'
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
# Endpoint URL ex. localhost.local:port/api/
|
14
|
+
config_param :endpoint_url, :string, :default => 'https://localhost/zoomdata-web/service/upload'
|
15
|
+
|
16
|
+
config_param :sourcename, :string, :default => nil
|
17
|
+
|
18
|
+
config_param :ssl, :bool, :default => false
|
19
|
+
config_param :verify_ssl, :bool, :default => false
|
20
|
+
|
21
|
+
config_param :username, :string, :default => ''
|
22
|
+
config_param :password, :string, :default => ''
|
23
|
+
|
24
|
+
def configure(conf)
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
def start
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def shutdown
|
33
|
+
super
|
34
|
+
end
|
35
|
+
|
36
|
+
def format_url(tag)
|
37
|
+
if @sourcename
|
38
|
+
@endpoint_url + URI.escape('?source='+@sourcename)
|
39
|
+
else
|
40
|
+
@endpoint_url + URI.escape('?source='+tag)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def post(tag, time, record)
|
45
|
+
url = format_url(tag)
|
46
|
+
res = nil
|
47
|
+
begin
|
48
|
+
uri = URI.parse(url)
|
49
|
+
req = Net::HTTP::Post.new(url)
|
50
|
+
req.basic_auth(@username, @password)
|
51
|
+
req['Content-Type'] = 'application/json'
|
52
|
+
req.body = JSON.dump(record)
|
53
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
54
|
+
if @ssl
|
55
|
+
http.use_ssl = true
|
56
|
+
unless @verify_ssl
|
57
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
58
|
+
end
|
59
|
+
end
|
60
|
+
res = http.start {|http| http.request(req)}
|
61
|
+
rescue IOError, EOFError, SystemCallError
|
62
|
+
# server didn't respond
|
63
|
+
$log.warn "Net::HTTP.post_form raises exception: #{$!.class}, '#{$!.message}'"
|
64
|
+
end
|
65
|
+
unless res and res.is_a?(Net::HTTPSuccess)
|
66
|
+
$log.warn "failed to post to zoomdata: #{url}, json: #{record}, code: #{res && res.code}"
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def emit(tag, es, chain)
|
72
|
+
es.each do |time, record|
|
73
|
+
post(tag, time, record)
|
74
|
+
end
|
75
|
+
chain.next
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'fluent/test'
|
15
|
+
unless ENV.has_key?('VERBOSE')
|
16
|
+
nulllogger = Object.new
|
17
|
+
nulllogger.instance_eval {|obj|
|
18
|
+
def method_missing(method, *args)
|
19
|
+
# pass
|
20
|
+
end
|
21
|
+
}
|
22
|
+
$log = nulllogger
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'webmock/test_unit'
|
26
|
+
WebMock.disable_net_connect!
|
27
|
+
|
28
|
+
require 'fluent/plugin/out_zoomdata'
|
29
|
+
|
30
|
+
class Test::Unit::TestCase
|
31
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ZoomdataOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def stub_zoomdata(source='testsource',url="https://user:pass@localhost:#{ZOOMDATA_TEST_LISTEN_PORT}/zoomdata-web/service/upload?source=")
|
9
|
+
stub_request(:post, url+source).with do |req|
|
10
|
+
@post_json = JSON.parse(req.body)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
ZOOMDATA_TEST_LISTEN_PORT = 443
|
15
|
+
|
16
|
+
CONFIG_NO_SOURCE = %[
|
17
|
+
endpoint_url https://localhost:#{ZOOMDATA_TEST_LISTEN_PORT}/zoomdata-web/service/upload
|
18
|
+
ssl true
|
19
|
+
username user
|
20
|
+
password pass
|
21
|
+
]
|
22
|
+
|
23
|
+
CONFIG_WITH_SOURCE = %[
|
24
|
+
endpoint_url https://localhost:#{ZOOMDATA_TEST_LISTEN_PORT}/zoomdata-web/service/upload
|
25
|
+
ssl true
|
26
|
+
sourcename testsource
|
27
|
+
username user
|
28
|
+
password pass
|
29
|
+
]
|
30
|
+
|
31
|
+
def sample_json
|
32
|
+
{'test' => 100}
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_driver(conf = CONFIG_NO_SOURCE, tag='test')
|
36
|
+
Fluent::Test::OutputTestDriver.new(Fluent::ZoomdataOutput, tag).configure(conf)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_configure
|
40
|
+
d = create_driver(CONFIG_NO_SOURCE)
|
41
|
+
assert_equal("https://localhost:#{ZOOMDATA_TEST_LISTEN_PORT}/zoomdata-web/service/upload", d.instance.endpoint_url)
|
42
|
+
assert_equal(true, d.instance.ssl)
|
43
|
+
assert_equal(false, d.instance.verify_ssl)
|
44
|
+
assert_equal("user", d.instance.username)
|
45
|
+
assert_equal("pass", d.instance.password)
|
46
|
+
assert_nil(d.instance.sourcename)
|
47
|
+
|
48
|
+
d = create_driver(CONFIG_WITH_SOURCE)
|
49
|
+
assert_equal("https://localhost:#{ZOOMDATA_TEST_LISTEN_PORT}/zoomdata-web/service/upload", d.instance.endpoint_url)
|
50
|
+
assert_equal(true, d.instance.ssl)
|
51
|
+
assert_equal(false, d.instance.verify_ssl)
|
52
|
+
assert_equal("user", d.instance.username)
|
53
|
+
assert_equal("pass", d.instance.password)
|
54
|
+
assert_equal("testsource", d.instance.sourcename)
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
# exist source config
|
59
|
+
def test_emit_with_source
|
60
|
+
stub_zoomdata
|
61
|
+
d = create_driver(CONFIG_WITH_SOURCE)
|
62
|
+
d.emit(sample_json)
|
63
|
+
d.run
|
64
|
+
assert_requested(:post, "https://user:pass@localhost:#{ZOOMDATA_TEST_LISTEN_PORT}/zoomdata-web/service/upload?source=testsource",
|
65
|
+
:body => sample_json, :headers => {'Content-Type' => 'application/json'})
|
66
|
+
end
|
67
|
+
|
68
|
+
# no source config
|
69
|
+
def test_emit_no_source
|
70
|
+
stub_zoomdata('test')
|
71
|
+
d = create_driver(CONFIG_NO_SOURCE)
|
72
|
+
d.emit(sample_json)
|
73
|
+
d.run
|
74
|
+
assert_requested(:post, "https://user:pass@localhost:#{ZOOMDATA_TEST_LISTEN_PORT}/zoomdata-web/service/upload?source=test",
|
75
|
+
:body => sample_json, :headers => {'Content-Type' => 'application/json'})
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_emit_2
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-zoomdata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jun Ohtani
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: fluentd
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: webmock
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: fluentd
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Fluentd output plugin to post json to zoomdata
|
79
|
+
email:
|
80
|
+
- johtani@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- fluent-plugin-zoomdata.gemspec
|
91
|
+
- lib/fluent/plugin/out_zoomdata.rb
|
92
|
+
- test/helper.rb
|
93
|
+
- test/plugin/test_out_zoomdata.rb
|
94
|
+
homepage: https://github.com/johtani/fluent-plugin-zoomdata
|
95
|
+
licenses: []
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.8.23
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: see zoomdata http://www.zoomdata.com
|
118
|
+
test_files:
|
119
|
+
- test/helper.rb
|
120
|
+
- test/plugin/test_out_zoomdata.rb
|