logstash-output-slack 2.0.0 → 2.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7ed0b67218b6d30873ab18cff4600407ab3a2de6
4
- data.tar.gz: c8812f662d0e6494e40cce9e0515e6b98bc28773
2
+ SHA256:
3
+ metadata.gz: 78f7c062cb7a792fdc5270882b0ebfec4a885372c85327c47c923e29d959effb
4
+ data.tar.gz: 6ad61931eae24664a5023979119502564e8aa9203c6cf80112b2c004f35e0701
5
5
  SHA512:
6
- metadata.gz: 790c57a0474e423ca3701897e05fefd5394788a94e527ef549142fc6e330cdc5e7e1c0305b76ca20d7d8ab9e27ffc64d3f046507f1ae254a9063cb6fa34b7415
7
- data.tar.gz: 1b95a21c8eade1b1d388ebd6ea4db7d1befb8d043bfaa35a0802b83d2c0b2e939380b0e6fd97e669171e15587ef0e7c1e8a6fab2e7e98c10013dad9abf3bc964
6
+ metadata.gz: 7b2a42e23f1e2a167901394d016db05ef3695c6d8ee193659a1e760e20689015a14f4f2dbbdc9ed22459e885854f1a93f798223fc332f5e8ec419a7d28f3af18
7
+ data.tar.gz: a52bbdfc0c31b96436e8a7af15b2dc439bc31b433d03163a21ca6af4fb8fbe8b515f4a9e98e3c040e8727c80e56c07d7fea32a0ccd77925f4e2afb47807e5cf3
@@ -1,12 +1,27 @@
1
- ## 3.0.0
1
+ ## 2.2.0
2
+ - Dependencies: Remove constraint on public_suffix and enforce ruby >= 2.x
3
+
4
+ ## 2.1.1
5
+ - Docs: Set the default_codec doc attribute.
6
+
7
+ ## 2.1.0
8
+ - allow interpolation of event fields in url [#11](https://github.com/logstash-plugins/logstash-output-slack/pull/11)
9
+
10
+ ## 2.0.2
11
+ - Enable event based data in attachments
12
+
13
+ ## 2.0.1
14
+ - Update codec dependencies
15
+
16
+ ## 2.0.0
2
17
  - Breaking: Updated plugin to use new Java Event APIs
3
18
  - relax logstash-core-plugin-api constrains
4
19
  - update .travis.yml
5
20
 
6
- - [v0.1.1](https://github.com/cyli/logstash-output-slack/releases/tag/v0.1.1):
7
- - Added variable expansion to usernames and channel names ([#6](https://github.com/cyli/logstash-output-slack/pull/6))
8
- - Fixed bug when reporting malformed requests ([#3](https://github.com/cyli/logstash-output-slack/pull/3))
9
- - Test fixes since newer versions of logstash-core expects the values in
10
- the `add_field` hash to not be integers.
11
- - [v0.1.0](https://github.com/cyli/logstash-output-slack/releases/tag/v0.1.0):
12
- - initial version containing basic slack functionality
21
+ ## 0.1.1 (https://github.com/cyli/logstash-output-slack/releases/tag/v0.1.1):
22
+ - Added variable expansion to usernames and channel names ([#6](https://github.com/cyli/logstash-output-slack/pull/6))
23
+ - Fixed bug when reporting malformed requests ([#3](https://github.com/cyli/logstash-output-slack/pull/3))
24
+ - Test fixes since newer versions of logstash-core expects the values in
25
+ the `add_field` hash to not be integers.
26
+ ## 0.1.0(https://github.com/cyli/logstash-output-slack/releases/tag/v0.1.0):
27
+ - initial version containing basic slack functionality
data/Gemfile CHANGED
@@ -1,2 +1,11 @@
1
1
  source 'https://rubygems.org'
2
+
2
3
  gemspec
4
+
5
+ logstash_path = ENV["LOGSTASH_PATH"] || "../../logstash"
6
+ use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "1"
7
+
8
+ if Dir.exist?(logstash_path) && use_logstash_source
9
+ gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
10
+ gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
11
+ end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://travis-ci.org/cyli/logstash-output-slack.svg?branch=master)](https://travis-ci.org/cyli/logstash-output-slack)
1
+ [![Build Status](https://travis-ci.org/logstash-plugins/logstash-output-slack.svg?branch=master)](https://travis-ci.org/logstash-plugins/logstash-output-slack)
2
2
 
3
3
  Reviews of the code/contributions are very welcome (particularly with testing!), since I don't really know Ruby.
4
4
 
@@ -0,0 +1,110 @@
1
+ :plugin: slack
2
+ :type: output
3
+ :default_codec: plain
4
+
5
+ ///////////////////////////////////////////
6
+ START - GENERATED VARIABLES, DO NOT EDIT!
7
+ ///////////////////////////////////////////
8
+ :version: %VERSION%
9
+ :release_date: %RELEASE_DATE%
10
+ :changelog_url: %CHANGELOG_URL%
11
+ :include_path: ../../../../logstash/docs/include
12
+ ///////////////////////////////////////////
13
+ END - GENERATED VARIABLES, DO NOT EDIT!
14
+ ///////////////////////////////////////////
15
+
16
+ [id="plugins-{type}s-{plugin}"]
17
+
18
+ === Slack output plugin
19
+
20
+ include::{include_path}/plugin_header.asciidoc[]
21
+
22
+ ==== Description
23
+
24
+ Write events to Slack.
25
+
26
+ [id="plugins-{type}s-{plugin}-options"]
27
+ ==== Slack Output Configuration Options
28
+
29
+ This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
30
+
31
+ [cols="<,<,<",options="header",]
32
+ |=======================================================================
33
+ |Setting |Input type|Required
34
+ | <<plugins-{type}s-{plugin}-attachments>> |<<array,array>>|No
35
+ | <<plugins-{type}s-{plugin}-channel>> |<<string,string>>|No
36
+ | <<plugins-{type}s-{plugin}-format>> |<<string,string>>|No
37
+ | <<plugins-{type}s-{plugin}-icon_emoji>> |<<string,string>>|No
38
+ | <<plugins-{type}s-{plugin}-icon_url>> |<<string,string>>|No
39
+ | <<plugins-{type}s-{plugin}-url>> |<<string,string>>|Yes
40
+ | <<plugins-{type}s-{plugin}-username>> |<<string,string>>|No
41
+ |=======================================================================
42
+
43
+ Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
44
+ output plugins.
45
+
46
+ &nbsp;
47
+
48
+ [id="plugins-{type}s-{plugin}-attachments"]
49
+ ===== `attachments`
50
+
51
+ * Value type is <<array,array>>
52
+ * There is no default value for this setting.
53
+
54
+ Attachments array as described https://api.slack.com/docs/attachments
55
+
56
+ [id="plugins-{type}s-{plugin}-channel"]
57
+ ===== `channel`
58
+
59
+ * Value type is <<string,string>>
60
+ * There is no default value for this setting.
61
+
62
+ The channel to post to
63
+
64
+ [id="plugins-{type}s-{plugin}-format"]
65
+ ===== `format`
66
+
67
+ * Value type is <<string,string>>
68
+ * Default value is `"%{message}"`
69
+
70
+ The text to post in slack
71
+
72
+ [id="plugins-{type}s-{plugin}-icon_emoji"]
73
+ ===== `icon_emoji`
74
+
75
+ * Value type is <<string,string>>
76
+ * There is no default value for this setting.
77
+
78
+ Emoji icon to use
79
+
80
+ [id="plugins-{type}s-{plugin}-icon_url"]
81
+ ===== `icon_url`
82
+
83
+ * Value type is <<string,string>>
84
+ * There is no default value for this setting.
85
+
86
+ Icon URL to use
87
+
88
+ [id="plugins-{type}s-{plugin}-url"]
89
+ ===== `url`
90
+
91
+ * This is a required setting.
92
+ * Value type is <<string,string>>
93
+ * There is no default value for this setting.
94
+
95
+ The incoming webhook URI needed to post a message
96
+
97
+ [id="plugins-{type}s-{plugin}-username"]
98
+ ===== `username`
99
+
100
+ * Value type is <<string,string>>
101
+ * There is no default value for this setting.
102
+
103
+ The username to use for posting
104
+
105
+
106
+
107
+ [id="plugins-{type}s-{plugin}-common-options"]
108
+ include::{include_path}/{type}.asciidoc[]
109
+
110
+ :default_codec!:
@@ -42,6 +42,7 @@ class LogStash::Outputs::Slack < LogStash::Outputs::Base
42
42
 
43
43
  payload_json = Hash.new
44
44
  payload_json['text'] = event.sprintf(@format)
45
+ url = event.sprintf(@url)
45
46
 
46
47
  if not @channel.nil?
47
48
  payload_json['channel'] = event.sprintf(@channel)
@@ -60,9 +61,9 @@ class LogStash::Outputs::Slack < LogStash::Outputs::Base
60
61
  end
61
62
 
62
63
  if @attachments and @attachments.any?
63
- payload_json['attachments'] = @attachments
64
+ payload_json['attachments'] = @attachments.map { |x| JSON.parse(event.sprintf(JSON.dump(x))) }
64
65
  end
65
- if event.include?('attachments') and event['attachments'].is_a?(Array)
66
+ if event.include?('attachments') and event.get('attachments').is_a?(Array)
66
67
  if event.get('attachments').any?
67
68
  # need to convert possibly from Java objects to Ruby Array, because
68
69
  # JSON dumps does not work well with Java ArrayLists, etc.
@@ -75,7 +76,7 @@ class LogStash::Outputs::Slack < LogStash::Outputs::Base
75
76
 
76
77
  begin
77
78
  RestClient.post(
78
- @url,
79
+ url,
79
80
  "payload=#{CGI.escape(JSON.dump(payload_json))}",
80
81
  :accept => "application/json",
81
82
  :'User-Agent' => "logstash-output-slack",
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-slack'
3
- s.version = '2.0.0'
3
+ s.version = '2.2.0'
4
4
  s.licenses = ['MIT','Apache License (2.0)']
5
5
  s.summary = "Write events to Slack"
6
6
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.require_paths = ["lib"]
11
11
 
12
12
  # Files
13
- s.files = `git ls-files`.split($\)
13
+ s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "docs/**/*"]
14
14
 
15
15
  # Tests
16
16
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -18,15 +18,16 @@ Gem::Specification.new do |s|
18
18
  # Special flag to let us know this is actually a logstash plugin
19
19
  s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
20
20
 
21
+ s.required_ruby_version = '~> 2'
22
+
21
23
  # Gem dependencies
22
24
 
23
25
  s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
24
- s.add_runtime_dependency "public_suffix", "< 1.5.0"
25
-
26
- s.add_runtime_dependency "logstash-codec-plain", "~> 2.0.0", ">= 1.0.0"
26
+
27
+ s.add_runtime_dependency "logstash-codec-plain"
27
28
  s.add_runtime_dependency "rest-client", '~> 1.8', ">= 1.8.0"
28
- s.add_development_dependency "logstash-devutils", "~> 0.0.16"
29
- s.add_development_dependency "logstash-filter-json", "~> 2.0.1", ">= 1.0.1"
30
- s.add_development_dependency "logstash-input-generator", "~> 2.0.1", ">= 1.0.0"
29
+ s.add_development_dependency "logstash-devutils"
30
+ s.add_development_dependency "logstash-filter-json"
31
+ s.add_development_dependency "logstash-input-generator"
31
32
  s.add_development_dependency "webmock", "~> 1.22", ">= 1.21.0"
32
33
  end
@@ -2,17 +2,22 @@ require_relative "../spec_helper"
2
2
 
3
3
  describe LogStash::Outputs::Slack do
4
4
 
5
+ subject { described_class.new(config) }
6
+ let(:config) { { } }
7
+ let(:event) { LogStash::Event.new(data) }
8
+ let(:data) { {} }
9
+
5
10
  # Actually do most of the boiler plate by stubbing out the request, running
6
11
  # the logstash pipeline, and asserting that a request was made with the
7
12
  # expected JSON.
8
- def test_one_event(logstash_config, expected_json)
13
+ def test_one_event(event, expected_json, expected_url = "http://requestb.in/r9lkbzr9")
9
14
  stub_request(:post, "requestb.in").
10
15
  to_return(:body => "", :status => 200,
11
16
  :headers => { 'Content-Length' => 0 })
12
17
 
13
- LogStash::Pipeline.new(logstash_config).run
18
+ subject.receive(event)
14
19
 
15
- expect(a_request(:post, "http://requestb.in/r9lkbzr9").
20
+ expect(a_request(:post, expected_url).
16
21
  with(:body => "payload=#{CGI.escape(JSON.dump(expected_json))}",
17
22
  :headers => {
18
23
  'Content-Type' => 'application/x-www-form-urlencoded',
@@ -22,275 +27,231 @@ describe LogStash::Outputs::Slack do
22
27
  to have_been_made.once
23
28
  end
24
29
 
25
- before do
30
+ before(:each) do
31
+ subject.register
26
32
  WebMock.disable_net_connect!
27
33
  end
28
34
 
29
- after do
35
+ after(:each) do
30
36
  WebMock.reset!
31
37
  WebMock.allow_net_connect!
32
38
  end
33
39
 
34
- context "passes the right payload to slack and" do
35
- it "uses all default values" do
36
- expected_json = {
37
- :text => "This message should show in slack"
38
- }
39
- logstash_config = <<-CONFIG
40
- input {
41
- generator {
42
- message => "This message should show in slack"
43
- count => 1
44
- }
45
- }
46
- output {
47
- slack {
48
- url => "http://requestb.in/r9lkbzr9"
49
- }
50
- }
51
- CONFIG
40
+ context "passes the right payload to slack" do
41
+ context "simple" do
42
+ let(:data) { { "message" => "This message should show in slack" } }
43
+ let(:config) { { "url" => "http://requestb.in/r9lkbzr9" } }
52
44
 
53
- test_one_event(logstash_config, expected_json)
45
+ it "uses all default values" do
46
+ expected_json = { :text => "This message should show in slack" }
47
+ test_one_event(event, expected_json)
48
+ end
54
49
  end
55
50
 
56
- it "uses and formats all provided values" do
57
- expected_json = {
58
- :text => "This message should show in slack 3",
59
- :channel => "mychannel",
60
- :username => "slackbot",
61
- :icon_emoji => ":chart_with_upwards_trend:",
62
- :icon_url => "http://lorempixel.com/48/48"
63
- }
64
-
65
- logstash_config = <<-CONFIG
66
- input {
67
- generator {
68
- message => "This message should show in slack"
69
- add_field => {"x" => "3"
70
- "channelname" => "mychannel"
71
- "username" => "slackbot"}
72
- count => 1
73
- }
74
- }
75
- output {
76
- slack {
77
- url => "http://requestb.in/r9lkbzr9"
78
- format => "%{message} %{x}"
79
- channel => "%{channelname}"
80
- username => "%{username}"
81
- icon_emoji => ":chart_with_upwards_trend:"
82
- icon_url => "http://lorempixel.com/48/48"
83
- }
84
- }
85
- CONFIG
86
-
87
- test_one_event(logstash_config, expected_json)
51
+ context "with multiple interpolations" do
52
+ let(:data) { {
53
+ "message" => "This message should show in slack",
54
+ "x" => "3",
55
+ "channelname" => "mychannel",
56
+ "username" => "slackbot"
57
+ } }
58
+
59
+ let(:config) { {
60
+ "url" => "http://requestb.in/r9lkbzr9",
61
+ "format" => "%{message} %{x}",
62
+ "channel" => "%{channelname}",
63
+ "username" => "%{username}",
64
+ "icon_emoji" => ":chart_with_upwards_trend:",
65
+ "icon_url" => "http://lorempixel.com/48/48",
66
+ } }
67
+
68
+ it "uses and formats all provided values" do
69
+ expected_json = {
70
+ :text => "This message should show in slack 3",
71
+ :channel => "mychannel",
72
+ :username => "slackbot",
73
+ :icon_emoji => ":chart_with_upwards_trend:",
74
+ :icon_url => "http://lorempixel.com/48/48"
75
+ }
76
+ test_one_event(event, expected_json)
77
+ end
88
78
  end
89
79
 
90
- it "uses and formats all provided values" do
91
- expected_json = {
92
- :text => "Unformatted message",
93
- :channel => "mychannel",
94
- :username => "slackbot",
95
- :icon_emoji => ":chart_with_upwards_trend:",
96
- :icon_url => "http://lorempixel.com/48/48"
97
- }
98
-
99
- logstash_config = <<-CONFIG
100
- input {
101
- generator {
102
- message => "This message should show in slack"
103
- count => 1
104
- }
105
- }
106
- output {
107
- slack {
108
- url => "http://requestb.in/r9lkbzr9"
109
- format => "Unformatted message"
110
- channel => "mychannel"
111
- username => "slackbot"
112
- icon_emoji => ":chart_with_upwards_trend:"
113
- icon_url => "http://lorempixel.com/48/48"
114
- }
115
- }
116
- CONFIG
117
-
118
- test_one_event(logstash_config, expected_json)
80
+ context "if the message contains no interpolations" do
81
+
82
+ let(:data) { {
83
+ "message" => "This message should show in slack"
84
+ } }
85
+
86
+ let(:config) { {
87
+ "url" => "http://requestb.in/r9lkbzr9",
88
+ "format" => "Unformatted message",
89
+ "channel" => "mychannel",
90
+ "username" => "slackbot",
91
+ "icon_emoji" => ":chart_with_upwards_trend:",
92
+ "icon_url" => "http://lorempixel.com/48/48"
93
+ } }
94
+
95
+ it "uses and formats all provided values" do
96
+ expected_json = {
97
+ :text => "Unformatted message",
98
+ :channel => "mychannel",
99
+ :username => "slackbot",
100
+ :icon_emoji => ":chart_with_upwards_trend:",
101
+ :icon_url => "http://lorempixel.com/48/48"
102
+ }
103
+ test_one_event(event, expected_json)
104
+ end
119
105
  end
120
106
 
121
- it "uses the default attachments if none are in the event" do
122
- expected_json = {
123
- :text => "This message should show in slack",
124
- :attachments => [{:image_url => "http://example.com/image.png"}]
125
- }
126
-
127
- logstash_config = <<-CONFIG
128
- input {
129
- generator {
130
- message => "This message should show in slack"
131
- count => 1
132
- }
107
+ describe "default attachements" do
108
+ let(:config) { {
109
+ "url" => "http://requestb.in/r9lkbzr9",
110
+ "attachments" => [{ "image_url" => "http://example.com/image.png" }]
111
+ } }
112
+
113
+ context "when none are in the event" do
114
+ let(:data) { { "message" => "This message should show in slack" } }
115
+ it "uses the default" do
116
+ expected_json = {
117
+ :text => "This message should show in slack",
118
+ :attachments => [{:image_url => "http://example.com/image.png"}]
133
119
  }
134
- output {
135
- slack {
136
- url => "http://requestb.in/r9lkbzr9"
137
- attachments => [
138
- {image_url => "http://example.com/image.png"}
139
- ]
140
- }
120
+ test_one_event(event, expected_json)
121
+ end
122
+ end
123
+
124
+ context "when using multiple attachments" do
125
+ let(:data) { { "message" => "This message should show in slack" } }
126
+ let(:config) { {
127
+ "url" => "http://requestb.in/r9lkbzr9",
128
+ "attachments" => [
129
+ {"image_url" => "http://example.com/image1.png"},
130
+ {"image_url" => "http://example.com/image2.png"}
131
+ ]
132
+ } }
133
+ it "sends them" do
134
+ expected_json = {
135
+ :text => "This message should show in slack",
136
+ :attachments => [{:image_url => "http://example.com/image1.png"},
137
+ {:image_url => "http://example.com/image2.png"}]
141
138
  }
142
- CONFIG
143
-
144
- test_one_event(logstash_config, expected_json)
139
+ test_one_event(event, expected_json)
140
+ end
141
+ end
145
142
  end
146
143
 
147
- it "supports multiple default attachments" do
148
- expected_json = {
149
- :text => "This message should show in slack",
150
- :attachments => [{:image_url => "http://example.com/image1.png"},
151
- {:image_url => "http://example.com/image2.png"}]
152
- }
153
-
154
- logstash_config = <<-CONFIG
155
- input {
156
- generator {
157
- message => "This message should show in slack"
158
- count => 1
159
- }
160
- }
161
- output {
162
- slack {
163
- url => "http://requestb.in/r9lkbzr9"
164
- attachments => [
165
- {image_url => "http://example.com/image1.png"},
166
- {image_url => "http://example.com/image2.png"}
167
- ]
168
- }
169
- }
170
- CONFIG
171
-
172
- test_one_event(logstash_config, expected_json)
144
+ context "empty default attachments" do
145
+ let(:data) { {
146
+ "message" => "This message should show in slack"
147
+ }}
148
+
149
+ let(:config) { {
150
+ "url" => "http://requestb.in/r9lkbzr9",
151
+ "attachments" => []
152
+ }}
153
+
154
+ it "are ignored" do
155
+ expected_json = {
156
+ :text => "This message should show in slack"
157
+ }
158
+ test_one_event(event, expected_json)
159
+ end
173
160
  end
174
161
 
175
- it "ignores empty default attachments" do
176
- expected_json = {
177
- :text => "This message should show in slack"
178
- }
179
-
180
- logstash_config = <<-CONFIG
181
- input {
182
- generator {
183
- message => "This message should show in slack"
184
- count => 1
185
- }
186
- }
187
- output {
188
- slack {
189
- url => "http://requestb.in/r9lkbzr9"
190
- attachments => []
191
- }
192
- }
193
- CONFIG
194
-
195
- test_one_event(logstash_config, expected_json)
162
+ context "when both event attachments and default attachments are set" do
163
+
164
+ let(:data) { {
165
+ "message" => "This message should show in slack",
166
+ "attachments" => [{"thumb_url" => "http://other.com/thumb.png"}]
167
+ } }
168
+
169
+ let(:config) { {
170
+ "url" => "http://requestb.in/r9lkbzr9",
171
+ "attachments" => [
172
+ {"image_url" => "http://example.com/image1.png"},
173
+ {"image_url" => "http://example.com/image2.png"}
174
+ ]
175
+ } }
176
+
177
+ it "event attachements prevail" do
178
+ expected_json = {
179
+ :text => "This message should show in slack",
180
+ :attachments => [{:thumb_url => "http://other.com/thumb.png"}]
181
+ }
182
+ test_one_event(event, expected_json)
183
+ end
196
184
  end
197
185
 
198
- it "uses event attachments over default attachments" do
199
- expected_json = {
200
- :text => "This message should show in slack",
201
- :attachments => [{:thumb_url => "http://other.com/thumb.png"}]
202
- }
203
-
204
- # add_field only takes string values, so we'll have to mutate to JSON
205
- logstash_config = <<-CONFIG
206
- input {
207
- generator {
208
- message => "This message should show in slack"
209
- count => 1
210
- add_field => {
211
- attachments => '[{"thumb_url": "http://other.com/thumb.png"}]'
212
- }
213
- }
214
- }
215
- filter {
216
- json {
217
- source => "attachments"
218
- target => "attachments"
219
- }
220
- }
221
- output {
222
- slack {
223
- url => "http://requestb.in/r9lkbzr9"
224
- attachments => [
225
- {image_url => "http://example.com/image1.png"},
226
- {image_url => "http://example.com/image2.png"}
227
- ]
228
- }
229
- }
230
- CONFIG
186
+ context "if event attachments empty" do
187
+
188
+ let(:data) { {
189
+ "message" => "This message should show in slack",
190
+ "attachments" => []
191
+ } }
192
+
193
+ let(:config) { {
194
+ "url" => "http://requestb.in/r9lkbzr9",
195
+ "attachments" => [
196
+ {"image_url" => "http://example.com/image1.png"},
197
+ {"image_url" => "http://example.com/image2.png"}
198
+ ]
199
+ } }
200
+
201
+ it "erases default attachments" do
202
+ expected_json = {
203
+ :text => "This message should show in slack"
204
+ }
205
+ test_one_event(event, expected_json)
206
+ end
207
+ end
231
208
 
232
- test_one_event(logstash_config, expected_json)
209
+ context "when event attachements field isn't an array" do
210
+ let(:data) { {
211
+ "message" => "This message should show in slack",
212
+ "attachments" => "baddata"
213
+ } }
214
+
215
+ let(:config) { {
216
+ "url" => "http://requestb.in/r9lkbzr9",
217
+ "attachments" => [
218
+ {"image_url" => "http://example.com/image.png"}
219
+ ]
220
+ } }
221
+
222
+
223
+ it "is ignored" do
224
+ expected_json = {
225
+ :text => "This message should show in slack",
226
+ :attachments => [{:image_url => "http://example.com/image.png"}]
227
+ }
228
+ test_one_event(event, expected_json)
229
+ end
233
230
  end
231
+ end
234
232
 
235
- it "erases default attachments if event attachments empty" do
236
- expected_json = {
237
- :text => "This message should show in slack"
238
- }
233
+ describe "interpolation in url field" do
234
+ let(:expected_url) { "http://incoming-webhook.example.com" }
239
235
 
240
- # add_field only takes string values, so we'll have to mutate to JSON
241
- logstash_config = <<-CONFIG
242
- input {
243
- generator {
244
- message => "This message should show in slack"
245
- count => 1
246
- add_field => {attachments => '[]'}
247
- }
248
- }
249
- filter {
250
- json {
251
- source => "attachments"
252
- target => "attachments"
253
- }
254
- }
255
- output {
256
- slack {
257
- url => "http://requestb.in/r9lkbzr9"
258
- attachments => [
259
- {image_url => "http://example.com/image1.png"},
260
- {image_url => "http://example.com/image2.png"}
261
- ]
262
- }
263
- }
264
- CONFIG
236
+ let(:event) {
237
+ event = LogStash::Event.new("message" => "This message should show in slack")
238
+ event.set("[@metadata][slack_url]", "#{expected_url}")
239
+ event
240
+ }
265
241
 
266
- test_one_event(logstash_config, expected_json)
267
- end
242
+ let(:config) { {
243
+ "url" => "%{[@metadata][slack_url]}",
244
+ "attachments" => [
245
+ {"image_url" => "http://example.com/image.png"}
246
+ ]
247
+ } }
268
248
 
269
- it "ignores event attachment if not array" do
249
+ it "allows interpolation in url field" do
270
250
  expected_json = {
271
251
  :text => "This message should show in slack",
272
252
  :attachments => [{:image_url => "http://example.com/image.png"}]
273
253
  }
274
-
275
- logstash_config = <<-CONFIG
276
- input {
277
- generator {
278
- message => "This message should show in slack"
279
- count => 1
280
- add_field => {attachments => "baddata"}
281
- }
282
- }
283
- output {
284
- slack {
285
- url => "http://requestb.in/r9lkbzr9"
286
- attachments => [
287
- {image_url => "http://example.com/image.png"}
288
- ]
289
- }
290
- }
291
- CONFIG
292
-
293
- test_one_event(logstash_config, expected_json)
254
+ test_one_event(event, expected_json, expected_url)
294
255
  end
295
256
  end
296
257
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ying Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-06 00:00:00.000000000 Z
11
+ date: 2020-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -33,37 +33,17 @@ dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
- - - "<"
37
- - !ruby/object:Gem::Version
38
- version: 1.5.0
39
- name: public_suffix
40
- prerelease: false
41
- type: :runtime
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "<"
45
- - !ruby/object:Gem::Version
46
- version: 1.5.0
47
- - !ruby/object:Gem::Dependency
48
- requirement: !ruby/object:Gem::Requirement
49
- requirements:
50
- - - "~>"
51
- - !ruby/object:Gem::Version
52
- version: 2.0.0
53
36
  - - ">="
54
37
  - !ruby/object:Gem::Version
55
- version: 1.0.0
38
+ version: '0'
56
39
  name: logstash-codec-plain
57
40
  prerelease: false
58
41
  type: :runtime
59
42
  version_requirements: !ruby/object:Gem::Requirement
60
43
  requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: 2.0.0
64
44
  - - ">="
65
45
  - !ruby/object:Gem::Version
66
- version: 1.0.0
46
+ version: '0'
67
47
  - !ruby/object:Gem::Dependency
68
48
  requirement: !ruby/object:Gem::Requirement
69
49
  requirements:
@@ -87,57 +67,45 @@ dependencies:
87
67
  - !ruby/object:Gem::Dependency
88
68
  requirement: !ruby/object:Gem::Requirement
89
69
  requirements:
90
- - - "~>"
70
+ - - ">="
91
71
  - !ruby/object:Gem::Version
92
- version: 0.0.16
72
+ version: '0'
93
73
  name: logstash-devutils
94
74
  prerelease: false
95
75
  type: :development
96
76
  version_requirements: !ruby/object:Gem::Requirement
97
77
  requirements:
98
- - - "~>"
78
+ - - ">="
99
79
  - !ruby/object:Gem::Version
100
- version: 0.0.16
80
+ version: '0'
101
81
  - !ruby/object:Gem::Dependency
102
82
  requirement: !ruby/object:Gem::Requirement
103
83
  requirements:
104
- - - "~>"
105
- - !ruby/object:Gem::Version
106
- version: 2.0.1
107
84
  - - ">="
108
85
  - !ruby/object:Gem::Version
109
- version: 1.0.1
86
+ version: '0'
110
87
  name: logstash-filter-json
111
88
  prerelease: false
112
89
  type: :development
113
90
  version_requirements: !ruby/object:Gem::Requirement
114
91
  requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: 2.0.1
118
92
  - - ">="
119
93
  - !ruby/object:Gem::Version
120
- version: 1.0.1
94
+ version: '0'
121
95
  - !ruby/object:Gem::Dependency
122
96
  requirement: !ruby/object:Gem::Requirement
123
97
  requirements:
124
- - - "~>"
125
- - !ruby/object:Gem::Version
126
- version: 2.0.1
127
98
  - - ">="
128
99
  - !ruby/object:Gem::Version
129
- version: 1.0.0
100
+ version: '0'
130
101
  name: logstash-input-generator
131
102
  prerelease: false
132
103
  type: :development
133
104
  version_requirements: !ruby/object:Gem::Requirement
134
105
  requirements:
135
- - - "~>"
136
- - !ruby/object:Gem::Version
137
- version: 2.0.1
138
106
  - - ">="
139
107
  - !ruby/object:Gem::Version
140
- version: 1.0.0
108
+ version: '0'
141
109
  - !ruby/object:Gem::Dependency
142
110
  requirement: !ruby/object:Gem::Requirement
143
111
  requirements:
@@ -158,22 +126,19 @@ dependencies:
158
126
  - - ">="
159
127
  - !ruby/object:Gem::Version
160
128
  version: 1.21.0
161
- description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
129
+ description: This gem is a logstash plugin required to be installed on top of the
130
+ Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
131
+ a stand-alone program
162
132
  email: cyli@ying.com
163
133
  executables: []
164
134
  extensions: []
165
135
  extra_rdoc_files: []
166
136
  files:
167
- - ".github/CONTRIBUTING.md"
168
- - ".github/ISSUE_TEMPLATE.md"
169
- - ".github/PULL_REQUEST_TEMPLATE.md"
170
- - ".gitignore"
171
- - ".travis.yml"
172
137
  - CHANGELOG.md
173
138
  - Gemfile
174
139
  - NOTICE.TXT
175
140
  - README.md
176
- - Rakefile
141
+ - docs/index.asciidoc
177
142
  - lib/logstash/outputs/slack.rb
178
143
  - logstash-output-slack.gemspec
179
144
  - spec/outputs/slack_spec.rb
@@ -191,9 +156,9 @@ require_paths:
191
156
  - lib
192
157
  required_ruby_version: !ruby/object:Gem::Requirement
193
158
  requirements:
194
- - - ">="
159
+ - - "~>"
195
160
  - !ruby/object:Gem::Version
196
- version: '0'
161
+ version: '2'
197
162
  required_rubygems_version: !ruby/object:Gem::Requirement
198
163
  requirements:
199
164
  - - ">="
@@ -201,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
166
  version: '0'
202
167
  requirements: []
203
168
  rubyforge_project:
204
- rubygems_version: 2.4.8
169
+ rubygems_version: 2.6.13
205
170
  signing_key:
206
171
  specification_version: 4
207
172
  summary: Write events to Slack
@@ -1,65 +0,0 @@
1
- # Contributing to Logstash
2
-
3
- All contributions are welcome: ideas, patches, documentation, bug reports,
4
- complaints, etc!
5
-
6
- Programming is not a required skill, and there are many ways to help out!
7
- It is more important to us that you are able to contribute.
8
-
9
- That said, some basic guidelines, which you are free to ignore :)
10
-
11
- ## Want to learn?
12
-
13
- Want to lurk about and see what others are doing with Logstash?
14
-
15
- * The irc channel (#logstash on irc.freenode.org) is a good place for this
16
- * The [forum](https://discuss.elastic.co/c/logstash) is also
17
- great for learning from others.
18
-
19
- ## Got Questions?
20
-
21
- Have a problem you want Logstash to solve for you?
22
-
23
- * You can ask a question in the [forum](https://discuss.elastic.co/c/logstash)
24
- * Alternately, you are welcome to join the IRC channel #logstash on
25
- irc.freenode.org and ask for help there!
26
-
27
- ## Have an Idea or Feature Request?
28
-
29
- * File a ticket on [GitHub](https://github.com/elastic/logstash/issues). Please remember that GitHub is used only for issues and feature requests. If you have a general question, the [forum](https://discuss.elastic.co/c/logstash) or IRC would be the best place to ask.
30
-
31
- ## Something Not Working? Found a Bug?
32
-
33
- If you think you found a bug, it probably is a bug.
34
-
35
- * If it is a general Logstash or a pipeline issue, file it in [Logstash GitHub](https://github.com/elasticsearch/logstash/issues)
36
- * If it is specific to a plugin, please file it in the respective repository under [logstash-plugins](https://github.com/logstash-plugins)
37
- * or ask the [forum](https://discuss.elastic.co/c/logstash).
38
-
39
- # Contributing Documentation and Code Changes
40
-
41
- If you have a bugfix or new feature that you would like to contribute to
42
- logstash, and you think it will take more than a few minutes to produce the fix
43
- (ie; write code), it is worth discussing the change with the Logstash users and developers first! You can reach us via [GitHub](https://github.com/elastic/logstash/issues), the [forum](https://discuss.elastic.co/c/logstash), or via IRC (#logstash on freenode irc)
44
- Please note that Pull Requests without tests will not be merged. If you would like to contribute but do not have experience with writing tests, please ping us on IRC/forum or create a PR and ask our help.
45
-
46
- ## Contributing to plugins
47
-
48
- Check our [documentation](https://www.elastic.co/guide/en/logstash/current/contributing-to-logstash.html) on how to contribute to plugins or write your own! It is super easy!
49
-
50
- ## Contribution Steps
51
-
52
- 1. Test your changes! [Run](https://github.com/elastic/logstash#testing) the test suite
53
- 2. Please make sure you have signed our [Contributor License
54
- Agreement](https://www.elastic.co/contributor-agreement/). We are not
55
- asking you to assign copyright to us, but to give us the right to distribute
56
- your code without restriction. We ask this of all contributors in order to
57
- assure our users of the origin and continuing existence of the code. You
58
- only need to sign the CLA once.
59
- 3. Send a pull request! Push your changes to your fork of the repository and
60
- [submit a pull
61
- request](https://help.github.com/articles/using-pull-requests). In the pull
62
- request, describe what your changes do and mention any bugs/issues related
63
- to the pull request.
64
-
65
-
@@ -1,9 +0,0 @@
1
- Please post all product and debugging questions on our [forum](https://discuss.elastic.co/c/logstash). Your questions will reach our wider community members there, and if we confirm that there is a bug, then we can open a new issue here.
2
-
3
- For all general issues, please provide the following details for fast resolution:
4
-
5
- - Version:
6
- - Operating System:
7
- - Config File (if you have sensitive info, please remove it):
8
- - Sample Data:
9
- - Steps to Reproduce:
@@ -1 +0,0 @@
1
- Thanks for contributing to Logstash! If you haven't already signed our CLA, here's a handy link: https://www.elastic.co/contributor-agreement/
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- *.gem
2
- Gemfile.lock
3
- .ruby-version
4
- .bundle
5
- vendor
6
- lib/com
7
- lib/logstash-output-slack_jars.rb
8
- lib/org
@@ -1,9 +0,0 @@
1
- sudo: false
2
- jdk:
3
- - oraclejdk8
4
- language: ruby
5
- cache: bundler
6
- rvm:
7
- - jruby-1.7.25
8
- script:
9
- - bundle exec rspec spec
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- @files=[]
2
-
3
- task :default do
4
- system("rake -T")
5
- end
6
-
7
- require "logstash/devutils/rake"