fix(sc-event): replay status-change events after a downtime ends#345
Draft
sdepassio wants to merge 1 commit into
Conversation
6de8b1c to
585cbc5
Compare
585cbc5 to
80edc33
Compare
tanguyvda
reviewed
Jun 30, 2026
Comment on lines
+78
to
+80
| if not self.downtimes_storage then | ||
| self.downtimes_storage = sc_storage.new(self.sc_common, self.sc_logger, self.params) | ||
| end |
Contributor
There was a problem hiding this comment.
the stream connector starts a sc_storage instance and set it as an argument of the sc_event instance.
therefore, you can already have access to the storage with self.sc_storage
By creating a new storage instance in each instance of the sc_event class you'll end up loading the sqlite db each time we receive an event
tanguyvda
reviewed
Jun 30, 2026
| downtime_start = self.event.actual_start_time, | ||
| downtime_end = self.event.actual_end_time | ||
| } | ||
| if not self.downtimes_storage:set_multiple(object_id, storage_data) then |
Contributor
There was a problem hiding this comment.
Suggested change
| if not self.downtimes_storage:set_multiple(object_id, storage_data) then | |
| if not self.sc_storage:set_multiple(object_id, storage_data) then |
based on my previous comment, you can just use the already existing storage instance
| self.sc_logger:error("[sc_event:is_valid_element]: Cannot register downtime datas in storage.") | ||
| end | ||
| elseif self:is_valid_downtime_event_end() then | ||
| local ok, stored = self.downtimes_storage:get_multiple(object_id, {"object_type", "status", "broker_event"}) |
Contributor
There was a problem hiding this comment.
Suggested change
| local ok, stored = self.downtimes_storage:get_multiple(object_id, {"object_type", "status", "broker_event"}) | |
| local ok, stored = self.sc_storage:get_multiple(object_id, {"object_type", "status", "broker_event"}) |
| if stored.broker_event and pending_event_handler then | ||
| -- delete broker_event from storage before sending to prevent duplicate dispatch | ||
| -- on the second downtime end event (cancellation + deletion both trigger this path) | ||
| self.downtimes_storage:delete(object_id, "broker_event") |
Contributor
There was a problem hiding this comment.
Suggested change
| self.downtimes_storage:delete(object_id, "broker_event") | |
| self.sc_storage:delete(object_id, "broker_event") |
| else | ||
| object_id = 'downtime_host_' .. self.event.host_id | ||
| end | ||
| local ok, stored = self.downtimes_storage:get_multiple(object_id, {"object_type", "status"}) |
Contributor
There was a problem hiding this comment.
Suggested change
| local ok, stored = self.downtimes_storage:get_multiple(object_id, {"object_type", "status"}) | |
| local ok, stored = self.sc_storage:get_multiple(object_id, {"object_type", "status"}) |
| if ok then | ||
| if stored.status ~= self.event.state then | ||
| -- store broker_event as explicit JSON string to avoid relying on storage backend type conversion | ||
| if not self.downtimes_storage:set(object_id, "broker_event", broker.json_encode(self.broker_event)) then |
Contributor
There was a problem hiding this comment.
Suggested change
| if not self.downtimes_storage:set(object_id, "broker_event", broker.json_encode(self.broker_event)) then | |
| if not self.sc_storage:set(object_id, "broker_event", broker.json_encode(self.broker_event)) then |
| self.sc_logger:error("[sc_event:is_valid_event_downtime_state]: event hasn't been stored in storage") | ||
| end | ||
| else | ||
| self.downtimes_storage:set(object_id, "broker_event", nil) |
Contributor
There was a problem hiding this comment.
Suggested change
| self.downtimes_storage:set(object_id, "broker_event", nil) | |
| self.sc_storage:set(object_id, "broker_event", nil) |
Comment on lines
+805
to
+807
| if not self.downtimes_storage then | ||
| self.downtimes_storage = sc_storage.new(self.sc_common, self.sc_logger, self.params) | ||
| end |
Contributor
There was a problem hiding this comment.
not supposed to be needed
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.
Description
When a status change during a downtime, the event is never sent to the stream connector.
Fix: the last status event is stored, and if at the end of the downtime the status has changed the event is sent.
Fixes CTOR-2043
Type of change
Checklist
Community contributors & Centreon team