Skip to content
This repository was archived by the owner on Jan 17, 2022. It is now read-only.

Added summary from hits collection #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.graylog.plugins</groupId>
<artifactId>graylog-plugin-pagerduty</artifactId>
<version>1.3.1-SNAPSHOT</version>
<version>1.3.2-SNAPSHOT</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this unrelated change.

<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public URI getURL() {

@Override
public Version getVersion() {
return new Version(1, 3, 1, "SNAPSHOT");
return new Version(1, 3, 2, "SNAPSHOT");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this unrelated change.

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ private PagerDutyEvent buildPagerDutyEvent(final Stream stream, final AlertCondi
final String description = "[ " + stream.getTitle() + " ] " + checkResult.getResultDescription() + " - "
+ buildStreamLink(clientUrl, stream);

final List<Message> backlog_items = getAlarmBacklog(checkResult);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use camelCase for variable names, e. g. backlogItems and backlogSummary.

final String backlog_summary = getAlarmBacklogSummary(backlog_items);
return new PagerDutyEvent(
serviceKey, "trigger", description, incidentKey, clientName, buildStreamLink(clientUrl, stream),
ImmutableMap.<String, Object>of(
"stream_id", stream.getId(),
"stream_title", stream.getTitle(),
"backlog", checkResult.getTriggeredCondition().getBacklog(),
"search_hits", getAlarmBacklog(checkResult).size(),
"hits", backlog_summary,
"alert_description", alertDescription
),
ImmutableList.<Object>of(
Expand All @@ -173,6 +175,19 @@ private PagerDutyEvent buildPagerDutyEvent(final Stream stream, final AlertCondi
);
}

protected String getAlarmBacklogSummary(List<Message> messages) {
final StringBuilder sb = new StringBuilder();
for (Message message : messages) {
final String msg = message.getMessage();
if (msg.length() > 225) {
sb.append("Message: {").append(msg.substring(0, 255)).append("... } ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this use the same number in the condition (225) and inside the block (255)?

} else {
sb.append("Message: {").append(msg).append("} ");
}
}
return sb.toString();
}

protected List<Message> getAlarmBacklog(AlertCondition.CheckResult result) {
final AlertCondition alertCondition = result.getTriggeredCondition();
final List<MessageSummary> matchingMessages = result.getMatchingMessages();
Expand Down