logstash-filter-weblookup 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c96b1c02dc9936abcbed2834158d6df2d37b65423b92e0ddc0fb676b77c4b00
4
- data.tar.gz: 49283b96b0ab8c0f00638c965897e01c0a6f29d8a413b7275bbe650c804849fb
3
+ metadata.gz: c5839cc6259028cb20d7eb1395f0b37f739c12508489bf34c241506bb9d5ac33
4
+ data.tar.gz: 9b65c6f9f316daf2974f5e982d79a87a2108c465502c4f3649db7f2ce1f11994
5
5
  SHA512:
6
- metadata.gz: fba0a7b28e64f24b4cc9733a161a7a368579edc0f0de2317992ee530811c196d11bef2f8fc2a328745f7c9b7cb531748d27f4632486171659f3fecfb0c0f5f26
7
- data.tar.gz: 50517ea043a5b254db9e74ffed413d2cdaf0f6b4c3bb3ee1ce3890288b69be7fc1bc9591b50fec9649f49b18d96b99fe6d3df73673194060bcba44f4ce51179f
6
+ metadata.gz: 96f53b391486a826b7a9b1c22c99c97a1f473b1a1284dcd7fa0300f75737b02279a5da8e08948a3c80aaf7343218987ebe19f6b8223972cce5074399c4fac2fc
7
+ data.tar.gz: 38387275e213910b857db6364deaffdf85f8fb2cfb2fc8315d6b918e3d905992da7171a6452cca6204c0023c27f3883c6864869c14dad916ae23f5971d233349
data/README.md CHANGED
@@ -1,86 +1,25 @@
1
1
  # Logstash Plugin
2
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.
3
+ This gem is a plugin for [Logstash](https://github.com/elastic/logstash). During filter it takes one or more fields and uses that as input to query additional information. The original purpose is to enrich IP addresses with matching subnet, netname and hostname, but it is generic so that any field can be looked up. The function is similar to the translate filter's dictionary lookup, which supports files and regex. The jdbc_streaming filter plugin is also very useful if the data resides in a database. This plugins features are web based lookups and redis caching, for fast lookups.
6
4
 
7
5
  ## Documentation
8
6
 
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
7
+ weblookup {
8
+ fields => ['[client][ip]']
9
+ destinations => ['net']
10
+ url => "http://localhost/ripe.php?ip=<item>"
11
+ use_redis => true
12
+ redis_path => "/var/run/redis/redis-server.sock"
13
+ normalize => true
14
+ newroot => "[records][properties]"
15
+ roottostrip => "[records]"
16
+ }
33
17
 
34
- - Update your dependencies
18
+ Where <item> will be replaced by the value of client.ip
35
19
 
36
- ```sh
37
- bundle install
38
- ```
20
+ The first three components are needed for the plugin, the others are optional. use_redis and redis_path are for caching the response, this speedsup the requists. It's also possible to hardcode values here, but I'm not using it myself yet. normalize, newroot and roottostrip probably would be better in a separte plugin, but for now weblookup can move the json objects inside the roottostrip into it's own root, by default elasticsearch uses _source as invisible root.
39
21
 
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.
22
+ ## Need Help?
83
23
 
84
- It is more important to the community that you are able to contribute.
24
+ Need help? Raise an issue on https://github.com/janmg/logstash-filter-weblookup
85
25
 
86
- For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -108,8 +108,12 @@ def filter(event)
108
108
  else
109
109
  fields.each_with_index do |field, index|
110
110
  # @logger.info(event.get("["+field+"]"))
111
- json = parse(event.get(field).to_s)
112
- event.set("["+destinations[index]+"]", json)
111
+ begin
112
+ json = parse(event.get(field).to_s)
113
+ event.set("["+destinations[index]+"]", json)
114
+ rescue Exception => e
115
+ @logger.error(" caught: #{e.message}")
116
+ end
113
117
  end
114
118
  end
115
119
  if @normalize
@@ -127,16 +131,18 @@ def parse(field)
127
131
  begin
128
132
  json = JSON.parse(x)
129
133
  rescue JSON::ParserError
130
- json = x
131
- end
134
+ json = JSON.parse("{\"ip\": \""+field+"\"}")
135
+ end
136
+ # @logger.info("json parse option for field #{field} / #{json}")
132
137
  end
133
138
 
134
139
  def find(item)
135
- res = nil
136
- # Is item in list? (list is an optional hash)
137
- unless list.nil?
138
- return list[item]
139
- end
140
+ res = "{}"
141
+ # Is item in list? (list is an optional array)
142
+ #unless list.nil?
143
+ # What if the list exists, but item is not on the list?
144
+ # return list[item]
145
+ #end
140
146
  # Is item in redis?
141
147
  unless @red.nil?
142
148
  res = @red.get(item)
@@ -150,7 +156,11 @@ def find(item)
150
156
  current_uri.query_values = @params.merge({@ip => item})
151
157
  #logger.info(@uri.to_s)
152
158
  @connpool.with do |conn|
153
- res = conn.request_get(current_uri).read_body
159
+ http_response = conn.request_get(current_uri)
160
+ res = http_response.read_body if http_response.is_a?(Net::HTTPSuccess)
161
+ if res.eql? "null"
162
+ res = "{}"
163
+ end
154
164
  #logger.info(res.to_s)
155
165
  unless @red.nil?
156
166
  @red.set(item, res)
@@ -193,4 +203,4 @@ def yml_loader(data)
193
203
  get_map.merge!(YAML.load_file(data))
194
204
  end
195
205
 
196
- end # class LogStash::Filters::Lookup
206
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-weblookup'
3
- s.version = '0.1.1'
3
+ s.version = '0.1.2'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = 'This logstash filter plugin takes one or more fields and enriches with a lookup value from a list, redis cache or webservice'
6
6
  s.description = <<-EOF
@@ -20,7 +20,7 @@ EOF
20
20
  s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
21
21
 
22
22
  # Gem dependencies
23
- s.add_runtime_dependency 'logstash-core-plugin-api', '~> 2.0'
23
+ s.add_runtime_dependency 'logstash-core-plugin-api', '~> 2.1'
24
24
  s.add_runtime_dependency 'connection_pool', '~> 2.2'
25
25
  #s.add_runtime_dependency 'addressable', '~> 2.3.8'
26
26
  s.add_development_dependency 'logstash-devutils', '~> 0'
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-weblookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Geertsma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-31 00:00:00.000000000 Z
11
+ date: 2019-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '2.0'
18
+ version: '2.1'
19
19
  name: logstash-core-plugin-api
20
20
  prerelease: false
21
21
  type: :runtime
@@ -23,7 +23,7 @@ dependencies:
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
@@ -96,8 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.7.9
99
+ rubygems_version: 3.0.6
101
100
  signing_key:
102
101
  specification_version: 4
103
102
  summary: This logstash filter plugin takes one or more fields and enriches with a