logstash-output-xlsx 0.1.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: c7482f48e498568a392fc1000dfa6f18d74451ab
4
+ data.tar.gz: 9b16b8100a55041c2de2fa9ef4eab91c598caa4c
5
+ SHA512:
6
+ metadata.gz: 908bb63d037a11c03bbc110febcdc170302b1af2de6e7cb65e87a23e7f7344fd053b91c5f161d5ce95e74cbb015ffbeed3b0e6a5b993298eb0a8118b352baa9b
7
+ data.tar.gz: 330d713dc55eb41c3f65478964e58352960278119a7f0b9545449f7f2080b2299379e275cf440f54f8591ab72e251bbe890078cf8301d85dcb7aaf19f3abe847
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ .ruby-version
3
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012-2014 Elasticsearch <http://www.elasticsearch.org>
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.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ @files=[]
2
+
3
+ task :default do
4
+ system("rake -T")
5
+ end
6
+
7
+ require "logstash/devutils/rake"
@@ -0,0 +1,103 @@
1
+ require "logstash/outputs/base"
2
+ require "logstash/namespace"
3
+ require "axlsx"
4
+
5
+ # A null output. This is useful for testing logstash inputs and filters for
6
+ # performance.
7
+ class LogStash::Outputs::Xlsx < LogStash::Outputs::Base
8
+ config_name "xlsx"
9
+ milestone 1
10
+
11
+ default :codec, "xls"
12
+
13
+ # The format to use when writing events to the file. This value
14
+ # supports any string and can include %{name} and other dynamic
15
+ # strings.
16
+ #
17
+ # If this setting is omitted, the full json representation of the
18
+ # event will be written as a single line.
19
+ config :message_format, :validate => :string
20
+
21
+ # The path to the file to write. Event fields can be used here,
22
+ # like "/var/log/logstash/%{host}/%{application}"
23
+ # One may also utilize the path option for date-based log
24
+ # rotation via the joda time format. This will use the event
25
+ # timestamp.
26
+ # E.g.: path => "./test-%{+YYYY-MM-dd}.txt" to create
27
+ # ./test-2013-05-29.txt
28
+ config :path, :validate => :string
29
+
30
+ public
31
+ def register
32
+ @files = {}
33
+
34
+ @codec.on_event do |event|
35
+ if @path
36
+ path = event.sprintf(@path)
37
+ else
38
+ path = event["path"]
39
+ end
40
+
41
+ if event.is_a? LogStash::Event and @message_format
42
+ output = event.sprintf(@message_format)
43
+ else
44
+ output = event["message"]
45
+ end
46
+
47
+ cells = output.split(/;/)
48
+
49
+ wsname = event["wsname"]
50
+
51
+ worksheet = get_worksheet(path, wsname)
52
+
53
+ worksheet.add_row cells
54
+ end
55
+ end # def register
56
+
57
+ public
58
+ def receive(event)
59
+ @codec.encode(event)
60
+
61
+ if event.include? "tags" and event["tags"].include?("eof")
62
+ flush event['path']
63
+ end
64
+ end # def event
65
+
66
+ private
67
+ def open(path)
68
+ return @files[path] if @files.include?(path) and not @files[path].nil?
69
+ @logger.info("Opening file", :path => path)
70
+
71
+ dir = File.dirname(path)
72
+ if !Dir.exists?(dir)
73
+ @logger.info("Creating directory", :directory => dir)
74
+ FileUtils.mkdir_p(dir)
75
+ end
76
+ package = Axlsx::Package.new
77
+ @files[path] = package
78
+ end
79
+
80
+ public
81
+ def flush(path)
82
+ @files.each do |path, package|
83
+ if(File.basename(path) == File.basename(path))
84
+ package.serialize(path)
85
+ end
86
+ end
87
+ end
88
+
89
+ private
90
+ def get_worksheet(path, wsname)
91
+ package = open(path)
92
+
93
+ worksheet = package.workbook.sheet_by_name(wsname)
94
+
95
+ if(worksheet.nil?)
96
+ package.workbook.add_worksheet(:name => wsname) do |ws|
97
+ return ws
98
+ end
99
+ else
100
+ return worksheet
101
+ end
102
+ end
103
+ end # class LogStash::Outputs::Xls
@@ -0,0 +1,29 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-output-xlsx'
4
+ s.version = '0.1.0'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "Output to xlsx"
7
+ s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
8
+ s.authors = ["Signify"]
9
+ s.email = 'dietmar@signifydata.com'
10
+ s.homepage = "http://www.signifydata.com"
11
+ s.require_paths = ["lib"]
12
+
13
+ # Files
14
+ s.files = `git ls-files`.split($\)
15
+
16
+ # Tests
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+
19
+ # Special flag to let us know this is actually a logstash plugin
20
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency 'logstash-core', '>= 1.4.0', '< 2.0.0'
24
+
25
+ s.add_runtime_dependency "axlsx", ["~> 2.0.1"]
26
+
27
+ s.add_development_dependency 'logstash-devutils'
28
+ end
29
+
@@ -0,0 +1,5 @@
1
+ require "logstash/devutils/rspec/spec_helper"
2
+ require 'logstash/outputs/xlsx'
3
+
4
+ describe LogStash::Outputs::Xlsx do
5
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-xlsx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Signify
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-25 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: 1.4.0
19
+ - - <
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0
22
+ name: logstash-core
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.4.0
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 2.0.1
39
+ name: axlsx
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 2.0.1
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ name: logstash-devutils
54
+ prerelease: false
55
+ type: :development
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 Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
62
+ email: dietmar@signifydata.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - .gitignore
68
+ - Gemfile
69
+ - LICENSE
70
+ - Rakefile
71
+ - lib/logstash/outputs/xlsx.rb
72
+ - logstash-output-xlsx.gemspec
73
+ - spec/outputs/xlsx_spec.rb
74
+ homepage: http://www.signifydata.com
75
+ licenses:
76
+ - Apache License (2.0)
77
+ metadata:
78
+ logstash_plugin: 'true'
79
+ logstash_group: output
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.1.9
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Output to xlsx
100
+ test_files:
101
+ - spec/outputs/xlsx_spec.rb