rack-logstash-writer 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/examples/regular rack file/config.ru +11 -1
- data/examples/sinatra-project/config.ru +2 -1
- data/lib/rack/logstash-writer.rb +6 -6
- data/lib/rack/logstash-writer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2834072c7db69eee168bf9e594ab769700e5c5bc
|
4
|
+
data.tar.gz: 4ce942aa199028576f30d3835837e2e41577b662
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e60cec96a27abb6bcde2e7af3f3a9013cb2d9c16eaff20211bd5e4e7766d4a927f288cb34bfa6d4af2dfe52b5cbc912ed26b87fafb11b890d94a9ddd3606272
|
7
|
+
data.tar.gz: 851ff915b6f8e7b79b6614205221f4c46bf05f57dfe5b6c25d70955cd8b8524ebc1f4d33058c8d1dee4de653e4a9aecce39304ae1edefacc9eea461b0ae2cda4
|
data/README.md
CHANGED
@@ -35,6 +35,7 @@ use Rack::LogstashWriter , {url: "file:///home/org/Desktop/logsample", # require
|
|
35
35
|
statuses: [*(500..600)], # optional, send events to log stash only for those statuses. default [*(500..600)]
|
36
36
|
body_len: 50 # optional, include the first given chars from the body. default 1000
|
37
37
|
body_regex: {:name_to_show => 'regex'}, include the regular expression from the body
|
38
|
+
proc: {|env| p "#{env}"}, enter proc, the proc will get the env as variable and merge the retuened data if it return as hash
|
38
39
|
}
|
39
40
|
|
40
41
|
run Proc.new {[200, {"Content-Type" => "application/json"}, ['{ "message" : "Hello!" }']]}
|
@@ -15,12 +15,22 @@ class JSONServerError
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
prc = Proc.new do |env|
|
19
|
+
data = {}
|
20
|
+
if env["REMOTE_HOST"] =='localhost'
|
21
|
+
soc = Socket.ip_address_list.map {|s| s.ip_address}.reject {|s| s=='127.0.0.1'}.select {|s| 16 >(s.size) && (s.size)>10}.first
|
22
|
+
data[:host] = "ip-#{soc.gsub(".","-")}"
|
23
|
+
end
|
24
|
+
data[:service_name] = Dir.pwd.split("/").last
|
25
|
+
data
|
26
|
+
end
|
27
|
+
|
18
28
|
use Rack::LogstashWriter , {url: "file:///home/org/Desktop/logsample", # or another examples "udp://localhost:5228" # "tcp://localhost:5228"
|
19
29
|
request_headers: {'head1'=>'head1'},
|
20
30
|
response_headers: {'head1'=>'head1'},
|
21
31
|
statuses: [*(500..600)] ,
|
22
32
|
body_len: 50 ,
|
23
|
-
body_regex: {service_name: 'service_namev:(.*).*[,]?.*}' }
|
33
|
+
body_regex: {service_name: 'service_namev:(.*).*[,]?.*}' , proc: prc}
|
24
34
|
}
|
25
35
|
|
26
36
|
map '/hello.json' do
|
@@ -7,9 +7,10 @@ require ::File.expand_path('../lib/sinatra', __FILE__)
|
|
7
7
|
|
8
8
|
# use Rails::Rack::Debugger
|
9
9
|
# use Rack::ContentLength
|
10
|
+
prc = Proc.new {|env| p env}
|
10
11
|
use Rack::LogstashWriter, {url: "tcp://localhost:5228" ,statuses: [*(200..600)], body_len: 100, response_headers: {'message' => 'This-is-a-message-man'},
|
11
12
|
request_headers: {'User-agent'=>'ua-nimrod'}, #"udp://localhost:5228" # "file:///home/org/Desktop/logsample"
|
12
|
-
body_regex: {service_name: 'service_namev:(.*).*[,]?.*}' }
|
13
|
+
body_regex: {service_name: 'service_namev:(.*).*[,]?.*}' , proc: prc}
|
13
14
|
}
|
14
15
|
|
15
16
|
run Sinatra::Application
|
data/lib/rack/logstash-writer.rb
CHANGED
@@ -12,10 +12,12 @@ module Rack
|
|
12
12
|
# @option options [Hash] :response_headers, optional, parameters to add to the report from the responce headers. default nil
|
13
13
|
# @option options [Fixnum] :body_len, optional, include the first given chars from the body. default 1000
|
14
14
|
# @option options [Array] :statuses, optional, send events to log stash only for those statuses. default [*(500..600)]
|
15
|
+
# @option options [Proc] :proc, optional, the function will call the proc with the env and call
|
15
16
|
def initialize app, options = {} #, statuses = [*(500..600)] , body_len = 1000 , url
|
16
17
|
@app = app
|
17
18
|
@options = validate defaults.merge options
|
18
19
|
@options[:url]= URI(@options[:url])
|
20
|
+
@proc = @options[:proc]
|
19
21
|
end
|
20
22
|
|
21
23
|
# Call to the app cal and log if the returned status is in the array of return data.
|
@@ -62,13 +64,13 @@ module Rack
|
|
62
64
|
:duration => (Time.now - began_at),
|
63
65
|
:remote_addr => env['REMOTE_ADDR'],
|
64
66
|
:request => request_line(env),
|
65
|
-
:service_name => Dir.pwd.split("/").last ,
|
66
67
|
:"X-Forwarded-For" => response_headers['X-Forwarded-For']
|
67
68
|
}
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
# Added calling for the proc and merge the data if it exists
|
71
|
+
if @proc
|
72
|
+
new_hash = @proc.call(env)
|
73
|
+
data = data.merge new_hash if new_hash.class == Hash
|
72
74
|
end
|
73
75
|
|
74
76
|
# This just works for all body types (magic?)... see http://www.rubydoc.info/github/rack/rack/Rack/BodyProxy
|
@@ -86,11 +88,9 @@ module Rack
|
|
86
88
|
when 400..599 then severity = "ERROR"
|
87
89
|
end
|
88
90
|
event = {:severity => severity}.merge data
|
89
|
-
# logger.puts({'@fields' => data, '@tags' => ['request'], '@timestamp' => ::Time.now.utc, '@version' => 23})
|
90
91
|
# TODO to include this lines
|
91
92
|
begin
|
92
93
|
device.puts( event.to_json )
|
93
|
-
# rescue Errno::EPIPE, Errno::EINVAL
|
94
94
|
rescue Exception => e
|
95
95
|
STDERR.puts "Error : Failed to write log to : #{@options[:url]}, #{e.message}."
|
96
96
|
@device = nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-logstash-writer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- or garfunkel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|