logstash-codec-cef 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/DEVELOPER.md +49 -0
- data/Gemfile +3 -0
- data/LICENSE +13 -0
- data/README.md +95 -0
- data/Rakefile +7 -0
- data/lib/logstash/codecs/cef.rb +64 -0
- data/lib/logstash/version.rb +6 -0
- data/logstash-codec-cef.gemspec +27 -0
- data/spec/codecs/cef_spec.rb +37 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 87b1c006ad2c6b9f408a1916584c8395aaa1055e
|
4
|
+
data.tar.gz: 3be4bfb1d8b3b2ef05cb22a35adb2f734bfe57a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cdde709159e93287bdfa22bb4b233d2e5d044132ea29c1a4610e260f3cc5b9a3c6b3b6095bffb8a82cba4dead39eba9553106b2da1d22dbe0ed97da482238697
|
7
|
+
data.tar.gz: cc9f48c5c29e2f922fbe291b50e0ec907e96fcbe47ec32bd8f5e82c3b597e63c4419a3f2dfb9ffef0a81baa003e6aa737c2583cb16b0486749e47f894d8b1e7b
|
data/DEVELOPER.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
logstash-CEF
|
2
|
+
============
|
3
|
+
|
4
|
+
Logstash Codec to handle CEF encoded data
|
5
|
+
|
6
|
+
Build
|
7
|
+
=====
|
8
|
+
|
9
|
+
Run 'make tarball' to build the project. A tarball will end up in ./build. Extract the file over top of your logstash directory.
|
10
|
+
(Hint: or, just copy the ./lib and ./vendor directories to your logstash folder)
|
11
|
+
|
12
|
+
|
13
|
+
Config
|
14
|
+
======
|
15
|
+
|
16
|
+
This is an example input config.
|
17
|
+
|
18
|
+
```
|
19
|
+
input {
|
20
|
+
generator {
|
21
|
+
message => "TODO"
|
22
|
+
count => 1
|
23
|
+
codec => cef
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
output {
|
28
|
+
stdout {
|
29
|
+
codec => "rubydebug"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
```
|
33
|
+
|
34
|
+
This is an example output config.
|
35
|
+
|
36
|
+
```
|
37
|
+
input {
|
38
|
+
generator {
|
39
|
+
message => "TODO"
|
40
|
+
count => 1
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
output {
|
45
|
+
stdout {
|
46
|
+
codec => cef
|
47
|
+
}
|
48
|
+
}
|
49
|
+
```
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012-2015 Elasticsearch <http://www.elasticsearch.org>
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
|
4
|
+
|
5
|
+
It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
|
6
|
+
|
7
|
+
## Documentation
|
8
|
+
|
9
|
+
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elasticsearch.org/guide/en/logstash/current/).
|
10
|
+
|
11
|
+
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
12
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
|
13
|
+
|
14
|
+
## Need Help?
|
15
|
+
|
16
|
+
Need help? Try #logstash on freenode IRC or the logstash-users@googlegroups.com mailing list.
|
17
|
+
|
18
|
+
## Developing
|
19
|
+
|
20
|
+
### 1. Plugin Developement and Testing
|
21
|
+
|
22
|
+
#### Code
|
23
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
24
|
+
|
25
|
+
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization.
|
26
|
+
|
27
|
+
- Install dependencies
|
28
|
+
```sh
|
29
|
+
bundle install
|
30
|
+
```
|
31
|
+
|
32
|
+
#### Test
|
33
|
+
|
34
|
+
```sh
|
35
|
+
bundle exec rspec
|
36
|
+
```
|
37
|
+
|
38
|
+
The Logstash code required to run the tests/specs is specified in the `Gemfile` by the line similar to:
|
39
|
+
```ruby
|
40
|
+
gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
|
41
|
+
```
|
42
|
+
To test against another version or a local Logstash, edit the `Gemfile` to specify an alternative location, for example:
|
43
|
+
```ruby
|
44
|
+
gem "logstash", :github => "elasticsearch/logstash", :ref => "master"
|
45
|
+
```
|
46
|
+
```ruby
|
47
|
+
gem "logstash", :path => "/your/local/logstash"
|
48
|
+
```
|
49
|
+
|
50
|
+
Then update your dependencies and run your tests:
|
51
|
+
|
52
|
+
```sh
|
53
|
+
bundle install
|
54
|
+
bundle exec rspec
|
55
|
+
```
|
56
|
+
|
57
|
+
### 2. Running your unpublished Plugin in Logstash
|
58
|
+
|
59
|
+
#### 2.1 Run in a local Logstash clone
|
60
|
+
|
61
|
+
- Edit Logstash `tools/Gemfile` and add the local plugin path, for example:
|
62
|
+
```ruby
|
63
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
64
|
+
```
|
65
|
+
- Update Logstash dependencies
|
66
|
+
```sh
|
67
|
+
rake vendor:gems
|
68
|
+
```
|
69
|
+
- Run Logstash with your plugin
|
70
|
+
```sh
|
71
|
+
bin/logstash -e 'filter {awesome {}}'
|
72
|
+
```
|
73
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
74
|
+
|
75
|
+
#### 2.2 Run in an installed Logstash
|
76
|
+
|
77
|
+
- Build your plugin gem
|
78
|
+
```sh
|
79
|
+
gem build logstash-filter-awesome.gemspec
|
80
|
+
```
|
81
|
+
- Install the plugin from the Logstash home
|
82
|
+
```sh
|
83
|
+
bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
|
84
|
+
```
|
85
|
+
- Start Logstash and proceed to test the plugin
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
90
|
+
|
91
|
+
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
92
|
+
|
93
|
+
It is more important to me that you are able to contribute.
|
94
|
+
|
95
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
|
data/Rakefile
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "logstash/codecs/base"
|
2
|
+
|
3
|
+
class LogStash::Codecs::CEF < LogStash::Codecs::Base
|
4
|
+
config_name "cef"
|
5
|
+
|
6
|
+
|
7
|
+
# Specify if the Syslog header will be expected
|
8
|
+
config :syslog, :validate => :boolean, :default => false
|
9
|
+
|
10
|
+
config :signature, :validate => :string, :default => "Logstash"
|
11
|
+
config :name, :validate => :string, :default => "Logstash"
|
12
|
+
config :sev, :validate => :number, :default => 6
|
13
|
+
|
14
|
+
config :fields, :validate => :array
|
15
|
+
|
16
|
+
public
|
17
|
+
def initialize(params={})
|
18
|
+
super(params)
|
19
|
+
end
|
20
|
+
|
21
|
+
public
|
22
|
+
def decode(data)
|
23
|
+
# Need to break out the headers, then return the headers as individual fields, and the extension to be processed by a filter (ie: KV)
|
24
|
+
# %{SYSLOGDATE} %{HOST} CEF:Version|Device Vendor|Device Product|Device Version|SignatureID|Name|Severity|Extension
|
25
|
+
event = LogStash::Event.new()
|
26
|
+
if @syslog
|
27
|
+
@logger.debug("Expecting SYSLOG headers")
|
28
|
+
event['syslog'], data = data.split('CEF:', 1)
|
29
|
+
# Since we have the syslog headers, lets pull them out first and put them into their own field to be handled
|
30
|
+
else
|
31
|
+
# We don't have syslog headers, so we just need to remove CEF:
|
32
|
+
data.sub! /^CEF:/, ''
|
33
|
+
end #if @syslog
|
34
|
+
# Now, break out the rest of the headers
|
35
|
+
event['cef_version'], event['cef_vendor'], event['cef_product'], event['cef_device_version'], event['cef_sigid'], event['cef_name'], event['cef_severity'], event['message'] = data.scan /(?:[^\|\\]|\\.)+/
|
36
|
+
yield event
|
37
|
+
end
|
38
|
+
|
39
|
+
public
|
40
|
+
def encode(data)
|
41
|
+
# "CEF:0|Elasticsearch|Logstash|1.0|Signature|Name|Sev|"
|
42
|
+
|
43
|
+
# TODO: Need to check that fields are set!
|
44
|
+
|
45
|
+
# Signature, Name, and Sev should be set in the config, with ref to fields
|
46
|
+
# Should also probably set the fields sent
|
47
|
+
header = ["CEF:0", "Elasticsearch", "Logstash", "1.0", @signature, @name, @sev].join("|")
|
48
|
+
values = @fields.map {|name| get_value(name, data)}.join(" ")
|
49
|
+
# values = values.map {|k,v| "#{k}=#{v}"}.join(" ")
|
50
|
+
@on_event.call(header + " " + values + "\n")
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def get_value(name, event)
|
55
|
+
val = event[name]
|
56
|
+
case val
|
57
|
+
when Hash
|
58
|
+
return name + "=" + val.to_json
|
59
|
+
else
|
60
|
+
return name + "=" + val
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'logstash-codec-cef'
|
4
|
+
s.version = '0.1.1'
|
5
|
+
s.licenses = ['Apache License (2.0)']
|
6
|
+
s.summary = "CEF codec to parse CEF formated logs"
|
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"
|
8
|
+
s.authors = ["Elasticsearch"]
|
9
|
+
s.email = 'info@elasticsearch.com'
|
10
|
+
s.homepage = "http://www.elasticsearch.org/guide/en/logstash/current/index.html"
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
|
13
|
+
# Files
|
14
|
+
s.files = `git ls-files`.split($\)
|
15
|
+
|
16
|
+
# Tests
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
|
19
|
+
# Special flag to let us know this is actually a logstash plugin
|
20
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "codec" }
|
21
|
+
|
22
|
+
# Gem dependencies
|
23
|
+
s.add_runtime_dependency 'logstash', '>= 1.4.0', '< 2.0.0'
|
24
|
+
|
25
|
+
s.add_development_dependency 'logstash-devutils'
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "logstash/devutils/rspec/spec_helper"
|
4
|
+
require "logstash/codecs/cef"
|
5
|
+
require "logstash/event"
|
6
|
+
|
7
|
+
describe LogStash::Codecs::CEF do
|
8
|
+
subject do
|
9
|
+
next LogStash::Codecs::CEF.new
|
10
|
+
end
|
11
|
+
|
12
|
+
context "#encode" do
|
13
|
+
it "should assert all header fields are present"
|
14
|
+
end
|
15
|
+
|
16
|
+
context "#decode" do
|
17
|
+
let (:message) { "CEF:0|security|threatmanager|1.0|100|trojan successfully stopped|10|src=10.0.0.192 dst=12.121.122.82 spt=1232" }
|
18
|
+
|
19
|
+
it "should parse the cef header" do
|
20
|
+
subject.decode(message) do |e|
|
21
|
+
insist { e.is_a?(LogStash::Event) }
|
22
|
+
insist { e["cef_version"] } == "0"
|
23
|
+
insist { e["cef_vendor"] } == "security"
|
24
|
+
insist { e["cef_product"] } == "threatmanager"
|
25
|
+
insist { e["cef_device_version"] } == "1.0"
|
26
|
+
insist { e["cef_sigid"] } == "100"
|
27
|
+
insist { e["cef_name"] } == "trojan successfully stopped"
|
28
|
+
insist { e["cef_severity"] } == "10"
|
29
|
+
insist { e["message"] } == "src=10.0.0.192 dst=12.121.122.82 spt=1232"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should parse the cef body"
|
34
|
+
it "should handle values in the body that contain spaces"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-codec-cef
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elasticsearch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logstash
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.4.0
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.0.0
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 1.4.0
|
28
|
+
- - <
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 2.0.0
|
31
|
+
prerelease: false
|
32
|
+
type: :runtime
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: logstash-devutils
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
prerelease: false
|
46
|
+
type: :development
|
47
|
+
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
|
48
|
+
email: info@elasticsearch.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- DEVELOPER.md
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/logstash/codecs/cef.rb
|
59
|
+
- lib/logstash/version.rb
|
60
|
+
- logstash-codec-cef.gemspec
|
61
|
+
- spec/codecs/cef_spec.rb
|
62
|
+
homepage: http://www.elasticsearch.org/guide/en/logstash/current/index.html
|
63
|
+
licenses:
|
64
|
+
- Apache License (2.0)
|
65
|
+
metadata:
|
66
|
+
logstash_plugin: 'true'
|
67
|
+
logstash_group: codec
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.1.9
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: CEF codec to parse CEF formated logs
|
88
|
+
test_files:
|
89
|
+
- spec/codecs/cef_spec.rb
|