logstash-output-slack 0.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db23f70996dcdbc3878464c3c944aa6cd8fc08ae
4
- data.tar.gz: d724aa6471b1dbbd4ce760ce3af7436ceeda6030
3
+ metadata.gz: 7ed0b67218b6d30873ab18cff4600407ab3a2de6
4
+ data.tar.gz: c8812f662d0e6494e40cce9e0515e6b98bc28773
5
5
  SHA512:
6
- metadata.gz: 3bf5d70cacabf2a886b520398d96b98565258e0b71afa631e36135c9173e128eba8866486f793f7c0d2fbb9b51e4b3c40d5895f14a4c3fade1e921990705a9ac
7
- data.tar.gz: 3d258583fbd011a8c3637cee468c01304f4f4ce19187656dfb55f59ff5d5e485a78e7d905c1860c4679c5e11d7ef3729abca91d631b927cd139f4edda50b234a
6
+ metadata.gz: 790c57a0474e423ca3701897e05fefd5394788a94e527ef549142fc6e330cdc5e7e1c0305b76ca20d7d8ab9e27ffc64d3f046507f1ae254a9063cb6fa34b7415
7
+ data.tar.gz: 1b95a21c8eade1b1d388ebd6ea4db7d1befb8d043bfaa35a0802b83d2c0b2e939380b0e6fd97e669171e15587ef0e7c1e8a6fab2e7e98c10013dad9abf3bc964
@@ -0,0 +1,65 @@
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
+
@@ -0,0 +1,9 @@
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:
@@ -0,0 +1 @@
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/.travis.yml CHANGED
@@ -1,24 +1,9 @@
1
+ sudo: false
2
+ jdk:
3
+ - oraclejdk8
1
4
  language: ruby
2
5
  cache: bundler
3
6
  rvm:
4
- - jruby 1.7.21
5
- - jruby-head
6
-
7
- jdk:
8
- - openjdk6
9
- - openjdk7
10
- - oraclejdk7
11
- - oraclejdk8
12
-
13
- script: bundle exec rspec spec
14
-
15
- notifications:
16
- email: false
17
-
18
- matrix:
19
- fast_finish: true
20
- allow_failures:
21
- - rvm: jruby-head
22
- exclude:
23
- - rvm: jruby-head
24
- jdk: openjdk6
7
+ - jruby-1.7.25
8
+ script:
9
+ - bundle exec rspec spec
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## 3.0.0
2
+ - Breaking: Updated plugin to use new Java Event APIs
3
+ - relax logstash-core-plugin-api constrains
4
+ - update .travis.yml
5
+
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
data/NOTICE.TXT ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md CHANGED
@@ -4,9 +4,24 @@ Reviews of the code/contributions are very welcome (particularly with testing!),
4
4
 
5
5
  ## Logstash Slack Output Plugin
6
6
 
7
- Uses Slack [incoming webhooks API](https://api.slack.com/incoming-webhooks) to send log events to Slack.
7
+ [![Build
8
+ Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Outputs/job/logstash-plugin-output-slack-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Outputs/job/logstash-plugin-output-slack-unit/)
8
9
 
9
- Usage:
10
+ This is a plugin for [Logstash](https://github.com/elasticsearch/logstash) that pushes log events to [Slack](www.slack.com) using their [incoming webhooks API](https://api.slack.com/incoming-webhooks).
11
+
12
+ It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
13
+
14
+ =======
15
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
16
+
17
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
18
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide.
19
+
20
+ ## Need Help?
21
+
22
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
23
+
24
+ ## Usage
10
25
 
11
26
  ```
12
27
  input {
@@ -21,58 +36,22 @@ output {
21
36
  ...
22
37
  slack {
23
38
  url => <YOUR SLACK WEBHOOK URL HERE>
24
- channel => [channel-name - this is optional]
25
- username => [slack username - this is optional]
39
+ channel => [channel-name - optional]
40
+ username => [slack username - optional]
26
41
  icon_emoji => [emoji, something like ":simple_smile:" - optional]
27
42
  icon_url => [icon url, would be overriden by icon_emoji - optional]
28
43
  format => [default is "%{message}", but used to format the text - optional]
44
+ attachments => [an array of attachment maps as specified by the slack API - optional; if there is an "attachments" field in the event map and it is valid, it will override what is configured here, even if it's empty]
29
45
  }
30
46
  }
31
47
  ```
32
48
 
33
- Not supported yet: attachments
34
-
35
- ### Changelog:
36
- - v 0.1.1:
37
- - Added variable expansion to usernames and channel names ([#6](https://github.com/cyli/logstash-output-slack/pull/6))
38
- - Fixed bug when reporting malformed requests ([#3](https://github.com/cyli/logstash-output-slack/pull/3))
39
- - Test fixes since newer versions of logstash-core expects the values in
40
- the `add_field` hash to not be integers.
41
- - v 0.1.0:
42
- - initial version containing basic slack functionality
43
-
44
- ### Installation on Logstash >= 1.5
45
-
46
- In the logstash directory, run: `bin/plugin install logstash-output-slack`, which will download and install the public gem.
47
-
48
- #### To build your own gem and install:
49
-
50
- 1. `git clone <thisrepo>`
51
- 1. `bundle install`
52
- 1. `gem build logstash-output-slack.gemspec`
53
- 1. `cd <path to logstash>`
54
- 1. `logstash>1.5.0`: `bin/plugin install <path-to-your-built-gem>`
55
-
56
- On `logstash==1.5.0`, due to [this bug](https://github.com/elastic/logstash/issues/2674), installing from a local gem doesn't work right now. You will need to:
57
-
58
- 1. Make sure that the `logstash-core` gem you've installed matches the exact beta 1.5 logstash version you are running.
59
- 1. modify the logstash Gemfile to include the line `gem "logstash-output-slack", :path => <path_to_the_directory_your_gem_is_in>`
60
- 1. `bin/plugin install --no-verify`
61
-
62
- #### Verify that the plugin installed correctly
63
- `bin/plugin list | grep logstash-output-slack`
64
-
65
- #### Test that it works:
66
- ```
67
- bin/logstash -e '
68
- input { stdin {} }
69
- output { slack { <your slack config here> }}'
70
- ```
49
+ ## Contributing
71
50
 
72
- And type some text in. The same text should appear in the channel it's configured to go in.
51
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
73
52
 
74
- ### Installation on Logstash < 1.4
53
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
75
54
 
76
- Gem-installing this plugin would only work on Logstash 1.5. For Logstash < 1.5, you could just rename `lib` in this repo to `logstash`, and then run Logstash with `--pluginpath <path_to_this_repo>.
55
+ It is more important to the community that you are able to contribute.
77
56
 
78
- See the [flags](http://logstash.net/docs/1.4.2/flags) documentation for Logstash 1.4.
57
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -24,6 +24,8 @@ class LogStash::Outputs::Slack < LogStash::Outputs::Base
24
24
  # Icon URL to use
25
25
  config :icon_url, :validate => :string
26
26
 
27
+ # Attachments array as described https://api.slack.com/docs/attachments
28
+ config :attachments, :validate => :array
27
29
 
28
30
  public
29
31
  def register
@@ -57,6 +59,19 @@ class LogStash::Outputs::Slack < LogStash::Outputs::Base
57
59
  payload_json['icon_url'] = @icon_url
58
60
  end
59
61
 
62
+ if @attachments and @attachments.any?
63
+ payload_json['attachments'] = @attachments
64
+ end
65
+ if event.include?('attachments') and event['attachments'].is_a?(Array)
66
+ if event.get('attachments').any?
67
+ # need to convert possibly from Java objects to Ruby Array, because
68
+ # JSON dumps does not work well with Java ArrayLists, etc.
69
+ rubified = JSON.parse(event.to_json())
70
+ payload_json['attachments'] = rubified['attachments']
71
+ else
72
+ payload_json.delete('attachments')
73
+ end
74
+ end
60
75
 
61
76
  begin
62
77
  RestClient.post(
@@ -1,11 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-slack'
3
- s.version = '0.1.1'
3
+ s.version = '2.0.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"
7
7
  s.authors = ["Ying Li"]
8
- s.email = 'cyli@twistedmatrix.com'
8
+ s.email = 'cyli@ying.com'
9
+ s.homepage = "https://github.com/cyli/logstash-output-slack"
9
10
  s.require_paths = ["lib"]
10
11
 
11
12
  # Files
@@ -18,14 +19,14 @@ Gem::Specification.new do |s|
18
19
  s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
19
20
 
20
21
  # Gem dependencies
21
- s.add_runtime_dependency "logstash-core", ">= 1.4.0", "< 2.0.0"
22
- s.add_runtime_dependency "logstash-codec-plain"
23
- s.add_runtime_dependency "rest-client"
24
- s.add_development_dependency "logstash-devutils"
25
- s.add_development_dependency "logstash-input-generator"
26
- s.add_development_dependency "webmock"
27
22
 
28
- # Jar dependencies
29
- s.requirements << "jar 'org.elasticsearch:elasticsearch', '1.4.0'"
30
- s.add_runtime_dependency "jar-dependencies", ">= 0.1.7"
23
+ 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"
27
+ 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"
31
+ s.add_development_dependency "webmock", "~> 1.22", ">= 1.21.0"
31
32
  end
@@ -2,65 +2,24 @@ require_relative "../spec_helper"
2
2
 
3
3
  describe LogStash::Outputs::Slack do
4
4
 
5
- let(:short_config) do <<-CONFIG
6
- input {
7
- generator {
8
- message => "This message should show in slack"
9
- count => 1
10
- }
11
- }
12
-
13
- output {
14
- slack {
15
- url => "http://requestb.in/r9lkbzr9"
16
- }
17
- }
18
- CONFIG
19
- end
20
-
21
- let(:long_formatted_config) do <<-CONFIG
22
- input {
23
- generator {
24
- message => "This message should show in slack"
25
- add_field => {"x" => "3"
26
- "channelname" => "mychannel"
27
- "username" => "slackbot"}
28
- count => 1
29
- }
30
- }
31
-
32
- output {
33
- slack {
34
- url => "http://requestb.in/r9lkbzr9"
35
- format => "%{message} %{x}"
36
- channel => "%{channelname}"
37
- username => "%{username}"
38
- icon_emoji => ":chart_with_upwards_trend:"
39
- icon_url => "http://lorempixel.com/48/48"
40
- }
41
- }
42
- CONFIG
43
- end
5
+ # Actually do most of the boiler plate by stubbing out the request, running
6
+ # the logstash pipeline, and asserting that a request was made with the
7
+ # expected JSON.
8
+ def test_one_event(logstash_config, expected_json)
9
+ stub_request(:post, "requestb.in").
10
+ to_return(:body => "", :status => 200,
11
+ :headers => { 'Content-Length' => 0 })
44
12
 
45
- let(:long_unformatted_config) do <<-CONFIG
46
- input {
47
- generator {
48
- message => "This message should not show in slack"
49
- count => 1
50
- }
51
- }
13
+ LogStash::Pipeline.new(logstash_config).run
52
14
 
53
- output {
54
- slack {
55
- url => "http://requestb.in/r9lkbzr9"
56
- format => "Unformatted message"
57
- channel => "mychannel"
58
- username => "slackbot"
59
- icon_emoji => ":chart_with_upwards_trend:"
60
- icon_url => "http://lorempixel.com/48/48"
61
- }
62
- }
63
- CONFIG
15
+ expect(a_request(:post, "http://requestb.in/r9lkbzr9").
16
+ with(:body => "payload=#{CGI.escape(JSON.dump(expected_json))}",
17
+ :headers => {
18
+ 'Content-Type' => 'application/x-www-form-urlencoded',
19
+ 'Accept'=> 'application/json',
20
+ 'User-Agent' => 'logstash-output-slack'
21
+ })).
22
+ to have_been_made.once
64
23
  end
65
24
 
66
25
  before do
@@ -72,33 +31,29 @@ describe LogStash::Outputs::Slack do
72
31
  WebMock.allow_net_connect!
73
32
  end
74
33
 
75
- context "passes the right payload to slack" do
34
+ context "passes the right payload to slack and" do
76
35
  it "uses all default values" do
77
- stub_request(:post, "requestb.in").
78
- to_return(:body => "", :status => 200,
79
- :headers => { 'Content-Length' => 0 })
80
-
81
36
  expected_json = {
82
37
  :text => "This message should show in slack"
83
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
84
52
 
85
- LogStash::Pipeline.new(short_config).run
86
-
87
- expect(a_request(:post, "http://requestb.in/r9lkbzr9").
88
- with(:body => "payload=#{CGI.escape(JSON.dump(expected_json))}",
89
- :headers => {
90
- 'Content-Type' => 'application/x-www-form-urlencoded',
91
- 'Accept'=> 'application/json',
92
- 'User-Agent' => 'logstash-output-slack'
93
- })).
94
- to have_been_made.once
53
+ test_one_event(logstash_config, expected_json)
95
54
  end
96
55
 
97
56
  it "uses and formats all provided values" do
98
- stub_request(:post, "requestb.in").
99
- to_return(:body => "", :status => 200,
100
- :headers => { 'Content-Length' => 0 })
101
-
102
57
  expected_json = {
103
58
  :text => "This message should show in slack 3",
104
59
  :channel => "mychannel",
@@ -107,23 +62,32 @@ describe LogStash::Outputs::Slack do
107
62
  :icon_url => "http://lorempixel.com/48/48"
108
63
  }
109
64
 
110
- LogStash::Pipeline.new(long_formatted_config).run
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
111
86
 
112
- expect(a_request(:post, "http://requestb.in/r9lkbzr9").
113
- with(:body => "payload=#{CGI.escape(JSON.dump(expected_json))}",
114
- :headers => {
115
- 'Content-Type' => 'application/x-www-form-urlencoded',
116
- 'Accept'=> 'application/json',
117
- 'User-Agent' => 'logstash-output-slack'
118
- })).
119
- to have_been_made.once
87
+ test_one_event(logstash_config, expected_json)
120
88
  end
121
89
 
122
90
  it "uses and formats all provided values" do
123
- stub_request(:post, "requestb.in").
124
- to_return(:body => "", :status => 200,
125
- :headers => { 'Content-Length' => 0 })
126
-
127
91
  expected_json = {
128
92
  :text => "Unformatted message",
129
93
  :channel => "mychannel",
@@ -132,16 +96,201 @@ describe LogStash::Outputs::Slack do
132
96
  :icon_url => "http://lorempixel.com/48/48"
133
97
  }
134
98
 
135
- LogStash::Pipeline.new(long_unformatted_config).run
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)
119
+ end
120
+
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
+ }
133
+ }
134
+ output {
135
+ slack {
136
+ url => "http://requestb.in/r9lkbzr9"
137
+ attachments => [
138
+ {image_url => "http://example.com/image.png"}
139
+ ]
140
+ }
141
+ }
142
+ CONFIG
143
+
144
+ test_one_event(logstash_config, expected_json)
145
+ end
146
+
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)
173
+ end
174
+
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)
196
+ end
197
+
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
231
+
232
+ test_one_event(logstash_config, expected_json)
233
+ end
234
+
235
+ it "erases default attachments if event attachments empty" do
236
+ expected_json = {
237
+ :text => "This message should show in slack"
238
+ }
239
+
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
265
+
266
+ test_one_event(logstash_config, expected_json)
267
+ end
268
+
269
+ it "ignores event attachment if not array" do
270
+ expected_json = {
271
+ :text => "This message should show in slack",
272
+ :attachments => [{:image_url => "http://example.com/image.png"}]
273
+ }
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
136
292
 
137
- expect(a_request(:post, "http://requestb.in/r9lkbzr9").
138
- with(:body => "payload=#{CGI.escape(JSON.dump(expected_json))}",
139
- :headers => {
140
- 'Content-Type' => 'application/x-www-form-urlencoded',
141
- 'Accept'=> 'application/json',
142
- 'User-Agent' => 'logstash-output-slack'
143
- })).
144
- to have_been_made.once
293
+ test_one_event(logstash_config, expected_json)
145
294
  end
146
295
  end
147
296
  end
metadata CHANGED
@@ -1,135 +1,184 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 2.0.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: 2015-09-08 00:00:00.000000000 Z
11
+ date: 2016-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: logstash-core
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.60'
19
+ - - "<="
20
+ - !ruby/object:Gem::Version
21
+ version: '2.99'
22
+ name: logstash-core-plugin-api
23
+ prerelease: false
24
+ type: :runtime
15
25
  version_requirements: !ruby/object:Gem::Requirement
16
26
  requirements:
17
- - - '>='
27
+ - - ">="
18
28
  - !ruby/object:Gem::Version
19
- version: 1.4.0
20
- - - <
29
+ version: '1.60'
30
+ - - "<="
21
31
  - !ruby/object:Gem::Version
22
- version: 2.0.0
32
+ version: '2.99'
33
+ - !ruby/object:Gem::Dependency
23
34
  requirement: !ruby/object:Gem::Requirement
24
35
  requirements:
25
- - - '>='
26
- - !ruby/object:Gem::Version
27
- version: 1.4.0
28
- - - <
36
+ - - "<"
29
37
  - !ruby/object:Gem::Version
30
- version: 2.0.0
38
+ version: 1.5.0
39
+ name: public_suffix
31
40
  prerelease: false
32
41
  type: :runtime
33
- - !ruby/object:Gem::Dependency
34
- name: logstash-codec-plain
35
42
  version_requirements: !ruby/object:Gem::Requirement
36
43
  requirements:
37
- - - '>='
44
+ - - "<"
38
45
  - !ruby/object:Gem::Version
39
- version: '0'
46
+ version: 1.5.0
47
+ - !ruby/object:Gem::Dependency
40
48
  requirement: !ruby/object:Gem::Requirement
41
49
  requirements:
42
- - - '>='
50
+ - - "~>"
43
51
  - !ruby/object:Gem::Version
44
- version: '0'
52
+ version: 2.0.0
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.0.0
56
+ name: logstash-codec-plain
45
57
  prerelease: false
46
58
  type: :runtime
47
- - !ruby/object:Gem::Dependency
48
- name: rest-client
49
59
  version_requirements: !ruby/object:Gem::Requirement
50
60
  requirements:
51
- - - '>='
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: 2.0.0
64
+ - - ">="
52
65
  - !ruby/object:Gem::Version
53
- version: '0'
66
+ version: 1.0.0
67
+ - !ruby/object:Gem::Dependency
54
68
  requirement: !ruby/object:Gem::Requirement
55
69
  requirements:
56
- - - '>='
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '1.8'
73
+ - - ">="
57
74
  - !ruby/object:Gem::Version
58
- version: '0'
75
+ version: 1.8.0
76
+ name: rest-client
59
77
  prerelease: false
60
78
  type: :runtime
61
- - !ruby/object:Gem::Dependency
62
- name: logstash-devutils
63
79
  version_requirements: !ruby/object:Gem::Requirement
64
80
  requirements:
65
- - - '>='
81
+ - - "~>"
66
82
  - !ruby/object:Gem::Version
67
- version: '0'
83
+ version: '1.8'
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 1.8.0
87
+ - !ruby/object:Gem::Dependency
68
88
  requirement: !ruby/object:Gem::Requirement
69
89
  requirements:
70
- - - '>='
90
+ - - "~>"
71
91
  - !ruby/object:Gem::Version
72
- version: '0'
92
+ version: 0.0.16
93
+ name: logstash-devutils
73
94
  prerelease: false
74
95
  type: :development
75
- - !ruby/object:Gem::Dependency
76
- name: logstash-input-generator
77
96
  version_requirements: !ruby/object:Gem::Requirement
78
97
  requirements:
79
- - - '>='
98
+ - - "~>"
80
99
  - !ruby/object:Gem::Version
81
- version: '0'
100
+ version: 0.0.16
101
+ - !ruby/object:Gem::Dependency
82
102
  requirement: !ruby/object:Gem::Requirement
83
103
  requirements:
84
- - - '>='
104
+ - - "~>"
85
105
  - !ruby/object:Gem::Version
86
- version: '0'
106
+ version: 2.0.1
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 1.0.1
110
+ name: logstash-filter-json
87
111
  prerelease: false
88
112
  type: :development
89
- - !ruby/object:Gem::Dependency
90
- name: webmock
91
113
  version_requirements: !ruby/object:Gem::Requirement
92
114
  requirements:
93
- - - '>='
115
+ - - "~>"
94
116
  - !ruby/object:Gem::Version
95
- version: '0'
117
+ version: 2.0.1
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 1.0.1
121
+ - !ruby/object:Gem::Dependency
96
122
  requirement: !ruby/object:Gem::Requirement
97
123
  requirements:
98
- - - '>='
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: 2.0.1
127
+ - - ">="
99
128
  - !ruby/object:Gem::Version
100
- version: '0'
129
+ version: 1.0.0
130
+ name: logstash-input-generator
101
131
  prerelease: false
102
132
  type: :development
103
- - !ruby/object:Gem::Dependency
104
- name: jar-dependencies
105
133
  version_requirements: !ruby/object:Gem::Requirement
106
134
  requirements:
107
- - - '>='
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 2.0.1
138
+ - - ">="
108
139
  - !ruby/object:Gem::Version
109
- version: 0.1.7
140
+ version: 1.0.0
141
+ - !ruby/object:Gem::Dependency
110
142
  requirement: !ruby/object:Gem::Requirement
111
143
  requirements:
112
- - - '>='
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '1.22'
147
+ - - ">="
113
148
  - !ruby/object:Gem::Version
114
- version: 0.1.7
149
+ version: 1.21.0
150
+ name: webmock
115
151
  prerelease: false
116
- type: :runtime
152
+ type: :development
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '1.22'
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 1.21.0
117
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
118
- email: cyli@twistedmatrix.com
162
+ email: cyli@ying.com
119
163
  executables: []
120
164
  extensions: []
121
165
  extra_rdoc_files: []
122
166
  files:
123
- - .gitignore
124
- - .travis.yml
167
+ - ".github/CONTRIBUTING.md"
168
+ - ".github/ISSUE_TEMPLATE.md"
169
+ - ".github/PULL_REQUEST_TEMPLATE.md"
170
+ - ".gitignore"
171
+ - ".travis.yml"
172
+ - CHANGELOG.md
125
173
  - Gemfile
174
+ - NOTICE.TXT
126
175
  - README.md
127
176
  - Rakefile
128
177
  - lib/logstash/outputs/slack.rb
129
178
  - logstash-output-slack.gemspec
130
179
  - spec/outputs/slack_spec.rb
131
180
  - spec/spec_helper.rb
132
- homepage:
181
+ homepage: https://github.com/cyli/logstash-output-slack
133
182
  licenses:
134
183
  - MIT
135
184
  - Apache License (2.0)
@@ -142,16 +191,15 @@ require_paths:
142
191
  - lib
143
192
  required_ruby_version: !ruby/object:Gem::Requirement
144
193
  requirements:
145
- - - '>='
194
+ - - ">="
146
195
  - !ruby/object:Gem::Version
147
196
  version: '0'
148
197
  required_rubygems_version: !ruby/object:Gem::Requirement
149
198
  requirements:
150
- - - '>='
199
+ - - ">="
151
200
  - !ruby/object:Gem::Version
152
201
  version: '0'
153
- requirements:
154
- - jar 'org.elasticsearch:elasticsearch', '1.4.0'
202
+ requirements: []
155
203
  rubyforge_project:
156
204
  rubygems_version: 2.4.8
157
205
  signing_key: