fluent-plugin-zulip 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/fluent-plugin-zulip.gemspec +3 -2
- data/lib/fluent/plugin/out_zulip.rb +20 -28
- data/test/plugin/test_out_zulip.rb +13 -16
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c492b2c2284d81f89494a2f8627b269fba06772
|
4
|
+
data.tar.gz: 2e4034d94b629adc71b551ed062a1d048c0512a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c34389a79c8e7f34d9e7aaba5e9e9bc2c2cd531f0c57c4df92012f0545e07ea6e7c159c9dd3c731c8fa6f4ebc835035521840eaf296424ea0f400cef76493cd
|
7
|
+
data.tar.gz: 0d38b190a61dab04421b7bcdf590edbfd0fb2550296ffb642f1b8f447f89a281c44b2368ac8b5ac188c967775de0daf2249341fe3212eb6415bc168df515796a
|
data/README.md
CHANGED
@@ -4,6 +4,15 @@
|
|
4
4
|
|
5
5
|
[Zulip](https://zulip.org/) is a powerful open source group chat.
|
6
6
|
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
| fluent-plugin-zulip | fluentd | ruby |
|
10
|
+
|---------------------|------------|--------|
|
11
|
+
| >= 0.1.0 | >= v0.14.0 | >= 2.1 |
|
12
|
+
| N/A | >= v0.12.0 | >= 1.9 |
|
13
|
+
|
14
|
+
NOTE: fluent-plugin-zulip doesn't support Fluentd v0.12.x
|
15
|
+
|
7
16
|
## Installation
|
8
17
|
|
9
18
|
### RubyGems
|
data/fluent-plugin-zulip.gemspec
CHANGED
@@ -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-zulip"
|
6
|
-
spec.version = "0.
|
6
|
+
spec.version = "0.2.0"
|
7
7
|
spec.authors = ["Kenji Okimoto"]
|
8
8
|
spec.email = ["okimoto@clear-code.com"]
|
9
9
|
|
@@ -24,5 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
spec.add_development_dependency "test-unit"
|
26
26
|
spec.add_development_dependency "webmock"
|
27
|
-
spec.add_runtime_dependency "fluentd",
|
27
|
+
spec.add_runtime_dependency "fluentd", ">= 0.14.10", "< 2"
|
28
|
+
spec.add_runtime_dependency "zulip-client", ">= 0.2.0"
|
28
29
|
end
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
require "fluent/plugin/output"
|
16
16
|
require "json"
|
17
|
-
require "
|
17
|
+
require "zulip/client"
|
18
18
|
|
19
19
|
module Fluent
|
20
20
|
module Plugin
|
@@ -25,7 +25,7 @@ module Fluent
|
|
25
25
|
ZULIP_CONTENT_MAX_SIZE = 10000
|
26
26
|
|
27
27
|
desc "API endpoint"
|
28
|
-
config_param :
|
28
|
+
config_param :site, :string
|
29
29
|
desc "Bot email address"
|
30
30
|
config_param :bot_email_address, :string
|
31
31
|
desc "Bot API key"
|
@@ -61,46 +61,38 @@ module Fluent
|
|
61
61
|
raise Fluent::ConfigError, "subject max length is #{ZULIP_SUBJECT_MAX_SIZE}"
|
62
62
|
end
|
63
63
|
|
64
|
-
@
|
64
|
+
@client = Zulip::Client.new(site: @site,
|
65
|
+
username: @bot_email_address,
|
66
|
+
api_key: @bot_api_key)
|
65
67
|
end
|
66
68
|
|
67
69
|
def process(tag, es)
|
68
|
-
http = Net::HTTP.new(@api_endpoint_uri.host, @api_endpoint_uri.port)
|
69
|
-
http.use_ssl = @api_endpoint_uri.scheme == "https"
|
70
|
-
http.start
|
71
70
|
es.each do |time, record|
|
72
|
-
|
73
|
-
response
|
74
|
-
case response
|
75
|
-
when Net::HTTPSuccess
|
71
|
+
response = send_message(tag, time, record)
|
72
|
+
if response.success?
|
76
73
|
log.info(response.body)
|
77
|
-
when Net::HTTPServerError, Net::HTTPClientError
|
78
|
-
log.error(status: response.code, body: response.body)
|
79
74
|
else
|
80
|
-
log.
|
75
|
+
log.error(status: response.status,
|
76
|
+
message: response.reason_phrase,
|
77
|
+
body: response.body)
|
81
78
|
end
|
82
79
|
log.debug(response)
|
83
80
|
end
|
84
|
-
http.finish
|
85
81
|
end
|
86
82
|
|
87
|
-
def
|
88
|
-
request = Net::HTTP::Post.new(@api_endpoint_uri.path)
|
89
|
-
request.basic_auth(@bot_email_address, @bot_api_key)
|
90
|
-
request["Connection"] = "Keep-Alive"
|
91
|
-
params = {
|
92
|
-
"type" => @message_type,
|
93
|
-
"content" => record[@content_key]
|
94
|
-
}
|
83
|
+
def send_message(tag, time, record)
|
95
84
|
case @message_type
|
96
|
-
when :private
|
97
|
-
params["to"] = JSON.generate(@recipients)
|
98
85
|
when :stream
|
99
|
-
|
100
|
-
|
86
|
+
to = @stream_name
|
87
|
+
subject = @subject || record[@subject_key]
|
88
|
+
@client.send_public_message(to: to,
|
89
|
+
subject: subject,
|
90
|
+
content: record[@content_key])
|
91
|
+
when :private
|
92
|
+
to = @recipients
|
93
|
+
@client.send_private_message(to: to,
|
94
|
+
content: record[@content_key])
|
101
95
|
end
|
102
|
-
request.set_form_data(params, ";")
|
103
|
-
request
|
104
96
|
end
|
105
97
|
end
|
106
98
|
end
|
@@ -11,7 +11,7 @@ class ZulipOutputTest < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
|
13
13
|
CONF = config_element("ROOT", "", {
|
14
|
-
"
|
14
|
+
"site" => "https://zulip.example.com/",
|
15
15
|
"bot_email_address" => "example-bot@example.com",
|
16
16
|
"bot_api_key" => "very-secret-value",
|
17
17
|
})
|
@@ -26,12 +26,12 @@ class ZulipOutputTest < Test::Unit::TestCase
|
|
26
26
|
test "minimal" do
|
27
27
|
d = create_driver(CONF)
|
28
28
|
actual = {
|
29
|
-
|
29
|
+
site: d.instance.site,
|
30
30
|
bot_email_address: d.instance.bot_email_address,
|
31
31
|
bot_api_key: d.instance.bot_api_key
|
32
32
|
}
|
33
33
|
expected = {
|
34
|
-
|
34
|
+
site: "https://zulip.example.com/",
|
35
35
|
bot_email_address: "example-bot@example.com",
|
36
36
|
bot_api_key: "very-secret-value",
|
37
37
|
}
|
@@ -65,16 +65,14 @@ class ZulipOutputTest < Test::Unit::TestCase
|
|
65
65
|
d = create_driver(CONF)
|
66
66
|
record = { message: "This is test message" }
|
67
67
|
headers = {
|
68
|
-
"
|
69
|
-
"
|
70
|
-
"
|
71
|
-
"Content-Type" => "application/x-www-form-urlencoded",
|
72
|
-
"User-Agent" => "Ruby"
|
68
|
+
"Authorization" => "Basic ZXhhbXBsZS1ib3RAZXhhbXBsZS5jb206dmVyeS1zZWNyZXQtdmFsdWU=",
|
69
|
+
"Expect" => "",
|
70
|
+
"User-Agent" => "Faraday v0.12.0.1"
|
73
71
|
}
|
74
72
|
stub_request(:post, "https://zulip.example.com/api/v1/messages")
|
75
73
|
.with(basic_auth: ["example-bot@example.com", "very-secret-value"],
|
76
74
|
headers: headers,
|
77
|
-
body: "
|
75
|
+
body: "content&subject&to=social&type=stream")
|
78
76
|
.to_return(headers: {},
|
79
77
|
body: { message: "", result: "success", id: 1234 }.to_json)
|
80
78
|
d.run(default_tag: "test") do
|
@@ -89,16 +87,14 @@ class ZulipOutputTest < Test::Unit::TestCase
|
|
89
87
|
d = create_driver(CONF)
|
90
88
|
record = { message: "This is test message" }
|
91
89
|
headers = {
|
92
|
-
"
|
93
|
-
"
|
94
|
-
"
|
95
|
-
"Content-Type" => "application/x-www-form-urlencoded",
|
96
|
-
"User-Agent" => "Ruby"
|
90
|
+
"Authorization" => "Basic ZXhhbXBsZS1ib3RAZXhhbXBsZS5jb206dmVyeS1zZWNyZXQtdmFsdWU=",
|
91
|
+
"Expect" => "",
|
92
|
+
"User-Agent" => "Faraday v0.12.0.1"
|
97
93
|
}
|
98
94
|
stub_request(:post, "https://zulip.example.com/api/v1/messages")
|
99
95
|
.with(basic_auth: ["example-bot@example.com", "very-secret-value"],
|
100
96
|
headers: headers,
|
101
|
-
body: "
|
97
|
+
body: "content&subject&to=social&type=stream")
|
102
98
|
.to_return(status: 500,
|
103
99
|
headers: {},
|
104
100
|
body: { message: "", result: "failure" }.to_json)
|
@@ -106,8 +102,9 @@ class ZulipOutputTest < Test::Unit::TestCase
|
|
106
102
|
d.feed(event_time, record)
|
107
103
|
end
|
108
104
|
line = d.logs.first
|
105
|
+
puts line
|
109
106
|
message = line[/(\[error\]: status=.+ body=.+)/, 1]
|
110
|
-
assert_equal(%q([error]: status=
|
107
|
+
assert_equal(%q([error]: status=500 message=nil body="{\\"message\\":\\"\\",\\"result\\":\\"failure\\"}"), message)
|
111
108
|
end
|
112
109
|
end
|
113
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-zulip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenji Okimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,6 +86,20 @@ dependencies:
|
|
86
86
|
- - "<"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '2'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: zulip-client
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.2.0
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.2.0
|
89
103
|
description: Fluentd output plugin for Zulip powerful open source group chat.
|
90
104
|
email:
|
91
105
|
- okimoto@clear-code.com
|
@@ -122,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
136
|
version: '0'
|
123
137
|
requirements: []
|
124
138
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.6.
|
139
|
+
rubygems_version: 2.6.11
|
126
140
|
signing_key:
|
127
141
|
specification_version: 4
|
128
142
|
summary: Fluentd output plugin for Zulip powerful open source group chat.
|