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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 592c7a6c492a234c331d225cf58de2d35c669a03
4
- data.tar.gz: b59b98a1889229052058739831f17ce4516df099
3
+ metadata.gz: cde3b38a6cf1ea9399cb57f3ee6a9eb55605b076
4
+ data.tar.gz: ed00a25b45352a8cb794a1fff40652032b1a696e
5
5
  SHA512:
6
- metadata.gz: d723fa0a431a2eb320b59d5012e72153ab6e59786422411c965dbfc7e43a5f566663b437eaf660caa9d30f5ad5798888aa545c04538a7d4054fbf96d0c616292
7
- data.tar.gz: 72919a44209008f6fb1d5ca9bf7bf58fadb5f1ce5827dd87f73a89082f318096bde0da9b0409748d9ba42f9167e4cdc271f257b78ad83a1a72d9dc71eb697cf3
6
+ metadata.gz: 61bc3096df8b34e6cb7dcf231585d6f05156661308a93a81ec9ff8bfbbf6507c48d95915c9a23f90ea7ea83365e5a9e844805dc06dc0cf71c7428257c732af97
7
+ data.tar.gz: a368fc420027c2a042abe628abab572d7fc9874e3befbc1bdbb09577cbb8baacd8892fcfde4266a6fa5e3e72960feceb9eda31d290f0121edcdf5b5897729934
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-filter-geoip"
7
- spec.version = "0.2.3"
7
+ spec.version = "0.2.4"
8
8
  spec.authors = ["Minoru Osuka"]
9
9
  spec.email = ["minoru.osuka@gmail.com"]
10
10
 
@@ -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.expand_path(File.dirname(database_path))
266
- md5_dir = File.expand_path(File.dirname(md5_path))
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
- saved_md5 = nil
276
+ current_md5 = nil
277
277
  begin
278
278
  open(md5_path, 'rb') do |data|
279
- saved_md5 = data.read
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 saved_md5 == fetched_md5 then
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-filter-geoip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minoru Osuka