Skip to content

Commit d359bbc

Browse files
committed
initial commit
0 parents  commit d359bbc

File tree

10 files changed

+216
-0
lines changed

10 files changed

+216
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.gem
2+
Gemfile.lock
3+
.bundle
4+
vendor

CHANGELOG.md

Whitespace-only changes.

DEVELOPER.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# logstash-input-example
2+
Example input plugin. This should help bootstrap your effort to write your own input plugin!

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source 'https://rubygems.org'
2+
gemspec

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 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/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/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/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require "logstash/devutils/rake"

lib/logstash/inputs/rest.rb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# encoding: utf-8
2+
require "logstash/inputs/base"
3+
require "logstash/namespace"
4+
require "socket" # for Socket.gethostname
5+
require "json"
6+
require "rest-client"
7+
8+
9+
# Read from a list of url returning some json
10+
# The config should look like this:
11+
#
12+
# filter {
13+
# rest {
14+
# urls => {"test1" => "http://localhost:11100/management/metrics"
15+
# "test2" => "http://localhost:21100/management/metrics"}
16+
# timeout => 60
17+
# interval => 60
18+
# }
19+
# }
20+
21+
class LogStash::Inputs::Rest < LogStash::Inputs::Base
22+
23+
config_name "rest"
24+
milestone 1
25+
26+
default :codec, "json"
27+
28+
# A Hash of urls in this format : "name" => "url"
29+
# The name and the url will be passed in the outputed event
30+
#
31+
config :urls, :validate => :hash, :required => true
32+
33+
# How often (in seconds) the urls will be called
34+
config :interval, :validate => :number, :required => true
35+
36+
# Timeout (in seconds) for the rest call
37+
config :timeout, :validate => :number, :default => 60
38+
39+
public
40+
def register
41+
@host = Socket.gethostname.force_encoding(Encoding::UTF_8)
42+
43+
@logger.info("Registering rest Input", :type => @type,
44+
:urls => @urls, :interval => @interval, :timeout => @timeout)
45+
end # def register
46+
47+
public
48+
def run(queue)
49+
Stud.interval(@interval) do
50+
@urls.each do |name, url|
51+
@logger.debug? && @logger.debug("Checking url ", :name => name , :url => url)
52+
begin
53+
RestClient::Request.execute(method: :get, url: url, timeout: timeout, accept: 'json'){ |response, request, result, &block|
54+
@codec.decode(response) do |event|
55+
event["name"] = name
56+
event["host"] = @host
57+
event["url"] = url
58+
event["success"] = true
59+
event["responseCode"] = response.code
60+
61+
case response.code
62+
when 200
63+
event["success"] = true
64+
else
65+
event["success"] = false
66+
end
67+
decorate(event)
68+
queue << event
69+
end
70+
}
71+
rescue
72+
@logger.error("cannot read URL", :name => name, :url => url)
73+
end
74+
end #urls.each
75+
end #interval loop
76+
end #def run
77+
78+
end

logstash-input-rest.gemspec

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Gem::Specification.new do |s|
2+
s.name = 'logstash-input-rest'
3+
s.version = '0.0.1'
4+
s.licenses = ['Apache License (2.0)']
5+
s.summary = "This example input streams a string at a definable interval."
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 = ["Maximede"]
8+
s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
9+
s.require_paths = ["lib"]
10+
11+
# Files
12+
s.files = `git ls-files`.split($\)
13+
# Tests
14+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
15+
16+
# Special flag to let us know this is actually a logstash plugin
17+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
18+
19+
# Gem dependencies
20+
s.add_runtime_dependency "logstash-core", '>= 1.5.0', '< 2.0.0'
21+
s.add_runtime_dependency 'logstash-codec-plain'
22+
s.add_runtime_dependency 'logstash-codec-json'
23+
s.add_runtime_dependency 'stud'
24+
s.add_runtime_dependency 'rest-client'
25+
end

spec/inputs/rest_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require "logstash/devutils/rspec/spec_helper"
2+
require 'logstash/inputs/rest'
3+
4+
describe LogStash::Inputs::Rest do
5+
end

0 commit comments

Comments
 (0)