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