logstash-output-seq 0.0.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -7
- data/CONTRIBUTORS +11 -10
- data/DEVELOPER.md +2 -2
- data/DEVELOPING.md +69 -69
- data/Gemfile +11 -2
- data/LICENSE +22 -22
- data/README.md +37 -37
- data/lib/logstash/outputs/seq.rb +145 -145
- data/lib/version-info.rb +7 -7
- data/logstash-output-seq.gemspec +42 -39
- data/spec/outputs/seq_spec.rb +240 -239
- data/spec/spec_helper.rb +5 -4
- metadata +48 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77fb12736b1e9f994bb397f7c928d69b05e09722
|
4
|
+
data.tar.gz: 83cd2c244614defb64b18d5eb31e52165cd902b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0749fc14cdfdb6b5727fef69e74d52d718ba08b0aa76a66f75f40bc173ca18adad9772938332486415c3eaea4309aa6f50f2ecfb6f85ff594321b525b711baf
|
7
|
+
data.tar.gz: dab7f60b4dcff4ccd36491140009ffaf8b30c2bf660d1a300171f74133903567608b9a38bca82b932c9d5415412c5fc1d05d2512d5bed0a92d3c1fe9ca9e730e
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
## 2.0.1
|
2
|
-
- Add encoding: utf-8 to spec files. This can help prevent issues during testing.
|
3
|
-
## 2.0.0
|
4
|
-
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
|
5
|
-
instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
|
6
|
-
- Dependency on logstash-core update to 2.0
|
7
|
-
|
1
|
+
## 2.0.1
|
2
|
+
- Add encoding: utf-8 to spec files. This can help prevent issues during testing.
|
3
|
+
## 2.0.0
|
4
|
+
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
|
5
|
+
instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
|
6
|
+
- Dependency on logstash-core update to 2.0
|
7
|
+
|
data/CONTRIBUTORS
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
The following is a list of people who have contributed ideas, code, bug
|
2
|
-
reports, or in general have helped the Seq plugin for Logstash along its way.
|
3
|
-
|
4
|
-
Contributors:
|
5
|
-
* Adam Friedman (tintoy)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
and
|
10
|
-
|
1
|
+
The following is a list of people who have contributed ideas, code, bug
|
2
|
+
reports, or in general have helped the Seq plugin for Logstash along its way.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Adam Friedman ([@tintoy](https://github.com/tintoy))
|
6
|
+
* [@mjnorman](https://github.com/mjnorman)
|
7
|
+
|
8
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
9
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
10
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
11
|
+
open source awesome.
|
data/DEVELOPER.md
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
# logstash-output-seq
|
2
|
-
Seq output plugin.
|
1
|
+
# logstash-output-seq
|
2
|
+
Seq output plugin.
|
data/DEVELOPING.md
CHANGED
@@ -1,69 +1,69 @@
|
|
1
|
-
## Developing
|
2
|
-
|
3
|
-
### 1. Plugin Developement and Testing
|
4
|
-
|
5
|
-
#### Code
|
6
|
-
- To get started, you'll need JRuby with the Bundler gem installed.
|
7
|
-
|
8
|
-
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
9
|
-
|
10
|
-
- Install dependencies
|
11
|
-
```sh
|
12
|
-
bundle install
|
13
|
-
```
|
14
|
-
|
15
|
-
#### Test
|
16
|
-
|
17
|
-
- Update your dependencies
|
18
|
-
|
19
|
-
```sh
|
20
|
-
bundle install
|
21
|
-
```
|
22
|
-
|
23
|
-
- Run tests
|
24
|
-
|
25
|
-
```sh
|
26
|
-
bundle exec rspec
|
27
|
-
```
|
28
|
-
|
29
|
-
### 2. Running your unpublished Plugin in Logstash
|
30
|
-
|
31
|
-
#### 2.1 Run in a local Logstash clone
|
32
|
-
|
33
|
-
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
34
|
-
```ruby
|
35
|
-
gem "logstash-output-seq", :path => "/your/local/logstash-output-seq"
|
36
|
-
```
|
37
|
-
- Install plugin
|
38
|
-
```sh
|
39
|
-
# Logstash 2.3 and higher
|
40
|
-
bin/logstash-plugin install --no-verify
|
41
|
-
|
42
|
-
# Prior to Logstash 2.3
|
43
|
-
bin/plugin install --no-verify
|
44
|
-
|
45
|
-
```
|
46
|
-
- Run Logstash with your plugin
|
47
|
-
```sh
|
48
|
-
bin/logstash -e 'output {seq {}}'
|
49
|
-
```
|
50
|
-
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
51
|
-
|
52
|
-
#### 2.2 Run in an installed Logstash
|
53
|
-
|
54
|
-
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
55
|
-
|
56
|
-
- Build your plugin gem
|
57
|
-
```sh
|
58
|
-
gem build logstash-output-seq.gemspec
|
59
|
-
```
|
60
|
-
- Install the plugin from the Logstash home
|
61
|
-
```sh
|
62
|
-
# Logstash 2.3 and higher
|
63
|
-
bin/logstash-plugin install --no-verify
|
64
|
-
|
65
|
-
# Prior to Logstash 2.3
|
66
|
-
bin/plugin install --no-verify
|
67
|
-
|
68
|
-
```
|
69
|
-
- Start Logstash and proceed to test the plugin
|
1
|
+
## Developing
|
2
|
+
|
3
|
+
### 1. Plugin Developement and Testing
|
4
|
+
|
5
|
+
#### Code
|
6
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
7
|
+
|
8
|
+
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
9
|
+
|
10
|
+
- Install dependencies
|
11
|
+
```sh
|
12
|
+
bundle install
|
13
|
+
```
|
14
|
+
|
15
|
+
#### Test
|
16
|
+
|
17
|
+
- Update your dependencies
|
18
|
+
|
19
|
+
```sh
|
20
|
+
bundle install
|
21
|
+
```
|
22
|
+
|
23
|
+
- Run tests
|
24
|
+
|
25
|
+
```sh
|
26
|
+
bundle exec rspec
|
27
|
+
```
|
28
|
+
|
29
|
+
### 2. Running your unpublished Plugin in Logstash
|
30
|
+
|
31
|
+
#### 2.1 Run in a local Logstash clone
|
32
|
+
|
33
|
+
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
34
|
+
```ruby
|
35
|
+
gem "logstash-output-seq", :path => "/your/local/logstash-output-seq"
|
36
|
+
```
|
37
|
+
- Install plugin
|
38
|
+
```sh
|
39
|
+
# Logstash 2.3 and higher
|
40
|
+
bin/logstash-plugin install --no-verify
|
41
|
+
|
42
|
+
# Prior to Logstash 2.3
|
43
|
+
bin/plugin install --no-verify
|
44
|
+
|
45
|
+
```
|
46
|
+
- Run Logstash with your plugin
|
47
|
+
```sh
|
48
|
+
bin/logstash -e 'output {seq {}}'
|
49
|
+
```
|
50
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
51
|
+
|
52
|
+
#### 2.2 Run in an installed Logstash
|
53
|
+
|
54
|
+
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
55
|
+
|
56
|
+
- Build your plugin gem
|
57
|
+
```sh
|
58
|
+
gem build logstash-output-seq.gemspec
|
59
|
+
```
|
60
|
+
- Install the plugin from the Logstash home
|
61
|
+
```sh
|
62
|
+
# Logstash 2.3 and higher
|
63
|
+
bin/logstash-plugin install --no-verify
|
64
|
+
|
65
|
+
# Prior to Logstash 2.3
|
66
|
+
bin/plugin install --no-verify
|
67
|
+
|
68
|
+
```
|
69
|
+
- Start Logstash and proceed to test the plugin
|
data/Gemfile
CHANGED
@@ -1,2 +1,11 @@
|
|
1
|
-
source '
|
2
|
-
|
1
|
+
source 'https://rubygems.org'
|
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/LICENSE
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2015 tin oscillator
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
22
|
-
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 tin oscillator
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
# Seq output plugin for Logstash
|
2
|
-
|
3
|
-
[![Travis Build Status](https://travis-ci.org/tintoy/logstash-output-seq.svg)](https://travis-ci.org/tintoy/logstash-output-seq)
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/logstash-output-seq.svg)](https://badge.fury.io/rb/logstash-output-seq)
|
5
|
-
[![Coverage Status (master)](https://coveralls.io/repos/github/tintoy/logstash-output-seq/badge.svg?branch=master)](https://coveralls.io/github/tintoy/logstash-output-seq?branch=master)
|
6
|
-
|
7
|
-
This is an output plugin for [Logstash](https://github.com/elastic/logstash) that publishes events to [Seq](https://getseq.net/).
|
8
|
-
|
9
|
-
It is fully free and fully open source. The license is MIT, meaning you are pretty much free to use it however you want in whatever way.
|
10
|
-
|
11
|
-
## Usage
|
12
|
-
|
13
|
-
To install the Seq output plugin for Logstash:
|
14
|
-
|
15
|
-
```sh
|
16
|
-
# Logstash 2.3 and higher
|
17
|
-
${LOGSTASH_HOME}/bin/logstash-plugin install logstash-output-seq
|
18
|
-
```
|
19
|
-
|
20
|
-
The plugin has the following configuration options:
|
21
|
-
|
22
|
-
* `url` (Required) - The Seq server URL (e.g. `http://localhost:5341/`)
|
23
|
-
* `api_key` (Optional) - The Seq API key (if any) to use for authentication.
|
24
|
-
* Any parameters from the Logstash HttpClient mix-in (e.g. configuring SSL behaviour, etc).
|
25
|
-
|
26
|
-
### Docker
|
27
|
-
|
28
|
-
There is also a [docker image](https://hub.docker.com/r/tintoy/logstash-output-seq/) available that has this plugin preinstalled.
|
29
|
-
|
30
|
-
## Developing
|
31
|
-
|
32
|
-
[Developing](DEVELOPING.md)
|
33
|
-
|
34
|
-
## Contributing
|
35
|
-
|
36
|
-
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
37
|
-
|
1
|
+
# Seq output plugin for Logstash
|
2
|
+
|
3
|
+
[![Travis Build Status](https://travis-ci.org/tintoy/logstash-output-seq.svg)](https://travis-ci.org/tintoy/logstash-output-seq)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/logstash-output-seq.svg)](https://badge.fury.io/rb/logstash-output-seq)
|
5
|
+
[![Coverage Status (master)](https://coveralls.io/repos/github/tintoy/logstash-output-seq/badge.svg?branch=master)](https://coveralls.io/github/tintoy/logstash-output-seq?branch=master)
|
6
|
+
|
7
|
+
This is an output plugin for [Logstash](https://github.com/elastic/logstash) that publishes events to [Seq](https://getseq.net/).
|
8
|
+
|
9
|
+
It is fully free and fully open source. The license is MIT, meaning you are pretty much free to use it however you want in whatever way.
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
To install the Seq output plugin for Logstash:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
# Logstash 2.3 and higher
|
17
|
+
${LOGSTASH_HOME}/bin/logstash-plugin install logstash-output-seq
|
18
|
+
```
|
19
|
+
|
20
|
+
The plugin has the following configuration options:
|
21
|
+
|
22
|
+
* `url` (Required) - The Seq server URL (e.g. `http://localhost:5341/`)
|
23
|
+
* `api_key` (Optional) - The Seq API key (if any) to use for authentication.
|
24
|
+
* Any parameters from the Logstash HttpClient mix-in (e.g. configuring SSL behaviour, etc).
|
25
|
+
|
26
|
+
### Docker
|
27
|
+
|
28
|
+
There is also a [docker image](https://hub.docker.com/r/tintoy/logstash-output-seq/) available that has this plugin preinstalled.
|
29
|
+
|
30
|
+
## Developing
|
31
|
+
|
32
|
+
[Developing](DEVELOPING.md)
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
37
|
+
|
38
38
|
For more information about contributing, see the [CONTRIBUTING](https://github.com/tintoy/logstash-output-seq/blob/master/.github/CONTRIBUTING.md) file.
|
data/lib/logstash/outputs/seq.rb
CHANGED
@@ -1,145 +1,145 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'logstash/outputs/base'
|
3
|
-
require 'logstash/plugin_mixins/http_client'
|
4
|
-
require 'logstash/json'
|
5
|
-
require 'logstash/namespace'
|
6
|
-
|
7
|
-
require 'jrjackson'
|
8
|
-
|
9
|
-
# An output that sends events to Seq.
|
10
|
-
class LogStash::Outputs::Seq < LogStash::Outputs::Base
|
11
|
-
include LogStash::PluginMixins::HttpClient
|
12
|
-
|
13
|
-
@@ignore_properties = {
|
14
|
-
'@timestamp' => true,
|
15
|
-
'@level' => true,
|
16
|
-
'@version' => true,
|
17
|
-
'message' => true
|
18
|
-
}
|
19
|
-
|
20
|
-
config_name 'seq'
|
21
|
-
|
22
|
-
# The Seq server URL
|
23
|
-
config :url, :validate => :string, :required => :true
|
24
|
-
|
25
|
-
# The Seq API key
|
26
|
-
config :api_key, :validate => :string, :optional => :true
|
27
|
-
|
28
|
-
public
|
29
|
-
def register
|
30
|
-
url = @url
|
31
|
-
|
32
|
-
url += '/' unless url.end_with? '/'
|
33
|
-
url += 'api/events/raw'
|
34
|
-
|
35
|
-
@url = url
|
36
|
-
|
37
|
-
@default_headers = {
|
38
|
-
'X-Seq-ApiKey' => @api_key,
|
39
|
-
'Content-Type' => 'application/json'
|
40
|
-
}
|
41
|
-
|
42
|
-
# We count outstanding requests with this queue; it tracks outstanding requests to create backpressure
|
43
|
-
# When this queue is empty no new requests may be sent, tokens must be added back by the client on success
|
44
|
-
@request_tokens = SizedQueue.new(@pool_max)
|
45
|
-
@pool_max.times {|t| @request_tokens << true }
|
46
|
-
end # def register
|
47
|
-
|
48
|
-
public
|
49
|
-
def multi_receive(events)
|
50
|
-
payload = {
|
51
|
-
'Events' => events.map {|event| to_seq_payload(event)}
|
52
|
-
}
|
53
|
-
post_to_seq(payload)
|
54
|
-
|
55
|
-
"#{events.length} events received"
|
56
|
-
end # def multi_receive
|
57
|
-
|
58
|
-
public
|
59
|
-
def receive(event)
|
60
|
-
payload = {
|
61
|
-
'Events' => [to_seq_payload(event)]
|
62
|
-
}
|
63
|
-
post_to_seq(payload)
|
64
|
-
|
65
|
-
'Event received'
|
66
|
-
end # def receive
|
67
|
-
|
68
|
-
private
|
69
|
-
def post_to_seq(payload)
|
70
|
-
token = @request_tokens.pop
|
71
|
-
|
72
|
-
request = client.post(@url, {
|
73
|
-
headers: @default_headers,
|
74
|
-
body: JrJackson::Json.dump(payload),
|
75
|
-
async: true
|
76
|
-
})
|
77
|
-
|
78
|
-
request.on_complete do
|
79
|
-
@request_tokens << token
|
80
|
-
end
|
81
|
-
|
82
|
-
request.on_success do |response|
|
83
|
-
if response.code < 200 || response.code > 299
|
84
|
-
log_failure("Encountered non-200 HTTP code #{200}",
|
85
|
-
:response_code => response.code,
|
86
|
-
:url => url,
|
87
|
-
:event => event
|
88
|
-
)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
request.on_failure do |exception|
|
93
|
-
log_failure("Could not submit POST request.",
|
94
|
-
:url => url,
|
95
|
-
:method => @http_method,
|
96
|
-
:body => body,
|
97
|
-
:headers => headers,
|
98
|
-
:message => exception.message,
|
99
|
-
:class => exception.class.name,
|
100
|
-
:backtrace => exception.backtrace
|
101
|
-
)
|
102
|
-
end
|
103
|
-
|
104
|
-
request_async_background(request)
|
105
|
-
end # def post_to_seq
|
106
|
-
|
107
|
-
# Convert a Logstash event to a Seq event payload.
|
108
|
-
#
|
109
|
-
# Note that we return a hash here, not the JSON, because it's more efficient to convert batched events to JSON all-in-one go.
|
110
|
-
private
|
111
|
-
def to_seq_payload(event)
|
112
|
-
props = {
|
113
|
-
'@Version' => event
|
114
|
-
}
|
115
|
-
payload = {
|
116
|
-
:Timestamp => event
|
117
|
-
:Level => get_level(event),
|
118
|
-
:MessageTemplate => event
|
119
|
-
:Properties => props
|
120
|
-
}
|
121
|
-
|
122
|
-
event.
|
123
|
-
props[property] = value unless @@ignore_properties.has_key? property
|
124
|
-
end
|
125
|
-
|
126
|
-
payload
|
127
|
-
end # def to_seq_payload
|
128
|
-
|
129
|
-
private
|
130
|
-
def get_level(event)
|
131
|
-
level = event
|
132
|
-
|
133
|
-
level ? level : 'Verbose'
|
134
|
-
end # def get_level
|
135
|
-
|
136
|
-
# Manticore doesn't provide a way to attach handlers to background or async requests well
|
137
|
-
# It wants you to use futures. The #async method kinda works but expects single thread batches
|
138
|
-
# and background only returns futures.
|
139
|
-
# Proposed fix to manticore here: https://github.com/cheald/manticore/issues/32
|
140
|
-
private
|
141
|
-
def request_async_background(request)
|
142
|
-
@method ||= client.executor.java_method(:submit, [java.util.concurrent.Callable.java_class])
|
143
|
-
@method.call(request)
|
144
|
-
end
|
145
|
-
end # class LogStash::Outputs::Seq
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'logstash/outputs/base'
|
3
|
+
require 'logstash/plugin_mixins/http_client'
|
4
|
+
require 'logstash/json'
|
5
|
+
require 'logstash/namespace'
|
6
|
+
|
7
|
+
require 'jrjackson'
|
8
|
+
|
9
|
+
# An output that sends events to Seq.
|
10
|
+
class LogStash::Outputs::Seq < LogStash::Outputs::Base
|
11
|
+
include LogStash::PluginMixins::HttpClient
|
12
|
+
|
13
|
+
@@ignore_properties = {
|
14
|
+
'@timestamp' => true,
|
15
|
+
'@level' => true,
|
16
|
+
'@version' => true,
|
17
|
+
'message' => true
|
18
|
+
}
|
19
|
+
|
20
|
+
config_name 'seq'
|
21
|
+
|
22
|
+
# The Seq server URL
|
23
|
+
config :url, :validate => :string, :required => :true
|
24
|
+
|
25
|
+
# The Seq API key
|
26
|
+
config :api_key, :validate => :string, :optional => :true
|
27
|
+
|
28
|
+
public
|
29
|
+
def register
|
30
|
+
url = @url
|
31
|
+
|
32
|
+
url += '/' unless url.end_with? '/'
|
33
|
+
url += 'api/events/raw'
|
34
|
+
|
35
|
+
@url = url
|
36
|
+
|
37
|
+
@default_headers = {
|
38
|
+
'X-Seq-ApiKey' => @api_key,
|
39
|
+
'Content-Type' => 'application/json'
|
40
|
+
}
|
41
|
+
|
42
|
+
# We count outstanding requests with this queue; it tracks outstanding requests to create backpressure
|
43
|
+
# When this queue is empty no new requests may be sent, tokens must be added back by the client on success
|
44
|
+
@request_tokens = SizedQueue.new(@pool_max)
|
45
|
+
@pool_max.times {|t| @request_tokens << true }
|
46
|
+
end # def register
|
47
|
+
|
48
|
+
public
|
49
|
+
def multi_receive(events)
|
50
|
+
payload = {
|
51
|
+
'Events' => events.map {|event| to_seq_payload(event)}
|
52
|
+
}
|
53
|
+
post_to_seq(payload)
|
54
|
+
|
55
|
+
"#{events.length} events received"
|
56
|
+
end # def multi_receive
|
57
|
+
|
58
|
+
public
|
59
|
+
def receive(event)
|
60
|
+
payload = {
|
61
|
+
'Events' => [to_seq_payload(event)]
|
62
|
+
}
|
63
|
+
post_to_seq(payload)
|
64
|
+
|
65
|
+
'Event received'
|
66
|
+
end # def receive
|
67
|
+
|
68
|
+
private
|
69
|
+
def post_to_seq(payload)
|
70
|
+
token = @request_tokens.pop
|
71
|
+
|
72
|
+
request = client.post(@url, {
|
73
|
+
headers: @default_headers,
|
74
|
+
body: JrJackson::Json.dump(payload),
|
75
|
+
async: true
|
76
|
+
})
|
77
|
+
|
78
|
+
request.on_complete do
|
79
|
+
@request_tokens << token
|
80
|
+
end
|
81
|
+
|
82
|
+
request.on_success do |response|
|
83
|
+
if response.code < 200 || response.code > 299
|
84
|
+
log_failure("Encountered non-200 HTTP code #{200}",
|
85
|
+
:response_code => response.code,
|
86
|
+
:url => url,
|
87
|
+
:event => event
|
88
|
+
)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
request.on_failure do |exception|
|
93
|
+
log_failure("Could not submit POST request.",
|
94
|
+
:url => url,
|
95
|
+
:method => @http_method,
|
96
|
+
:body => body,
|
97
|
+
:headers => headers,
|
98
|
+
:message => exception.message,
|
99
|
+
:class => exception.class.name,
|
100
|
+
:backtrace => exception.backtrace
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
request_async_background(request)
|
105
|
+
end # def post_to_seq
|
106
|
+
|
107
|
+
# Convert a Logstash event to a Seq event payload.
|
108
|
+
#
|
109
|
+
# Note that we return a hash here, not the JSON, because it's more efficient to convert batched events to JSON all-in-one go.
|
110
|
+
private
|
111
|
+
def to_seq_payload(event)
|
112
|
+
props = {
|
113
|
+
'@Version' => event.get('@version')
|
114
|
+
}
|
115
|
+
payload = {
|
116
|
+
:Timestamp => event.get('@timestamp'),
|
117
|
+
:Level => get_level(event),
|
118
|
+
:MessageTemplate => event.get('message'),
|
119
|
+
:Properties => props
|
120
|
+
}
|
121
|
+
|
122
|
+
event.to_hash.each do |property, value|
|
123
|
+
props[property] = value unless @@ignore_properties.has_key? property
|
124
|
+
end
|
125
|
+
|
126
|
+
payload
|
127
|
+
end # def to_seq_payload
|
128
|
+
|
129
|
+
private
|
130
|
+
def get_level(event)
|
131
|
+
level = event.get('@level')
|
132
|
+
|
133
|
+
level ? level : 'Verbose'
|
134
|
+
end # def get_level
|
135
|
+
|
136
|
+
# Manticore doesn't provide a way to attach handlers to background or async requests well
|
137
|
+
# It wants you to use futures. The #async method kinda works but expects single thread batches
|
138
|
+
# and background only returns futures.
|
139
|
+
# Proposed fix to manticore here: https://github.com/cheald/manticore/issues/32
|
140
|
+
private
|
141
|
+
def request_async_background(request)
|
142
|
+
@method ||= client.executor.java_method(:submit, [java.util.concurrent.Callable.java_class])
|
143
|
+
@method.call(request)
|
144
|
+
end
|
145
|
+
end # class LogStash::Outputs::Seq
|