fluent-plugin-sendgrid-event 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/fluent-plugin-sendgrid-event.gemspec +1 -1
- data/lib/fluent/plugin/in_sendgrid_event.rb +14 -0
- data/test/plugin/test_in_sendgrid_event.rb +73 -17
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ffe235b5621c727bcfa07587de682d13f2ebf1d
|
4
|
+
data.tar.gz: b79173a1dc1c3134351ef4ec494de4c693e9b751
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4e2e92312512a50bfd916057c6bc7cf2b90b4485659051e5210ebc7a6da2f7d51c487218fa80a6c46502c97b97445057dc8e9350a1d68f19445350ae2d3eceb
|
7
|
+
data.tar.gz: 04034943a93378947169bd27a4b5ecca4c90e5c835233ba4f32f24cdb3de6379a495fb420568370a026d509f87d16d74678c7a3918fbc2def87f8671b653fd4d
|
data/README.md
CHANGED
@@ -34,6 +34,21 @@ The following is an example of configuration.
|
|
34
34
|
</source>
|
35
35
|
```
|
36
36
|
|
37
|
+
If you would like to use ssl, you can enable as below.
|
38
|
+
|
39
|
+
```
|
40
|
+
<source>
|
41
|
+
type sendgrid_event
|
42
|
+
host 127.0.0.1
|
43
|
+
port 9191
|
44
|
+
tag sendgrid
|
45
|
+
|
46
|
+
ssl true
|
47
|
+
certificate /path/to/certificate.pem
|
48
|
+
private_key /path/to/private_key.key
|
49
|
+
</source>
|
50
|
+
```
|
51
|
+
|
37
52
|
## Contributing
|
38
53
|
|
39
54
|
1. Fork it ( http://github.com/hiroakis/fluent-plugin-sendgrid-event/fork )
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-sendgrid-event"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.2"
|
8
8
|
spec.authors = ["Hiroaki Sano"]
|
9
9
|
spec.email = ["hiroaki.sano.9stories@gmail.com"]
|
10
10
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'webrick/https'
|
2
|
+
|
1
3
|
module Fluent
|
2
4
|
class SendGridEventInput < Input
|
3
5
|
Plugin.register_input('sendgrid_event', self)
|
@@ -5,6 +7,9 @@ module Fluent
|
|
5
7
|
config_param :tag, :string, :default => nil
|
6
8
|
config_param :host, :string, :default => "0.0.0.0"
|
7
9
|
config_param :port, :integer, :default => 9191
|
10
|
+
config_param :ssl, :bool, :default => false
|
11
|
+
config_param :certificate, :string, :default => nil
|
12
|
+
config_param :private_key, :string, :default => nil
|
8
13
|
config_param :request_uri, :string, :default => "/"
|
9
14
|
|
10
15
|
unless method_defined?(:log)
|
@@ -45,6 +50,15 @@ module Fluent
|
|
45
50
|
:BindAddress => @host,
|
46
51
|
:Port => @port
|
47
52
|
}
|
53
|
+
if @ssl
|
54
|
+
if File.exists?(@certificate) && File.exists?(@private_key)
|
55
|
+
listen[:SSLEnable] = @ssl
|
56
|
+
listen[:SSLCertificate] = OpenSSL::X509::Certificate.new(open(@certificate).read)
|
57
|
+
listen[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(open(@private_key).read)
|
58
|
+
else
|
59
|
+
log.error "in_sendgrid_event: couldn't find certificate: '#{@certificate}' or ssl key: '#{@private_key}'"
|
60
|
+
end
|
61
|
+
end
|
48
62
|
|
49
63
|
@server = WEBrick::HTTPServer.new(listen)
|
50
64
|
@server.mount_proc(@request_uri) do |req, res|
|
@@ -39,27 +39,27 @@ class SendGridEventTest < Test::Unit::TestCase
|
|
39
39
|
def valid_event_json
|
40
40
|
[
|
41
41
|
{
|
42
|
-
"sg_message_id"
|
43
|
-
"email"
|
44
|
-
"timestamp"
|
45
|
-
"smtp-id"
|
46
|
-
"event"
|
42
|
+
"sg_message_id" => "sendgrid_internal_message_id",
|
43
|
+
"email" => "john.doe@sendgrid.com",
|
44
|
+
"timestamp" => 1337197600,
|
45
|
+
"smtp-id" => "<4FB4041F.6080505@sendgrid.com>",
|
46
|
+
"event" => "processed"
|
47
47
|
},
|
48
48
|
{
|
49
|
-
"sg_message_id"
|
50
|
-
"email"
|
51
|
-
"timestamp"
|
52
|
-
"category"
|
53
|
-
"event"
|
54
|
-
"url"
|
49
|
+
"sg_message_id" => "sendgrid_internal_message_id",
|
50
|
+
"email" => "john.doe@sendgrid.com",
|
51
|
+
"timestamp" => 1337966815,
|
52
|
+
"category" => "newuser",
|
53
|
+
"event" => "click",
|
54
|
+
"url" => "https://sendgrid.com"
|
55
55
|
},
|
56
56
|
{
|
57
|
-
"sg_message_id"
|
58
|
-
"email"
|
59
|
-
"timestamp"
|
60
|
-
"smtp-id"
|
61
|
-
"event"
|
62
|
-
"asm_group_id"
|
57
|
+
"sg_message_id" => "sendgrid_internal_message_id",
|
58
|
+
"email" => "john.doe@sendgrid.com",
|
59
|
+
"timestamp" => 1337969592,
|
60
|
+
"smtp-id" => "<20120525181309.C1A9B40405B3@Example-Mac.local>",
|
61
|
+
"event" => "group_unsubscribe",
|
62
|
+
"asm_group_id" => 42
|
63
63
|
}
|
64
64
|
].to_json
|
65
65
|
end
|
@@ -78,6 +78,18 @@ class SendGridEventTest < Test::Unit::TestCase
|
|
78
78
|
res
|
79
79
|
end
|
80
80
|
|
81
|
+
def send_event_with_https(post_data)
|
82
|
+
require 'net/http'
|
83
|
+
http = Net::HTTP.new("hiroakis.com", 9191)
|
84
|
+
http.use_ssl = true
|
85
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
86
|
+
req = Net::HTTP::Post.new('/')
|
87
|
+
req.body = post_data
|
88
|
+
req["Content-Type"] = "application/json"
|
89
|
+
res = http.request(req)
|
90
|
+
res
|
91
|
+
end
|
92
|
+
|
81
93
|
def test_with_valid_event_json
|
82
94
|
d = create_driver %[
|
83
95
|
type sendgrid_event
|
@@ -86,6 +98,7 @@ class SendGridEventTest < Test::Unit::TestCase
|
|
86
98
|
tag sendgrid.event
|
87
99
|
]
|
88
100
|
|
101
|
+
sleep 1
|
89
102
|
d.run do
|
90
103
|
res = send_event(valid_event_json)
|
91
104
|
assert_equal("200", res.code)
|
@@ -131,4 +144,47 @@ class SendGridEventTest < Test::Unit::TestCase
|
|
131
144
|
end
|
132
145
|
assert_equal(0, d.emits.size)
|
133
146
|
end
|
147
|
+
|
148
|
+
# def test_https_with_valid_event_json
|
149
|
+
# d = create_driver %[
|
150
|
+
# type sendgrid_event
|
151
|
+
# host 127.0.0.1
|
152
|
+
# port 9191
|
153
|
+
# ssl true
|
154
|
+
# certificate /Users/hiroakis/work/hiroakis.com.pem
|
155
|
+
# private_key /Users/hiroakis/work/hiroakis.com.key
|
156
|
+
# tag sendgrid.event
|
157
|
+
# ]
|
158
|
+
|
159
|
+
# sleep 1
|
160
|
+
# d.run do
|
161
|
+
# res = send_event_with_https(valid_event_json)
|
162
|
+
# assert_equal("200", res.code)
|
163
|
+
# end
|
164
|
+
|
165
|
+
# assert_equal(3, d.emits.size)
|
166
|
+
|
167
|
+
# assert_equal("sendgrid.event", d.emits[0][0])
|
168
|
+
# assert_equal("sendgrid_internal_message_id", d.emits[0][2]["sg_message_id"])
|
169
|
+
# assert_equal("john.doe@sendgrid.com", d.emits[0][2]["email"])
|
170
|
+
# assert_equal(1337197600, d.emits[0][2]["timestamp"])
|
171
|
+
# assert_equal("<4FB4041F.6080505@sendgrid.com>", d.emits[0][2]["smtp-id"])
|
172
|
+
# assert_equal("processed", d.emits[0][2]["event"])
|
173
|
+
|
174
|
+
# assert_equal("sendgrid.event", d.emits[1][0])
|
175
|
+
# assert_equal("sendgrid_internal_message_id", d.emits[1][2]["sg_message_id"])
|
176
|
+
# assert_equal("john.doe@sendgrid.com", d.emits[1][2]["email"])
|
177
|
+
# assert_equal(1337966815, d.emits[1][2]["timestamp"])
|
178
|
+
# assert_equal("newuser", d.emits[1][2]["category"])
|
179
|
+
# assert_equal("click", d.emits[1][2]["event"])
|
180
|
+
# assert_equal("https://sendgrid.com", d.emits[1][2]["url"])
|
181
|
+
|
182
|
+
# assert_equal("sendgrid.event", d.emits[2][0])
|
183
|
+
# assert_equal("sendgrid_internal_message_id", d.emits[2][2]["sg_message_id"])
|
184
|
+
# assert_equal("john.doe@sendgrid.com", d.emits[2][2]["email"])
|
185
|
+
# assert_equal(1337969592, d.emits[2][2]["timestamp"])
|
186
|
+
# assert_equal("<20120525181309.C1A9B40405B3@Example-Mac.local>", d.emits[2][2]["smtp-id"])
|
187
|
+
# assert_equal("group_unsubscribe", d.emits[2][2]["event"])
|
188
|
+
# assert_equal(42, d.emits[2][2]["asm_group_id"])
|
189
|
+
# end
|
134
190
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-sendgrid-event
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroaki Sano
|
@@ -14,56 +14,56 @@ dependencies:
|
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.10'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.10'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: test-unit
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: fluentd
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description:
|
@@ -73,7 +73,7 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
-
|
76
|
+
- .gitignore
|
77
77
|
- Gemfile
|
78
78
|
- README.md
|
79
79
|
- Rakefile
|
@@ -91,17 +91,17 @@ require_paths:
|
|
91
91
|
- lib
|
92
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
98
|
requirements:
|
99
|
-
- -
|
99
|
+
- - '>='
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.0.14
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Fluent input plugin to receive sendgrid event.
|