本文整理汇总了Java中oi.thekraken.grok.api.Match.toMap方法的典型用法代码示例。如果您正苦于以下问题:Java Match.toMap方法的具体用法?Java Match.toMap怎么用?Java Match.toMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oi.thekraken.grok.api.Match
的用法示例。
在下文中一共展示了Match.toMap方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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());
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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();
}
示例10: 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();
}
示例11: getMap
import oi.thekraken.grok.api.Match; //导入方法依赖的package包/类
private Map<String, Object> getMap(String pattern, String text)
throws GrokException {
Grok g = grokMap.get(pattern);
if (g != null) {
Match gm = g.match(text);
gm.captures();
return gm.toMap();
} else {
return new HashMap<String, Object>();
}
}
示例12: afterAllLinesRead
import oi.thekraken.grok.api.Match; //导入方法依赖的package包/类
@Override
public void afterAllLinesRead(Map<String, Object> mutable) {
mutable.remove("SECOND");
mutable.remove("MONTHNUM");
mutable.remove("YEAR");
mutable.remove("MONTHDAY");
String pat = grok.getOriginalGrokPattern();
mutable.remove(pat.substring(2, pat.length() - 1));
// try to break out the mdc context if available
String mdc = (String)mutable.get("mdc_s");
if (mdc != null)
unpackMdcInfo(mdc, mutable);
// if this message looks like a request message (such as a query), try to parse out the additional fields
String category = (String)mutable.get("category_s");
String message = (String)mutable.get(logMessageFieldName);
if (("o.a.s.c.S.Request".equals(category) || "org.apache.solr.core.SolrCore".equals(category)) && message != null) {
// see if this request line matches the Solr request format to parse out additional fields like query params
String requestPart = message.replaceAll("\\s+"," ").trim();
Match requestMatch = requestGrok.match(requestPart);
requestMatch.captures();
if (!requestMatch.isNull()) {
Map<String,Object> requestMap = requestMatch.toMap();
requestMap.remove("logmessage");
requestMap.remove("BASE10NUM");
String rpat = requestGrok.getOriginalGrokPattern();
requestMap.remove(rpat.substring(2,rpat.length()-1));
mutable.putAll(requestMap);
if (parseParams) {
String params_s = (String)requestMap.get("params_s");
if (params_s != null) {
String[] pairs = params_s.split("&");
for (String nvp : pairs) {
int eqAt = nvp.indexOf("=");
if (eqAt != -1) {
String key = nvp.substring(0,eqAt);
String value = nvp.substring(eqAt+1);
if (!"_".equals(key)) {
if (!key.endsWith("_s")) {
key += "_s";
}
mutable.put(key, value);
}
}
}
}
}
}
}
}
示例13: apply
import oi.thekraken.grok.api.Match; //导入方法依赖的package包/类
private Map<String, Object> apply(final Grok grok, final String line) {
final Match gm = grok.match(line);
gm.captures();
return gm.toMap();
}