Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions modules/centreon-stream-connectors-lib/sc_event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ function ScEvent:is_valid_host_status_event()
return false
end

-- return false if event status is a duplicate and dedup is enabled
if self:is_host_status_event_duplicated() then
-- return false if event status is a duplicate and dedup is enabled and status is not in the dedup ignore list
if self:is_host_status_event_duplicated()
and not self.params.dedup_ignore_list[self.event.category][self.event.element][self.event.state]
then
self.sc_logger:warning("[sc_event:is_host_status_event_duplicated]: host_id: " .. tostring(self.event.host_id)
.. " is sending a duplicated event. Dedup option (enable_host_status_dedup) is set to: " .. tostring(self.params.enable_host_status_dedup))
return false
Expand Down Expand Up @@ -198,8 +200,10 @@ function ScEvent:is_valid_service_status_event()
return false
end

-- return false if event status is a duplicate and dedup is enabled
if self:is_service_status_event_duplicated() then
-- return false if event status is a duplicate and dedup is enabled and status is not in the dedup ignore list
if self:is_service_status_event_duplicated()
and not self.params.dedup_ignore_list[self.event.category][self.event.element][self.event.state]
then
self.sc_logger:warning("[sc_event:is_service_status_event_duplicated]: host_id: " .. tostring(self.event.host_id)
.. " service_id: " .. tostring(self.event.service_id) .. " is sending a duplicated event. Dedup option (enable_service_status_dedup) is set to: " .. tostring(self.params.enable_service_status_dedup))
return false
Expand Down
70 changes: 70 additions & 0 deletions modules/centreon-stream-connectors-lib/sc_params.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ function sc_params.new(common, logger)

-- enable or disable dedup
enable_host_status_dedup = 1,
force_send_host_status_list = "",
enable_service_status_dedup = 1,
force_send_service_status_list = "",

-- communication parameters
max_buffer_size = 1,
Expand Down Expand Up @@ -1039,6 +1041,9 @@ function ScParams:check_params()

-- handle some dedicated parameters that can use lua pattern (such as accepted_hosts and accepted_services)
self:build_and_validate_filters_pattern({"accepted_hosts", "accepted_services"})

-- create a table of hosts and services status that will ignore the dedup option
self:build_ignore_event_dedup_table()
end

--- get_kafka_params: retrieve the kafka parameters and store them the self.params.kafka table
Expand Down Expand Up @@ -1242,4 +1247,69 @@ function ScParams:build_and_validate_filters_pattern(param_list)
end
end

function ScParams:build_ignore_event_dedup_table()
self.params.dedup_ignore_list = {
[self.params.bbdo.categories.neb.id] = {
[self.params.bbdo.elements.host_status.id] = {},
[self.params.bbdo.elements.service_status.id] = {}
}
}

local force_host_status, force_service_status

if self.params.force_send_host_status_list ~= "" then
force_host_status = self.common:split(self.params.force_send_host_status_list)
end

if self.params.force_send_service_status_list ~= "" then
force_service_status = self.common:split(self.params.force_send_service_status_list)
end


-- we create the following structure if we have the below configuration
-- force_send_host_status_list = "1"
-- force_send_service_status_list = "1,2"
--[[
dedup_ignore_list = {
[1] = {
[32] = {
[1] = "DOWN"
},
[29] = {
[1] = "WARNING",
[2] = "CRITICAL"
}
}
}
]]
-- this is a bit overkill since we don't need status naming, but it facilitates the event validation to have the status as a key of a table + it allows us to validate that the status is a valid one during SC init
if type(force_host_status) == "table" then
for i, status in ipairs(force_host_status) do
status = tonumber(status)

if self.params.status_mapping[self.params.bbdo.categories.neb.id][self.params.bbdo.elements.host_status.id][status] then
self.params.dedup_ignore_list[self.params.bbdo.categories.neb.id][self.params.bbdo.elements.host_status.id][status] = self.params.status_mapping[self.params.bbdo.categories.neb.id][self.params.bbdo.elements.host_status.id][status]
else
self.logger:error("[sc_params:build_ignore_event_dedup_table]: invalid host status value: "
.. tostring(status) .. " found when parsing parameter 'force_send_host_status_list' with value: "
.. tostring(self.params.force_send_host_status_list))
end
end
end

if type(force_service_status) == "table" then
for i, status in ipairs(force_service_status) do
status = tonumber(status)

if self.params.status_mapping[self.params.bbdo.categories.neb.id][self.params.bbdo.elements.service_status.id][status] then
self.params.dedup_ignore_list[self.params.bbdo.categories.neb.id][self.params.bbdo.elements.service_status.id][status] = self.params.status_mapping[self.params.bbdo.categories.neb.id][self.params.bbdo.elements.service_status.id][status]
else
self.logger:error("[sc_params:build_ignore_event_dedup_table]: invalid service status value: "
.. tostring(status) .. " found when parsing parameter 'force_send_service_status_list' with value: "
.. tostring(self.params.force_send_service_status_list))
end
end
end
end

return sc_params