Search in sources :

Example 1 with InterfaceToNodeCache

use of org.opennms.netmgt.dao.api.InterfaceToNodeCache in project opennms by OpenNMS.

the class ConvertToEvent method toEventBuilder.

public static final EventBuilder toEventBuilder(SyslogMessage message, String systemId, String location) {
    if (message == null) {
        return null;
    }
    // Build a basic event out of the syslog message
    final String priorityTxt = message.getSeverity().toString();
    final String facilityTxt = message.getFacility().toString();
    EventBuilder bldr = new EventBuilder();
    bldr.setUei("uei.opennms.org/syslogd/" + facilityTxt + "/" + priorityTxt);
    bldr.setSource("syslogd");
    // Set constant values in EventBuilder
    // Set monitoring system
    bldr.setDistPoller(systemId);
    // Set event host
    bldr.setHost(InetAddressUtils.getLocalHostName());
    // Set default event destination to logndisplay
    bldr.setLogDest("logndisplay");
    // Set values from SyslogMessage in the EventBuilder
    bldr.addParam("hostname", message.getHostName());
    final InetAddress hostAddress = message.getHostAddress();
    if (hostAddress != null) {
        // Set nodeId
        InterfaceToNodeCache cache = AbstractInterfaceToNodeCache.getInstance();
        if (cache != null) {
            int nodeId = cache.getNodeId(location, hostAddress);
            if (nodeId > 0) {
                bldr.setNodeid(nodeId);
            }
        }
        bldr.setInterface(hostAddress);
    }
    if (message.getDate() == null) {
        if (message.getYear() != null)
            bldr.setYear(message.getYear());
        if (message.getMonth() != null)
            bldr.setMonth(message.getMonth());
        if (message.getDayOfMonth() != null)
            bldr.setDayOfMonth(message.getDayOfMonth());
        if (message.getHourOfDay() != null)
            bldr.setHourOfDay(message.getHourOfDay());
        if (message.getMinute() != null)
            bldr.setMinute(message.getMinute());
        if (message.getSecond() != null)
            bldr.setSecond(message.getSecond());
        if (message.getMillisecond() != null)
            bldr.setMillisecond(message.getMillisecond());
        if (message.getZoneId() != null)
            bldr.setZoneId(message.getZoneId());
    } else {
        bldr.setTime(message.getDate());
    }
    bldr.setLogMessage(message.getMessage());
    // Using parms provides configurability.
    bldr.addParam("syslogmessage", message.getMessage());
    bldr.addParam("severity", priorityTxt);
    bldr.addParam("timestamp", SyslogMessage.getRfc3164FormattedDate(bldr.currentEventTime()));
    if (message.getMessageID() != null) {
        bldr.addParam("messageid", message.getMessageID());
    }
    if (message.getProcessName() != null) {
        bldr.addParam("process", message.getProcessName());
    }
    bldr.addParam("service", facilityTxt);
    if (message.getProcessId() != null) {
        bldr.addParam("processid", message.getProcessId().toString());
    }
    return bldr;
}
Also used : InterfaceToNodeCache(org.opennms.netmgt.dao.api.InterfaceToNodeCache) AbstractInterfaceToNodeCache(org.opennms.netmgt.dao.api.AbstractInterfaceToNodeCache) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) InetAddress(java.net.InetAddress)

Aggregations

InetAddress (java.net.InetAddress)1 AbstractInterfaceToNodeCache (org.opennms.netmgt.dao.api.AbstractInterfaceToNodeCache)1 InterfaceToNodeCache (org.opennms.netmgt.dao.api.InterfaceToNodeCache)1 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)1