-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved tokenizer filter to a converter
fixes #177
- Loading branch information
Lennart Koopmann
committed
Aug 25, 2013
1 parent
403c4b2
commit b2dc585
Showing
18 changed files
with
297 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 0 additions & 102 deletions
102
graylog2-server/src/main/java/org/graylog2/filters/TokenizerFilter.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
graylog2-server/src/main/java/org/graylog2/inputs/converters/TokenizerConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* Copyright 2013 Lennart Koopmann <lennart@torch.sh> | ||
* | ||
* This file is part of Graylog2. | ||
* | ||
* Graylog2 is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog2 is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog2. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
package org.graylog2.inputs.converters; | ||
|
||
import com.google.common.base.CharMatcher; | ||
import com.google.common.collect.Maps; | ||
import org.graylog2.plugin.inputs.Converter; | ||
|
||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* @author Lennart Koopmann <lennart@torch.sh> | ||
*/ | ||
public class TokenizerConverter extends Converter { | ||
|
||
private static final Pattern p = Pattern.compile("[a-zA-Z0-9_-]*"); | ||
private static final Pattern kvPattern = Pattern.compile("\\s?=\\s?"); | ||
private static final Pattern spacePattern = Pattern.compile(" "); | ||
private static final Pattern quotedValuePattern = Pattern.compile("([a-zA-Z0-9_-]+=\"[^\"]+\")"); | ||
private static final CharMatcher QUOTE_MATCHER = CharMatcher.is('"').precomputed(); | ||
private static final CharMatcher EQUAL_SIGN_MATCHER = CharMatcher.is('=').precomputed(); | ||
|
||
public TokenizerConverter(Map<String, Object> config) { | ||
super(Type.TOKENIZER, config); | ||
} | ||
|
||
@Override | ||
public Object convert(String value) { | ||
if (value == null || value.isEmpty()) { | ||
return value; | ||
} | ||
|
||
Map<String, String> fields = Maps.newHashMap(); | ||
|
||
if (value.contains("=")) { | ||
final String nmsg = kvPattern.matcher(value).replaceAll("="); | ||
if (nmsg.contains("=\"")) { | ||
Matcher m = quotedValuePattern.matcher(nmsg); | ||
while (m.find()) { | ||
String[] kv = m.group(1).split("="); | ||
if (kv.length == 2 && p.matcher(kv[0]).matches()) { | ||
fields.put(kv[0].trim(), QUOTE_MATCHER.removeFrom(kv[1]).trim()); | ||
} | ||
} | ||
} else { | ||
final String[] parts = spacePattern.split(nmsg); | ||
if (parts != null) { | ||
for (String part : parts) { | ||
if (part.contains("=") && EQUAL_SIGN_MATCHER.countIn(part) == 1) { | ||
String[] kv = part.split("="); | ||
if (kv.length == 2 && p.matcher(kv[0]).matches() && !fields.containsKey(kv[0])) { | ||
fields.put(kv[0].trim(), kv[1].trim()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return fields; | ||
} | ||
|
||
@Override | ||
public boolean buildsMultipleFields() { | ||
return true; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.