logstash-filter-rest 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/CONTRIBUTORS +11 -0
- data/Gemfile +2 -0
- data/LICENSE +13 -0
- data/README.md +58 -0
- data/Rakefile +1 -0
- data/lib/logstash/filters/rest.rb +66 -0
- data/logstash-filter-rest.gemspec +24 -0
- data/spec/filters/rest_spec.rb +19 -0
- data/spec/spec_helper.rb +1 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a94fca67a197ad30fca3782583513944208a718d
|
4
|
+
data.tar.gz: 2220544e6212c28180aee679701c5b1d30639db0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f40441ed6c6c920a264b7de52cf4d04d96b72b171f03df9ef4371deb0eb34260dcc7ac400e439d34d74cd2e440533b359aef9b6b463bb8447ac1f8b13d0a790
|
7
|
+
data.tar.gz: fa852b78a2bcf66ba6aea78d4fd9546420d3eed72483869282b7222b2fb69fc82a571d685768a221f4e5c22e351a47a643f11a4af74e558556a3517e3982441e
|
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,11 @@
|
|
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
|
+
* Aaron Mildenstein (untergeek)
|
6
|
+
* Pier-Hugues Pellerin (ph)
|
7
|
+
|
8
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
9
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
10
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
11
|
+
open source awesome.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
|
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,58 @@
|
|
1
|
+
# Logstash REST Filter
|
2
|
+
|
3
|
+
This is a filter 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
|
+
This logstash filter provides an easy way to access RESTful Resources within logstash. It can be used to post data to a REST API or to gather data and save it in your log file.
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
### 1. Installation
|
13
|
+
You can use the built in plugin tool of Logstash to install the filter:
|
14
|
+
```
|
15
|
+
$LS_HOME/bin/plugin install logstash-filter-rest
|
16
|
+
```
|
17
|
+
|
18
|
+
Or you can build it yourself:
|
19
|
+
```
|
20
|
+
git clone https://github.com/lucashenning/logstash-filter-rest.git
|
21
|
+
bundle install
|
22
|
+
gem build logstash-filter-rest.gemspec
|
23
|
+
$LS_HOME/bin/plugin install logstash-filter-rest-0.1.0.gem
|
24
|
+
```
|
25
|
+
|
26
|
+
### 2. Filter Configuration
|
27
|
+
Add the following inside the filter section of your logstash configuration:
|
28
|
+
|
29
|
+
```sh
|
30
|
+
rest {
|
31
|
+
url => "http://icanhazip.com" # string (required)
|
32
|
+
json => true # boolean (optional, default = false)
|
33
|
+
method => "post" # string (optional, default = "get")
|
34
|
+
header => { # hash (optional)
|
35
|
+
'key1' => 'value1'
|
36
|
+
'key2' => 'value2'
|
37
|
+
'key3' => '%{somefield}'
|
38
|
+
}
|
39
|
+
params => { # hash (optional, only available for method => "post")
|
40
|
+
'key1' => 'value1'
|
41
|
+
'key2' => 'value2'
|
42
|
+
'key3' => '%{somefield}'
|
43
|
+
}
|
44
|
+
}
|
45
|
+
```
|
46
|
+
### 3. Accessing the result
|
47
|
+
If you are expecting a single output and 'json => false' you will get a logstash field called 'response' which contains the result.
|
48
|
+
If 'json => true' you will get a new logstash field for each key.
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
53
|
+
|
54
|
+
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.
|
55
|
+
|
56
|
+
It is more important to the community that you are able to contribute.
|
57
|
+
|
58
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "logstash/devutils/rake"
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/filters/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
|
5
|
+
# Logstash REST Filter
|
6
|
+
# This filter calls a defined URL and saves the answer into a specified field.
|
7
|
+
#
|
8
|
+
class LogStash::Filters::Rest < LogStash::Filters::Base
|
9
|
+
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# filter {
|
13
|
+
# rest {
|
14
|
+
# url => "http://example.com"
|
15
|
+
# header => {
|
16
|
+
# 'key1' => 'value1'
|
17
|
+
# 'key2' => 'value2'
|
18
|
+
# 'key3' => '%{somefield}'
|
19
|
+
# }
|
20
|
+
# method => "post"
|
21
|
+
# json => true
|
22
|
+
# params => {
|
23
|
+
# 'key1' => 'value1'
|
24
|
+
# 'key2' => 'value2'
|
25
|
+
# 'key3' => '%{somefield}'
|
26
|
+
# }
|
27
|
+
# }
|
28
|
+
# }
|
29
|
+
#
|
30
|
+
config_name "rest"
|
31
|
+
|
32
|
+
# Replace the message with this value.
|
33
|
+
config :url, :validate => :string, :required => true
|
34
|
+
config :method, :validate => :string, :default => "get"
|
35
|
+
config :json, :validate => :boolean, :default => false
|
36
|
+
config :header, :validate => :hash, :default => { }
|
37
|
+
config :params, :validate => :hash, :default => { }
|
38
|
+
|
39
|
+
public
|
40
|
+
def register
|
41
|
+
require "json"
|
42
|
+
require "rest_client"
|
43
|
+
@resource = RestClient::Resource.new(@url, :headers => @header)
|
44
|
+
end # def register
|
45
|
+
|
46
|
+
public
|
47
|
+
def filter(event)
|
48
|
+
return unless filter?(event)
|
49
|
+
if method == "get"
|
50
|
+
response = @resource.get()
|
51
|
+
else
|
52
|
+
response = @resource.post(@params)
|
53
|
+
end
|
54
|
+
|
55
|
+
if json == true
|
56
|
+
h = JSON.parse(response)
|
57
|
+
h.each do |key, value|
|
58
|
+
event[key] = value
|
59
|
+
end
|
60
|
+
else
|
61
|
+
event['response'] = response.strip
|
62
|
+
end
|
63
|
+
|
64
|
+
filter_matched(event)
|
65
|
+
end # def filter
|
66
|
+
end # class LogStash::Filters::Rest
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-filter-rest'
|
3
|
+
s.version = '0.1.1'
|
4
|
+
s.licenses = ['Apache License (2.0)']
|
5
|
+
s.summary = "This filter requests data from a RESTful Web Service."
|
6
|
+
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"
|
7
|
+
s.authors = ["Lucas Henning"]
|
8
|
+
s.email = 'mail@hurb.de'
|
9
|
+
s.homepage = "https://github.com/lucashenning/logstash-filter-rest/"
|
10
|
+
s.require_paths = ["lib"]
|
11
|
+
|
12
|
+
# Files
|
13
|
+
s.files = `git ls-files`.split($\)
|
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", '>= 1.4.0', '< 2.0.0'
|
22
|
+
s.add_runtime_dependency "rest-client", '>= 1.8.0'
|
23
|
+
s.add_development_dependency 'logstash-devutils'
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "logstash/filters/rest"
|
3
|
+
|
4
|
+
describe LogStash::Filters::Rest do
|
5
|
+
describe "Set to Rest Filter" do
|
6
|
+
let(:config) do <<-CONFIG
|
7
|
+
filter {
|
8
|
+
rest {
|
9
|
+
url => "http://icanhazip.com"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
CONFIG
|
13
|
+
end
|
14
|
+
|
15
|
+
sample("message" => "some text") do
|
16
|
+
expect(subject).to include("message")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "logstash/devutils/rspec/spec_helper"
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-filter-rest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lucas Henning
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logstash-core
|
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: rest-client
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.8.0
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.8.0
|
45
|
+
prerelease: false
|
46
|
+
type: :runtime
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: logstash-devutils
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
prerelease: false
|
60
|
+
type: :development
|
61
|
+
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
|
62
|
+
email: mail@hurb.de
|
63
|
+
executables: []
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files: []
|
66
|
+
files:
|
67
|
+
- CONTRIBUTORS
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- lib/logstash/filters/rest.rb
|
73
|
+
- logstash-filter-rest.gemspec
|
74
|
+
- spec/filters/rest_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
homepage: https://github.com/lucashenning/logstash-filter-rest/
|
77
|
+
licenses:
|
78
|
+
- Apache License (2.0)
|
79
|
+
metadata:
|
80
|
+
logstash_plugin: 'true'
|
81
|
+
logstash_group: filter
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.4.6
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: This filter requests data from a RESTful Web Service.
|
102
|
+
test_files:
|
103
|
+
- spec/filters/rest_spec.rb
|
104
|
+
- spec/spec_helper.rb
|