fluent-plugin-replace 0.0.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d96e67513cea7cd337a16e6a9c998956556a02e
4
- data.tar.gz: 6c2580ba3c57c523d5520d45d8b29a13f5ccebba
3
+ metadata.gz: 075291576f6796e35260172cc9fc7c6ddefa7bef
4
+ data.tar.gz: ec0e00fff4f88c632da5cd148f069e8b5c2c85b1
5
5
  SHA512:
6
- metadata.gz: dd707c5f0b142f1b0915c1a26971e26c1a07632ab020a2992dff77b1b2d2437c8761d860b77d4473fe3b0255e087bc28f02eda771a51c2eded592c426d1a3f8a
7
- data.tar.gz: 272b88ae7cbb295751318eec080f33478fc83e352695e84cc035aac8c2a093b433474f53c3d4a812df3bc0d96dc14b91364e49f8a958a2c2a07a62144fe780dc
6
+ metadata.gz: ea8f93f547c4b53b0372c802db9e8526890f3c1a60ba8e236af99916cc4c9197c2bce0884ad0fbf7793fe0ba8d6c2a1c96d9b2cecc1c13a77cf634430484e95d
7
+ data.tar.gz: b7d47b0067f12fe99a9149b94fd0c1d67a9919d06c9a727d134d7e5ab9ca7d597bbd87bb460322f7c930cb3dab924c777d886d4e339ec8c1515082fe6b5480cf
data/README.md CHANGED
@@ -26,10 +26,23 @@ $ gem install fluent-plugin-replace
26
26
  # test_rules.yml
27
27
 
28
28
  ip:
29
- - 127.0.0.1: 'localhost'
29
+ 127.0.0.1: 'localhost'
30
+ /^192\.168.*$/: 'private network'
31
+
32
+ host:
33
+ /.*\.sakigakeweb\.com$/: 'Old Domain'
34
+
35
+ status:
36
+ 200: 'OK'
37
+
38
+ referer:
39
+ /http:\/\/kaihar4\.com/: ''
30
40
  ```
31
41
 
32
42
  ```
33
- $ echo '{"ip":"127.0.0.1","host":"foobar.com"}' | fluent-cat test
34
- {"ip":"localhost","host":"foobar.com"}
43
+ $ echo '{"ip":"127.0.0.1","host":"kaihar4.com","status":200,"referer":"http://kaihar4.com/about.html"}' | fluent-cat test
44
+ {"ip":"localhost","host":"kaihar4.com","status","OK","referer":"/about.html"}
45
+
46
+ $ echo '{"ip":"192.168.1.2","host":"foo.sakigakeweb.com","status":404,"referer":"https://www.google.co.jp/"}' | fluent-cat test
47
+ {"ip":"private network","host":"Old Domain","status":404,"referer":"https://www.google.co.jp/"}
35
48
  ```
@@ -18,9 +18,16 @@ class Fluent::ReplaceOutput < Fluent::Output
18
18
 
19
19
  es.each do |time, record|
20
20
  begin
21
- @rules.each do |key, array|
22
- array.each do |rule|
23
- record[key] = rule[record[key]] if rule.keys.include?(record[key])
21
+ @rules.each do |key, rule|
22
+ target = record[key].to_s
23
+
24
+ rule.each do |from, to|
25
+ if match_data = from.to_s.match(/\/(?<pattern>.+)\//)
26
+ pattern = Regexp.new(match_data[:pattern])
27
+ record[key] = target.gsub(pattern, to) if target.match(pattern)
28
+ else
29
+ record[key] = to if from.to_s == target
30
+ end
24
31
  end
25
32
  end
26
33
  rescue
@@ -1,7 +1,7 @@
1
1
  module Fluent
2
2
  module Plugin
3
3
  module Replace
4
- VERSION = '0.0.1'
4
+ VERSION = '0.1.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-replace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaihar4
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-07 00:00:00.000000000 Z
11
+ date: 2015-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler