logstash-filter-linelookup 0.1.0
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 +7 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +10 -0
- data/LICENSE +21 -0
- data/README.md +37 -0
- data/lib/logstash/filters/linelookup.rb +61 -0
- data/logstash-filter-linelookup.gemspec +24 -0
- data/spec/spec_helper.rb +18 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e05f8ed58a5a3da6b96b39e003aa564d78ebd3d13fbc0caf73c0d71eb4e444c9
|
4
|
+
data.tar.gz: a49de6db640b18c72345e626ac63ebdeee5437d3b538fdfa90367a12a954cb75
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d32fde2a7a298ba98741efe296a90381faa6d5f76eb93146eaaa75670450d664322919cad1c072b7da76263fe47e9b171352c87e43b48d1c44475004fd1e3155
|
7
|
+
data.tar.gz: d44589afe4fa35c8005a8d2a3b710900136e1b04ead85aa9949d8f352797630e65f5a7550b582c54aa80fb5e5a91e92498f6890d92c3632740f9f060382f233c
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gemspec
|
3
|
+
|
4
|
+
logstash_path = ENV['LOGSTASH_PATH'] || '/usr/share/logstash'
|
5
|
+
|
6
|
+
if Dir.exist?(logstash_path)
|
7
|
+
gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
|
8
|
+
gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
|
9
|
+
end
|
10
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Julian Wecke
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Logstash Plugin for lookups via line based protocol
|
2
|
+
|
3
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
4
|
+
|
5
|
+
It is fully free and fully open source. The license is [MIT](LICENSE).
|
6
|
+
|
7
|
+
|
8
|
+
## Documentation
|
9
|
+
This filter plugin does simple lookups for enrichment via a line based protocol. A query(1 line) is send via a socket and a response(1 line) is received and stored at the *target* field.
|
10
|
+
|
11
|
+
The query is dynamicly build and can use *%{...}* style variables
|
12
|
+
|
13
|
+
|
14
|
+
### Configuration Options
|
15
|
+
|
16
|
+
|
17
|
+
| Setting | Type | Required |
|
18
|
+
| ----------- | ------ | ----------|
|
19
|
+
| query | string | yes |
|
20
|
+
| target | string | yes |
|
21
|
+
| socket_path | string | yes |
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
### Example config
|
26
|
+
|
27
|
+
|
28
|
+
```
|
29
|
+
filter {
|
30
|
+
linelookup {
|
31
|
+
query => "%{[source][ip]}"
|
32
|
+
target => "[source][geo][name]"
|
33
|
+
socket_path => "/var/run/lookup.sock"
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
```
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/filters/base"
|
3
|
+
require "socket"
|
4
|
+
|
5
|
+
class LogStash::Filters::Linelookup < LogStash::Filters::Base
|
6
|
+
|
7
|
+
#
|
8
|
+
# filter {
|
9
|
+
# linelookup {
|
10
|
+
# query => "%{[source][ip]}"
|
11
|
+
# socket_path => "/var/run/lookup.sock"
|
12
|
+
# }
|
13
|
+
# }
|
14
|
+
#
|
15
|
+
config_name "linelookup"
|
16
|
+
|
17
|
+
config :query, :validate => :string, :required => true
|
18
|
+
config :target, :validate => :string, :required => true
|
19
|
+
config :miss_value, :validate => :string, :default => ""
|
20
|
+
config :socket_path, :validate => :string, :default => ""
|
21
|
+
|
22
|
+
public
|
23
|
+
def register
|
24
|
+
@lookupconn = nil
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
public
|
29
|
+
def filter(event)
|
30
|
+
retries = 2
|
31
|
+
begin
|
32
|
+
@lookupconn ||= connect
|
33
|
+
|
34
|
+
@lookupconn.puts(event.sprintf(@query))
|
35
|
+
|
36
|
+
response = @lookupconn.gets.chop
|
37
|
+
|
38
|
+
if response != @miss_value
|
39
|
+
event.set(@target, response)
|
40
|
+
filter_matched(event)
|
41
|
+
end
|
42
|
+
|
43
|
+
rescue => e
|
44
|
+
@lookupconn = nil
|
45
|
+
retries -= 1
|
46
|
+
unless retries < 0
|
47
|
+
retry
|
48
|
+
else
|
49
|
+
@logger.warn("Failed to query lookup service", :event => event, :exception => e)
|
50
|
+
event.tag("_linelookup_failure")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end # def filter
|
55
|
+
|
56
|
+
private
|
57
|
+
def connect
|
58
|
+
|
59
|
+
Socket.unix(@socket_path)
|
60
|
+
end
|
61
|
+
end # class LogStash::Filters::Linelookup
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-filter-linelookup'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.licenses = ['MIT']
|
5
|
+
s.summary = 'Logstash Filter Plugin for Linelookup'
|
6
|
+
s.description = 'A logstash filter for enrichment via a simple line-protocol over a socket'
|
7
|
+
s.homepage = 'https://github.com/securitym0nkey/logstash-filter-linelookup'
|
8
|
+
s.authors = ['Julian Wecke']
|
9
|
+
s.email = 'julian@wecke.me'
|
10
|
+
s.require_paths = ['lib']
|
11
|
+
|
12
|
+
|
13
|
+
# Files
|
14
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
15
|
+
# Tests
|
16
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
|
+
|
18
|
+
# Special flag to let us know this is actually a logstash plugin
|
19
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
|
20
|
+
|
21
|
+
# Gem dependencies
|
22
|
+
s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
|
23
|
+
s.add_development_dependency 'logstash-devutils', '~> 0'
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
require "logstash/devutils/rspec/spec_helper"
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-filter-linelookup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julian Wecke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logstash-core-plugin-api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: logstash-devutils
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A logstash filter for enrichment via a simple line-protocol over a socket
|
42
|
+
email: julian@wecke.me
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- CHANGELOG.md
|
48
|
+
- Gemfile
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- lib/logstash/filters/linelookup.rb
|
52
|
+
- logstash-filter-linelookup.gemspec
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
homepage: https://github.com/securitym0nkey/logstash-filter-linelookup
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata:
|
58
|
+
logstash_plugin: 'true'
|
59
|
+
logstash_group: filter
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubygems_version: 3.3.25
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Logstash Filter Plugin for Linelookup
|
79
|
+
test_files:
|
80
|
+
- spec/spec_helper.rb
|