Store the notification START event where the END never arrives - #3
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The same as statusengine/worker#42, for this worker: where a broker module such as mod_gearman distributes notifications,
statusengine_host_notificationsandstatusengine_service_notificationsstay empty. mod_gearman answersNEBTYPE_CONTACTNOTIFICATIONMETHOD_START(604) withNEBERROR_CALLBACKOVERRIDE, Naemon skips running the command and never brokersNEBTYPE_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:
store_notification_startSTATUSENGINE_STORE_NOTIFICATION_START-store-notification-startWith it on,
newContactNotificationMethodHandlerstores 604 instead of 605:end_timeis set tostart_time, since the end is not known. The column isNOT NULLwithout a sub-second part, so 0 would read as 1970.NewRoutertakes the option as a new last parameter, asstatusMaxAgeandmysqlBatchSizewere added.config.example.yamldocuments 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 withend_time == start_timeand the contact of the START event, and a following 605 is dropped.TestContactNotificationMethodHandlerDiscardsNonEndTypepasses unchanged, so the default behaves as before.go vetandgofmtare clean. Six tests fail, all for want of a Gearman or RabbitMQ broker on localhost; the same six fail onmain.