Search in sources :

Example 1 with SyslogServerEventIF

use of org.graylog2.syslog4j.server.SyslogServerEventIF in project graylog2-server by Graylog2.

the class SyslogCodec method parseAdditionalData.

private Map<String, Object> parseAdditionalData(SyslogServerEventIF msg, boolean expand) {
    // Structured syslog has more data we can parse.
    if (msg instanceof StructuredSyslogServerEvent) {
        final StructuredSyslogServerEvent sMsg = (StructuredSyslogServerEvent) msg;
        final Map<String, Object> structuredData = new HashMap<>(extractFields(sMsg, expand));
        if (!isNullOrEmpty(sMsg.getApplicationName())) {
            structuredData.put("application_name", sMsg.getApplicationName());
        }
        if (!isNullOrEmpty(sMsg.getProcessId())) {
            structuredData.put("process_id", sMsg.getProcessId());
        }
        return structuredData;
    } else {
        return Collections.emptyMap();
    }
}
Also used : HashMap(java.util.HashMap) StructuredSyslogServerEvent(org.graylog2.syslog4j.server.impl.event.structured.StructuredSyslogServerEvent)

Example 2 with SyslogServerEventIF

use of org.graylog2.syslog4j.server.SyslogServerEventIF in project graylog2-server by Graylog2.

the class SyslogCodec method parse.

private Message parse(String msg, InetAddress remoteAddress, DateTime receivedTimestamp) {
    /*
         * ZOMG funny 80s neckbeard protocols. We are now deciding if to parse
         * structured (RFC5424) or unstructured (classic BSD, RFC3164) syslog
         * by checking if there is a VERSION after the PRI. Sorry.
         *
         *                            ._.                                  _
         *    R-O-F-L-R-O-F-L-R-O-F-L-IOI-R-O-F-L-R-O-F-L-R-O-F-L         / l
         *                ___________/LOL\____                           /: ]
         *            .__/°         °\___/°   \                         / ::\
         *           /^^ \            °  °     \_______.__________.____/: OO:\
         *      .__./     j      ________             _________________ ::OO::|
         *    ./ ^^ j____/°     [\______/]      .____/                 \__:__/
         *  ._|____/°    °       <{(OMG{<       /                         ::
         * /  °    °              (OMFG{       /
         * |°  loooooooooooooooooooooooooooooooool
         *         °L|                   L|
         *          ()                   ()
         *
         *
         *  http://open.spotify.com/track/2ZtQKBB8wDTtPPqDZhy7xZ
         *
         */
    final SyslogServerEventIF e;
    if (STRUCTURED_SYSLOG_PATTERN.matcher(msg).matches()) {
        e = new StructuredSyslogServerEvent(msg, remoteAddress);
    } else {
        e = new SyslogServerEvent(msg, remoteAddress);
    }
    // If the message is a structured one, we do not want the message ID and the structured data in the
    // message string. See: https://github.com/Graylog2/graylog2-server/issues/845#issuecomment-69499719
    final String syslogMessage;
    if (e instanceof StructuredSyslogServerEvent) {
        final String structMessage = ((StructuredSyslogServerEvent) e).getStructuredMessage().getMessage();
        syslogMessage = isNullOrEmpty(structMessage) ? e.getMessage() : structMessage;
    } else {
        syslogMessage = e.getMessage();
    }
    final Message m = new Message(syslogMessage, parseHost(e, remoteAddress), parseDate(e, receivedTimestamp));
    m.addField("facility", Tools.syslogFacilityToReadable(e.getFacility()));
    m.addField("level", e.getLevel());
    // Store full message if configured.
    if (configuration.getBoolean(CK_STORE_FULL_MESSAGE)) {
        m.addField("full_message", new String(e.getRaw(), StandardCharsets.UTF_8));
    }
    final boolean expandStructuredData = configuration.getBoolean(CK_EXPAND_STRUCTURED_DATA);
    m.addFields(parseAdditionalData(e, expandStructuredData));
    return m;
}
Also used : SyslogServerEventIF(org.graylog2.syslog4j.server.SyslogServerEventIF) RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) StructuredSyslogServerEvent(org.graylog2.syslog4j.server.impl.event.structured.StructuredSyslogServerEvent) SyslogServerEvent(org.graylog2.syslog4j.server.impl.event.SyslogServerEvent) StructuredSyslogServerEvent(org.graylog2.syslog4j.server.impl.event.structured.StructuredSyslogServerEvent)

Aggregations

StructuredSyslogServerEvent (org.graylog2.syslog4j.server.impl.event.structured.StructuredSyslogServerEvent)2 HashMap (java.util.HashMap)1 Message (org.graylog2.plugin.Message)1 RawMessage (org.graylog2.plugin.journal.RawMessage)1 SyslogServerEventIF (org.graylog2.syslog4j.server.SyslogServerEventIF)1 SyslogServerEvent (org.graylog2.syslog4j.server.impl.event.SyslogServerEvent)1