Skip to content

Commit

Permalink
Fix json service check status (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreYang authored Apr 2, 2020
1 parent 19d4b8c commit f39e75a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void doSendServiceCheck(
sc.put("check", serviceCheckName);
sc.put("host_name", "default");
sc.put("timestamp", System.currentTimeMillis() / 1000);
sc.put("status", this.statusToServiceCheckStatus(status));
sc.put("status", this.statusToServiceCheckStatusValue(status));
sc.put("message", message);
sc.put("tags", tags);

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/datadog/jmxfetch/reporter/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ protected ServiceCheck.Status statusToServiceCheckStatus(String status) {
return ServiceCheck.Status.UNKNOWN;
}

protected int statusToServiceCheckStatusValue(String status) {
ServiceCheck sc = ServiceCheck.builder()
.withStatus(this.statusToServiceCheckStatus(status))
.build();
return sc.getStatus();
}

protected abstract void sendMetricPoint(
String metricType, String metricName, double value, String[] tags);

Expand Down
19 changes: 19 additions & 0 deletions src/test/java/org/datadog/jmxfetch/reporter/ReporterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.datadog.jmxfetch.reporter;

import org.datadog.jmxfetch.Status;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ReporterTest {

@Test
public void statusToInteger() {
JsonReporter jsonReporter = new JsonReporter();

assertEquals(0, jsonReporter.statusToServiceCheckStatusValue(Status.STATUS_OK));
assertEquals(1, jsonReporter.statusToServiceCheckStatusValue(Status.STATUS_WARNING));
assertEquals(2, jsonReporter.statusToServiceCheckStatusValue(Status.STATUS_ERROR));
assertEquals(3, jsonReporter.statusToServiceCheckStatusValue("XX_UNKNOWN__XX"));
}
}

0 comments on commit f39e75a

Please sign in to comment.