Skip to content

Store the notification START event where the END never arrives - #3

Merged
nook24 merged 1 commit into
statusengine:mainfrom
ponmeloco:store-notification-start
Sep 18, 2026
Merged

nook24 merged 1 commit into
statusengine:mainfrom
ponmeloco:store-notification-start

Conversation

@ponmeloco

@ponmeloco ponmeloco commented Sep 18, 2026 •

Copy link
Copy Markdown

Problem

The same as statusengine/worker#42, for this worker: where a broker module such as mod_gearman distributes notifications, statusengine_host_notifications and statusengine_service_notifications stay empty. mod_gearman answers NEBTYPE_CONTACTNOTIFICATIONMETHOD_START (604) with NEBERROR_CALLBACKOVERRIDE, Naemon skips running the command and never brokers NEBTYPE_CONTACTNOTIFICATIONMETHOD_END (605), and the worker stores only 605. The openITCOCKPIT Docker images distribute notifications by default.

Change

A new option, off by default, in the configuration pattern of this repository:

YAML store_notification_start
environment STATUSENGINE_STORE_NOTIFICATION_START
flag -store-notification-start

With it on, newContactNotificationMethodHandler stores 604 instead of 605:

  • end_time is set to start_time, since the end is not known. The column is NOT NULL without a sub-second part, so 0 would read as 1970.
  • This happens before the events are published on the WebSocket, so the stream and the database show the same value.
  • The END event is dropped, so where it does arrive nothing is stored twice.

NewRouter takes the option as a new last parameter, as statusMaxAge and mysqlBatchSize were added. config.example.yaml documents the key.

It is the same option as statusengine/worker#42, keeping both workers alike, in the spirit of "Use ev.StartTime ... as this is what the PHP worker used as well".

Tests

  • TestContactNotificationMethodHandlerStoresStartEventWhenAsked (new): with the option on, 604 is stored with end_time == start_time and the contact of the START event, and a following 605 is dropped.
  • TestContactNotificationMethodHandlerDiscardsNonEndType passes unchanged, so the default behaves as before.
  • go vet and gofmt are clean. Six tests fail, all for want of a Gearman or RabbitMQ broker on localhost; the same six fail on main.

Note: this change was prepared with AI assistance (Claude Code). The cause was traced in the Naemon, mod_gearman and Statusengine sources, and the fix was measured in a running openITCOCKPIT Docker stack.

A broker module that distributes notifications, such as mod_gearman, answers
NEBTYPE_CONTACTNOTIFICATIONMETHOD_START with NEBERROR_CALLBACKOVERRIDE. Naemon
then continues with the next notification command without running this one,
so it never brokers NEBTYPE_CONTACTNOTIFICATIONMETHOD_END (notifications.c:
the override at the method level is a `continue`, and the END call comes
after the command). This worker stores only the END event, so in that setup
statusengine_host_notifications and statusengine_service_notifications stay
empty for good while the notifications themselves go out.

The START event does arrive and carries everything but the end time: state,
output, contact, command and start time. store_notification_start, or
STATUSENGINE_STORE_NOTIFICATION_START, or -store-notification-start, makes the
worker store it instead. It defaults to off, so a core that brokers the END
event is stored exactly as before, and with it on the END event is dropped so
no notification is recorded twice.

end_time is filled from start_time. The column is NOT NULL with no sub-second
part, so a zero would be rendered as 1970, and a duration of exactly zero
reads as the placeholder it is rather than as a measurement. The same is
done before the event is published on the WebSocket, so both see one value.

This is the same option as in the PHP worker. Measured with it on in an
openITCOCKPIT Docker stack, which distributes notifications by default:
3489 service and 2325 host notifications stored, where there had been none.

NewRouter takes the flag as a new last parameter, as statusMaxAge and
mysqlBatchSize were added. The failing tests are the six that need a Gearman
or RabbitMQ broker on localhost; the same six fail on main.
@nook24
nook24 merged commit 20b0454 into statusengine:main Sep 18, 2026
2 checks passed
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.

2 participants