use of com.googlecode.jsendnsca.NagiosException 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