logstash-output-stackify 1.0.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
+ SHA256:
3
+ metadata.gz: 9b2320f9ea79745878a8cbc29761a30f1b1c545d9566ae3a3ddc55b4fc218401
4
+ data.tar.gz: 604531df1db73e71429b7e19f4bf319caa96742fd0f5f3f6a4b19dbea73345c6
5
+ SHA512:
6
+ metadata.gz: 521ae011b795fbe0b6e430fa38bbb855703ac7b4f1a8c603a6adf720794669f3ed86353e9ba990706462cb326efca591e212e6496717b749e3c15190a062137e
7
+ data.tar.gz: 458ec4060d1a30b0956cea9a1ee1d37f5c1cd32f4d90af730d7087470f52afe61568e3109e870f70c2c41aabd1f510c3ba352f7788b3692f87f8e910e3528226
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Logstash Plugin
2
+ This is a plugin for Logstash
@@ -0,0 +1,184 @@
1
+ # encoding: utf-8
2
+ require 'date'
3
+ require 'socket'
4
+ require 'json'
5
+ require 'uri'
6
+ require "net/http"
7
+ require "net/https"
8
+ require "logstash/outputs/base"
9
+ require "logstash/namespace"
10
+
11
+ # An example output that does nothing.
12
+ class LogStash::Outputs::Stackify < LogStash::Outputs::Base
13
+ config_name "stackify"
14
+
15
+ # activation key
16
+ config :key, :validate => :string, :required => true
17
+
18
+ # default env_name
19
+ config :default_env_name, :validate => :string, :required => false, :default => 'Production'
20
+
21
+ # default app_name
22
+ config :default_app_name, :validate => :string, :required => false, :default => 'Logstash'
23
+
24
+ # environment name field
25
+ config :env_name_field, :validate => :string, :required => false, :default => nil
26
+
27
+ # server name field
28
+ config :server_name_field, :validate => :string, :required => false, :default => nil
29
+
30
+ # application name field
31
+ config :app_name_field, :validate => :string, :required => false, :default => nil
32
+
33
+ # log level field
34
+ config :level_field, :validate => :string, :required => false, :default => nil
35
+
36
+ # event field to use for message
37
+ config :message_field, :validate => :string, :required => false, :default => 'message'
38
+
39
+ public
40
+
41
+ def register
42
+ end
43
+
44
+ # def register
45
+
46
+ public
47
+
48
+ def multi_receive(events)
49
+
50
+ begin
51
+
52
+ default_level = 'info'
53
+ default_servername = Socket.gethostname
54
+ log_msg_groups = Hash.new
55
+
56
+ events.each do |event|
57
+
58
+ begin
59
+
60
+ # message
61
+ default_message = event.get('message')
62
+ message = default_message
63
+ unless @message_field.nil?
64
+ message = event.get(@message_field.to_s)
65
+ if message.nil? || message.empty?
66
+ message = default_message
67
+ end
68
+ end
69
+
70
+ # level
71
+ level = default_level
72
+ unless @level_field.nil?
73
+ level = event.get(@level_field.to_s)
74
+ if level.nil? || level.empty?
75
+ level = default_level
76
+ end
77
+ end
78
+ level = level.downcase
79
+ if level != 'debug' && level != 'info' && level != 'warn' && level != 'error'
80
+ $stdout.write('Invalid level defined: ' + level.to_s)
81
+ level = default_level
82
+ end
83
+
84
+ # application name
85
+ app_name = @default_app_name.to_s
86
+ unless @app_name_field.nil?
87
+ app_name = event.get(@app_name_field.to_s)
88
+ if app_name.nil? || app_name.empty?
89
+ app_name = @default_app_name.to_s
90
+ end
91
+ end
92
+
93
+ # env name
94
+ env_name = @default_env_name.to_s
95
+ unless @env_name_field.nil?
96
+ env_name = event.get(@env_name_field.to_s)
97
+ if env_name.nil? || env_name.empty?
98
+ env_name = @default_env_name.to_s
99
+ end
100
+ end
101
+
102
+ # server name
103
+ server_name = default_servername
104
+ unless @server_name_field.nil?
105
+ server_name = event.get(@server_name_field.to_s)
106
+ if server_name.nil? || server_name.empty?
107
+ server_name = default_servername
108
+ end
109
+ end
110
+
111
+ # timestamp
112
+ timestamp = nil
113
+ begin
114
+ timestamp = (event.get('@timestamp').to_f * 1000).to_i
115
+ rescue StandardError => e
116
+ $stdout.write('Error parsing @timestamp: ' + e.to_s)
117
+ end
118
+ if timestamp.nil?
119
+ timestamp = DateTime.now.strftime('%Q')
120
+ end
121
+
122
+ # generate key
123
+ log_msg_group_key = app_name + '|' + env_name + '|' + server_name
124
+
125
+ # setup log msg group if needed
126
+ unless log_msg_groups.key?(log_msg_group_key)
127
+ log_msg_group = Hash.new
128
+ log_msg_group['Env'] = env_name
129
+ log_msg_group['ServerName'] = server_name
130
+ log_msg_group['AppName'] = app_name
131
+ log_msg_group['Logger'] = 'Logstash'
132
+ log_msg_group['Platform'] = 'Logstash'
133
+ log_msg_group['Msgs'] = Array.new
134
+ log_msg_groups[log_msg_group_key] = log_msg_group
135
+ end
136
+
137
+ # generate log msg
138
+ log_msg = Hash.new
139
+ log_msg['Msg'] = message
140
+ log_msg['EpochMs'] = timestamp
141
+ log_msg['Level'] = level
142
+
143
+ # add to log msg group
144
+ log_msg_groups[log_msg_group_key]['Msgs'].push(log_msg)
145
+
146
+ rescue StandardError => e
147
+ $stdout.write(e.to_s)
148
+ end
149
+
150
+ end
151
+
152
+ # post
153
+ log_msg_groups.each do |key, log_msg_group|
154
+
155
+ begin
156
+
157
+ data = log_msg_group.to_json
158
+ header = {
159
+ 'Content-Type' => 'application/json',
160
+ 'Accept' => 'appliation/json',
161
+ 'X-Stackify-PV' => 'V1',
162
+ 'X-Stackify-Key' => @key.to_s
163
+ }
164
+
165
+
166
+ uri = URI.parse('https://api.stackify.com/Log/Save')
167
+ https = Net::HTTP.new(uri.host, uri.port)
168
+ https.use_ssl = true
169
+ req = Net::HTTP::Post.new(uri.path, initheader = header)
170
+ req.body = data
171
+ https.request(req)
172
+
173
+ rescue StandardError => e
174
+ $stdout.write(e.to_s)
175
+ end
176
+
177
+ end
178
+
179
+ rescue StandardError => e
180
+ $stdout.write(e.to_s)
181
+ end
182
+
183
+ end
184
+ end # class LogStash::Outputs::Stackify
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-stackify'
3
+ s.version = '1.0.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "Sends logs to Stackify"
6
+ s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
7
+ s.authors = ["Stackify"]
8
+ s.email = "support@stackify.com"
9
+ s.homepage = "https://www.stackify.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
+ #
22
+ s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
23
+ s.add_runtime_dependency "logstash-codec-plain"
24
+ s.add_development_dependency 'logstash-devutils'
25
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-stackify
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Stackify
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-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: '1.60'
19
+ - - "<="
20
+ - !ruby/object:Gem::Version
21
+ version: '2.99'
22
+ name: logstash-core-plugin-api
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.60'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.99'
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ name: logstash-codec-plain
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
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
62
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
63
+ gem is not a stand-alone program
64
+ email: support@stackify.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - Gemfile
70
+ - README.md
71
+ - lib/logstash/outputs/stackify.rb
72
+ - logstash-output-stackify.gemspec
73
+ homepage: https://www.stackify.com
74
+ licenses:
75
+ - Apache License (2.0)
76
+ metadata:
77
+ logstash_plugin: 'true'
78
+ logstash_group: output
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.7.6
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Sends logs to Stackify
99
+ test_files: []