logstash-output-awslogs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 99e6b6d40e097febb27b8025eba26a2d9213e251
4
+ data.tar.gz: 524e1b29c57f34d41b08b1985260081b31639bec
5
+ SHA512:
6
+ metadata.gz: 0a2fc689d1a136b8f77371217414e033abf69fca691d99ce453fe30080ec0d57516d9765dbf2e0de64f856cf55f697819d7b00b35d56435afef6f728fb8163a1
7
+ data.tar.gz: 385ea7c63731ebe57a4810429094a576dc0d0328c031c82e183c170791065eaeb3e7d5367f1beabac3c06101ec0082640a2872d45f41166b57b93fcf0e586b97
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
@@ -0,0 +1,10 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * - Ricky Cook (rickycook)
6
+
7
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
8
+ Logstash, and you aren't on the list above and want to be, please let us know
9
+ and we'll make sure you're here. Contributions from folks like you are what make
10
+ open source awesome.
@@ -0,0 +1,2 @@
1
+ # logstash-output-awslogs
2
+ Example output plugin. This should help bootstrap your effort to write your own output plugin!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem "logstash", :github => "elastic/logstash", :branch => "6.4"
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
@@ -0,0 +1,86 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
5
+ 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.
6
+
7
+ ## Documentation
8
+
9
+ 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/).
10
+
11
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
17
+
18
+ ## Developing
19
+
20
+ ### 1. Plugin Developement and Testing
21
+
22
+ #### Code
23
+ - To get started, you'll need JRuby with the Bundler gem installed.
24
+
25
+ - 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).
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ - Update your dependencies
35
+
36
+ ```sh
37
+ bundle install
38
+ ```
39
+
40
+ - Run tests
41
+
42
+ ```sh
43
+ bundle exec rspec
44
+ ```
45
+
46
+ ### 2. Running your unpublished Plugin in Logstash
47
+
48
+ #### 2.1 Run in a local Logstash clone
49
+
50
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
51
+ ```ruby
52
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
53
+ ```
54
+ - Install plugin
55
+ ```sh
56
+ bin/logstash-plugin install --no-verify
57
+ ```
58
+ - Run Logstash with your plugin
59
+ ```sh
60
+ bin/logstash -e 'filter {awesome {}}'
61
+ ```
62
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
63
+
64
+ #### 2.2 Run in an installed Logstash
65
+
66
+ 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:
67
+
68
+ - Build your plugin gem
69
+ ```sh
70
+ gem build logstash-filter-awesome.gemspec
71
+ ```
72
+ - Install the plugin from the Logstash home
73
+ ```sh
74
+ bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.gem
75
+ ```
76
+ - Start Logstash and proceed to test the plugin
77
+
78
+ ## Contributing
79
+
80
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
81
+
82
+ 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.
83
+
84
+ It is more important to the community that you are able to contribute.
85
+
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,79 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/base"
3
+ require "logstash/namespace"
4
+ require "logstash/plugin_mixins/aws_config"
5
+ require "aws-sdk"
6
+
7
+ Aws.eager_autoload!
8
+
9
+ # An awslogs output that does nothing.
10
+ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
11
+ include LogStash::PluginMixins::AwsConfig::V2
12
+
13
+ config_name "awslogs"
14
+ default :codec, "line"
15
+
16
+ config :log_group_name, :validate => :string, :required => true
17
+ config :log_stream_name, :validate => :string, :required => true
18
+
19
+ public
20
+ def register
21
+ @client = Aws::CloudWatchLogs::Client.new(aws_options_hash)
22
+ @next_sequence_tokens = {}
23
+ end # def register
24
+
25
+ public
26
+ def multi_receive_encoded(events_and_encoded)
27
+ to_send = {}
28
+
29
+ events_and_encoded.each do |event, encoded|
30
+ event_log_stream_name = event.sprintf(log_stream_name)
31
+ event_log_group_name = event.sprintf(log_group_name)
32
+
33
+ next_sequence_token_key = [event_log_group_name, event_log_stream_name]
34
+ if ! to_send.keys.include? next_sequence_token_key
35
+ to_send.store(next_sequence_token_key, [])
36
+ end
37
+ to_send[next_sequence_token_key].push({
38
+ timestamp: (event.timestamp.time.to_f * 1000).to_int,
39
+ message: encoded,
40
+ })
41
+ end
42
+ to_send.each do |event_log_names, log_events|
43
+ event_log_group_name = event_log_names[0]
44
+ event_log_stream_name = event_log_names[1]
45
+ next_sequence_token_key = [event_log_group_name, event_log_stream_name]
46
+
47
+ ident_opts = {
48
+ log_group_name: event_log_group_name,
49
+ log_stream_name: event_log_stream_name,
50
+ }
51
+ send_opts = ident_opts.merge({
52
+ log_events: log_events,
53
+ })
54
+
55
+ if @next_sequence_tokens.keys.include? next_sequence_token_key
56
+ send_opts[:sequence_token] = @next_sequence_tokens[next_sequence_token_key]
57
+ else
58
+ resp = @client.describe_log_streams({
59
+ log_group_name: event_log_group_name,
60
+ log_stream_name_prefix: event_log_stream_name,
61
+ })
62
+ if resp.log_streams.length < 1
63
+ @client.create_log_stream(ident_opts)
64
+ else
65
+ resp.log_streams.each do |log_stream_data|
66
+ if log_stream_data.log_stream_name == event_log_stream_name
67
+ send_opts[:sequence_token] = log_stream_data.upload_sequence_token
68
+ break
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ resp = @client.put_log_events(send_opts)
75
+ # TODO: handle rejected events with debug message
76
+ @next_sequence_tokens.store(next_sequence_token_key, resp.next_sequence_token)
77
+ end
78
+ end # def multi_receive_encoded
79
+ end # class LogStash::Outputs::Awslogs
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-awslogs'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'Writes events to AWS CloudWatch logs.'
6
+ s.homepage = 'https://github.com/rickycook/logstash-output-awslogs'
7
+ s.authors = ['Ricky Cook']
8
+ s.email = 'logstash-output-awslogs@auto.thatpanda.com'
9
+ s.require_paths = ['lib']
10
+
11
+ # Files
12
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
13
+ # Tests
14
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
15
+
16
+ # Special flag to let us know this is actually a logstash plugin
17
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
18
+
19
+ # Gem dependencies
20
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
21
+ s.add_runtime_dependency "logstash-codec-plain"
22
+ s.add_runtime_dependency 'logstash-mixin-aws', '>= 4.3.0'
23
+ s.add_development_dependency "logstash-devutils"
24
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-awslogs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ricky Cook
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: logstash-codec-plain
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: logstash-mixin-aws
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 4.3.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 4.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: logstash-devutils
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email: logstash-output-awslogs@auto.thatpanda.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - CHANGELOG.md
76
+ - CONTRIBUTORS
77
+ - DEVELOPER.md
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - lib/logstash/outputs/awslogs.rb
82
+ - logstash-output-awslogs.gemspec
83
+ homepage: https://github.com/rickycook/logstash-output-awslogs
84
+ licenses:
85
+ - Apache-2.0
86
+ metadata:
87
+ logstash_plugin: 'true'
88
+ logstash_group: output
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.5.2.3
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Writes events to AWS CloudWatch logs.
109
+ test_files: []