use of org.sakuli.services.forwarder.icinga2.model.Icinga2Result 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.Icinga2Result in project sakuli by ConSol.
the class Icinga2ResultServiceImplTest method testSaveAllResultsWrongStatus.
@Test(expectedExceptions = SakuliForwarderException.class, expectedExceptionsMessageRegExp = "Unexpected result of REST-POST.*")
public void testSaveAllResultsWrongStatus() throws Exception {
Icinga2Result result = new Icinga2Result();
Map<String, String> map = new HashMap<>();
map.put("code", "200.00");
map.put("status", "Unsuccessfully processed");
result.setResults(Collections.singletonList(map));
when(icinga2CheckResultBuilder.build()).thenReturn(getRequestExample());
mockAndReturn(result);
testling.teardownTestSuite(new TestSuite());
}
use of org.sakuli.services.forwarder.icinga2.model.Icinga2Result in project sakuli by ConSol.
the class Icinga2ResultServiceImpl method teardownTestSuite.
@Override
public void teardownTestSuite(@NonNull TestSuite testSuite) throws RuntimeException {
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 {
throw new SakuliForwarderRuntimeException(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.Icinga2Result in project sakuli by ConSol.
the class Icinga2ResultServiceImplTest method testSaveAllResults.
@Test
public void testSaveAllResults() throws Exception {
Icinga2Result result = new Icinga2Result();
Map<String, String> map = new HashMap<>();
map.put("code", "200.00");
map.put("status", "Successfully processed");
result.setResults(Collections.singletonList(map));
mockAndReturn(result);
when(icinga2CheckResultBuilder.build()).thenReturn(getRequestExample());
testling.teardownTestSuite(new TestSuite());
verify(exceptionHandler, never()).handleException(any(Exception.class));
verify(icinga2CheckResultBuilder).build();
}
use of org.sakuli.services.forwarder.icinga2.model.Icinga2Result in project sakuli by ConSol.
the class Icinga2ResultServiceImplTest method testSaveAllResultsWrongCode.
@Test(expectedExceptions = SakuliForwarderException.class, expectedExceptionsMessageRegExp = "Unexpected result of REST-POST.*")
public void testSaveAllResultsWrongCode() throws Exception {
Icinga2Result result = new Icinga2Result();
Map<String, String> map = new HashMap<>();
map.put("code", "20.00");
map.put("status", "Successfully processed");
result.setResults(Collections.singletonList(map));
mockAndReturn(result);
when(icinga2CheckResultBuilder.build()).thenReturn(getRequestExample());
testling.teardownTestSuite(new TestSuite());
}
Aggregations