-
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.
Parse key=values even with whitespace around the equals sign. Prevent ArrayOutOfBounds exception.
- Loading branch information
Kay Roepke
committed
Oct 14, 2012
1 parent
80e7b3a
commit c70f626
Showing
1 changed file
with
6 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,15 +22,15 @@ | |
|
||
import com.yammer.metrics.Metrics; | ||
import com.yammer.metrics.core.TimerContext; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.regex.Pattern; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.log4j.Logger; | ||
import org.graylog2.logmessage.LogMessageImpl; | ||
import org.graylog2.plugin.GraylogServer; | ||
import org.graylog2.plugin.filters.MessageFilter; | ||
import org.graylog2.plugin.logmessage.LogMessage; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* @author Lennart Koopmann <[email protected]> | ||
*/ | ||
|
@@ -60,12 +60,13 @@ public void filter(LogMessage msg, GraylogServer server) { | |
int extracted = 0; | ||
if (msg.getShortMessage().contains("=")) { | ||
try { | ||
String[] parts = msg.getShortMessage().split(" "); | ||
String nmsg = msg.getShortMessage().replaceAll("\\s?=\\s?", "="); | ||
String[] parts = nmsg.split(" "); | ||
if (parts != null) { | ||
for (String part : parts) { | ||
if (part.contains("=") && StringUtils.countMatches(part, "=") == 1) { | ||
String[] kv = part.split("="); | ||
if (kv[0] != null && kv[1] != null && p.matcher(kv[0]).matches() && !msg.getAdditionalData().containsKey("_" + kv[0])) { | ||
if (kv.length == 2 && p.matcher(kv[0]).matches() && !msg.getAdditionalData().containsKey("_" + kv[0])) { | ||
msg.addAdditionalData(kv[0].trim(), kv[1].trim()); | ||
extracted++; | ||
} | ||
|