logstash-filter-phpipam 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/logstash/filters/phpipam.rb +46 -5
- data/logstash-filter-phpipam.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86ccd5f712ea9d516d35656b23461458aef1dbcad3ccb2abb1b9317608b5666a
|
4
|
+
data.tar.gz: 0df24f83330d1d6805bcfeac7e3a74b99ca40c40fd4302658bd12a73dcb3a31e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e926b71dbc4607835193539b8ee1c2ca7ec9f3b0065d6f36a88a3b2475f0898074f8c8b82d875604ee6a76a247aef562acdfe9c3a147733ce9fcdf96b99fa2d
|
7
|
+
data.tar.gz: a7a04639bfd827461d0522eb33b86d8931bc1d0bc992d0b420771251c59b894f5b09c68ff450c146a0ab9f533b03a3654c284010a63d290c72c4e412c3afcad4
|
@@ -23,7 +23,13 @@ class LogStash::Filters::Phpipam < LogStash::Filters::Base
|
|
23
23
|
config :password, validate: :string, default: ''
|
24
24
|
|
25
25
|
# Whether to use authentication or not
|
26
|
-
config :auth, validate: :boolean,
|
26
|
+
config :auth, validate: :boolean, default: true
|
27
|
+
|
28
|
+
# Whether to use caching or not
|
29
|
+
config :cache, validate: :boolean, default: true
|
30
|
+
|
31
|
+
# Which file to use as cache storage. Should be placed on a tmpfs volume for maximum performance
|
32
|
+
config :cache_path, validate: :string, default: '/tmp/logstash-filter-phpipam.json'
|
27
33
|
|
28
34
|
# IP-address field to look up
|
29
35
|
config :source, validate: :string, required: true
|
@@ -46,8 +52,9 @@ class LogStash::Filters::Phpipam < LogStash::Filters::Base
|
|
46
52
|
|
47
53
|
return unless valid_ip?(ip, event)
|
48
54
|
|
49
|
-
# Get data from phpIPAM
|
50
|
-
event_data =
|
55
|
+
# Get data from cache or phpIPAM if not in cache
|
56
|
+
event_data = search_cache(ip)
|
57
|
+
event_data = phpipam_data(ip) if event_data.is_a?(FalseClass)
|
51
58
|
|
52
59
|
return if !event_data['error'].nil? && event_data['error']
|
53
60
|
|
@@ -63,7 +70,7 @@ class LogStash::Filters::Phpipam < LogStash::Filters::Base
|
|
63
70
|
# @param target: the target to normalize
|
64
71
|
# @return [string]
|
65
72
|
def normalize_target(target)
|
66
|
-
target = "[#{target}]" if target
|
73
|
+
target = "[#{target}]" if target !~ %r{^\[[^\[\]]+\]$}
|
67
74
|
target
|
68
75
|
end
|
69
76
|
|
@@ -87,7 +94,6 @@ class LogStash::Filters::Phpipam < LogStash::Filters::Base
|
|
87
94
|
# Sends a GET method REST request.
|
88
95
|
# @param method: which HTTP method to use (POST, GET)
|
89
96
|
# @param url_path: path to connect to
|
90
|
-
# @param basic_auth: whether to use basic_auth or not
|
91
97
|
# @return [hash]
|
92
98
|
def send_rest_request(method, url_path)
|
93
99
|
@logger.debug? && @logger.debug('Sending request', host: @host, path: url_path)
|
@@ -190,7 +196,42 @@ class LogStash::Filters::Phpipam < LogStash::Filters::Base
|
|
190
196
|
base['vlan']['description'] = vlan_data['description'] unless nil_or_empty?(vlan_data['description'])
|
191
197
|
end
|
192
198
|
|
199
|
+
# Cache it for future needs
|
200
|
+
cache_data(base)
|
201
|
+
|
193
202
|
# all your base are belong to us
|
194
203
|
base
|
195
204
|
end
|
205
|
+
|
206
|
+
# Caches data (if possible)
|
207
|
+
# @param data: the data to cache
|
208
|
+
# @return [void]
|
209
|
+
def cache_data(data)
|
210
|
+
data = data.to_json
|
211
|
+
|
212
|
+
File.open(@cache_path, 'a') do |file|
|
213
|
+
file.write(data + "\n")
|
214
|
+
@logger.debug? && @logger.debug('Cached data', data: data)
|
215
|
+
rescue StandardError
|
216
|
+
@logger.debug? && @logger.debug('Cache file is not writable, skipping caching of data', data: data, cache_file: @cache_path)
|
217
|
+
break
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
# Seaches the cache file for the IP.
|
222
|
+
# Returns a hash if the IP was found, else false
|
223
|
+
# @param ip: The IP-address to search for
|
224
|
+
# @return [hash/bool]
|
225
|
+
def search_cache(ip)
|
226
|
+
@logger.debug? && @logger.debug('Searching cache...', ip: ip)
|
227
|
+
|
228
|
+
return false unless File.exist?(@cache_path)
|
229
|
+
|
230
|
+
File.foreach(@cache_path) do |line|
|
231
|
+
line = JSON.parse(line)
|
232
|
+
return line if line['ip']['address'] == ip
|
233
|
+
end
|
234
|
+
|
235
|
+
false
|
236
|
+
end
|
196
237
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'logstash-filter-phpipam'
|
5
|
-
s.version = '0.
|
5
|
+
s.version = '0.7.0'
|
6
6
|
s.licenses = ['Apache-2.0']
|
7
7
|
s.summary = 'A Logstash filter that returns results from phpIPAM'
|
8
8
|
s.description = 'A Logstash filter that looks up an IP-address, and returns results from phpIPAM'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-phpipam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- magnuslarsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-core-plugin-api
|