logstash-output-sumologic 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/CONTRIBUTORS +13 -0
- data/DEVELOPER.md +2 -0
- data/Gemfile +3 -0
- data/LICENSE +18 -0
- data/README.md +49 -0
- data/lib/logstash/outputs/sumologic.rb +139 -0
- data/logstash-output-sumologic.gemspec +24 -0
- data/spec/outputs/sumologic_spec.rb +22 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 15ebf5a83834cd6cad674708a813abe835270481
|
4
|
+
data.tar.gz: 930252e23ef4d415f321a5f837bc43ced4b56a74
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bb790a13d2f84126b7ea350ae0413398858f3abef2054063de8fbf56913affef97e116f06950c9df413ece298c1753dc674e540a1e4ef5c05708be02a2b1e67c
|
7
|
+
data.tar.gz: f8ce4d93bf8b70a16a26004df5db415f6bc9c2231504cdfa674a4b17df5ab0057e183d19bdd3fc5f0b3cfe0986d00c109d67fdd845c1e9ac0c732b878ebd50cc
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
The following is a list of people who have contributed ideas, code, bug
|
2
|
+
reports, or in general have helped Sumo Logic plug-in along its way.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Bin Yi (bin3377)
|
6
|
+
* Brain Goleno (bgoleno)
|
7
|
+
* Jacek Migdal (jakozaur)
|
8
|
+
* Cris Dessonville (cddude229)
|
9
|
+
|
10
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
11
|
+
Sumo Logic plug-in, and you aren't on the list above and want to be, please let us know
|
12
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
13
|
+
open source awesome.
|
data/DEVELOPER.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2016 Sumo Logic <https://www.sumologic.com>
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
14
|
+
|
15
|
+
This product includes software developed by The Apache Software
|
16
|
+
Foundation (http://www.apache.org/).
|
17
|
+
|
18
|
+
This product includes software developed by Elasticsearch (http://www.elastic.co/).
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Logstash Sumo Logic Output Plugin
|
2
|
+
|
3
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
4
|
+
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.
|
5
|
+
|
6
|
+
## Getting Started
|
7
|
+
|
8
|
+
### 1. Create a Sumo Logic HTTP source
|
9
|
+
- Create a [Sumo Logic](https://www.sumologic.com/) free account if you currently don't have one.
|
10
|
+
- Create a [HTTP source](http://help.sumologic.com/Send_Data/Sources/HTTP_Source) in your account and get the URL for this source. It should be something like
|
11
|
+
```
|
12
|
+
https://events.sumologic.net/receiver/v1/http/XXXXXXXXXX
|
13
|
+
```
|
14
|
+
|
15
|
+
### 2. Install LogStash on your machine
|
16
|
+
- Following this [instruction](https://www.elastic.co/guide/en/logstash/current/getting-started-with-logstash.html) to download and install LogStash. This plugin require Logstash 2.3 or higher to run.
|
17
|
+
|
18
|
+
### 3. Build plugin gem and install to LogStash
|
19
|
+
- Build your plugin gem
|
20
|
+
|
21
|
+
In your local Git clone, running:
|
22
|
+
```sh
|
23
|
+
gem build logstash-output-sumologic.gemspec
|
24
|
+
```
|
25
|
+
|
26
|
+
You will get a .gem file as `logstash-output-sumologic-1.0.0.gem`
|
27
|
+
|
28
|
+
- Install plugin into LogStash
|
29
|
+
|
30
|
+
In the Logstash home, running:
|
31
|
+
```sh
|
32
|
+
bin/logstash-plugin install <path of .gem>
|
33
|
+
```
|
34
|
+
|
35
|
+
### 4. Start Logstash and send log
|
36
|
+
In the Logstash home, running:
|
37
|
+
```sh
|
38
|
+
bin/logstash -e 'input{stdin{}}output{sumologic{url=>"<url from step 1>"}}'
|
39
|
+
```
|
40
|
+
|
41
|
+
This will send any input from console to Sumo Logic cloud service.
|
42
|
+
|
43
|
+
### 5. Get result from Sumo Logic web app
|
44
|
+
- Logon to Sumo Logic [web app](https://prod-www.sumologic.net/ui/) and run [Search](http://help.sumologic.com/Search) or [Live Tail](http://help.sumologic.com/Search/Live_Tail)
|
45
|
+
|
46
|
+
### Further things
|
47
|
+
- Try it with different input/filter/codec plugins
|
48
|
+
- Start LogStash as a service/daemon in your production environment
|
49
|
+
- Report and issue or idea through [Git Hub](https://github.com/SumoLogic/logstash-output-sumologic)
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/json"
|
3
|
+
require "logstash/namespace"
|
4
|
+
require "logstash/outputs/base"
|
5
|
+
require "logstash/plugin_mixins/http_client"
|
6
|
+
require 'thread'
|
7
|
+
require "uri"
|
8
|
+
require "zlib"
|
9
|
+
|
10
|
+
# Now you can use logstash to deliver logs to Sumo Logic
|
11
|
+
#
|
12
|
+
# Create a HTTP Source
|
13
|
+
# in your Sumo Logic account and you can now use logstash to parse your log and
|
14
|
+
# send your logs to your account at Sumo Logic.
|
15
|
+
#
|
16
|
+
class LogStash::Outputs::SumoLogic < LogStash::Outputs::Base
|
17
|
+
include LogStash::PluginMixins::HttpClient
|
18
|
+
|
19
|
+
config_name "sumologic"
|
20
|
+
|
21
|
+
# The hostname to send logs to. This should be given when creating a HTTP Source
|
22
|
+
# on Sumo Logic web app http://help.sumologic.com/Send_Data/Sources/HTTP_Source
|
23
|
+
config :url, :validate => :string, :required => true
|
24
|
+
|
25
|
+
# Include extra HTTP headers on request if needed
|
26
|
+
config :extra_headers, :validate => :hash, :default => []
|
27
|
+
|
28
|
+
# The formatter of message, by default is message with timestamp as prefix
|
29
|
+
config :format, :validate => :string, :default => "%{@timestamp} %{host} %{message}"
|
30
|
+
|
31
|
+
# Hold messages for at least (x) seconds as a pile; 0 means sending every events immediately
|
32
|
+
config :interval, :validate => :number, :default => 0
|
33
|
+
|
34
|
+
# Compress the payload
|
35
|
+
config :compress, :validate => :boolean, :default => false
|
36
|
+
|
37
|
+
public
|
38
|
+
def register
|
39
|
+
# initialize request pool
|
40
|
+
@request_tokens = SizedQueue.new(@pool_max)
|
41
|
+
@pool_max.times { |t| @request_tokens << true }
|
42
|
+
@timer = Time.now
|
43
|
+
@pile = Array.new
|
44
|
+
@semaphore = Mutex.new
|
45
|
+
end # def register
|
46
|
+
|
47
|
+
public
|
48
|
+
def multi_receive(events)
|
49
|
+
events.each { |event| receive(event) }
|
50
|
+
client.execute!
|
51
|
+
end # def multi_receive
|
52
|
+
|
53
|
+
public
|
54
|
+
def receive(event)
|
55
|
+
if event == LogStash::SHUTDOWN
|
56
|
+
finished
|
57
|
+
return
|
58
|
+
end
|
59
|
+
|
60
|
+
content = event.sprintf(@format)
|
61
|
+
|
62
|
+
if @interval <= 0 # means send immediately
|
63
|
+
send_request(content)
|
64
|
+
return
|
65
|
+
end
|
66
|
+
|
67
|
+
@semaphore.synchronize {
|
68
|
+
now = Time.now
|
69
|
+
@pile << content
|
70
|
+
|
71
|
+
if now - @timer > @interval # ready to send
|
72
|
+
send_request(@pile.join($/))
|
73
|
+
@timer = now
|
74
|
+
@pile.clear
|
75
|
+
end
|
76
|
+
}
|
77
|
+
end # def receive
|
78
|
+
|
79
|
+
public
|
80
|
+
def close
|
81
|
+
@semaphore.synchronize {
|
82
|
+
send_request(@pile.join($/))
|
83
|
+
@pile.clear
|
84
|
+
}
|
85
|
+
client.close
|
86
|
+
end # def close
|
87
|
+
|
88
|
+
private
|
89
|
+
def send_request(content)
|
90
|
+
token = @request_tokens.pop
|
91
|
+
body = if @compress
|
92
|
+
Zlib::Deflate.deflate(content)
|
93
|
+
else
|
94
|
+
content
|
95
|
+
end
|
96
|
+
headers = get_headers()
|
97
|
+
|
98
|
+
request = client.send(:parallel).send(:post, @url, :body => body, :headers => headers)
|
99
|
+
request.on_complete do
|
100
|
+
@request_tokens << token
|
101
|
+
end
|
102
|
+
|
103
|
+
request.on_success do |response|
|
104
|
+
if response.code < 200 || response.code > 299
|
105
|
+
log_failure(
|
106
|
+
"HTTP response #{response.code}",
|
107
|
+
:body => body,
|
108
|
+
:headers => headers
|
109
|
+
)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
request.on_failure do |exception|
|
114
|
+
log_failure(
|
115
|
+
"Could not fetch URL",
|
116
|
+
:body => body,
|
117
|
+
:headers => headers,
|
118
|
+
:message => exception.message,
|
119
|
+
:class => exception.class.name,
|
120
|
+
:backtrace => exception.backtrace
|
121
|
+
)
|
122
|
+
end
|
123
|
+
|
124
|
+
request.call
|
125
|
+
end # def send_request
|
126
|
+
|
127
|
+
private
|
128
|
+
def get_headers()
|
129
|
+
base = { "Content-Type" => "text/plain" }
|
130
|
+
base["Content-Encoding"] = "deflate" if @compress
|
131
|
+
return base.merge(@extra_headers)
|
132
|
+
end # def get_header
|
133
|
+
|
134
|
+
private
|
135
|
+
def log_failure(message, opts)
|
136
|
+
@logger.error(message, opts)
|
137
|
+
end # def log_failure
|
138
|
+
|
139
|
+
end # class LogStash::Outputs::SumoLogic
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-output-sumologic'
|
3
|
+
s.version = "1.0.0"
|
4
|
+
s.licenses = ["Apache-2.0"]
|
5
|
+
s.summary = "Deliever the log to Sumo Logic cloud service."
|
6
|
+
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
|
7
|
+
s.authors = ["Sumo Logic"]
|
8
|
+
s.email = "byi@sumologic.com"
|
9
|
+
s.homepage = "http://www.sumologic.com"
|
10
|
+
s.require_paths = ["lib"]
|
11
|
+
|
12
|
+
# Files
|
13
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
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", ">= 2.0.0", "< 3.0.0"
|
22
|
+
s.add_runtime_dependency "logstash-codec-plain"
|
23
|
+
s.add_development_dependency "logstash-devutils"
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/devutils/rspec/spec_helper"
|
3
|
+
require "logstash/outputs/sumologic"
|
4
|
+
require "logstash/codecs/plain"
|
5
|
+
require "logstash/event"
|
6
|
+
|
7
|
+
describe LogStash::Outputs::SumoLogic do
|
8
|
+
let(:sample_event) { LogStash::Event.new }
|
9
|
+
let(:output) { LogStash::Outputs::SumoLogic.new }
|
10
|
+
|
11
|
+
before do
|
12
|
+
output.register
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "receive message" do
|
16
|
+
subject { output.receive(sample_event) }
|
17
|
+
|
18
|
+
it "returns a string" do
|
19
|
+
expect(subject).to eq("Event received")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-output-sumologic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sumo Logic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logstash-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: logstash-codec-plain
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: logstash-devutils
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
description: This gem is a Logstash plugin required to be installed on top of the
|
62
|
+
Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
|
63
|
+
gem is not a stand-alone program
|
64
|
+
email: byi@sumologic.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- CHANGELOG.md
|
70
|
+
- CONTRIBUTORS
|
71
|
+
- DEVELOPER.md
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE
|
74
|
+
- README.md
|
75
|
+
- lib/logstash/outputs/sumologic.rb
|
76
|
+
- logstash-output-sumologic.gemspec
|
77
|
+
- spec/outputs/sumologic_spec.rb
|
78
|
+
homepage: http://www.sumologic.com
|
79
|
+
licenses:
|
80
|
+
- Apache-2.0
|
81
|
+
metadata:
|
82
|
+
logstash_plugin: 'true'
|
83
|
+
logstash_group: output
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.6.6
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Deliever the log to Sumo Logic cloud service.
|
104
|
+
test_files:
|
105
|
+
- spec/outputs/sumologic_spec.rb
|