logstash-filter-apcera_translate 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/CONTRIBUTORS +10 -0
- data/DEVELOPER.md +2 -0
- data/Gemfile +3 -0
- data/LICENSE +11 -0
- data/README.md +86 -0
- data/lib/encryption-tool-1.0.jar +0 -0
- data/lib/logstash/filters/access_token.rb +11 -0
- data/lib/logstash/filters/apcera_translate.rb +147 -0
- data/logstash-filter-apcera_translate.gemspec +23 -0
- data/spec/filters/apcera_translate_spec.rb +20 -0
- data/spec/spec_helper.rb +2 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2031eabe3d97e405791717f622f4dc58211d9804498266a09fcdaa6f6df06461
|
4
|
+
data.tar.gz: 9ebaa36b7d5b4a1a5ed8d28eae4569c8cc61dc7492f0d764caea661932602ef1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7d87a1c665f7e87f0ca4b671aa5df3d5c405b626834a449e998722c5319dd4133027cc85d8f87950e1da12f5514be31a7382804a6d91d0d4668fcd8d14e84c6
|
7
|
+
data.tar.gz: 311f5fccaa298c4fedefc0e260bfd68ea5f5185e659fa394c7c6de7ca79a7c657d01042639184019be953ea26e99f2fc4903d7b8dba018432f04995155fa97b8
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
The following is a list of people who have contributed ideas, code, bug
|
2
|
+
reports, or in general have helped logstash along its way.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* -
|
6
|
+
|
7
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
8
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
9
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
10
|
+
open source awesome.
|
data/DEVELOPER.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
2
|
+
you may not use this file except in compliance with the License.
|
3
|
+
You may obtain a copy of the License at
|
4
|
+
|
5
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
10
|
+
See the License for the specific language governing permissions and
|
11
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Logstash Plugin
|
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 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.elastic.co/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/elastic/docs#asciidoc-guide
|
13
|
+
|
14
|
+
## Need Help?
|
15
|
+
|
16
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
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. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
26
|
+
|
27
|
+
- Install dependencies
|
28
|
+
```sh
|
29
|
+
bundle install
|
30
|
+
```
|
31
|
+
|
32
|
+
#### Test
|
33
|
+
|
34
|
+
- Update your dependencies
|
35
|
+
|
36
|
+
```sh
|
37
|
+
bundle install
|
38
|
+
```
|
39
|
+
|
40
|
+
- Run tests
|
41
|
+
|
42
|
+
```sh
|
43
|
+
bundle exec rspec
|
44
|
+
```
|
45
|
+
|
46
|
+
### 2. Running your unpublished Plugin in Logstash
|
47
|
+
|
48
|
+
#### 2.1 Run in a local Logstash clone
|
49
|
+
|
50
|
+
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
51
|
+
```ruby
|
52
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
53
|
+
```
|
54
|
+
- Install plugin
|
55
|
+
```sh
|
56
|
+
bin/logstash-plugin install --no-verify
|
57
|
+
```
|
58
|
+
- Run Logstash with your plugin
|
59
|
+
```sh
|
60
|
+
bin/logstash -e 'filter {awesome {}}'
|
61
|
+
```
|
62
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
63
|
+
|
64
|
+
#### 2.2 Run in an installed Logstash
|
65
|
+
|
66
|
+
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
67
|
+
|
68
|
+
- Build your plugin gem
|
69
|
+
```sh
|
70
|
+
gem build logstash-filter-awesome.gemspec
|
71
|
+
```
|
72
|
+
- Install the plugin from the Logstash home
|
73
|
+
```sh
|
74
|
+
bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.gem
|
75
|
+
```
|
76
|
+
- Start Logstash and proceed to test the plugin
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
81
|
+
|
82
|
+
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.
|
83
|
+
|
84
|
+
It is more important to the community that you are able to contribute.
|
85
|
+
|
86
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
Binary file
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
class AccessToken
|
3
|
+
|
4
|
+
attr_reader :accessToken, :expiresTimestamp
|
5
|
+
attr_writer :accessToken, :expiresTimestamp
|
6
|
+
|
7
|
+
def initialize(accessToken, expiresTimestamp)
|
8
|
+
@accessToken = accessToken
|
9
|
+
@expiresTimestamp = expiresTimestamp
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/filters/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
|
5
|
+
require "net/http"
|
6
|
+
require "uri"
|
7
|
+
require "json"
|
8
|
+
require 'rufus-scheduler'
|
9
|
+
|
10
|
+
require_relative "access_token"
|
11
|
+
|
12
|
+
require 'java'
|
13
|
+
require 'encryption-tool-1.0.jar'
|
14
|
+
java_import 'com.ericsson.automotive.tools.encryption.EncryptionUtils'
|
15
|
+
|
16
|
+
# A general search and translate tool that uses a configured hash to
|
17
|
+
# determine translation values.
|
18
|
+
#
|
19
|
+
# The dictionary entries specified in one way: apcera rest api.
|
20
|
+
#
|
21
|
+
# Operationally, if the event field specified in the `field` configuration
|
22
|
+
# matches the contents of a dictionary entry key, the field's value will be
|
23
|
+
# set to two new field specified in the `job_name_field` and 'name_space_field'
|
24
|
+
# configuration with the matched key's value from the dictionary.
|
25
|
+
#
|
26
|
+
class LogStash::Filters::ApceraTranslate < LogStash::Filters::Base
|
27
|
+
|
28
|
+
# Setting the config_name here is required. This is how you
|
29
|
+
# configure this filter from your Logstash config.
|
30
|
+
#
|
31
|
+
# filter {
|
32
|
+
# apcera_translate {
|
33
|
+
# field => "apcera_job"
|
34
|
+
# ...
|
35
|
+
# }
|
36
|
+
# }
|
37
|
+
#
|
38
|
+
config_name "apcera_translate"
|
39
|
+
|
40
|
+
# The name of the logstash event field containing the value to be compared for a
|
41
|
+
# match by the translate filter
|
42
|
+
config :field, :validate => :string, :required => true
|
43
|
+
# The job_name_field field you wish to populate with the translated value.
|
44
|
+
config :job_name_field, :validate => :string, :default => "job_name"
|
45
|
+
# The name_space_field field you wish to populate with the translated value.
|
46
|
+
config :name_space_field, :validate => :string, :default => "name_space"
|
47
|
+
# username for LDAP authentication
|
48
|
+
config :user_name, :validate => :string, :required => true
|
49
|
+
# password for LDAP authentication
|
50
|
+
config :pwd, :validate => :string, :required => true
|
51
|
+
# LDAP authentication uri
|
52
|
+
config :authentication_api, :validate => :string, :required => true
|
53
|
+
# Apcera REST API uri
|
54
|
+
config :rest_api, :validate => :string, :required => true
|
55
|
+
# The dictionary refresh interval
|
56
|
+
config :refresh_interval, :validate => :string, :default => "5m"
|
57
|
+
|
58
|
+
public
|
59
|
+
def register
|
60
|
+
# Add instance variables
|
61
|
+
@dictionary = {}
|
62
|
+
getAllJobs
|
63
|
+
# Add scheduler for refresh dictionary every refresh_interval
|
64
|
+
scheduler = Rufus::Scheduler.new
|
65
|
+
scheduler.every @refresh_interval do
|
66
|
+
getAllJobs
|
67
|
+
end
|
68
|
+
end # def register
|
69
|
+
|
70
|
+
public
|
71
|
+
def filter(event)
|
72
|
+
uuid = event.get(@field)
|
73
|
+
if @dictionary[uuid]
|
74
|
+
fqn = @dictionary[uuid]
|
75
|
+
setEvent(event, fqn)
|
76
|
+
else
|
77
|
+
fqn = getOneJob(uuid)
|
78
|
+
setEvent(event, fqn)
|
79
|
+
end
|
80
|
+
# filter_matched should go in the last line of our successful code
|
81
|
+
filter_matched(event)
|
82
|
+
end # def filter
|
83
|
+
|
84
|
+
def setEvent(event, fqn)
|
85
|
+
if fqn.kind_of?(Array)
|
86
|
+
event.set(@job_name_field, fqn[1])
|
87
|
+
event.set(@name_space_field, fqn[0])
|
88
|
+
else
|
89
|
+
event.set(@job_name_field, fqn)
|
90
|
+
event.set(@name_space_field, fqn)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def getToken
|
95
|
+
if @accessToken.nil? || @accessToken.expiresTimestamp < (Time.now.to_f * 1000).to_i
|
96
|
+
@accessToken = requestToken
|
97
|
+
end
|
98
|
+
@accessToken
|
99
|
+
end
|
100
|
+
|
101
|
+
def requestToken
|
102
|
+
uri = URI.parse(@authentication_api)
|
103
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
104
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
105
|
+
request.basic_auth(@user_name, EncryptionUtils.decode(@pwd))
|
106
|
+
response = http.request(request)
|
107
|
+
data = JSON.parse(response.body)
|
108
|
+
access_token = data['access_token']
|
109
|
+
expiresIn = data['expires_in']
|
110
|
+
AccessToken.new(access_token, (Time.now.to_f * 1000).to_i + (expiresIn.to_i - 15) * 1000)
|
111
|
+
end
|
112
|
+
|
113
|
+
def getAllJobs
|
114
|
+
uri_api = URI.parse(@rest_api + "/v1/jobs")
|
115
|
+
http_api = Net::HTTP.new(uri_api.host, uri_api.port)
|
116
|
+
request_api = Net::HTTP::Get.new(uri_api.request_uri)
|
117
|
+
token = getToken
|
118
|
+
request_api["Authorization"] = "Bearer #{token.accessToken}"
|
119
|
+
response_api = http_api.request(request_api)
|
120
|
+
api_data = JSON.parse(response_api.body)
|
121
|
+
api_data.each do |child|
|
122
|
+
fqn = child['fqn']
|
123
|
+
reg = /.+::(.+)::(.+)/.match(fqn)
|
124
|
+
array = [reg[1].sub(/\//, "").gsub(/\//, "_"), reg[2]]
|
125
|
+
@dictionary[child['uuid']] = array
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def getOneJob(uuid)
|
130
|
+
uri_api = URI.parse(@rest_api + "/v1/jobs/" + uuid)
|
131
|
+
http_api = Net::HTTP.new(uri_api.host, uri_api.port)
|
132
|
+
request_api = Net::HTTP::Get.new(uri_api.request_uri)
|
133
|
+
token = getToken
|
134
|
+
request_api["Authorization"] = "Bearer #{token.accessToken}"
|
135
|
+
response_api = http_api.request(request_api)
|
136
|
+
api_data = JSON.parse(response_api.body)
|
137
|
+
if api_data['fqn'].nil?
|
138
|
+
@dictionary[uuid] = "Job was not found"
|
139
|
+
else
|
140
|
+
fqn = api_data['fqn']
|
141
|
+
reg = /.+::(.+)::(.+)/.match(fqn)
|
142
|
+
array = [reg[1].sub(/\//, "").gsub(/\//, "_"), reg[2]]
|
143
|
+
@dictionary[uuid] = array
|
144
|
+
end
|
145
|
+
@dictionary[uuid]
|
146
|
+
end
|
147
|
+
end # class LogStash::Filters::ApceraTranslate
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-filter-apcera_translate'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.licenses = ['Apache-2.0']
|
5
|
+
s.summary = 'A general search and translate tool that uses a configured hash to determine translation values'
|
6
|
+
s.description = 'Operationally, if the event field specified in the field configuration matches the contents of a dictionary entry key, the fields value will be set to a new field specified in the destination configuration with the matched keys value from the dictionary.'
|
7
|
+
s.homepage = 'https://github.com/lukenYang'
|
8
|
+
s.authors = ['liuhuayang']
|
9
|
+
s.email = 'liuhua.yang@ericsson.com'
|
10
|
+
s.require_paths = ['lib']
|
11
|
+
|
12
|
+
# Files
|
13
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
14
|
+
# Tests
|
15
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
+
|
17
|
+
# Special flag to let us know this is actually a logstash plugin
|
18
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
|
19
|
+
|
20
|
+
# Gem dependencies
|
21
|
+
s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
|
22
|
+
s.add_development_dependency 'logstash-devutils'
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
require "logstash/filters/apcera_translate"
|
4
|
+
|
5
|
+
describe LogStash::Filters::ApceraTranslate do
|
6
|
+
describe "Add job_name and name_space" do
|
7
|
+
let(:config) do <<-CONFIG
|
8
|
+
filter {
|
9
|
+
apcera_translate {
|
10
|
+
field => "apcera_job"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
CONFIG
|
14
|
+
end
|
15
|
+
|
16
|
+
sample("field" => "UUID") do
|
17
|
+
expect(subject).to include("field")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-filter-apcera_translate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- liuhuayang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '2.0'
|
19
|
+
name: logstash-core-plugin-api
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
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
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
name: logstash-devutils
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Operationally, if the event field specified in the field configuration
|
42
|
+
matches the contents of a dictionary entry key, the fields value will be set to
|
43
|
+
a new field specified in the destination configuration with the matched keys value
|
44
|
+
from the dictionary.
|
45
|
+
email: liuhua.yang@ericsson.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- CHANGELOG.md
|
51
|
+
- CONTRIBUTORS
|
52
|
+
- DEVELOPER.md
|
53
|
+
- Gemfile
|
54
|
+
- LICENSE
|
55
|
+
- README.md
|
56
|
+
- lib/encryption-tool-1.0.jar
|
57
|
+
- lib/logstash/filters/access_token.rb
|
58
|
+
- lib/logstash/filters/apcera_translate.rb
|
59
|
+
- logstash-filter-apcera_translate.gemspec
|
60
|
+
- spec/filters/apcera_translate_spec.rb
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
homepage: https://github.com/lukenYang
|
63
|
+
licenses:
|
64
|
+
- Apache-2.0
|
65
|
+
metadata:
|
66
|
+
logstash_plugin: 'true'
|
67
|
+
logstash_group: filter
|
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.7.6
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: A general search and translate tool that uses a configured hash to determine
|
88
|
+
translation values
|
89
|
+
test_files:
|
90
|
+
- spec/filters/apcera_translate_spec.rb
|
91
|
+
- spec/spec_helper.rb
|