Search in sources :

Example 1 with Icinga2Result

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())));
    }
}
Also used : Response(javax.ws.rs.core.Response) Icinga2Result(org.sakuli.services.forwarder.icinga2.model.Icinga2Result) SakuliForwarderException(org.sakuli.exceptions.SakuliForwarderException) Icinga2Request(org.sakuli.services.forwarder.icinga2.model.Icinga2Request)

Example 2 with Icinga2Result

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());
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) HashMap(java.util.HashMap) Icinga2Result(org.sakuli.services.forwarder.icinga2.model.Icinga2Result) Test(org.testng.annotations.Test)

Example 3 with Icinga2Result

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()));
    }
}
Also used : Response(javax.ws.rs.core.Response) SakuliForwarderRuntimeException(org.sakuli.exceptions.SakuliForwarderRuntimeException) Icinga2Result(org.sakuli.services.forwarder.icinga2.model.Icinga2Result) Icinga2Request(org.sakuli.services.forwarder.icinga2.model.Icinga2Request)

Example 4 with Icinga2Result

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();
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) HashMap(java.util.HashMap) Icinga2Result(org.sakuli.services.forwarder.icinga2.model.Icinga2Result) SakuliForwarderException(org.sakuli.exceptions.SakuliForwarderException) Test(org.testng.annotations.Test)

Example 5 with Icinga2Result

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());
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) HashMap(java.util.HashMap) Icinga2Result(org.sakuli.services.forwarder.icinga2.model.Icinga2Result) Test(org.testng.annotations.Test)

Aggregations

Icinga2Result (org.sakuli.services.forwarder.icinga2.model.Icinga2Result)5 HashMap (java.util.HashMap)3 TestSuite (org.sakuli.datamodel.TestSuite)3 Test (org.testng.annotations.Test)3 Response (javax.ws.rs.core.Response)2 SakuliForwarderException (org.sakuli.exceptions.SakuliForwarderException)2 Icinga2Request (org.sakuli.services.forwarder.icinga2.model.Icinga2Request)2 SakuliForwarderRuntimeException (org.sakuli.exceptions.SakuliForwarderRuntimeException)1