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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ff2b86195cfeda0d8087a23d4ea91059993c0a1
4
- data.tar.gz: 35fcf1f76924d92d67534730151bceb9a21f8603
3
+ metadata.gz: 2834072c7db69eee168bf9e594ab769700e5c5bc
4
+ data.tar.gz: 4ce942aa199028576f30d3835837e2e41577b662
5
5
  SHA512:
6
- metadata.gz: 518508d1c5acf891ded2773f8139286992c751f2269b7e782e73385e56c11f2d65ec2348c676f49fe720e4ff92544da092e5d8822ba3b997537bf748d6c4002e
7
- data.tar.gz: 8f539024bc70c3e191f12e3817fff186ba7cdbad2b6b63555b15e8ec665f3e972db319bb9003fdd1840813a326db86c1895cd54f1e14bd3657715340a1e46c43
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
@@ -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
- 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(".","-")}"
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
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class LogstashWriter
3
- VERSION = "1.0.7"
3
+ VERSION = "1.0.8"
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.7
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-07-29 00:00:00.000000000 Z
11
+ date: 2015-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake