Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log a direct link to the graylog message (github workaround) #60

Merged
merged 3 commits into from Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/org/graylog2/plugins/slack/SlackPluginBase.java
Expand Up @@ -77,4 +77,13 @@ protected static SlackMessage createSlackMessage(Configuration configuration, St
configuration.getBoolean(SlackConfiguration.CK_LINK_NAMES)
);
}

protected String buildMessageLink(String baseUrl, String index, String id) {
if (!baseUrl.endsWith("/")) {
baseUrl = baseUrl + "/";
}

return baseUrl + "messages/" + index + "/" + id;
}

}
Expand Up @@ -80,16 +80,24 @@ private String buildFullMessageBody(Stream stream, Message msg) {
String graylogUri = configuration.getString(SlackConfiguration.CK_GRAYLOG2_URL);
boolean notifyChannel = configuration.getBoolean(SlackConfiguration.CK_NOTIFY_CHANNEL);

String titleLink;
String streamLink;
if (!isNullOrEmpty(graylogUri)) {
titleLink = "<" + buildStreamLink(graylogUri, stream) + "|" + stream.getTitle() + ">";
streamLink = "<" + buildStreamLink(graylogUri, stream) + "|" + stream.getTitle() + ">";
} else {
titleLink = "_" + stream.getTitle() + "_";
streamLink = "_" + stream.getTitle() + "_";
}

String messageLink;
if (!isNullOrEmpty(graylogUri)) {
String index = "graylog_deflector"; // would use msg.getFieldAs(String.class, "_index"), but it returns null
messageLink = "<" + buildMessageLink(graylogUri, index, msg.getId()) + "|New message>";
} else {
messageLink = "New message";
}

String audience = notifyChannel ? "@channel " : "";
return String.format("%s*New message in Graylog stream %s*:\n> %s",
audience, titleLink, msg.getMessage());
return String.format("%s*%s in Graylog stream %s*:\n> %s",
audience, messageLink, streamLink, msg.getMessage());
}

private String buildShortMessageBody(Message msg) {
Expand Down