Skip to content

Commit

Permalink
Issue #427: Add StatusInformation to the connector Monitor
Browse files Browse the repository at this point in the history
* Update validateConnectorDetectionCriteria to put StatusInformation in the legacyTextParameters monitor attribute map of the connector monitor
* Add unit tests assertions in DiscoveryStrategyTest, SimpleStrategyTest and CollectStrategyTest
  • Loading branch information
MedMaalej committed Sep 27, 2024
1 parent 43c6b7c commit 8d53a59
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -420,12 +422,46 @@ protected boolean validateConnectorDetectionCriteria(final Connector currentConn
KnownMonitorType.CONNECTOR.getKey(),
String.format(CONNECTOR_ID_FORMAT, KnownMonitorType.CONNECTOR.getKey(), connectorId)
);

collectConnectorStatus(connectorTestResult.isSuccess(), connectorId, monitor);

final String statusInformation = buildStatusInformation(hostname, connectorTestResult);
final Map<String, String> legacyTextParameters = monitor.getLegacyTextParameters();
legacyTextParameters.put("StatusInformation", statusInformation);
return connectorTestResult.isSuccess();
}

/**
* Builds the status information for the connector
* @param hostname Hostname of the resource being monitored
* @param testResult Test result of the connector
* @return String representing the status information
*/
protected String buildStatusInformation(final String hostname, final ConnectorTestResult testResult) {
final StringBuilder value = new StringBuilder();

final String builtTestResult = testResult
.getCriterionTestResults()
.stream()
.map(criterionResult -> {
final String result = criterionResult.getResult();
final String message = criterionResult.getMessage();
return String.format(
"Received Result: %s. %s",
result != null ? result : "N/A",
message != null ? message : "N/A"
);
})
.collect(Collectors.joining("\n"));
value
.append(builtTestResult)
.append("\nConclusion: ")
.append("Test on ")
.append(hostname)
.append(" ")
.append(testResult.isSuccess() ? "SUCCEEDED" : "FAILED");

return value.toString();
}

/**
* Collects the connector status and sets the metric
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,12 @@ void testRun() throws Exception {
assertEquals(HEALTHY, diskController.getLegacyTextParameters().get(STATUS_INFORMATION));
assertEquals(1.0, enclosure.getMetric("hw.status{hw.type=\"enclosure\"}", NumberMetric.class).getValue());
assertEquals(HEALTHY, enclosure.getLegacyTextParameters().get(STATUS_INFORMATION));

// Check that StatusInformation is collected on the connector monitor
assertEquals("Received Result: 1.3.6.1.4.1.795.10.1.1.3.1.1.0\tASN_OCTET_STR\tTest. SnmpGetNextCriterion test succeeded:\n" +
"SnmpGetNextCriterion(super=SnmpCriterion(super=Criterion(type=snmpGetNext, forceSerialization=false), oid=1.3.6.1.4.1.795.10.1.1.3.1.1, expectedResult=null))\n" +
"\n" +
"Result: 1.3.6.1.4.1.795.10.1.1.3.1.1.0\tASN_OCTET_STR\tTest\n" +
"Conclusion: Test on host.name SUCCEEDED", connectorMonitor.getLegacyTextParameters().get(STATUS_INFORMATION));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.sentrysoftware.metricshub.engine.common.helpers.MetricsHubConstants.IS_ENDPOINT;
import static org.sentrysoftware.metricshub.engine.constants.Constants.HOST_ID;
import static org.sentrysoftware.metricshub.engine.constants.Constants.HOST_NAME;
import static org.sentrysoftware.metricshub.engine.constants.Constants.STATUS_INFORMATION;
import static org.sentrysoftware.metricshub.engine.strategy.AbstractStrategy.CONNECTOR_ID_FORMAT;

import java.nio.file.Path;
Expand Down Expand Up @@ -208,5 +209,12 @@ void testRun() throws Exception {
PHYSICAL_DISK.getKey()
);
assertEquals(expectedOrder, discoveredMonitors.keySet());

// Check that StatusInformation is collected on the connector monitor
assertEquals("Received Result: 1.3.6.1.4.1.795.10.1.1.3.1.1.0\tASN_OCTET_STR\tTest. SnmpGetNextCriterion test succeeded:\n" +
"SnmpGetNextCriterion(super=SnmpCriterion(super=Criterion(type=snmpGetNext, forceSerialization=false), oid=1.3.6.1.4.1.795.10.1.1.3.1.1, expectedResult=null))\n" +
"\n" +
"Result: 1.3.6.1.4.1.795.10.1.1.3.1.1.0\tASN_OCTET_STR\tTest\n" +
"Conclusion: Test on host.name SUCCEEDED", connectorMonitor.getLegacyTextParameters().get(STATUS_INFORMATION));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.sentrysoftware.metricshub.engine.common.helpers.KnownMonitorType.ENCLOSURE;
import static org.sentrysoftware.metricshub.engine.common.helpers.KnownMonitorType.HOST;
import static org.sentrysoftware.metricshub.engine.common.helpers.MetricsHubConstants.IS_ENDPOINT;
import static org.sentrysoftware.metricshub.engine.constants.Constants.STATUS_INFORMATION;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -176,5 +177,12 @@ void testRun() throws Exception {
1.0,
diskController.getMetric("hw.status{hw.type=\"disk_controller\"}", NumberMetric.class).getValue()
);

// Check that StatusInformation is collected on the connector monitor
assertEquals("Received Result: 1.3.6.1.4.1.795.10.1.1.3.1.1.0\tASN_OCTET_STR\tTest. SnmpGetNextCriterion test succeeded:\n" +
"SnmpGetNextCriterion(super=SnmpCriterion(super=Criterion(type=snmpGetNext, forceSerialization=false), oid=1.3.6.1.4.1.795.10.1.1.3.1.1, expectedResult=null))\n" +
"\n" +
"Result: 1.3.6.1.4.1.795.10.1.1.3.1.1.0\tASN_OCTET_STR\tTest\n" +
"Conclusion: Test on ec-02 SUCCEEDED", connectorMonitor.getLegacyTextParameters().get(STATUS_INFORMATION));
}
}

0 comments on commit 8d53a59

Please sign in to comment.