本文整理汇总了Java中oi.thekraken.grok.api.Match类的典型用法代码示例。如果您正苦于以下问题:Java Match类的具体用法?Java Match怎么用?Java Match使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Match类属于oi.thekraken.grok.api包,在下文中一共展示了Match类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parserGrok
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
/**
* 正则解析
* @param event
* @param value
*/
public void parserGrok(Map<String,Object> event,String value){
try{
Map<String,String> patterns11 =grok.getPatterns();
Match match =grok.match(value);
match.captures();
Map<String,Object> map =match.toMap();
if(map!=null&&map.size()>0){
Set<Map.Entry<String,Object>> sets =map.entrySet();
for(Map.Entry<String,Object> set:sets){
String key = set.getKey();
if(!patterns11.containsKey(key)){
event.put(key, set.getValue());
}
}
}
}catch(Exception e){
logger.error("parserGrok_error", e);
}
}
示例2: processLine
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
void processLine(String line) {
//executer.field("raw", line);
//System.out.println(line);
Match gm = grok.match(line);
gm.captures();
Map<String, Object> m = gm.toMap();
Document document = new Document();
for (Map.Entry<String, Object> entry : m.entrySet()) {
Object value = entry.getValue();
document.addField(entry.getKey(),String.valueOf(value));
}
if (!m.isEmpty()) {
document.addField("filename", currentFileName);
if (keepRaw) {
document.addField("raw", line);
}
executer.document(document);
}
}
示例3: processLine
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
void processLine(String line) {
//executer.field("raw", line);
System.out.println(line);
Match gm = grok.match(line);
gm.captures();
Map<String, Object> m = gm.toMap();
Document document = new Document();
for (Map.Entry<String, Object> entry : m.entrySet()) {
Object value = entry.getValue();
document.addField(entry.getKey(),String.valueOf(value));
}
if (!m.isEmpty()) {
document.addField("filename", currentFileName);
if (keepRaw) {
document.addField("raw", line);
}
executer.document(document);
}
}
示例4: processLine
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
void processLine(String line) {
//executer.field("raw", line);
//System.out.println(line);
Match gm = grok.match(line);
gm.captures();
Map<String, Object> m = gm.toMap();
Document document = new Document();
for (Map.Entry<String, Object> entry : m.entrySet()) {
Object value = entry.getValue();
document.addField(entry.getKey(),String.valueOf(value));
}
/*
if (!m.isEmpty()) {
document.addField("filename", currentFileName);
if (keepRaw) {
document.addField("raw", line);
}
}
executer.document(document);
*/
}
示例5: test1
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
@Test
public void test1() throws GrokException {
// Get an instance of grok
Grok grok = Grok.EMPTY;
// add a pattern to grok
grok.addPattern("foo", "\\w+");
// compile and add semantic
grok.compile("%{foo:bar}");
// Match with some log
Match m = grok.match("hello");
m.captures();
// Print
System.out.println(m.toMap());
// Then the output should be
// {bar=hello}
}
示例6: evaluate
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
@Override
public GrokResult evaluate(FunctionArgs args, EvaluationContext context) {
final String value = valueParam.required(args, context);
final String pattern = patternParam.required(args, context);
final boolean onlyNamedCaptures = namedOnly.optional(args, context).orElse(false);
if (value == null || pattern == null) {
return null;
}
final Grok grok = grokPatternRegistry.cachedGrokForPattern(pattern, onlyNamedCaptures);
final Match match = grok.match(value);
match.captures();
return new GrokResult(match.toMap());
}
示例7: testGrok
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
public void testGrok() throws IOException, GrokException {
List<String> logs = Files.readAllLines(Paths.get("./testset/apache.log"));
IGrokPatternLoader iGrokPatternLoader = new FileSystemGrokPatternLoader();
Grok grok = iGrokPatternLoader.loadGrokPattern();
logs.forEach(e -> {
try {
grok.compile("%{COMMONAPACHELOG}");
Match match = grok.match(e);
match.captures();
System.out.println(match.toJson());
} catch (GrokException e1) {
e1.printStackTrace();
}
});
}
示例8: paralleGrok
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
private void paralleGrok(int num, String pattern, Timer instanceTimmer, Timer grokTimer) throws IOException {
Timer.Context instanceContext = instanceTimmer.time();
String logs = Files.readAllLines(Paths.get("./testset/apache.log")).get(0);
ArrayList<Object> list = new ArrayList<Object>(
Collections.nCopies(num, new Object()));
instanceContext.stop();
list.parallelStream().forEach(e -> {
try {
Timer.Context gromContext = grokTimer.time();
IGrokPatternLoader iGrokPatternLoader = new FileSystemGrokPatternLoader();
Grok grok = iGrokPatternLoader.loadGrokPattern();
grok.compile(pattern);
Match match = grok.match(logs);
match.captures();
match.toMap();
gromContext.stop();
} catch (GrokException e1) {
e1.printStackTrace();
}
});
}
示例9: parseLine
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
public Map<String, Object> parseLine(String fileName, int lineNum, String line) throws Exception {
if (line == null || line.isEmpty())
return null;
Match gm = grok.match(line);
gm.captures();
if (gm.isNull())
return null;
Map<String,Object> grokMap = gm.toMap();
// add the ISO-8601 timestamp field if was requested in the config
if (timestampFieldName != null) {
Date timestamp = getLogDate(grokMap);
if (timestamp != null) {
grokMap.put(timestampFieldName, iso8601.get().format(timestamp));
}
}
return grokMap;
}
示例10: guessColumns
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
public List<Map<String, Object>> guessColumns(List<String> sampleLines, String pattern) throws GrokException {
Grok grok = new Grok();
for (String file : patternFiles) {
grok.addPatternFromFile(file);
}
grok.compile(pattern);
List<Map<String, Object>> records = sampleLines.stream().map(line -> {
Match m = grok.match(line);
m.captures();
return m.toMap();
}).collect(Collectors.toList());
return guessTypesFromRecords(records);
}
示例11: validateGrokStatement
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
@Override
public GrokValidation validateGrokStatement(GrokValidation grokValidation) throws RestException {
Map<String, Object> results;
try {
if (grokValidation.getPatternLabel() == null) {
throw new RestException("Pattern label is required");
}
if (Strings.isEmpty(grokValidation.getStatement())) {
throw new RestException("Grok statement is required");
}
Grok grok = new Grok();
grok.addPatternFromReader(new InputStreamReader(getClass().getResourceAsStream("/patterns/common")));
grok.addPatternFromReader(new StringReader(grokValidation.getStatement()));
String grokPattern = "%{" + grokValidation.getPatternLabel() + "}";
grok.compile(grokPattern);
Match gm = grok.match(grokValidation.getSampleData());
gm.captures();
results = gm.toMap();
results.remove(grokValidation.getPatternLabel());
} catch (Exception e) {
throw new RestException(e);
}
grokValidation.setResults(results);
return grokValidation;
}
示例12: parseLine
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
public Map<String, Object> parseLine(String fileName, int lineNum, String line) throws Exception {
if (line == null || line.isEmpty())
return null;
Match gm = grok.match(line);
gm.captures();
if (gm.isNull()){
if (unmatchedLineName != null && unmatchedLineName.isEmpty() == false){
return Collections.<String, Object>singletonMap(unmatchedLineName, line);
} else {
return null;
}
}
Map<String,Object> grokMap = gm.toMap();
// add the ISO-8601 timestamp field if was requested in the config
if (timestampFieldName != null) {
Date timestamp = getLogDate(grokMap);
if (timestamp != null) {
grokMap.put(timestampFieldName, iso8601.get().format(timestamp));
}
}
return grokMap;
}
示例13: parse
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
public Map<String, Object> parse(final String input) {
final Match m = instance.match(input);
if (m == Match.EMPTY) {
return ImmutableMap.of();
}
m.captures();
return m.toMap();
}
示例14: getCurrentRecord
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
public Map<String, Object> getCurrentRecord() {
Match gm = grok.match(currentLine);
gm.captures();
if (gm.isNull()) {
throw new GrokRecordValidateException("Couldn't parse line");
}
return gm.toMap();
}
示例15: testDate
import oi.thekraken.grok.api.Match; //导入依赖的package包/类
@Test
public void testDate() throws Exception {
Grok grok = Grok.EMPTY;
grok.addPattern("WORD", "\\b\\w+\\b");
grok.addPattern("GREEDYDATA", ".*");
grok.addPattern("YEAR", "(?>\\d\\d){1,2}");
grok.addPattern("MONTHNUM", "(?:0?[1-9]|1[0-2])");
grok.addPattern("MONTHDAY", "(?:(?:0[1-9])|(?:[12][0-9])|(?:3[01])|[1-9])");
grok.addPattern("HOUR", "(?:2[0123]|[01]?[0-9])");
grok.addPattern("MINUTE", "(?:[0-5][0-9])");
grok.addPattern("SECOND", "(?:(?:[0-5]?[0-9]|60)(?:[:.,][0-9]+)?)");
grok.addPattern("ISO8601_TIMEZONE", "(?:Z|[+-]%{HOUR}(?::?%{MINUTE}))");
grok.addPattern("MY_HOUR", "(2[0123]|[01]?[0-9])");
grok.addPattern("MY_MINUTE", "([0-5][0-9])");
grok.addPattern("MY_SECOND", "((?:[0-5]?[0-9]|60)(?:[:.,][0-9]+)?)");
grok.addPattern("startDate", "%{YEAR}-%{MONTHNUM}-%{MONTHDAY}[T ]%{MY_HOUR}_%{MY_MINUTE}_%{MY_SECOND}?%{ISO8601_TIMEZONE}?");
// compile and add semantic
grok.compile("%{WORD:employeeId}/%{GREEDYDATA:empName}/%{startDate}");
String inputData = "E1234/Aparna/Chaudhary/2014-1-15T13_02_49+01:00";
Match match = grok.match(inputData);
match.captures();
// extract parsed data
HashMap<String, String> resultData = new ObjectMapper().readValue(match.toJson(), HashMap.class);
assertEquals("invalid employee id", "E1234", resultData.get("employeeId"));
assertEquals("invalid name", "Aparna/Chaudhary", resultData.get("empName"));
assertEquals("invalid date", "2014-1-15T13_02_49+01:00", resultData.get("startDate"));
}