Search in sources :

Example 1 with NagiosException

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;
}
Also used : NagiosException(com.googlecode.jsendnsca.NagiosException) Level(com.googlecode.jsendnsca.Level) IOException(java.io.IOException) MessagePayload(com.googlecode.jsendnsca.MessagePayload)

Aggregations

Level (com.googlecode.jsendnsca.Level)1 MessagePayload (com.googlecode.jsendnsca.MessagePayload)1 NagiosException (com.googlecode.jsendnsca.NagiosException)1 IOException (java.io.IOException)1