logstash-output-coralogix_logger 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 34b00e650c539bd94627c74175f6718d6624f343
4
+ data.tar.gz: 3d7769872c0e21de88941e3ee616bd9f2c68b928
5
+ SHA512:
6
+ metadata.gz: 23fe1631de57734bf7acc4e3b6a545046f701c7700b815ece07526604de74057df4504c62cd28e20dd89d90443af5cd6dae576fbc99742e18121cf9c502f8e1a
7
+ data.tar.gz: 7524f411b085c885bf37aceec6446aee7058828c2fc91868a0508598de23a78fe7088ab521549dbda757a5fef3e31867063e77779414ad962feeb5efdd1d5d6d
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
data/CONTRIBUTORS ADDED
@@ -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
+ * coralogix -
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.
data/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-output-coralogix_logger
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 'centralized_ruby_logger'
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.
data/README.md ADDED
@@ -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,88 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/base"
3
+ require "logstash/namespace"
4
+ require 'centralized_ruby_logger'
5
+
6
+ DEFAULT_APP_NAME = "FAILED_APP_NAME"
7
+ DEFAULT_SUB_SYSTEM = "FAILED_SUB_SYSTEM_NAME"
8
+
9
+ class LogStash::Outputs::CoralogixLogger < LogStash::Outputs::Base
10
+ config_name "coralogix_logger"
11
+ concurrency :single
12
+ config :config_params, :validate => :hash, :required => true
13
+ config :log_key_name, :validate => :string, :required => false
14
+ config :is_json, :validate => :bool, :required => false
15
+ @configured = false
16
+
17
+ public
18
+ def register
19
+ configure
20
+ end # def register
21
+
22
+ public
23
+ def multi_receive(events)
24
+ events.each do |record|
25
+ record = record.to_hash["message"]
26
+ logger = get_logger(record)
27
+
28
+ log_record = log_key_name != nil ? record.fetch(log_key_name, record) : record
29
+ log_record = is_json ? log_record.to_json : log_record
30
+ log_record = log_record.to_s.empty? ? record : log_record
31
+ #puts log_record
32
+ logger.debug log_record
33
+ end
34
+
35
+ return 1
36
+ end # def event
37
+
38
+
39
+ # This method is called before starting.
40
+ def configure
41
+ begin
42
+ @loggers = {}
43
+ #If config parameters doesn't start with $ then we can configure Coralogix logger now.
44
+ if !config_params["APP_NAME"].start_with?("$") && !config_params["SUB_SYSTEM"].start_with?("$")
45
+ @logger = Coralogix::CoralogixLogger.new config_params["PRIVATE_KEY"], config_params["APP_NAME"], config_params["SUB_SYSTEM"], true, "Logstash"
46
+ @configured = true
47
+ end
48
+ rescue Exception => e
49
+ $stdout.write "Failed to configure: #{e}"
50
+ end
51
+ end
52
+
53
+ def extract record, key, default
54
+ begin
55
+ res = record
56
+ return key unless key.start_with?("$")
57
+ key[1..-1].split(".").each do |k|
58
+ res = res.fetch(k,nil)
59
+ return default if res == nil
60
+ end
61
+ return res
62
+ rescue Exception => e
63
+ $stdout.write "Failed to extract #{key}: #{e}"
64
+ return default
65
+ end
66
+ end
67
+
68
+
69
+ def get_app_sub_name(record)
70
+ app_name = extract(record, config_params["APP_NAME"], DEFAULT_APP_NAME)
71
+ sub_name = extract(record, config_params["SUB_SYSTEM"], DEFAULT_SUB_SYSTEM)
72
+ return app_name, sub_name
73
+ end
74
+
75
+ def get_logger(record)
76
+
77
+ return @logger if @configured
78
+
79
+ app_name, sub_name = get_app_sub_name(record)
80
+
81
+ if !@loggers.key?("#{app_name}.#{sub_name}")
82
+ @loggers["#{app_name}.#{sub_name}"] = Coralogix::CoralogixLogger.new config_params["PRIVATE_KEY"], app_name, sub_name, true, "Logstash"
83
+ end
84
+
85
+ return @loggers["#{app_name}.#{sub_name}"]
86
+ end
87
+
88
+ end # class LogStash::Outputs::CoralogixLogger
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-coralogix_logger'
3
+ s.version = '0.3.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = 'Coralogix Logstash logger SDK'
6
+ s.description = 'Coralogix Logstash logger to send logs to Coralogix server'
7
+ s.homepage = 'http://www.coralogix.com'
8
+ s.authors = ['Royee Goldberg']
9
+ s.email = 'royee@coralogix.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_dependency 'centralized_ruby_logger'
22
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
23
+ s.add_runtime_dependency "logstash-codec-plain"
24
+ s.add_runtime_dependency "centralized_ruby_logger"
25
+ s.add_development_dependency "logstash-devutils"
26
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/outputs/coralogix_logger"
4
+ require "logstash/codecs/plain"
5
+ require "logstash/event"
6
+
7
+ file = "logstash.test.conf"
8
+ @@configuration = String.new
9
+ @@configuration << File.read(file)
10
+
11
+
12
+ describe LogStash::Outputs::CoralogixLogger do
13
+
14
+ config(@@configuration)
15
+
16
+ let(:output) { LogStash::Outputs::CoralogixLogger.new }
17
+
18
+ before do
19
+ output.register
20
+ end
21
+
22
+ describe "receive message" do
23
+ records = []
24
+ records << "Hello from Logstash"
25
+ subject { output.multi_receive(records) }
26
+
27
+ it "returns 1" do
28
+ expect(subject).to eq(1)
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-coralogix_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Royee Goldberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ name: logstash-core-plugin-api
20
+ prerelease: false
21
+ type: :runtime
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
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: logstash-codec-plain
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ name: centralized_ruby_logger
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ name: logstash-devutils
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Coralogix Logstash logger to send logs to Coralogix server
70
+ email: royee@coralogix.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/coralogix_logger.rb
82
+ - logstash-output-coralogix-logger.gemspec
83
+ - spec/outputs/coralogix-logger_spec.rb
84
+ homepage: http://www.coralogix.com
85
+ licenses:
86
+ - Apache License (2.0)
87
+ metadata:
88
+ logstash_plugin: 'true'
89
+ logstash_group: output
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.8
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Coralogix Logstash logger SDK
110
+ test_files:
111
+ - spec/outputs/coralogix-logger_spec.rb