Uploaded image for project: 'OpenNMS'
  1. OpenNMS
  2. NMS-6730

CustomSyslogParser fails to parse process name when brackets appear in the message text

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.12.8
    • Fix Version/s: 19.1.0
    • Security Level: Default (Default Security Scheme)
    • Labels:
      None
    • Environment:
      Linux
    • Sprint:
      Horizon - March 29th

      Description

      The CustomSyslogParser class's parse method will fail to parse the process name from a syslog message that contains brackets in the regular message text.

      The code in question is at line 186 in opennms-services/src/main/java/org/opennms/netmgt/syslogd/CustomSyslogParser.java:

          lbIdx = message.indexOf('[');
          rbIdx = message.indexOf(']');
          final int colonIdx = message.indexOf(':');
          final int spaceIdx = message.indexOf(' ');
          ...
          if (lbIdx < (rbIdx - 1) && colonIdx == (rbIdx + 1) && spaceIdx == (colonIdx + 1)) {
              // remove/save the name and ID
          } else if (lbIdx < 0 && rbIdx < 0 && colonIdx > 0 && spaceIdx == (colonIdx + 1)) {
              // remove/save the name
          }
      

      The code assumes all message bodies (after removing the header) look like:

          procname: text
      

      or

          procname[id]: text
      

      But if the message looks like:

          procname: t[ex]t
      

      where there is no process id with the process name, but the actual message text contains bracket characters, then the code will fail to parse the name because it's assuming that the only valid bracket pair that can exist in the entire message are those housing the process ID. When brackets exist elsewhere in the message, the name isn't parsed.

      I propose the following change:

          -        } else if (lbIdx < 0 && rbIdx < 0 && colonIdx > 0 && spaceIdx == (colonIdx + 1)) {
          +        } else if (colonIdx > 0 && spaceIdx == (colonIdx + 1)) {
      

      In order to allow the code to ignore the existence of brackets elsewhere in the message text and to continue with the parsing of the process name.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                seth Seth Leger
                Reporter:
                caneylan Christopher Neylan
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: