fluent-plugin-filter-geoip 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fluent-plugin-filter-geoip.gemspec +1 -1
- data/lib/fluent/plugin/filter_geoip.rb +18 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cde3b38a6cf1ea9399cb57f3ee6a9eb55605b076
|
4
|
+
data.tar.gz: ed00a25b45352a8cb794a1fff40652032b1a696e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61bc3096df8b34e6cb7dcf231585d6f05156661308a93a81ec9ff8bfbbf6507c48d95915c9a23f90ea7ea83365e5a9e844805dc06dc0cf71c7428257c732af97
|
7
|
+
data.tar.gz: a368fc420027c2a042abe628abab572d7fc9874e3befbc1bdbb09577cbb8baacd8892fcfde4266a6fa5e3e72960feceb9eda31d290f0121edcdf5b5897729934
|
@@ -262,8 +262,8 @@ module Fluent
|
|
262
262
|
|
263
263
|
def download_database(download_url, md5_url, database_path, md5_path)
|
264
264
|
# database directory
|
265
|
-
database_dir = File.
|
266
|
-
md5_dir = File.
|
265
|
+
database_dir = File.dirname database_path
|
266
|
+
md5_dir = File.dirname md5_path
|
267
267
|
|
268
268
|
# create database directory if directory does not exist.
|
269
269
|
FileUtils.mkdir_p(database_dir) unless File.exist?(database_dir)
|
@@ -273,11 +273,12 @@ module Fluent
|
|
273
273
|
File.open(md5_path, 'wb').close() unless File.exist?(md5_path)
|
274
274
|
|
275
275
|
# read saved md5
|
276
|
-
|
276
|
+
current_md5 = nil
|
277
277
|
begin
|
278
278
|
open(md5_path, 'rb') do |data|
|
279
|
-
|
279
|
+
current_md5 = data.read
|
280
280
|
end
|
281
|
+
log.info "Current MD5: %s" % current_md5
|
281
282
|
rescue => e
|
282
283
|
log.warn e.message
|
283
284
|
end
|
@@ -288,20 +289,23 @@ module Fluent
|
|
288
289
|
open(md5_url, 'rb') do |data|
|
289
290
|
fetched_md5 = data.read
|
290
291
|
end
|
292
|
+
log.info "Fetched MD5: %s" % fetched_md5
|
291
293
|
rescue => e
|
292
294
|
log.warn e.message
|
293
295
|
end
|
294
296
|
|
295
297
|
# check md5
|
296
|
-
unless
|
298
|
+
unless current_md5 == fetched_md5 then
|
297
299
|
# download new database
|
298
300
|
download_path = database_dir + '/' + File.basename(download_url)
|
299
301
|
begin
|
302
|
+
log.info "Download: %s" % download_url
|
300
303
|
open(download_path, 'wb') do |output|
|
301
304
|
open(download_url, 'rb') do |data|
|
302
305
|
output.write(data.read)
|
303
306
|
end
|
304
307
|
end
|
308
|
+
log.info "Download done: %s" % download_path
|
305
309
|
rescue => e
|
306
310
|
log.warn e.message
|
307
311
|
end
|
@@ -309,22 +313,31 @@ module Fluent
|
|
309
313
|
# unzip new database temporaly
|
310
314
|
tmp_database_path = database_dir + '/tmp_' + File.basename(database_path)
|
311
315
|
begin
|
316
|
+
log.info "Unzip: %s" % download_path
|
312
317
|
open(tmp_database_path, 'wb') do |output|
|
313
318
|
Zlib::GzipReader.open(download_path) do |gz|
|
314
319
|
output.write(gz.read)
|
315
320
|
end
|
316
321
|
end
|
322
|
+
log.info "Unzip done: %s" % tmp_database_path
|
317
323
|
rescue => e
|
318
324
|
puts e.message
|
319
325
|
end
|
320
326
|
|
321
327
|
# check mkd5
|
322
328
|
temp_md5 = Digest::MD5.hexdigest(File.open(tmp_database_path, 'rb').read)
|
329
|
+
log.info "New MD5: %s" % temp_md5
|
323
330
|
if fetched_md5 == temp_md5 then
|
331
|
+
log.info "Rename: %s to %s" % [tmp_database_path, database_path]
|
324
332
|
FileUtils.mv(tmp_database_path, database_path)
|
333
|
+
log.info "Rename done: %s to %s" % [tmp_database_path, database_path]
|
325
334
|
|
326
335
|
# record new md5
|
336
|
+
log.info "Save: %s" % md5_path
|
327
337
|
File.write(md5_path, fetched_md5)
|
338
|
+
log.info "Save done: %s" % md5_path
|
339
|
+
else
|
340
|
+
log.info "MD5 missmatch: Fetched MD5 (%s) != New MD5 (%s) ; " % [fetched_md5, temp_md5]
|
328
341
|
end
|
329
342
|
end
|
330
343
|
end
|