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

Receiving message details #9

Open
ghost opened this issue Dec 18, 2019 · 3 comments
Open

Receiving message details #9

ghost opened this issue Dec 18, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented Dec 18, 2019

When events are posted to pager duty they don't contain any message information. How do we enable this?

@ghost
Copy link
Author

ghost commented Dec 19, 2019

If anyone is interested here is the patch. This will help with message formatting.

@ghost
Copy link
Author

ghost commented Dec 19, 2019

`diff --git a/pom.xml b/pom.xml
index 4b2f30f..c9a4d5c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@

 <groupId>org.graylog.plugins</groupId>
 <artifactId>graylog-plugin-pagerduty</artifactId>
  • 1.3.1-SNAPSHOT
  • 1.3.2-SNAPSHOT
    jar

    ${project.artifactId}
    diff --git a/src/main/java/org/graylog2/alarmcallbacks/pagerduty/PagerDutyClient.java b/src/main/java/org/graylog2/alarmcallbacks/pagerduty/PagerDutyClient.java
    index bf2f4c2..68d596f 100644
    --- a/src/main/java/org/graylog2/alarmcallbacks/pagerduty/PagerDutyClient.java
    +++ b/src/main/java/org/graylog2/alarmcallbacks/pagerduty/PagerDutyClient.java
    @@ -19,20 +19,7 @@
    */
    package org.graylog2.alarmcallbacks.pagerduty;

-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import org.graylog2.plugin.Message;
-import org.graylog2.plugin.MessageSummary;
-import org.graylog2.plugin.alarms.AlertCondition;
-import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException;
-import org.graylog2.plugin.streams.Stream;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import static com.google.common.base.Strings.nullToEmpty;

import java.io.IOException;
import java.io.InputStream;
@@ -47,7 +34,21 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;

-import static com.google.common.base.Strings.nullToEmpty;
+import org.graylog2.plugin.Message;
+import org.graylog2.plugin.MessageSummary;
+import org.graylog2.plugin.alarms.AlertCondition;
+import org.graylog2.plugin.alarms.callbacks.AlarmCallbackException;
+import org.graylog2.plugin.streams.Stream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;

public class PagerDutyClient {
private static final Logger LOG = LoggerFactory.getLogger(PagerDutyClient.class);
@@ -145,28 +146,44 @@ public class PagerDutyClient {

 private PagerDutyEvent buildPagerDutyEvent(final Stream stream, final AlertCondition.CheckResult checkResult) {
     final String incidentKey;
  •    if (customIncidentKey) {
    
  •        incidentKey = nullToEmpty(incidentKeyPrefix) + stream.getId() + "/" + checkResult.getTriggeredCondition().getId();
    
  •    LOG.debug("Received alert condition {}", checkResult);
    
  •    AlertCondition triggeredCondition = checkResult.getTriggeredCondition();
    
  •    Map<String, Object> parameters = checkResult.getTriggeredCondition().getParameters();
    
  •   if (customIncidentKey) {
    
  •        incidentKey = nullToEmpty(incidentKeyPrefix) + stream.getId() + "/" + triggeredCondition.getId();
       } else {
           incidentKey = "";
       }
    
  •    final String alertDescription = checkResult.getTriggeredCondition().getDescription();
    
  •    final String description = "[ " + stream.getTitle() + " ] " + checkResult.getResultDescription() + " - "
    
  •                                + buildStreamLink(clientUrl, stream);
    
  •    List<MessageSummary> matchingMessages = checkResult.getMatchingMessages();
    
  •    StringBuilder stringBuilder = new StringBuilder();
    
  •    for (MessageSummary messageSummary : matchingMessages) {
    
  •   	String message = messageSummary.getMessage();
    
  •   	stringBuilder.append(message);
    
  •   	stringBuilder.append("\n");
    
  •   }
    
  •    String messageDetails = stringBuilder.toString();
    
  •    final String alertDescription = triggeredCondition.getDescription();
    
  •    String buildStreamLink = buildStreamLink(clientUrl, stream);
    
  •   final String description = "[ " + stream.getTitle() + " ] " + checkResult.getResultDescription();
    
  •    return new PagerDutyEvent(
    
  •            serviceKey, "trigger", description, incidentKey, clientName, buildStreamLink(clientUrl, stream),
    
  •            serviceKey,
    
  •            "trigger",
    
  •            description,
    
  •            incidentKey,
    
  •            clientName,
    
  •            buildStreamLink,
               ImmutableMap.<String, Object>of(
                       "stream_id", stream.getId(),
                       "stream_title", stream.getTitle(),
                       "backlog", checkResult.getTriggeredCondition().getBacklog(),
                       "search_hits", getAlarmBacklog(checkResult).size(),
    
  •                    "alert_description", alertDescription
    
  •                    "alert_description", messageDetails
               ),
               ImmutableList.<Object>of(
                       ImmutableMap.<String, Object>of(
                               "type", "link",
    
  •                            "href", buildStreamLink(clientUrl, stream)
    
  •                            "href", buildStreamLink
                       )
    
               )`
    

@sam-celer
Copy link

Could this be included in the plugin please?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant