use of org.sakuli.services.forwarder.icinga2.model.Icinga2Request in project sakuli by ConSol.
the class Icinga2ResultServiceImpl method saveAllResults.
@Override
public void saveAllResults() {
LOGGER.info("======= SEND RESULTS TO ICINGA SERVER ======");
LOGGER.info("POST Sakuli results to '{}'", icinga2RestCient.getTargetCheckResult().getUri().toString());
Entity<Icinga2Request> payload = Entity.json(icinga2CheckResultBuilder.build());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("ICINGA Payload: {}", convertToJSON(payload));
}
Response response = icinga2RestCient.getTargetCheckResult().request(MediaType.APPLICATION_JSON_TYPE).post(payload);
Icinga2Result result = response.readEntity(Icinga2Result.class);
if (result.isSuccess()) {
LOGGER.info("ICINGA Response: {}", result.getFirstElementAsString());
LOGGER.info("======= FINISHED: SEND RESULTS TO ICINGA SERVER ======");
} else {
exceptionHandler.handleException(new SakuliForwarderException(String.format("Unexpected result of REST-POST to Incinga monitoring server (%s): %s", icinga2RestCient.getTargetCheckResult().getUri(), result.getFirstElementAsString())));
}
}
use of org.sakuli.services.forwarder.icinga2.model.Icinga2Request in project sakuli by ConSol.
the class Icinga2CheckResultBuilderTest method testBuild.
@Test
public void testBuild() throws Exception {
when(testSuite.getState()).thenReturn(TestSuiteState.OK);
String perfData = "sample_performance_data";
when(performanceDataBuilder.build()).thenReturn(Collections.singletonList(perfData));
String output = "sample_output";
when(outputBuilder.build()).thenReturn(output);
Icinga2Request result = testling.build();
assertEquals(result.getCheck_source(), "check_sakuli");
assertEquals(result.getExit_status(), 0);
assertEquals(result.getPerformance_data().size(), 1);
assertEquals(result.getPerformance_data().iterator().next(), perfData);
assertEquals(result.getPlugin_output(), output);
}
Aggregations