Search in sources :

Example 1 with SyslogMessageDTO

use of org.opennms.netmgt.syslogd.api.SyslogMessageDTO in project opennms by OpenNMS.

the class SyslogSinkConsumer method toEventLog.

public Log toEventLog(SyslogMessageLogDTO messageLog) {
    final Log elog = new Log();
    final Events events = new Events();
    elog.setEvents(events);
    for (SyslogMessageDTO message : messageLog.getMessages()) {
        try {
            LOG.debug("Converting syslog message into event.");
            ConvertToEvent re = new ConvertToEvent(messageLog.getSystemId(), messageLog.getLocation(), messageLog.getSourceAddress(), messageLog.getSourcePort(), message.getBytes(), syslogdConfig);
            events.addEvent(re.getEvent());
        } catch (final MessageDiscardedException e) {
            LOG.info("Message discarded, returning without enqueueing event.", e);
        } catch (final Throwable e) {
            LOG.error("Unexpected exception while processing SyslogConnection", e);
        }
    }
    return elog;
}
Also used : SyslogMessageDTO(org.opennms.netmgt.syslogd.api.SyslogMessageDTO) Log(org.opennms.netmgt.xml.event.Log) Events(org.opennms.netmgt.xml.event.Events)

Example 2 with SyslogMessageDTO

use of org.opennms.netmgt.syslogd.api.SyslogMessageDTO in project opennms by OpenNMS.

the class SyslogSinkModule method getAggregationPolicy.

@Override
public AggregationPolicy<SyslogConnection, SyslogMessageLogDTO> getAggregationPolicy() {
    final String systemId = distPollerDao.whoami().getId();
    final String systemLocation = distPollerDao.whoami().getLocation();
    return new AggregationPolicy<SyslogConnection, SyslogMessageLogDTO>() {

        @Override
        public int getCompletionSize() {
            return config.getBatchSize();
        }

        @Override
        public int getCompletionIntervalMs() {
            return config.getBatchIntervalMs();
        }

        @Override
        public Object key(SyslogConnection syslogConnection) {
            return syslogConnection.getSource();
        }

        @Override
        public SyslogMessageLogDTO aggregate(SyslogMessageLogDTO oldLog, SyslogConnection connection) {
            if (oldLog == null) {
                oldLog = new SyslogMessageLogDTO(systemLocation, systemId, connection.getSource());
            }
            SyslogMessageDTO messageDTO = new SyslogMessageDTO(connection.getBuffer());
            oldLog.getMessages().add(messageDTO);
            return oldLog;
        }
    };
}
Also used : SyslogMessageLogDTO(org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO) SyslogMessageDTO(org.opennms.netmgt.syslogd.api.SyslogMessageDTO) SyslogConnection(org.opennms.netmgt.syslogd.api.SyslogConnection) AggregationPolicy(org.opennms.core.ipc.sink.api.AggregationPolicy)

Example 3 with SyslogMessageDTO

use of org.opennms.netmgt.syslogd.api.SyslogMessageDTO in project opennms by OpenNMS.

the class SyslogSinkModule method toMessageLog.

/**
     * Used for testing.
     */
public SyslogMessageLogDTO toMessageLog(SyslogConnection... connections) {
    final String systemId = distPollerDao.whoami().getId();
    final String systemLocation = distPollerDao.whoami().getLocation();
    if (connections.length < 1) {
        throw new IllegalArgumentException("One or more connection are required.");
    }
    final SyslogMessageLogDTO messageLog = new SyslogMessageLogDTO(systemLocation, systemId, connections[0].getSource());
    for (SyslogConnection connection : connections) {
        final SyslogMessageDTO messageDTO = new SyslogMessageDTO(connection.getBuffer());
        messageLog.getMessages().add(messageDTO);
    }
    return messageLog;
}
Also used : SyslogMessageLogDTO(org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO) SyslogMessageDTO(org.opennms.netmgt.syslogd.api.SyslogMessageDTO) SyslogConnection(org.opennms.netmgt.syslogd.api.SyslogConnection)

Aggregations

SyslogMessageDTO (org.opennms.netmgt.syslogd.api.SyslogMessageDTO)3 SyslogConnection (org.opennms.netmgt.syslogd.api.SyslogConnection)2 SyslogMessageLogDTO (org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO)2 AggregationPolicy (org.opennms.core.ipc.sink.api.AggregationPolicy)1 Events (org.opennms.netmgt.xml.event.Events)1 Log (org.opennms.netmgt.xml.event.Log)1