hshek-logstash-output-sumologic 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2ab0c4c2b9fd38780ff28615212ace0688a4f18b7df9a7a8f57ac625d97495f6
4
+ data.tar.gz: 60c1c4671459227367525a7bc0b00e011f22260b262fba6e01a139fa20d69b3e
5
+ SHA512:
6
+ metadata.gz: 8bc7deee7fee975ce9034111e1f6e3c411c333e8f9d57d5a737217d6769cfc194175ee5349f6742424f96278ec2f64b70f2511cfbc2f0a44b7f3278aff57dab4
7
+ data.tar.gz: 93136d49ed12051198d10e88f120a484e12cd0ca202db095a220ea4aeb1359571bb38ee66e325c6bc85f848240eafad3f5a7474ebcfdf2d041aa4abbd8b2c8cb
@@ -0,0 +1,34 @@
1
+ # Change Log
2
+
3
+ ## 1.2.3
4
+ - #36
5
+ - Update sender to send in batch.
6
+ - Support %{} field evaluation in `source_category`, `source_name`, `source_host` parameters
7
+ - #39 Disable cookies by default
8
+ - #41
9
+ - Provide Docker image with Logstash 6.6 + output plugin on docker hub
10
+ - Kubernetes support with Logstash beats to SumoLogic
11
+ - CI improving
12
+
13
+ ## 1.2.2
14
+
15
+ - Bug fix: memory leak when using `%{@json}` in format
16
+
17
+ ## 1.2.1
18
+
19
+ - Bug fix on plug-in logging and samples
20
+
21
+ ## 1.2.0
22
+
23
+ - Support message piling with both `interval` and `pile_max`
24
+ - Support in memory message queue to overall enhance throughput
25
+ - Retry sending when get throttled or temporary server problem
26
+ - Support monitor throughput statistics in metrics
27
+
28
+ ## 1.1.0
29
+
30
+ - Support metrics sending
31
+
32
+ ## 1.0.0
33
+
34
+ - Initial release
@@ -0,0 +1,39 @@
1
+ # Development Guide
2
+
3
+ Logstash output plugin for delivering log to Sumo Logic cloud service through HTTP source.
4
+
5
+ ## How to build .gem file from repository
6
+
7
+ Open logstash-output-sumologic.gemspec and make any necessary configuration changes.
8
+ In your local Git clone, run:
9
+
10
+ ```bash
11
+ gem build logstash-output-sumologic.gemspec
12
+ ```
13
+
14
+ You will get a .gem file in the same directory as `logstash-output-sumologic-x.y.z.gem`
15
+ Remove old version of plugin (optional):
16
+
17
+ ```bash
18
+ bin/logstash-plugin remove logstash-output-sumologic
19
+ ```
20
+
21
+ And then install the plugin locally:
22
+
23
+ ```bash
24
+ bin/logstash-plugin install <full path of .gem>
25
+ ```
26
+
27
+ ## How to run test with rspec
28
+
29
+ The test requires JRuby to run. So you need to install [JRuby](http://jruby.org/), [bundle](https://bundler.io/bundle_install.html) and [RVM](https://rvm.io/) (for switching between JRuby and Ruby) first.
30
+ And then run:
31
+
32
+ ```bash
33
+ rvm use jruby
34
+ bundle install
35
+ export sumo_url=https://events.sumologic.net/receiver/v1/http/XXXXXXXXXX
36
+ rspec spec/
37
+ ```
38
+
39
+ The project is integrated to the Travis CI now. Make sure [all test passed](https://travis-ci.org/SumoLogic/logstash-output-sumologic) before creating PR
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem 'rspec'
4
+ gem 'rspec-eventually'
data/LICENSE ADDED
@@ -0,0 +1,196 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2018 Sumo Logic
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
191
+
192
+ This product includes software developed by The Apache Software
193
+ Foundation (http://www.apache.org/).
194
+
195
+ This product includes software developed by Elasticsearch
196
+ (http://www.elastic.co/).
@@ -0,0 +1,158 @@
1
+ # Logstash Sumo Logic Output Plugin
2
+
3
+ [![Build Status](https://travis-ci.org/SumoLogic/logstash-output-sumologic.svg?branch=master)](https://travis-ci.org/SumoLogic/logstash-output-sumologic) [![Gem Version](https://badge.fury.io/rb/logstash-output-sumologic.svg)](https://badge.fury.io/rb/logstash-output-sumologic) [![Docker Pulls](https://img.shields.io/docker/pulls/sumologic/logstash-output-sumologic.svg)](https://hub.docker.com/r/sumologic/logstash-output-sumologic)
4
+
5
+ This is an output plugin for [Logstash](https://github.com/elastic/logstash).
6
+ 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.
7
+
8
+ ## Getting Started
9
+
10
+ This guide is for the users just want to download the binary and make the plugin work. For the developer, please refer to the [Developer Guide](DEVELOPER.md)
11
+
12
+ ### 1. Create a Sumo Logic HTTP source
13
+
14
+ Create a [Sumo Logic](https://www.sumologic.com/) free account if you currently don't have one.
15
+
16
+ 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:
17
+ `https://events.sumologic.net/receiver/v1/http/XXXXXXXXXX`
18
+
19
+ ### 2. Install LogStash on your machine
20
+
21
+ Following this [instruction](https://www.elastic.co/guide/en/logstash/current/getting-started-with-logstash.html) to download and install LogStash. This plugin requires Logstash 2.3 or higher to work.
22
+
23
+ ### 3. Install latest Logstash Sumo Logic Output plugin from [RubyGems](https://rubygems.org/gems/logstash-output-sumologic)
24
+
25
+ ```bash
26
+ bin/logstash-plugin install logstash-output-sumologic
27
+ ```
28
+
29
+ ### 4. Start Logstash and send log
30
+
31
+ In the Logstash home, running:
32
+
33
+ ```bash
34
+ bin/logstash -e "input{stdin{}}output{sumologic{url=>'<URL from step 1>'}}"
35
+ ```
36
+
37
+ This will send any input from console to Sumo Logic cloud service.
38
+
39
+ ### 5. Try out samples
40
+
41
+ #### Send Log lines
42
+
43
+ Set the URL got from step 1 as environment variable:
44
+
45
+ ```bash
46
+ export sumo_url=https://events.sumologic.net/receiver/v1/http/XXXXXXXXXX
47
+ ```
48
+
49
+ Launch sample with:
50
+
51
+ ```bash
52
+ bin/logstash -f samples/log.conf
53
+ ```
54
+
55
+ The input from console will be sent to Sumo Logic cloud service as log lines.
56
+
57
+ #### Send Metrics
58
+
59
+ Set the URL got from step 1 as environment variable:
60
+
61
+ ```bash
62
+ export sumo_url=https://events.sumologic.net/receiver/v1/http/XXXXXXXXXX
63
+ ```
64
+
65
+ Install [plugins-filters-metrics](https://www.elastic.co/guide/en/logstash/current/plugins-filters-metrics.html) plugin
66
+
67
+ Launch sample with:
68
+
69
+ ```bash
70
+ bin/logstash -f samples/metrics.conf
71
+ ```
72
+
73
+ Mocked events will be sent to Sumo Logic server as 1 minute and 15 minutes rate metrics.
74
+
75
+ ### 6. Get result from Sumo Logic web app
76
+
77
+ Logon to Sumo Logic [web app](https://service.sumologic.com/) and run
78
+
79
+ - [Log Search](http://help.sumologic.com/Search)
80
+ - [Live Tail](http://help.sumologic.com/Search/Live_Tail)
81
+ - [Metrics Search](https://help.sumologic.com/Metrics)
82
+
83
+ ## What's Next
84
+
85
+ - Try it with different input/filter/codec plugins
86
+ - Start LogStash as a service/daemon in your production environment
87
+ - Report any issue or idea through [Git Hub](https://github.com/SumoLogic/logstash-output-sumologic)
88
+
89
+ ## Parameters of Plugin
90
+
91
+ | Parameter | Type | Required? | Default value | Description |
92
+ | ---------------------- | ------- | --------- | :-----------: | --------------------- |
93
+ | `url` | string | Yes | | HTTP Source URL
94
+ | `source_category` | string | No | `Logstash` | Source category to appear when searching in Sumo Logic by `_sourceCategory`. Using empty string if want keep source category of the HTTP source.
95
+ | `source_name` | string | No | `logstash-output-sumologic` | Source name to appear when searching in Sumo Logic by `_sourceName`. Using empty string if want keep source name of the HTTP source.
96
+ | `source_host` | string | No | machine name | Source host to appear when searching in Sumo Logic by `_sourceHost`. Using empty string if want keep source host of the HTTP source.
97
+ | `extra_headers` | hash | No | | Extra fields need to be send in HTTP headers.
98
+ | `compress` | boolean | No | `false` | Enable or disable compression.
99
+ | `compress_encoding` | string | No | `"deflate"` | Encoding method of comressing, can only be `"deflate"` or `"gzip"`.
100
+ | `interval` | number | No | `0` | The maximum time for waiting before sending the message pile, in seconds.
101
+ | `pile_max` | number | No | `102400` | The maximum size of message pile, in bytes.
102
+ | `queue_max` | number | No | `4096` | The maximum message piles can be hold in memory.
103
+ | `sender_max` | number | No | `100` | The maximum HTTP senders working in parallel.
104
+ | `format` | string | No | `"%{@timestamp} %{host} %{message}"` | For log only, the formatter of log lines. Use `%{@json}` as the placeholder for whole event json.
105
+ | `json_mapping` | hash | No | | Override the structure of `{@json}` tag with the given key value pairs.<br />For example:<br />`json_mapping => { "foo" => "%{@timestamp}" "bar" => "%{message}" }`<br />will create messages as:<br />`{"foo":"2016-07-27T18:37:59.460Z","bar":"hello world"}`<br />`{"foo":"2016-07-27T18:38:01.222Z","bar":"bye!"}`
106
+ | `metrics` | hash | No | | If defined, the event will be sent as metrics. Keys will be the metrics name and values will be the metrics value.
107
+ | `metrics_format` | string | No | `"cabon2"` | Metrics format, can only be `"graphite"` or `"carbon2"`.
108
+ | `metrics_name` | string | No | `"*"` | Define the metric name looking, the placeholder "*" will be replaced with the actual metric name.
109
+ | `intrinsic_tags` | hash | No | | For carbon2 format only, send extra intrinsic key-value pairs other than `metric` (which is the metric name).
110
+ | `meta_tags` | hash | No | | For carbon2 format only, send metadata key-value pairs.
111
+ | `fields_as_metrics` | boolean | No | `false` | If `true`, all fields in logstash event with number value will be sent as a metrics (with filtering by `fields_include` and `fields_exclude` ; the `metics` parameter is ignored.
112
+ | `fields_include` | array | No | all fields | Working with `fields_as_metrics` parameter, only the fields which full name matching these RegEx pattern(s) will be included in metrics.
113
+ | `fields_exclude` | array | No | none | Working with `fields_as_metrics` parameter, the fields which full name matching these RegEx pattern(s) will be ignored in metrics.
114
+ | `sleep_before_requeue` | number | No | `30` | The message failed to send to server will be retried after (x) seconds. Not retried if negative number set
115
+ | `stats_enabled` | boolean | No | `false` | If `true`, stats of this plugin will be sent as metrics
116
+ | `stats_interval` | number | No | `60` | The stats will be sent every (x) seconds
117
+
118
+ This plugin is based on [logstash-mixin-http_client](https://github.com/logstash-plugins/logstash-mixin-http_client) thus also supports all HTTP layer parameters like proxy, authentication, timeout etc.
119
+
120
+ ## Trouble Shooting
121
+
122
+ ### Enable plugin logging
123
+
124
+ Logstash is using log4j2 framework for [logging](https://www.elastic.co/guide/en/logstash/current/logging.html). Starting with 5.0, each individual plugin can configure the logging strategy. [Here](https://github.com/SumoLogic/logstash-output-sumologic/blob/master/samples/log4j2.properties) is a sample log4j2.properties to print plugin log to console and a rotating file.
125
+
126
+ ### Optimize throughput
127
+
128
+ The throughput can be tuning with following parameters:
129
+
130
+ - Messages will be piled before sending if both `interval` and `pile_max` are larger than `0`. (e.g. multiple messages will sent in single HTTP request); The maximum size of pile is defined in `pile_max` and if there is no more message comes in, piled message will be sent out every `interval` seconds. A higher number of these parameters normally means more messages will be piled together so overall reduce the overhead in transmission and benefit for compressing efficiency; but it may make a larger latency because messages may be hold in plugin for longer before sending;
131
+ - Message piles will be cached before sending in a memory queue. The maximum piles can stay in queue is defined with `queue_max`. A larger setting may be helpful if input is blocked by the plugin consuming speed, but may also consume more RAM (which can be set in [JVM options](https://www.elastic.co/guide/en/logstash/current/config-setting-files.html))
132
+ - The plugin will use up to `sender_max` HTTP senders in parallel for talking to Sumo Logic server. This number is also limited by the max TCP connections
133
+ - Depends on the content pattern, adjusting `compress`/`compress_encoding` for balancing between the CPU consumption and package size
134
+
135
+ On the other side, this version is marked as thread safe so if necessary, multiple plugins can work [in parallel as workers](https://www.elastic.co/guide/en/logstash/current/tuning-logstash.html)
136
+
137
+ ### Monitor throughput in metrics
138
+
139
+ If your Sumo Logic account supports metrics feature, you can enable the stats monitor of this plugin with configuring `stats_enabled` to `true`. For every `stats_interval` seconds, a batch of metrics data points will be sent to Sumo Logic with source category `XXX.stats` (`XXX` is the source category of main output):
140
+
141
+ | Metric | Description |
142
+ | ------------------------------- | ----------------------------------------------------------- |
143
+ | `total_input_events` | Total number of events handled from the plugin startup
144
+ | `total_input_bytes` | Total bytes of inputs after encoded to payload
145
+ | `total_metrics_datapoints` | Total metrics data points generated from input
146
+ | `total_log_lines` | Total log lines generated from input
147
+ | `total_output_requests` | Total number of HTTP requests sent to Sumo Logic server
148
+ | `total_output_bytes` | Total bytes of payloads sent to Sumo Logic server
149
+ | `total_output_bytes_compressed` | Total bytes of payloads sent to Sumo Logic server (after compressing)
150
+ | `total_response_times` | Total number of responses acknowledged by Sumo Logic server
151
+ | `total_response_success` | Total number of accepted(200) acknowledged by Sumo Logic server
152
+
153
+ **NOTE:** The data points will consume DPM quota
154
+
155
+
156
+ ### TLS 1.2 Requirement
157
+
158
+ Sumo Logic only accepts connections from clients using TLS version 1.2 or greater. To utilize the content of this repo, ensure that it's running in an execution environment that is configured to use TLS 1.2 or greater.
@@ -0,0 +1,158 @@
1
+ # encoding: utf-8
2
+ require "logstash/event"
3
+ require "logstash/json"
4
+ require "logstash/namespace"
5
+ require "logstash/outputs/base"
6
+ require "logstash/plugin_mixins/http_client"
7
+
8
+ # Now you can use logstash to deliver logs to Sumo Logic
9
+ #
10
+ # Create a HTTP Source
11
+ # in your Sumo Logic account and you can now use logstash to parse your log and
12
+ # send your logs to your account at Sumo Logic.
13
+ #
14
+ class LogStash::Outputs::SumoLogic < LogStash::Outputs::Base
15
+ declare_threadsafe!
16
+
17
+ require "logstash/outputs/sumologic/batch"
18
+ require "logstash/outputs/sumologic/common"
19
+ require "logstash/outputs/sumologic/compressor"
20
+ require "logstash/outputs/sumologic/header_builder"
21
+ require "logstash/outputs/sumologic/message_queue"
22
+ require "logstash/outputs/sumologic/monitor"
23
+ require "logstash/outputs/sumologic/payload_builder"
24
+ require "logstash/outputs/sumologic/piler"
25
+ require "logstash/outputs/sumologic/sender"
26
+ require "logstash/outputs/sumologic/statistics"
27
+
28
+ include LogStash::PluginMixins::HttpClient
29
+ include LogStash::Outputs::SumoLogic::Common
30
+
31
+ config_name "sumologic"
32
+
33
+ # The URL to send logs to. This should be given when creating a HTTP Source
34
+ # on Sumo Logic web app. See http://help.sumologic.com/Send_Data/Sources/HTTP_Source
35
+ config :url, :validate => :string, :required => true
36
+
37
+ # Define the source category metadata
38
+ config :source_category, :validate => :string
39
+
40
+ # Define the source host metadata
41
+ config :source_host, :validate => :string
42
+
43
+ # Define the source name metadata
44
+ config :source_name, :validate => :string
45
+
46
+ # Include extra HTTP headers on request if needed
47
+ config :extra_headers, :validate => :hash
48
+
49
+ # Compress the payload
50
+ config :compress, :validate => :boolean, :default => false
51
+
52
+ # The encoding method of compress
53
+ config :compress_encoding, :validate =>:string, :default => DEFLATE
54
+
55
+ # Accumulate events in (x) seconds as a pile/request; 0 means sending every events in isolated requests
56
+ config :interval, :validate => :number, :default => 0
57
+
58
+ # Accumulate events for up to (x) bytes as a pile/request; messages larger than this size will be sent in isolated requests
59
+ config :pile_max, :validate => :number, :default => 1024000
60
+
61
+ # Max # of events can be hold in memory before sending
62
+ config :queue_max, :validate => :number, :default => 4096
63
+
64
+ # Max # of HTTP senders working in parallel
65
+ config :sender_max, :validate => :number, :default => 100
66
+
67
+ # The formatter of log message, by default is message with timestamp and host as prefix
68
+ # Use %{@json} tag to send whole event
69
+ config :format, :validate => :string, :default => DEFAULT_LOG_FORMAT
70
+
71
+ # Override the structure of @json tag with the given key value pairs
72
+ config :json_mapping, :validate => :hash
73
+
74
+ # Send metric(s) if configured. This is a hash with k as metric name and v as metric value
75
+ # Both metric names and values support dynamic strings like %{host}
76
+ # For example:
77
+ # metrics => { "%{host}/uptime" => "%{uptime_1m}" }
78
+ config :metrics, :validate => :hash
79
+
80
+ # Create metric(s) automatically from @json fields if configured.
81
+ config :fields_as_metrics, :validate => :boolean, :default => false
82
+
83
+ config :fields_include, :validate => :array, :default => [ ]
84
+
85
+ config :fields_exclude, :validate => :array, :default => [ ]
86
+
87
+ # Defines the format of the metric, support "graphite" or "carbon2"
88
+ config :metrics_format, :validate => :string, :default => CARBON2
89
+
90
+ # Define the metric name looking, the placeholder "*" will be replaced with the actual metric name
91
+ # For example:
92
+ # metrics => { "uptime.1m" => "%{uptime_1m}" }
93
+ # metrics_name => "mynamespace.*"
94
+ # will produce metrics as:
95
+ # "mynamespace.uptime.1m xxx 1234567"
96
+ config :metrics_name, :validate => :string, :default => METRICS_NAME_PLACEHOLDER
97
+
98
+ # For carbon2 metrics format only, define the intrinsic tags (which will be used to identify the metrics)
99
+ # There is always an intrinsic tag as "metric" which value is from metrics_name
100
+ config :intrinsic_tags, :validate => :hash, :default => {}
101
+
102
+ # For carbon2 metrics format only, define the meta tags (which will NOT be used to identify the metrics)
103
+ config :meta_tags, :validate => :hash, :default => {}
104
+
105
+ # For messages fail to send or get 429/503/504 response, try to resend after (x) seconds; don't resend if (x) < 0
106
+ config :sleep_before_requeue, :validate => :number, :default => 30
107
+
108
+ # Sending throughput data as metrics
109
+ config :stats_enabled, :validate => :boolean, :default => false
110
+
111
+ # Sending throughput data points every (x) seconds
112
+ config :stats_interval, :validate => :number, :default => 60
113
+
114
+ # Disable cookies by default (used in HTTP mixin)
115
+ config :cookies, :validate => :boolean, :default => false
116
+
117
+ attr_reader :stats
118
+
119
+ def register
120
+ set_logger(@logger)
121
+ @stats = Statistics.new
122
+ @queue = MessageQueue.new(@stats, config)
123
+ @piler = Piler.new(@queue, @stats, config)
124
+ @monitor = Monitor.new(@queue, @stats, config)
125
+ @sender = Sender.new(client, @queue, @stats, config)
126
+ if @sender.connect()
127
+ @sender.start()
128
+ @piler.start()
129
+ @monitor.start()
130
+ else
131
+ throw "connection failed, please check the url and retry"
132
+ end
133
+ end # def register
134
+
135
+ def multi_receive(events)
136
+ Array(events).map { |event| receive(event) }
137
+ end # def multi_receive
138
+
139
+ def receive(event)
140
+ begin
141
+ @piler.input(event)
142
+ rescue Exception => exception
143
+ log_err("error when processing event",
144
+ :event => event,
145
+ :message => exception.message,
146
+ :class => exception.class.name,
147
+ :backtrace => exception.backtrace)
148
+ end
149
+ end # def receive
150
+
151
+ def close
152
+ @monitor.stop()
153
+ @piler.stop()
154
+ @sender.stop()
155
+ client.close()
156
+ end # def close
157
+
158
+ end # class LogStash::Outputs::SumoLogic