logstash-output-slack 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cd002e773f901f0e19f59cc7470426916b1df532
4
+ data.tar.gz: f2bb362492defe4a2e5fb67699baa1887cf239e9
5
+ SHA512:
6
+ metadata.gz: b2d83115a75c2c2439ac4f0d6f6a4f42cea987e3ee6b4a01355a6d462709feacd044f14778006d725967e51174d94b219403b0fd8b043e1408c2c0f09e661ee1
7
+ data.tar.gz: 0c17f282446caa837da74630205052315778a54192b00c2fd24f640c552d71778cd56599f207c39729f2c4ad9b8390737da174626aef35f8131f7e9b3b07b95a
data/.gitignore ADDED
@@ -0,0 +1,8 @@
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
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - jruby-head
5
+
6
+ jdk:
7
+ - openjdk7
8
+ - oraclejdk7
9
+ - oraclejdk8
10
+
11
+ script: bundle exec rspec spec
12
+
13
+ notifications:
14
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ [![Build Status](https://travis-ci.org/cyli/logstash-output-slack.svg?branch=master)](https://travis-ci.org/cyli/logstash-output-slack)
2
+
3
+ ## Logstash Slack Output Plugin
4
+
5
+ Uses Slack [incoming webhooks API](https://api.slack.com/incoming-webhooks) to send log events to Slack.
6
+
7
+ Usage:
8
+
9
+ ```
10
+ input {
11
+ ...
12
+ }
13
+
14
+ filters {
15
+ ...
16
+ }
17
+
18
+ output {
19
+ ...
20
+ slack {
21
+ url => <YOUR SLACK WEBHOOK URL HERE>
22
+ channel => [channel-name - this is optional]
23
+ username => [slack username - this is optional]
24
+ icon_emoji => [emoji, something like ":simple_smile:" - optional]
25
+ icon_url => [icon url, would be overriden by icon_emoji - optional]
26
+ format => [default is "%{message}", but used to format the text - optional]
27
+ }
28
+ }
29
+ ```
30
+
31
+ Not supported yet: attachments
32
+
33
+ ### Installation on Logstash >= 1.5
34
+
35
+ In the logstash directory, run: `bin/plugin install logstash-output-slack`
36
+
37
+ #### To build your own gem and install:
38
+
39
+ 1. `git clone <thisrepo>`
40
+ 1. `bundle install`
41
+ 1. `gem build logstash-output-slack.gemspec`
42
+
43
+ You should just be able to do `bin/plugin install <path-to-your-built-gem>`, but due to [this bug](https://github.com/elastic/logstash/issues/2674) installing from a local gem doesn't work right now.
44
+
45
+ You need to:
46
+
47
+ 1. Make sure that the `logstash-core` gem you've installed matches the exact beta 1.5 logstash version you are running.
48
+ 1. modify the logstash Gemfile to include the line `gem "logstash-output-slack", :path => <path_to_the_directory_your_gem_is_in>`
49
+ 1. `bin/plugin install --no-verify`
50
+
51
+ #### Verify that the plugin installed correctly
52
+ `bin/plugin list | grep logstash-output-slack`
53
+
54
+ #### Test that it works:
55
+ ```
56
+ bin/logstash -e '
57
+ input { stdin {} }
58
+ output { slack { <your slack config here> }}'
59
+ ```
60
+
61
+ And type some text in. The same text should appear in the channel it's configured to go in.
62
+
63
+ ### Installation on Logstash < 1.4
64
+
65
+ 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>.
66
+
67
+ See the [flags](http://logstash.net/docs/1.4.2/flags) documentation for Logstash 1.4.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ @files=[]
2
+
3
+ task :default do
4
+ system("rake -T")
5
+ end
6
+
7
+ require "logstash/devutils/rake"
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/base"
3
+ require "logstash/namespace"
4
+
5
+ class LogStash::Outputs::Slack < LogStash::Outputs::Base
6
+ config_name "slack"
7
+ milestone 1
8
+
9
+ # The incoming webhook URI needed to post a message
10
+ config :url, :validate => :string, :required => true
11
+
12
+ # The text to post in slack
13
+ config :format, :validate => :string, :default => "%{message}"
14
+
15
+ # The channel to post to
16
+ config :channel, :validate => :string
17
+
18
+ # The username to use for posting
19
+ config :username, :validate => :string
20
+
21
+ # Emoji icon to use
22
+ config :icon_emoji, :validate => :string
23
+
24
+ # Icon URL to use
25
+ config :icon_url, :validate => :string
26
+
27
+
28
+ public
29
+ def register
30
+ require 'rest-client'
31
+ require 'cgi'
32
+ require 'json'
33
+
34
+ @content_type = "application/x-www-form-urlencoded"
35
+ end # def register
36
+
37
+ public
38
+ def receive(event)
39
+ return unless output?(event)
40
+
41
+ payload_json = Hash.new
42
+ payload_json['text'] = event.sprintf(@format)
43
+
44
+ if not @channel.nil?
45
+ payload_json['channel'] = @channel
46
+ end
47
+
48
+ if not @username.nil?
49
+ payload_json['username'] = @username
50
+ end
51
+
52
+ if not @icon_emoji.nil?
53
+ payload_json['icon_emoji'] = @icon_emoji
54
+ end
55
+
56
+ if not @icon_url.nil?
57
+ payload_json['icon_url'] = @icon_url
58
+ end
59
+
60
+
61
+ begin
62
+ RestClient.post(
63
+ @url,
64
+ "payload=#{CGI.escape(JSON.dump(payload_json))}",
65
+ :accept => "application/json",
66
+ :'User-Agent' => "logstash-output-slack",
67
+ :content_type => @content_type) { |response, request, result, &block|
68
+ if response.code != 200
69
+ @logger.warn("Got a #{response.code} result: " + result)
70
+ end
71
+ }
72
+ rescue Exception => e
73
+ @logger.warn("Unhandled exception", :exception => e,
74
+ :stacktrace => e.backtrace)
75
+ end
76
+ end # def receive
77
+ end # class LogStash::Outputs::Slack
@@ -0,0 +1,31 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-slack'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['MIT','Apache License (2.0)']
5
+ s.summary = "Write events to Slack"
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
+ s.authors = ["Ying Li"]
8
+ s.email = 'cyli@twistedmatrix.com'
9
+ s.require_paths = ["lib"]
10
+
11
+ # Files
12
+ s.files = `git ls-files`.split($\)
13
+
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
19
+
20
+ # 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
+
28
+ # Jar dependencies
29
+ s.requirements << "jar 'org.elasticsearch:elasticsearch', '1.4.0'"
30
+ s.add_runtime_dependency "jar-dependencies", ">= 0.1.7"
31
+ end
@@ -0,0 +1,100 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe LogStash::Outputs::Slack do
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_config) do <<-CONFIG
22
+ input {
23
+ generator {
24
+ message => "This message should show in slack"
25
+ add_field => {"extra" => 3}
26
+ count => 1
27
+ }
28
+ }
29
+
30
+ output {
31
+ slack {
32
+ url => "http://requestb.in/r9lkbzr9"
33
+ format => "%{message} %{extra}"
34
+ channel => "mychannel"
35
+ username => "slackbot"
36
+ icon_emoji => ":chart_with_upwards_trend:"
37
+ icon_url => "http://lorempixel.com/48/48"
38
+ }
39
+ }
40
+ CONFIG
41
+ end
42
+
43
+ before do
44
+ WebMock.disable_net_connect!
45
+ end
46
+
47
+ after do
48
+ WebMock.reset!
49
+ WebMock.allow_net_connect!
50
+ end
51
+
52
+ context "passes the right payload to slack" do
53
+ it "uses all default values" do
54
+ stub_request(:post, "requestb.in").
55
+ to_return(:body => "", :status => 200,
56
+ :headers => { 'Content-Length' => 0 })
57
+
58
+ expected_json = {
59
+ :text => "This message should show in slack"
60
+ }
61
+
62
+ LogStash::Pipeline.new(short_config).run
63
+
64
+ expect(a_request(:post, "http://requestb.in/r9lkbzr9").
65
+ with(:body => "payload=#{CGI.escape(JSON.dump(expected_json))}",
66
+ :headers => {
67
+ 'Content-Type' => 'application/x-www-form-urlencoded',
68
+ 'Accept'=> 'application/json',
69
+ 'User-Agent' => 'logstash-output-slack'
70
+ })).
71
+ to have_been_made.once
72
+ end
73
+
74
+ it "uses all provided values" do
75
+ stub_request(:post, "requestb.in").
76
+ to_return(:body => "", :status => 200,
77
+ :headers => { 'Content-Length' => 0 })
78
+
79
+ expected_json = {
80
+ :text => "This message should show in slack 3",
81
+ :channel => "mychannel",
82
+ :username => "slackbot",
83
+ :icon_emoji => ":chart_with_upwards_trend:",
84
+ :icon_url => "http://lorempixel.com/48/48"
85
+ }
86
+
87
+ LogStash::Pipeline.new(long_config).run
88
+
89
+ expect(a_request(:post, "http://requestb.in/r9lkbzr9").
90
+ with(:body => "payload=#{CGI.escape(JSON.dump(expected_json))}",
91
+ :headers => {
92
+ 'Content-Type' => 'application/x-www-form-urlencoded',
93
+ 'Accept'=> 'application/json',
94
+ 'User-Agent' => 'logstash-output-slack'
95
+ })).
96
+ to have_been_made.once
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,3 @@
1
+ require "logstash/devutils/rspec/spec_helper"
2
+ require "logstash/outputs/slack"
3
+ require 'webmock/rspec'
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-slack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ying Li
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.4.0
28
+ - - <
29
+ - !ruby/object:Gem::Version
30
+ version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-codec-plain
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ prerelease: false
46
+ type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: rest-client
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ prerelease: false
60
+ type: :runtime
61
+ - !ruby/object:Gem::Dependency
62
+ name: logstash-devutils
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ prerelease: false
74
+ type: :development
75
+ - !ruby/object:Gem::Dependency
76
+ name: logstash-input-generator
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ prerelease: false
88
+ type: :development
89
+ - !ruby/object:Gem::Dependency
90
+ name: webmock
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirement: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ prerelease: false
102
+ type: :development
103
+ - !ruby/object:Gem::Dependency
104
+ name: jar-dependencies
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 0.1.7
110
+ requirement: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: 0.1.7
115
+ prerelease: false
116
+ type: :runtime
117
+ 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
119
+ executables: []
120
+ extensions: []
121
+ extra_rdoc_files: []
122
+ files:
123
+ - .gitignore
124
+ - .travis.yml
125
+ - Gemfile
126
+ - README.md
127
+ - Rakefile
128
+ - lib/logstash/outputs/slack.rb
129
+ - logstash-output-slack.gemspec
130
+ - spec/outputs/slack_spec.rb
131
+ - spec/spec_helper.rb
132
+ homepage:
133
+ licenses:
134
+ - MIT
135
+ - Apache License (2.0)
136
+ metadata:
137
+ logstash_plugin: 'true'
138
+ logstash_group: output
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements:
154
+ - jar 'org.elasticsearch:elasticsearch', '1.4.0'
155
+ rubyforge_project:
156
+ rubygems_version: 2.1.9
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Write events to Slack
160
+ test_files:
161
+ - spec/outputs/slack_spec.rb
162
+ - spec/spec_helper.rb