Search in sources :

Example 6 with MessagePayload

use of com.googlecode.jsendnsca.MessagePayload in project wildfly-camel by wildfly-extras.

the class NagiosIntegrationTest method testSendToNagios.

@Test
public void testSendToNagios() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(createRouteBuilder());
    MessagePayload expectedPayload = new MessagePayload("localhost", Level.OK, camelctx.getName(), "Hello Nagios");
    MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);
    mock.allMessages().body().isInstanceOf(String.class);
    mock.expectedBodiesReceived("Hello Nagios");
    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBody("direct:start", "Hello Nagios");
        mock.assertIsSatisfied();
        Mockito.verify(nagiosPassiveCheckSender, Mockito.times(1)).send(expectedPayload);
    } finally {
        camelctx.stop();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) MessagePayload(com.googlecode.jsendnsca.MessagePayload) Test(org.junit.Test)

Example 7 with MessagePayload

use of com.googlecode.jsendnsca.MessagePayload in project LogHub by fbacchella.

the class Nsca method send.

@Override
public boolean send(Event event) {
    boolean allfields = MAPFIELD.enumerate().allMatch(i -> {
        if (!event.containsKey(mapping.get(i))) {
            logger.error("event mapping field '{}' value missing", mapping.get(i));
            return false;
        } else {
            return true;
        }
    });
    if (!allfields) {
        return false;
    }
    Level level = Level.tolevel(event.get(mapping.get(MAPFIELD.LEVEL.name().toLowerCase())).toString().trim().toUpperCase());
    String serviceName = event.get(mapping.get(MAPFIELD.SERVICE.name().toLowerCase())).toString();
    String message = event.get(mapping.get(MAPFIELD.MESSAGE.name().toLowerCase())).toString();
    String hostName = event.get(mapping.get(MAPFIELD.HOST.name().toLowerCase())).toString();
    MessagePayload payload = new MessagePayload(hostName, level, serviceName, message);
    try {
        sender.send(payload);
    } catch (NagiosException | IOException e) {
        logger.error("NSCA send failed: {}", e.getMessage());
        return false;
    }
    return true;
}
Also used : NagiosException(com.googlecode.jsendnsca.NagiosException) Level(com.googlecode.jsendnsca.Level) IOException(java.io.IOException) MessagePayload(com.googlecode.jsendnsca.MessagePayload)

Aggregations

MessagePayload (com.googlecode.jsendnsca.MessagePayload)7 CamelContext (org.apache.camel.CamelContext)5 ProducerTemplate (org.apache.camel.ProducerTemplate)5 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)5 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)5 Test (org.junit.Test)5 Level (com.googlecode.jsendnsca.Level)2 NagiosException (com.googlecode.jsendnsca.NagiosException)1 NagiosPassiveCheckSender (com.googlecode.jsendnsca.NagiosPassiveCheckSender)1 NagiosSettings (com.googlecode.jsendnsca.NagiosSettings)1 MessagePayloadBuilder (com.googlecode.jsendnsca.builders.MessagePayloadBuilder)1 NagiosSettingsBuilder (com.googlecode.jsendnsca.builders.NagiosSettingsBuilder)1 Encryption (com.googlecode.jsendnsca.encryption.Encryption)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Result (org.pentaho.di.core.Result)1 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)1