本文整理汇总了Java中org.graylog2.plugin.MessageSummary.getFields方法的典型用法代码示例。如果您正苦于以下问题:Java MessageSummary.getFields方法的具体用法?Java MessageSummary.getFields怎么用?Java MessageSummary.getFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.graylog2.plugin.MessageSummary
的用法示例。
在下文中一共展示了MessageSummary.getFields方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildJIRATitle
import org.graylog2.plugin.MessageSummary; //导入方法依赖的package包/类
/**
* Build the JIRA issue title
* @param stream
* @param result
* @return
*/
private String buildJIRATitle (final Stream stream, final AlertCondition.CheckResult result) {
StringBuilder sb = new StringBuilder();
try {
if (!result.getMatchingMessages().isEmpty()) {
// get fields from last message only
MessageSummary lastMessage = result.getMatchingMessages().get(0);
Map<String, Object> lastMessageFields = lastMessage.getFields();
String strTitle = "[Alert] Graylog alert for stream: " + stream.getTitle();
if (configuration.stringIsSet(CK_JIRA_TITLE_TEMPLATE) && !configuration.getString(CK_JIRA_TITLE_TEMPLATE).equals("null")) {
strTitle = configuration.getString(CK_JIRA_TITLE_TEMPLATE);
}
strTitle = strTitle.replace("[LAST_MESSAGE.source]", lastMessage.getSource());
for (Map.Entry<String, Object> arg : lastMessageFields.entrySet()) {
strTitle = strTitle.replace("[LAST_MESSAGE." + arg.getKey() + "]", arg.getValue().toString());
}
if (configuration.stringIsSet(CK_MESSAGE_REGEX) && !configuration.getString(CK_MESSAGE_REGEX).equals("null")) {
Matcher matcher = Pattern.compile(configuration.getString(CK_MESSAGE_REGEX)).matcher(lastMessage.getMessage());
if (matcher.find()) {
if (configuration.stringIsSet(CK_JIRA_TITLE_TEMPLATE) && !configuration.getString(CK_JIRA_TITLE_TEMPLATE).equals("null")) {
strTitle = strTitle.replace("[MESSAGE_REGEX]", matcher.group());
} else {
strTitle = "[Graylog] " + matcher.group();
}
}
}
// We regex template fields which have not been replaced
strTitle = strTitle.replaceAll("\\[LAST_MESSAGE\\.[^\\]]*\\]", "");
sb.append(strTitle);
}
} catch (Exception ex) {
; // can not do anything - we skip
LOG.error("Error in building title: " + ex.getMessage());
}
if (sb.length() == 0) {
sb.append("[Alert] Graylog alert for stream: ").append(stream.getTitle());
}
return sb.toString();
}
示例2: buildDescription
import org.graylog2.plugin.MessageSummary; //导入方法依赖的package包/类
/**
* Build the JIRA description
* @param stream
* @param result
* @return
*/
private String buildDescription (final Stream stream, final AlertCondition.CheckResult result) {
String strMessage = CONST_JIRA_MESSAGE_TEMPLATE;
if (configuration.stringIsSet(CK_JIRA_MESSAGE_TEMPLATE) &&
!configuration.getString(CK_JIRA_MESSAGE_TEMPLATE).equals("null") &&
!configuration.getString(CK_JIRA_MESSAGE_TEMPLATE).isEmpty()) {
strMessage = configuration.getString(CK_JIRA_MESSAGE_TEMPLATE);
}
strMessage = StringEscapeUtils.unescapeJava(strMessage);
// Get the last message
if (!result.getMatchingMessages().isEmpty()) {
// get fields from last message only
MessageSummary lastMessage = result.getMatchingMessages().get(0);
Map<String, Object> lastMessageFields = lastMessage.getFields();
strMessage = strMessage.replace("[LAST_MESSAGE.message]", lastMessage.getMessage());
strMessage = strMessage.replace("[LAST_MESSAGE.source]", lastMessage.getSource());
for (Map.Entry<String, Object> arg : lastMessageFields.entrySet()) {
strMessage = strMessage.replace("[LAST_MESSAGE." + arg.getKey() + "]", arg.getValue().toString());
}
// We regex template fields which have not been replaced
strMessage = strMessage.replaceAll("\\[LAST_MESSAGE\\.[^\\]]*\\]", "");
}
// replace placeholders
strMessage = strMessage.replace("[CALLBACK_DATE]", Tools.iso8601().toString());
strMessage = strMessage.replace("[STREAM_ID]", stream.getId());
strMessage = strMessage.replace("[STREAM_TITLE]", stream.getTitle());
strMessage = strMessage.replace("[STREAM_URL]", buildStreamURL(configuration.getString(CK_GRAYLOG_URL), stream));
strMessage = strMessage.replace("[STREAM_RULES]", buildStreamRules(stream));
strMessage = strMessage.replace("[STREAM_RESULT]", result.getResultDescription());
strMessage = strMessage.replace("[ALERT_TRIGGERED_AT]", result.getTriggeredAt().toString());
strMessage = strMessage.replace("[ALERT_TRIGGERED_CONDITION]", result.getTriggeredCondition().toString());
// create final string
StringBuilder sb = new StringBuilder();
sb.append("\n\n");
sb.append(strMessage).append("\n\n");
return sb.toString();
}