Skip to content

NMS-20608: Trim and require UEIs in event configuration - #9179

Merged
synqotik merged 14 commits into
foundation-2026from
jira/NMS-20608-event-config-uei-whitespace-f2026-smoke
Nov 23, 2026
Merged

synqotik merged 14 commits into
foundation-2026from
jira/NMS-20608-event-config-uei-whitespace-f2026-smoke

Conversation

@synqotik

@synqotik synqotik commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Event configuration can keep a UEI that has whitespace around it. It can also keep a UEI that is empty.

Eventd reads each definition from xml_content, and the parser trims the UEI. Thus, the definitions in memory are already trimmed. The problems are in other places:

  • The threshold form saved a padded custom UEI in the threshold configuration. The threshold then sent events with the padded UEI, and Eventd did not match them to the trimmed definition.
  • The eventconf_events.uei column kept the padded value. The lookups by UEI use this column.

The XML and JSON REST paths already trim UEIs. The eventconf package has a package-level StringTrimAdapter, and JAXB and the Jackson provider both use it. These are the real gaps:

  • Java code that calls Event.setUei() does not go through the adapter. The plugin path and the threshold form are examples.
  • No path rejects a UEI that is empty after the trim. An edit to a blank UEI returned 200 and stored "".
  • The "events by UEI" lookup does not trim its parameter.

Changes

Model

  • Event.setUei() trims the value. It rejects a value that is blank after the trim.
  • All UEI checks use one rule: trim with String.trim(), then test with String.isBlank(). trim() removes control characters, and isBlank() finds Unicode spaces such as U+2003. Thus, a UEI of only these characters is blank everywhere. EventConfServiceHelper.isBlankUei() is the shared method for this rule.
  • JsmiMibParser trims the UEI base before it builds trap UEIs. This hunk is the same as the NMS-20603 change on develop, so it merges forward with no conflict.

Storage

  • EventConfServiceHelper.requireUei() rejects an event with a null or blank UEI.
  • Single-event writes call this check: add, upsert and edit.
  • Uploads and plugin definitions check the full list of events first. If one or more events have no UEI, the error gives the position and event-label of each such event:
    Events with no 'uei', by position: #2 (event-label 'Foo Down'), #4
  • A rejected file stores nothing. Other files in the same upload continue as before.

REST API (/rest/eventconf)

  • An edit with a blank or missing UEI now returns 400. Before, it returned 200 and stored an empty UEI.
  • The REST layer does this check before it calls the service. Other errors from the edit still return 500.
  • The upload checks the UEIs of each file before it opens a transaction. Thus, a bad file does not lock its source.
  • The "events by UEI" lookup trims the UEI parameter.
  • The OpenAPI text for the edit and the lookup now agrees with the code. The edit gives 400 for a body with no event or enabled, or with a blank uei. It gives 404 for an unknown source or event.

Plugins

  • An invalid plugin event definition now writes an error to the log. The log gives the plugin's extension class, the UEI and the event-label.
  • The behavior does not change: one invalid definition still stops all plugin event definitions from loading. This is an existing problem. A blank UEI caused it before, and now a UEI of only whitespace causes it too. A follow-up ticket covers it.

Threshold form (ThresholdController, only on foundation-*)

  • The form trims the optional "Triggered UEI" and "Rearmed UEI" fields. The threshold configuration and the event definition get the trimmed value.
  • A field with only whitespace now means "no custom UEI". Before, the form stored an event definition with a whitespace UEI.

Behavior changes for API clients

Request Before After
Edit with a blank UEI 200, empty UEI stored 400
Upload a file that has a blank UEI File stored with an empty UEI File rejected; the error names each event by position and label
Lookup with whitespace around the UEI No match Match

Not in this PR

  • No database migration. Rows that the threshold form or a plugin stored before this change can have whitespace in the uei column. Eventd is not affected, because it parses xml_content. For such a row:

    • The lookup by UEI does not find the row. An upsert does not find it either, so the upsert adds a second row.
    • At the first start after the upgrade, the plugin sync adds one trimmed copy of the plugin event. The old row stays.

    All writes now store a trimmed UEI, so this PR stops new rows of this type. Only Horizon 35 and later, and Meridian 2026, have this table.

  • Trim of UEIs in the threshold configuration (triggeredUEI and rearmedUEI in Basethresholddef). A separate ticket covers this.

  • Plugin sync: skip an invalid plugin event definition, so that the other definitions still load. This is a follow-up.

  • One validator for add, upsert and edit. The edit does not check event-label and severity. This is a follow-up.

  • A test for a re-upload of an existing source that has a blank UEI. The REST layer now rejects the file before the transaction, so the old events stay.

Merge forward to develop

Two files need manual work:

  1. opennms-webapp/.../thresholds/ThresholdController.java gives a modify/delete conflict, because develop deleted this file. Keep the delete.
  2. opennms-webapp/.../thresholds/ThresholdControllerUeiTest.java merges with no conflict, but it does not compile on develop. Delete it in the same merge.

All other files merge with no conflict.

After the merge, a small develop PR adds a test for the threshold UEI service.

External References

Event.setUei() now trims (parsing already trims through the package's
StringTrimAdapter), so Java callers such as the plugin API and the MIB
parser no longer store UEIs with surrounding whitespace; a whitespace-only
UEI is rejected like an empty one.

Also backports the UEI-base trim in JsmiMibParser.getTrapEventUEI from
develop (NMS-20603), unchanged, so it merges forward cleanly.
EventConfServiceHelper.requireUei() guards saveEvent and
createEventConfEventEntities, so an upload or a plugin can no longer
store an event definition whose UEI is empty after trimming.
Editing an event to a blank or missing UEI was accepted (stored empty)
or failed with a 500; it is now rejected with a 400, like add and
upsert. The lookup of a source's events by UEI trims its parameter.
Upload, add, upsert and edit with a padded UEI store it trimmed in the
uei column and in xml_content, and the reloaded definition is found by
the trimmed UEI. JSON request bodies are trimmed by the Jackson 1 JAXB
provider too. These pin the eventconf package's StringTrimAdapter, which
every one of these paths relies on.
With Event.setUei() now rejecting a whitespace-only UEI, a Triggered or
Rearmed UEI field holding only spaces made the threshold editor fail
with a 500. Both fields are now trimmed, and a blank one means no
custom UEI, so the threshold config and its auto-created event
definition carry the same trimmed UEI.
A rejected upload said only "Event 'uei' is required", leaving the user to
hunt through the file. List every event with a blank UEI by its position
and event-label instead, so one failed upload is enough to fix the file.
The edit now rejects a blank UEI before it calls the service, so the
handler no longer maps every IllegalArgumentException to 400; other
errors from the update return 500 again. The upload checks each file's
UEIs before it opens a transaction, so a bad file never locks its source.
The edit returns 400 for a missing event, a missing enabled flag or a blank
UEI, and 404 for an unknown source or event, not 500. The lookup by UEI
ignores whitespace around the parameter.
One invalid plugin event definition stops all plugin event definitions
from loading, with nothing in the log that names the plugin. Log the
plugin's extension class, the UEI and the event-label. The behavior is
unchanged; skipping the bad definition is a follow-up.
isBlank() and String.trim() disagree on control characters, so a field of
only control characters reached setUei as an empty UEI and failed. Use
String.trim() for both the check and the value.
@synqotik
synqotik marked this pull request as ready for review November 19, 2026 19:44

@marshallmassengill marshallmassengill left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Trim and blank checks: Event.setUei uses trim(), but EventConfServiceHelper.requireUei uses isBlank(). The two methods do not agree on Unicode space characters above U+0020. A UEI that contains only such characters passes setUei, and then the storage check rejects it. For a plugin, the log does not give the plugin name in this case. Use the same check in the two locations.
  • EventConfRestService.java, line 512: The edit handler does the blank UEI check again in local code. Use one shared method in EventConfServiceHelper for this check. Then the REST layer and the service cannot become different.
  • EventConfRestApi.java, line 1028: One line in the description of the lookup by UEI is too long. Divide the line.
  • EventConfRestApi.java, edit responses: The examples for 400, 404 and 500 are JSON objects, but the schema type is string. Change the schema type to agree with the examples.

Event.setUei used String.trim(), but the storage and REST checks used
isBlank(). The two disagree on control characters and on Unicode spaces
such as U+2003, so a plugin UEI of only Unicode spaces passed setUei and
failed later in the sync, where the log does not name the plugin.

The rule is now: trim with String.trim(), then test with isBlank().
EventConfServiceHelper.isBlankUei is the shared method; the storage
checks, the REST add/upsert/edit checks and the threshold form use it,
and Event.setUei applies the same rule.
The edit responses are JSON objects, so their schema type is object, and
the 200 example shows the real message body. Divide a long line in the
description of the lookup by UEI.
@synqotik

Copy link
Copy Markdown
Contributor Author

@marshallmassengill

  1. Trim and blank checks. Correct. trim() and isBlank() also disagree the other way: a UEI of only control characters (e.g. U+0001) passed the storage check but failed setUei. Made one rule and used it everywhere:
  • Trim with String.trim(), then test with isBlank().

    trim() removes control characters and isBlank() catches Unicode spaces such as U+2003, so a UEI made only of either is blank in every check.

    • EventConfServiceHelper.isBlankUei() is now the shared method. The storage checks and the threshold form call it.
    • Event.setUei() lives in a module that can't call the helper, so it applies the same rule inline. A comment points to isBlankUei.
    • A plugin UEI of only Unicode spaces now fails in setUei, so the error log names the plugin.

    We chose to reject these UEIs everywhere rather than accept and store them. Rejecting is what gets the plugin named in the log.

  1. Shared check. The edit handler now calls isBlankUei. Also switched the UEI check for add and upsert to it, so all three REST paths use the same rule.

  2. Long line. The line in the lookup description is now split.

  3. Schema types. The 400, 404 and 500 responses now use type = "object". The 200 response had the same problem: its example was a plain string, but the handler returns .{"message": ...}`; now also fixed.

@marshallmassengill marshallmassengill left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cgorantla cgorantla left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@synqotik
synqotik merged commit e512061 into foundation-2026 Nov 23, 2026
15 checks passed
@synqotik
synqotik deleted the jira/NMS-20608-event-config-uei-whitespace-f2026-smoke branch November 23, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants