Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 56 lines (44 sloc) 1.537 kb
4654755 @jordansissel - Style cleanup. Tests still pass, so I probably didn't break anythin…
jordansissel authored
1 require "logstash/namespace"
9fdbe25 @jordansissel - Add GELF output for graylog2: see http://www.graylog2.org/about/gelf
jordansissel authored
2 require "logstash/outputs/base"
3
fcce185 @jordansissel - More config doc and related cleanup
jordansissel authored
4 # GELF output. This is most useful if you want to use logstash
5 # to output events to graylog2.
6 #
7 # http://www.graylog2.org/about/gelf
9fdbe25 @jordansissel - Add GELF output for graylog2: see http://www.graylog2.org/about/gelf
jordansissel authored
8 class LogStash::Outputs::Gelf < LogStash::Outputs::Base
33d6619 @jordansissel - Config parsing works again; bug was causing '\' in a string to
jordansissel authored
9
10 config_name "gelf"
fcce185 @jordansissel - More config doc and related cleanup
jordansissel authored
11
12 # graylog2 server address
3b0f84b @lusis making all gelf params tunable
lusis authored
13 config :host, :validate => :string, :required => true
14
fcce185 @jordansissel - More config doc and related cleanup
jordansissel authored
15 # graylog2 server port
16 config :port, :validate => :number, :default => 12201
17
18 # The GELF chunksize
19 config :chunksize, :validate => :number, :default => 1420
3b0f84b @lusis making all gelf params tunable
lusis authored
20
fcce185 @jordansissel - More config doc and related cleanup
jordansissel authored
21 # The GELF message level
22 config :level, :validate => :number, :default => 1
3b0f84b @lusis making all gelf params tunable
lusis authored
23
fcce185 @jordansissel - More config doc and related cleanup
jordansissel authored
24 # The GELF facility.
25 config :facility, :validate => :string, :default => "logstash-gelf"
33d6619 @jordansissel - Config parsing works again; bug was causing '\' in a string to
jordansissel authored
26
4654755 @jordansissel - Style cleanup. Tests still pass, so I probably didn't break anythin…
jordansissel authored
27 public
9fdbe25 @jordansissel - Add GELF output for graylog2: see http://www.graylog2.org/about/gelf
jordansissel authored
28 def register
438aedc @jordansissel - move more requires to register method
jordansissel authored
29 require "gelf" # rubygem 'gelf'
3b0f84b @lusis making all gelf params tunable
lusis authored
30 option_hash = Hash.new
31 option_hash['level'] = @level
32 option_hash['facility'] = @facility
33
34 @gelf = GELF::Notifier.new(@host, @port, @chunksize, option_hash)
9fdbe25 @jordansissel - Add GELF output for graylog2: see http://www.graylog2.org/about/gelf
jordansissel authored
35 end # def register
36
4654755 @jordansissel - Style cleanup. Tests still pass, so I probably didn't break anythin…
jordansissel authored
37 public
9fdbe25 @jordansissel - Add GELF output for graylog2: see http://www.graylog2.org/about/gelf
jordansissel authored
38 def receive(event)
0726603 @jordansissel - add note about why we're making a hash
jordansissel authored
39 # We have to make our own hash here because GELF expects a hash
40 # with a specific format.
39377a4 @lusis fixing gelf output for deprecated usage
lusis authored
41 m = Hash.new
42 m["short_message"] = (event.fields["message"] or event.message)
43 m["full_message"] = (event.message)
44 m["host"] = event["@source_host"]
45 m["file"] = event["@source_path"]
46 m["level"] = 1
9decdf7 @jordansissel - Add fields and timestamp from to gelf
jordansissel authored
47
48 event.fields.each do |name, value|
b4612db @jordansissel - Skip empty fields
jordansissel authored
49 next if value == nil or value.empty?
39377a4 @lusis fixing gelf output for deprecated usage
lusis authored
50 m["#{name}"] = value
9decdf7 @jordansissel - Add fields and timestamp from to gelf
jordansissel authored
51 end
39377a4 @lusis fixing gelf output for deprecated usage
lusis authored
52 m["timestamp"] = event.timestamp
61f1bdb @lusis fixing notify call so opts will be passed
lusis authored
53 @gelf.notify!(m)
4654755 @jordansissel - Style cleanup. Tests still pass, so I probably didn't break anythin…
jordansissel authored
54 end # def receive
f22e259 @jordansissel - fix comment
jordansissel authored
55 end # class LogStash::Outputs::Gelf
Something went wrong with that request. Please try again.