rack-logstash-writer 1.0.5 → 1.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55e028d5e62b97b3c6ea5ea78bf4c9073e74bf6b
4
- data.tar.gz: 8776e5883b2322995556d624b8a531dc740121cb
3
+ metadata.gz: 7ff2b86195cfeda0d8087a23d4ea91059993c0a1
4
+ data.tar.gz: 35fcf1f76924d92d67534730151bceb9a21f8603
5
5
  SHA512:
6
- metadata.gz: 1e6a996eeaa3f3b786da57278057c3a4c022a17f393e179f2b3a89e08c601e0710e1cbcd02f2dae38c3b35d75a41af0f46672c90695434e178e65033d748d034
7
- data.tar.gz: 1f281f6ebae165c85a8dbda4b324e68b9f2e0814222c9ece32dc57e3d42806e34b939a95e688a19be5670ce17f89e89ce22f89bd26f7070d4faebabda024f5dc
6
+ metadata.gz: 518508d1c5acf891ded2773f8139286992c751f2269b7e782e73385e56c11f2d65ec2348c676f49fe720e4ff92544da092e5d8822ba3b997537bf748d6c4002e
7
+ data.tar.gz: 8f539024bc70c3e191f12e3817fff186ba7cdbad2b6b63555b15e8ec665f3e972db319bb9003fdd1840813a326db86c1895cd54f1e14bd3657715340a1e46c43
data/README.md CHANGED
@@ -34,6 +34,7 @@ use Rack::LogstashWriter , {url: "file:///home/org/Desktop/logsample", # require
34
34
  response_headers: {'head1'=>'head1'}, # optional, parameters to add to the report from the responce headers. default nil
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
+ body_regex: {:name_to_show => 'regex'}, include the regular expression from the body
37
38
  }
38
39
 
39
40
  run Proc.new {[200, {"Content-Type" => "application/json"}, ['{ "message" : "Hello!" }']]}
@@ -19,7 +19,9 @@ use Rack::LogstashWriter , {url: "file:///home/org/Desktop/logsample", # or anot
19
19
  request_headers: {'head1'=>'head1'},
20
20
  response_headers: {'head1'=>'head1'},
21
21
  statuses: [*(500..600)] ,
22
- body_len: 50 }
22
+ body_len: 50 ,
23
+ body_regex: {service_name: 'service_namev:(.*).*[,]?.*}' }
24
+ }
23
25
 
24
26
  map '/hello.json' do
25
27
  run JSONServer.new
@@ -1,10 +1,15 @@
1
- require 'rack/logstash-writer'
1
+ # require 'rack/logstash-writer'
2
+
3
+ require ::File.expand_path('../../../lib/rack/logstash-writer', __FILE__)
2
4
 
3
5
  # Rails.root/config.ru
4
6
  require ::File.expand_path('../lib/sinatra', __FILE__)
5
7
 
6
8
  # use Rails::Rack::Debugger
7
9
  # use Rack::ContentLength
8
- use Rack::LogstashWriter, {url: "file:///home/org/Desktop/logsample" ,statuses: [*(200..600)], body_len: 0, #response_headers: {'User-agent'=>'ua-nimrod'},
9
- request_headers: {'User-agent'=>'ua-nimrod'}} #"udp://localhost:5228" # "udp://localhost:5228"
10
+ use Rack::LogstashWriter, {url: "tcp://localhost:5228" ,statuses: [*(200..600)], body_len: 100, response_headers: {'message' => 'This-is-a-message-man'},
11
+ request_headers: {'User-agent'=>'ua-nimrod'}, #"udp://localhost:5228" # "file:///home/org/Desktop/logsample"
12
+ body_regex: {service_name: 'service_namev:(.*).*[,]?.*}' }
13
+ }
14
+
10
15
  run Sinatra::Application
@@ -6,10 +6,20 @@ get '/' do
6
6
  end
7
7
 
8
8
  get '/hello/:name' do |n|
9
- ssdaasdsdwads
10
9
  # matches "GET /hello/foo" and "GET /hello/bar"
11
10
  # params['name'] is 'foo' or 'bar'
12
11
  # n stores params['name']
13
12
  "Hello #{n}!"
14
13
  end
15
14
 
15
+ get '/goodbye/:name' do |n|
16
+ "Goodbye #{n}!"
17
+ [555, {"Content-Type" => "application/json"}, ['{\"keyword_finder\":\"http://localhost:11120\",\"service_namev:\"abi-mgmt\"}'] ]
18
+ # [{"\"db_host\":\"localhost\",\"env\":\"development\",\"redis\":\"redis://localhost:6379\",\"keyword_finder\":\"http://localhost:11120\",\"service_name\":\"abi-mgmt\"}\""}
19
+ end
20
+
21
+ get '/error/:name' do |n|
22
+ "Error #{n}!"
23
+ 1/0
24
+ end
25
+
@@ -1,11 +1,10 @@
1
1
  require 'socket'
2
2
  require 'uri'
3
3
  require 'json'
4
+ require 'socket'
4
5
 
5
6
  module Rack
6
-
7
7
  class LogstashWriter
8
-
9
8
  # Initialize a new Rack adapter, logstash writer
10
9
  # @param [Hash] options
11
10
  # @option options [String] :url: required, udp and files schemes are also avaliable. no default values.
@@ -58,14 +57,20 @@ module Rack
58
57
  :method => env["REQUEST_METHOD"],
59
58
  :path => env["PATH_INFO"],
60
59
  :query_string => env["QUERY_STRING"],
60
+ :host => env["REMOTE_HOST"],
61
61
  :status => status.to_i,
62
62
  :duration => (Time.now - began_at),
63
63
  :remote_addr => env['REMOTE_ADDR'],
64
64
  :request => request_line(env),
65
- :length => extract_content_length(response_headers),
65
+ :service_name => Dir.pwd.split("/").last ,
66
66
  :"X-Forwarded-For" => response_headers['X-Forwarded-For']
67
67
  }
68
68
 
69
+ if data[:host] =='localhost'
70
+ 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
71
+ data[:host] = "ip-#{soc.gsub(".","-")}"
72
+ end
73
+
69
74
  # This just works for all body types (magic?)... see http://www.rubydoc.info/github/rack/rack/Rack/BodyProxy
70
75
  body.each{|x| data[:body] = x[0..@options[:body_len]] }
71
76
  @options[:request_headers].each { |header, log_key| env_key = "HTTP_#{header.upcase.gsub('-', '_')}" ; data[log_key] = env[env_key] if env[env_key]} if !@options[:request_headers].nil?
@@ -73,9 +78,18 @@ module Rack
73
78
 
74
79
  data[:error_msg] = env["sinatra.error"] if env.has_key?("sinatra.error")
75
80
 
76
- event = {'@fields' => data, '@tags' => ['request'], '@timestamp' => ::Time.now.utc, '@version' => 1}
81
+ @options[:body_regex].each { |k,v| data[k] = data[:body].to_s.match(/#{v}/).captures[0].gsub("\\","").gsub("\"","") rescue data[k]= "" } if !@options[:body_regex].nil?
82
+
83
+ severity = "DEBUG"
84
+ case status
85
+ when 300..399 then severity = "WARN"
86
+ when 400..599 then severity = "ERROR"
87
+ end
88
+ event = {:severity => severity}.merge data
89
+ # logger.puts({'@fields' => data, '@tags' => ['request'], '@timestamp' => ::Time.now.utc, '@version' => 23})
90
+ # TODO to include this lines
77
91
  begin
78
- device.puts( event.to_json + '\n' )
92
+ device.puts( event.to_json )
79
93
  # rescue Errno::EPIPE, Errno::EINVAL
80
94
  rescue Exception => e
81
95
  STDERR.puts "Error : Failed to write log to : #{@options[:url]}, #{e.message}."
@@ -90,9 +104,5 @@ module Rack
90
104
  line
91
105
  end
92
106
 
93
- def extract_content_length headers
94
- value = headers[CONTENT_LENGTH] or return '-'
95
- value.to_s == '0' ? '-' : value
96
- end
97
107
  end
98
- end
108
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class LogstashWriter
3
- VERSION = "1.0.5"
3
+ VERSION = "1.0.7"
4
4
  end
5
5
  end
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.5
4
+ version: 1.0.7
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-06-30 00:00:00.000000000 Z
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake