Search in sources :

Example 1 with Icinga2Request

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())));
    }
}
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 Icinga2Request

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);
}
Also used : Icinga2Request(org.sakuli.services.forwarder.icinga2.model.Icinga2Request) Test(org.testng.annotations.Test)

Aggregations

Icinga2Request (org.sakuli.services.forwarder.icinga2.model.Icinga2Request)2 Response (javax.ws.rs.core.Response)1 SakuliForwarderException (org.sakuli.exceptions.SakuliForwarderException)1 Icinga2Result (org.sakuli.services.forwarder.icinga2.model.Icinga2Result)1 Test (org.testng.annotations.Test)1