fluent-plugin-filter-list 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -3
- data/README.md +33 -7
- data/lib/fluent/plugin/filter_filter_list.rb +2 -1
- data/lib/fluent/plugin/out_filter_list.rb +2 -1
- data/lib/fluent/plugin/out_filter_list/version.rb +1 -1
- data/lib/matcher.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17bee9e79c216bfbdf746e8d7d089d229b2997bccf376d24c5e7311f1931f2b4
|
4
|
+
data.tar.gz: b00d3238b9a8d775f5f1dc2e7fd03beedde536bc6894d38f22091395d3dde1bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c578ea80823b2c26e70a37cf63b3df24832bef79013fcd7e1c28cbf937d220130581bd2a382a6ef06b5c9d1b96838a12d154b1263512920214041cfdfe467ee5
|
7
|
+
data.tar.gz: 513142ca73ebf949f94d3f22fea2deff6e5147ffea92d65687ce33c80c6217e9d70d47dc3ec53b47858a5edb725c1b43ba70334e0feece51971978ca9fe886f4
|
data/.rubocop.yml
CHANGED
@@ -17,7 +17,7 @@ Style/FrozenStringLiteralComment:
|
|
17
17
|
Style/MutableConstant:
|
18
18
|
Enabled: false
|
19
19
|
Metrics/AbcSize:
|
20
|
-
Max:
|
20
|
+
Max: 30
|
21
21
|
Metrics/BlockLength:
|
22
22
|
Exclude:
|
23
23
|
- 'Rakefile'
|
@@ -29,9 +29,9 @@ Metrics/BlockLength:
|
|
29
29
|
- 'config/routes/**/*.rb'
|
30
30
|
- '*.gemspec'
|
31
31
|
Metrics/CyclomaticComplexity:
|
32
|
-
Max:
|
32
|
+
Max: 15
|
33
33
|
Metrics/PerceivedComplexity:
|
34
|
-
Max:
|
34
|
+
Max: 15
|
35
35
|
Style/GlobalVars:
|
36
36
|
Exclude:
|
37
37
|
- 'test/test_helper.rb'
|
data/README.md
CHANGED
@@ -34,8 +34,9 @@ Use the `filter_list` filter. Configure fluentd as follows.
|
|
34
34
|
@type filter_list
|
35
35
|
|
36
36
|
filter AC
|
37
|
-
key_to_filter
|
37
|
+
key_to_filter x
|
38
38
|
patterns_file_path blacklist.txt
|
39
|
+
filter_empty true
|
39
40
|
</filter>
|
40
41
|
```
|
41
42
|
|
@@ -50,13 +51,28 @@ buzz
|
|
50
51
|
The following message is discarded since its `x` field contains the sequence of characters _bar_, contained in the list.
|
51
52
|
|
52
53
|
```json
|
53
|
-
{
|
54
|
+
{
|
55
|
+
"x": "halbart",
|
56
|
+
"y": 1
|
57
|
+
}
|
54
58
|
```
|
55
59
|
|
56
|
-
While the following message is passed through as the target field specified in the config is not _y_ but _x_
|
60
|
+
While the following message is passed through as the target field specified in the config is not _y_ but _x_.
|
57
61
|
|
58
62
|
```json
|
59
|
-
{
|
63
|
+
{
|
64
|
+
"x": 1,
|
65
|
+
"y": "halbart"
|
66
|
+
}
|
67
|
+
```
|
68
|
+
|
69
|
+
Additionally, the following message is also omitted since `filter_empty` is `true`. The value is determined to be empty when the trimed value is empty.
|
70
|
+
|
71
|
+
```json
|
72
|
+
{
|
73
|
+
"x": " ",
|
74
|
+
"y": "halbart"
|
75
|
+
}
|
60
76
|
```
|
61
77
|
|
62
78
|
#### IPMatcher
|
@@ -81,19 +97,28 @@ Given the `blacklist.txt` is as follows.
|
|
81
97
|
The following message is discarded since its `ip` field is the IP address in the list (exact IP).
|
82
98
|
|
83
99
|
```json
|
84
|
-
{
|
100
|
+
{
|
101
|
+
"ip": "255.255.0.0",
|
102
|
+
"y": 1
|
103
|
+
}
|
85
104
|
```
|
86
105
|
|
87
106
|
Also the following message is discarded since its `ip` field is the IP address in the list (CIDR-notated IP).
|
88
107
|
|
89
108
|
```json
|
90
|
-
{
|
109
|
+
{
|
110
|
+
"ip": "192.168.1.255",
|
111
|
+
"y": 1
|
112
|
+
}
|
91
113
|
```
|
92
114
|
|
93
115
|
While the following message is passed through.
|
94
116
|
|
95
117
|
```json
|
96
|
-
{
|
118
|
+
{
|
119
|
+
"ip": "192.168.2.0",
|
120
|
+
"y": 1
|
121
|
+
}
|
97
122
|
```
|
98
123
|
|
99
124
|
### Output plugin
|
@@ -106,6 +131,7 @@ The other use case is to filter messages likewise, but process the filtered mess
|
|
106
131
|
|
107
132
|
key_to_filter field_name_you_want_to_filter
|
108
133
|
patterns_file_path file_including_patterns_separated_by_new_line
|
134
|
+
filter_empty true
|
109
135
|
|
110
136
|
<retag>
|
111
137
|
add_prefix x # retag non-filtered messages whose tag will be "x.your_tag"
|
@@ -14,6 +14,7 @@ module Fluent
|
|
14
14
|
config_param :filter, :string, default: 'AC'
|
15
15
|
config_param :key_to_filter, :string, default: nil
|
16
16
|
config_param :patterns_file_path, :string, default: ''
|
17
|
+
config_param :filter_empty, :bool, default: false
|
17
18
|
|
18
19
|
def configure(conf)
|
19
20
|
super
|
@@ -23,7 +24,7 @@ module Fluent
|
|
23
24
|
|
24
25
|
def filter(_tag, _time, record)
|
25
26
|
target = record[@key_to_filter]
|
26
|
-
return nil if target && @matcher.matches?(target)
|
27
|
+
return nil if target && (@matcher.matches?(target) || (@filter_empty && target.strip.empty?))
|
27
28
|
record
|
28
29
|
end
|
29
30
|
end
|
@@ -16,6 +16,7 @@ module Fluent
|
|
16
16
|
config_param :filter, :string, default: 'AC'
|
17
17
|
config_param :key_to_filter, :string, default: nil
|
18
18
|
config_param :patterns_file_path, :string, default: ''
|
19
|
+
config_param :filter_empty, :bool, default: false
|
19
20
|
|
20
21
|
config_section :retag, required: true, multi: false do
|
21
22
|
config_param :tag, :string, default: nil
|
@@ -71,7 +72,7 @@ module Fluent
|
|
71
72
|
target = record[@key_to_filter]
|
72
73
|
log.debug "target: #{target}"
|
73
74
|
# Do filter
|
74
|
-
if target && @matcher.matches?(target)
|
75
|
+
if target && (@matcher.matches?(target) || (@filter_empty && target.strip.empty?))
|
75
76
|
if @retag_for_filtered
|
76
77
|
t = @retag_for_filtered.tag || ((tag && !tag.empty?) ? @prefix_for_filtered_tag + tag : @retag_for_filtered.add_prefix)
|
77
78
|
log.debug "re-emit with the tag: '#{t}', originally: '#{tag}'"
|
data/lib/matcher.rb
CHANGED
@@ -12,7 +12,7 @@ module Matchers
|
|
12
12
|
|
13
13
|
def matches?(text)
|
14
14
|
node = @trie.root
|
15
|
-
text.to_s.
|
15
|
+
text.to_s.chars.each do |char|
|
16
16
|
node = node.failure while node.children[char].nil? # Follow failure if it exists in case pattern doesn't match
|
17
17
|
node = node.children[char]
|
18
18
|
return true unless node.output.nil?
|
@@ -50,7 +50,7 @@ module Matchers
|
|
50
50
|
|
51
51
|
def insert(pattern = '')
|
52
52
|
current_node = @root
|
53
|
-
pattern.
|
53
|
+
pattern.chars.each_with_index do |char, i|
|
54
54
|
current_node = current_node.insert(char)
|
55
55
|
current_node.output = pattern if i == pattern.length - 1
|
56
56
|
end
|
@@ -83,7 +83,7 @@ module Matchers
|
|
83
83
|
def forward_match(pattern)
|
84
84
|
return false if @root.children.empty?
|
85
85
|
cur_node = @root
|
86
|
-
pattern.
|
86
|
+
pattern.chars.each do |char|
|
87
87
|
return true if cur_node.children.empty?
|
88
88
|
return false unless cur_node.children.key?(char)
|
89
89
|
cur_node = cur_node.children[char]
|