logstash-input-yasuri 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fca00083b0ef4784c3bbc4b8e9746bf3683862d0
4
+ data.tar.gz: 960d03957a623340d5e9a1d772698b34357b38e4
5
+ SHA512:
6
+ metadata.gz: 4560bfd18fafdde32515312daa45b2cc37bc1972d1b6118410d2c0dc9a83eedd1c90dc8617f832252340e8af390afd7ddb476e050643a02fd6424b18e23767d3
7
+ data.tar.gz: 350a6b4f336db4dd519aaf23aea1e5bb52b7f46dc813deaf1c768be661facea2e16b193549048ac545b257d631cea1197211504553ab4b78e9549bd9551f8320
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## 2.0.4
2
+ - Add encoding: utf-8 line to spec file. This can prevent issues with tests.
3
+ ## 2.0.1
4
+ - Simplify the shutdown implementation a bit for easier understanding
5
+ ## 2.0.0
6
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
7
+ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
8
+ - Dependency on logstash-core update to 2.0
9
+
data/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-input-example
2
+ Example input plugin. This should help bootstrap your effort to write your own input plugin!
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2016 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/NOTICE.TXT ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # Logstash Plugin
2
+
3
+ [![Travis Build Status](https://travis-ci.org/tac0x2a/logstash-input-yasuri.svg)](https://travis-ci.org/tac0x2a/logstash-input-yasuri)
4
+
5
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
+
7
+ 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.
8
+
9
+ ## Documentation
10
+
11
+ 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/).
12
+
13
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
14
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
15
+
16
+ ## Need Help?
17
+
18
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
19
+
20
+ ## Developing
21
+
22
+ ### 1. Plugin Developement and Testing
23
+
24
+ #### Code
25
+ - To get started, you'll need JRuby with the Bundler gem installed.
26
+
27
+ - 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).
28
+
29
+ - Install dependencies
30
+ ```sh
31
+ bundle install
32
+ ```
33
+
34
+ #### Test
35
+
36
+ - Update your dependencies
37
+
38
+ ```sh
39
+ bundle install
40
+ ```
41
+
42
+ - Run tests
43
+
44
+ ```sh
45
+ bundle exec rspec
46
+ ```
47
+
48
+ ### 2. Running your unpublished Plugin in Logstash
49
+
50
+ #### 2.1 Run in a local Logstash clone
51
+
52
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
53
+ ```ruby
54
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
55
+ ```
56
+ - Install plugin
57
+ ```sh
58
+ # Logstash 2.3 and higher
59
+ bin/logstash-plugin install --no-verify
60
+
61
+ # Prior to Logstash 2.3
62
+ bin/plugin install --no-verify
63
+
64
+ ```
65
+ - Run Logstash with your plugin
66
+ ```sh
67
+ bin/logstash -e 'filter {awesome {}}'
68
+ ```
69
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
70
+
71
+ #### 2.2 Run in an installed Logstash
72
+
73
+ 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:
74
+
75
+ - Build your plugin gem
76
+ ```sh
77
+ gem build logstash-filter-awesome.gemspec
78
+ ```
79
+ - Install the plugin from the Logstash home
80
+ ```sh
81
+ # Logstash 2.3 and higher
82
+ bin/logstash-plugin install --no-verify
83
+
84
+ # Prior to Logstash 2.3
85
+ bin/plugin install --no-verify
86
+
87
+ ```
88
+ - Start Logstash and proceed to test the plugin
89
+
90
+ ## Contributing
91
+
92
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
93
+
94
+ 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.
95
+
96
+ It is more important to the community that you are able to contribute.
97
+
98
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+ require "logstash/inputs/base"
3
+ require "logstash/namespace"
4
+ require "socket" # for Socket.gethostname
5
+ require "mechanize"
6
+ require "yasuri"
7
+
8
+ class LogStash::Inputs::Yasuri < LogStash::Inputs::Base
9
+ config_name "yasuri"
10
+
11
+ default :codec, "plain"
12
+
13
+ # Parse tree as JSON.
14
+ # Read https://github.com/tac0x2a/yasuri/blob/master/USAGE.md#construct-parse-tree
15
+ config :parse_tree, :validate => :string
16
+
17
+ # Target web page url.
18
+ config :url, :validate => :string
19
+
20
+ # Split each results to individual events (struct or pages)
21
+ config :split, :default => false
22
+
23
+ config :interval, :validate => :number, :default => 60
24
+
25
+ public
26
+ def register
27
+ @host = Socket.gethostname
28
+ @agent = Mechanize.new
29
+ @tree = Yasuri.json2tree(@parse_tree)
30
+ end # def register
31
+
32
+ def run(queue)
33
+ # we can abort the loop if stop? becomes true
34
+ while !stop?
35
+ # because the sleep interval can be big, when shutdown happens
36
+ # we want to be able to abort the sleep
37
+ # Stud.stoppable_sleep will frequently evaluate the given block
38
+ # and abort the sleep(@interval) if the return value is true
39
+ inner_run(queue)
40
+ Stud.stoppable_sleep(@interval) { stop? }
41
+ end # loop
42
+ end # def run
43
+
44
+ def stop
45
+ # nothing to do in this case so it is not necessary to define stop
46
+ # examples of common "stop" tasks:
47
+ # * close sockets (unblocking blocking reads/accepts)
48
+ # * cleanup temporary files
49
+ # * terminate spawned threads
50
+ end
51
+
52
+ def inner_run(queue)
53
+ parsed = scrape()
54
+ elements = if @split
55
+ parsed.flatten
56
+ else
57
+ [parsed]
58
+ end
59
+
60
+ elements.each do |e|
61
+ event = LogStash::Event.new("parsed" => e, "host" => @host, "url" => @url)
62
+ decorate(event)
63
+ queue << event
64
+ end
65
+ end
66
+
67
+ def scrape()
68
+ page = @agent.get(@url)
69
+ @tree.inject(@agent, page)
70
+ end
71
+ end # class LogStash::Inputs::Example
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-input-yasuri'
3
+ s.version = '0.0.1'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "Web scraping input plugin for logstash."
6
+ s.description = "Web scraping input plugin for logstash."
7
+ s.authors = ["tac0x2a"]
8
+ s.email = 'tac@tac42.net'
9
+ s.homepage = "https://github.com/tac0x2a/logstash-input-yasuri"
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" => "input" }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
22
+ s.add_runtime_dependency 'logstash-codec-plain'
23
+ s.add_runtime_dependency 'stud', '>= 0.0.22'
24
+ s.add_runtime_dependency 'yasuri', '>= 0.0.1'
25
+ s.add_development_dependency 'logstash-devutils', '>= 0.0.16'
26
+ s.add_development_dependency 'fuubar', '>= 2.2.0'
27
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/inputs/yasuri"
4
+
5
+ describe LogStash::Inputs::Yasuri do
6
+
7
+ let(:input) {
8
+ input = LogStash::Plugin.lookup("input", "yasuri").new(
9
+ "flatten" => true,
10
+ "url" => "https://news.ycombinator.com/",
11
+ "parse_tree" => %Q|
12
+ {
13
+ "node": "struct",
14
+ "name": "titles",
15
+ "path": "//td[@class='title'][not(@align)]",
16
+ "children": [
17
+ {
18
+ "node": "text",
19
+ "name": "title",
20
+ "path": "./a"
21
+ },
22
+ {
23
+ "node": "text",
24
+ "name": "url",
25
+ "path": "./a/@href"
26
+ }
27
+ ]
28
+ }
29
+ | # end of "parse_tree"
30
+ )
31
+ }
32
+
33
+ it "should register" do
34
+ # register will try to load jars and raise if it cannot find jars or if org.apache.log4j.spi.LoggingEvent class is not present
35
+ expect {input.register}.to_not raise_error
36
+ end
37
+
38
+ let(:queue) { [] }
39
+ it "enqueues some events" do
40
+ input.register
41
+ input.inner_run(queue)
42
+ expect(queue.size).not_to be_zero
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-yasuri
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - tac0x2a
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-06 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.0
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ name: logstash-core
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ name: logstash-codec-plain
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.0.22
53
+ name: stud
54
+ prerelease: false
55
+ type: :runtime
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.0.22
61
+ - !ruby/object:Gem::Dependency
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 0.0.1
67
+ name: yasuri
68
+ prerelease: false
69
+ type: :runtime
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.0.1
75
+ - !ruby/object:Gem::Dependency
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 0.0.16
81
+ name: logstash-devutils
82
+ prerelease: false
83
+ type: :development
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 0.0.16
89
+ - !ruby/object:Gem::Dependency
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.2.0
95
+ name: fuubar
96
+ prerelease: false
97
+ type: :development
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.2.0
103
+ description: Web scraping input plugin for logstash.
104
+ email: tac@tac42.net
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - CHANGELOG.md
110
+ - DEVELOPER.md
111
+ - Gemfile
112
+ - LICENSE
113
+ - NOTICE.TXT
114
+ - README.md
115
+ - lib/logstash/inputs/yasuri.rb
116
+ - logstash-input-yasuri.gemspec
117
+ - spec/inputs/yasuri_spec.rb
118
+ homepage: https://github.com/tac0x2a/logstash-input-yasuri
119
+ licenses:
120
+ - Apache License (2.0)
121
+ metadata:
122
+ logstash_plugin: 'true'
123
+ logstash_group: input
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.6.6
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Web scraping input plugin for logstash.
144
+ test_files:
145
+ - spec/inputs/yasuri_spec.rb