hpess-logstash-codec-cef 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logstash/codecs/cef.rb +73 -62
- data/logstash-codec-cef.gemspec +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: 98b63ea410dc61a1a5ca4db98d63a486b48943e6
|
4
|
+
data.tar.gz: 0c6547cb59f0cb22ec04dd79e8709a78649eca3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7636b4a371ffcaf5714ec62b441d25ef0f70d87cf838e3551bd4fb1c70fcdfa873ce63fd100cb7cfb30b92f99cc417125bad25e2446668ba0122f8c53cb0bc4b
|
7
|
+
data.tar.gz: 5e171d9917c7c9c6e71524ceafdd4756d43787acaecff7e2468c14b96a77bc467bdb8d64e3c6fd59eae992aa163ceb95a8543e3f4653a01e15d1250fb8f4e82d
|
data/lib/logstash/codecs/cef.rb
CHANGED
@@ -1,69 +1,80 @@
|
|
1
1
|
require "logstash/codecs/base"
|
2
2
|
|
3
3
|
class LogStash::Codecs::CEF < LogStash::Codecs::Base
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
4
|
+
config_name "cef"
|
5
|
+
config :signature, :validate => :string, :default => "Logstash"
|
6
|
+
config :name, :validate => :string, :default => "Logstash"
|
7
|
+
config :sev, :validate => :number, :default => 6
|
8
|
+
|
9
|
+
config :fields, :validate => :array
|
10
|
+
|
11
|
+
public
|
12
|
+
def initialize(params={})
|
13
|
+
super(params)
|
14
|
+
end
|
15
|
+
|
16
|
+
public
|
17
|
+
def decode(data)
|
18
|
+
# Strip any quotations at the start and end, flex connectors seem to send this
|
19
|
+
if data[0] == "\""
|
20
|
+
data = data[0..-2]
|
21
|
+
data.slice!(0)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Split by the pipes
|
25
|
+
event['cef_version'], event['cef_vendor'], event['cef_product'], event['cef_device_version'], event['cef_sigid'], event['cef_name'], event['cef_severity'], message = data.split /(?<!\\)[\|]/
|
26
|
+
|
27
|
+
# Try and parse out the syslog header if there is one
|
28
|
+
if event['cef_version'].include? ' '
|
29
|
+
event['syslog'], event['cef_version'] = event['cef_version'].split(' ')
|
30
|
+
end
|
31
|
+
|
32
|
+
# Get rid of the CEF bit in the version
|
33
|
+
event['cef_version'].sub! /^CEF:/, ''
|
34
|
+
|
35
|
+
# Strip any whitespace from the message
|
36
|
+
message = message.to_s.strip
|
37
|
+
|
38
|
+
# Now parse the key value pairs into it
|
39
|
+
extensions = {}
|
40
|
+
if message.length != 0 and message.include? "="
|
41
|
+
message = message.split(/ ([\w\.]+)=/)
|
42
|
+
key, value = message.shift.split('=', 2)
|
43
|
+
extensions[key] = value
|
44
|
+
|
45
|
+
Hash[*message].each{|k, v|
|
46
|
+
extensions[k] = v
|
47
|
+
}
|
48
|
+
|
49
|
+
# And save the new has as the extensions
|
50
|
+
event['cef_ext'] = extensions
|
51
|
+
end
|
52
|
+
yield event
|
53
|
+
end
|
54
|
+
|
55
|
+
public
|
56
|
+
def encode(data)
|
57
|
+
# "CEF:0|Elasticsearch|Logstash|1.0|Signature|Name|Sev|"
|
58
|
+
|
59
|
+
# TODO: Need to check that fields are set!
|
60
|
+
|
61
|
+
# Signature, Name, and Sev should be set in the config, with ref to fields
|
62
|
+
# Should also probably set the fields sent
|
63
|
+
header = ["CEF:0", "Elasticsearch", "Logstash", "1.0", @signature, @name, @sev].join("|")
|
64
|
+
values = @fields.map {|name| get_value(name, data)}.join(" ")
|
65
|
+
# values = values.map {|k,v| "#{k}=#{v}"}.join(" ")
|
66
|
+
@on_event.call(header + " " + values + "\n")
|
40
67
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
# Should also probably set the fields sent
|
52
|
-
header = ["CEF:0", "Elasticsearch", "Logstash", "1.0", @signature, @name, @sev].join("|")
|
53
|
-
values = @fields.map {|name| get_value(name, data)}.join(" ")
|
54
|
-
# values = values.map {|k,v| "#{k}=#{v}"}.join(" ")
|
55
|
-
@on_event.call(header + " " + values + "\n")
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
def get_value(name, event)
|
60
|
-
val = event[name]
|
61
|
-
case val
|
62
|
-
when Hash
|
63
|
-
return name + "=" + val.to_json
|
64
|
-
else
|
65
|
-
return name + "=" + val
|
68
|
+
|
69
|
+
private
|
70
|
+
def get_value(name, event)
|
71
|
+
val = event[name]
|
72
|
+
case val
|
73
|
+
when Hash
|
74
|
+
return name + "=" + val.to_json
|
75
|
+
else
|
76
|
+
return name + "=" + val
|
77
|
+
end
|
66
78
|
end
|
67
|
-
end
|
68
79
|
|
69
80
|
end
|
data/logstash-codec-cef.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'hpess-logstash-codec-cef'
|
4
|
-
s.version = '0.2.
|
4
|
+
s.version = '0.2.2'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "CEF codec to parse CEF formated logs"
|
7
7
|
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hpess-logstash-codec-cef
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elasticsearch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-core
|