Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(stream/refactoring) Upgrade BSM to api-v2 #91

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

psamecentreon
Copy link
Contributor

@psamecentreon psamecentreon commented Dec 16, 2021

Refacto streamconnector BSM to api-v2

@psamecentreon psamecentreon added the enhancement Enhance existing label Dec 16, 2021
@psamecentreon psamecentreon self-assigned this Dec 16, 2021
@psamecentreon psamecentreon changed the title Refacto streamconnector BSM api-v2 feat(BSM) - Refacto streamconnector BSM to api-v2 Dec 16, 2021
@psamecentreon psamecentreon changed the title feat(BSM) - Refacto streamconnector BSM to api-v2 feat(bsm) - Refacto streamconnector BSM to api-v2 Dec 16, 2021
centreon-certified/bsm/bsm_connector-apiv2.lua Outdated Show resolved Hide resolved
centreon-certified/bsm/bsm_connector-apiv2.lua Outdated Show resolved Hide resolved
centreon-certified/bsm/bsm_connector-apiv2.lua Outdated Show resolved Hide resolved
centreon-certified/bsm/bsm_connector-apiv2.lua Outdated Show resolved Hide resolved
centreon-certified/bsm/bsm_connector-apiv2.lua Outdated Show resolved Hide resolved
centreon-certified/bsm/bsm_connector-apiv2.lua Outdated Show resolved Hide resolved
centreon-certified/bsm/bsm_connector-apiv2.lua Outdated Show resolved Hide resolved
centreon-certified/bsm/bsm_connector-apiv2.lua Outdated Show resolved Hide resolved
centreon-certified/bsm/bsm_connector-apiv2.lua Outdated Show resolved Hide resolved
centreon-certified/bsm/bsm_connector-apiv2.lua Outdated Show resolved Hide resolved
@Sims24 Sims24 changed the title feat(bsm) - Refacto streamconnector BSM to api-v2 (stream/refactoring) Upgrade BSM to api-v2 Dec 22, 2021
Copy link
Contributor

@tanguyvda tanguyvda left a comment

Choose a reason for hiding this comment

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

i don't know what you did but it also looks like you are going to remove everything from the sc_common file :p

centreon-certified/bsm/bsm-events-apiv2.lua Outdated Show resolved Hide resolved
centreon-certified/bsm/bsm-events-apiv2.lua Outdated Show resolved Hide resolved
Copy link
Contributor

@tanguyvda tanguyvda left a comment

Choose a reason for hiding this comment

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

just need to fix that and it's ready for merge

centreon-certified/bsm/bsm-events-apiv2.lua Outdated Show resolved Hide resolved

local categories = self.sc_params.params.bbdo.categories
local elements = self.sc_params.params.bbdo.elements

Copy link
Contributor

Choose a reason for hiding this comment

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

in today's world, we have a custom code feature

Suggested change
-- only load the custom code file, not executed yet
if self.sc_params.load_custom_code_file and not self.sc_params:load_custom_code_file(self.sc_params.params.custom_code_file) then
self.sc_logger:error("[EventQueue:new]: couldn't successfully load the custom code file: " .. tostring(self.sc_params.params.custom_code_file))
end

Copy link
Contributor

Choose a reason for hiding this comment

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

}

self.send_data_method = {
[1] = function (payload) return self:send_data(payload) end
Copy link
Contributor

Choose a reason for hiding this comment

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

there's a metadata system for queues now

Suggested change
[1] = function (payload) return self:send_data(payload) end
[1] = function (payload, queue_metadata) return self:send_data(payload, queue_metadata) end


-- Format XML file with host infoamtion
function EventQueue:format_event_host()
local xml_host_severity = self.sc_broker:get_severity(self.sc_event.event.host_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed to call broker cache

severity is already stored in self.sc_event.event.cache.severity.host

local xml_url = self.sc_common:ifnil_or_empty(self.sc_event.event.cache.host.action_url, 'no action url for this host')
local xml_notes = self.sc_common:ifnil_or_empty(self.sc_event.event.cache.host.notes, 'no notes found on host')

if xml_host_severity == false then
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if xml_host_severity == false then
if not xml_host_severity then

nil and false are not the same, both can be handled with "if not"


-- Format XML file with service infoamtion
function EventQueue:format_event_service()
local xml_url = self.sc_common:ifnil_or_empty(self.sc_event.event.cache.host.notes_url, 'no url for this service')
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed to call broker cache

severity is already stored in self.sc_event.event.cache.severity.service

local xml_url = self.sc_common:ifnil_or_empty(self.sc_event.event.cache.host.notes_url, 'no url for this service')
local xml_service_severity = self.sc_broker:get_severity(self.sc_event.event.host_id, self.sc_event.event.service_id)

if xml_service_severity == false then
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if xml_service_severity == false then
if not xml_service_severity then

return payload
end

function EventQueue:send_data(payload)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
function EventQueue:send_data(payload)
function EventQueue:send_data(payload, queue_metadata)

need to add the metadata with the new system

-- write payload in the logfile for test purpose
if self.sc_params.params.send_data_test == 1 then
self.sc_logger:notice("[send_data]: " .. tostring(payload))
return true
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return true
return true


function EventQueue:send_data(payload)
self.sc_logger:debug("[EventQueue:send_data]: Starting to send data")

Copy link
Contributor

Choose a reason for hiding this comment

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

before the send _data_test condition, there is a whole new system to create the curl command.

in this case it would look like

queue_metadata.headers = {
  "Content-Type: text/xml",
  "content-length: " .. string.len(payload)
}


self.sc_logger:log_curl_command(self.sc_params.params.http_server_url, queue_metadata, self.sc_params.params, payload)

Comment on lines +256 to +262
:setopt(
curl.OPT_HTTPHEADER,
{
"Content-Type: text/xml",
"content-length: " .. string.len(payload)
}
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
:setopt(
curl.OPT_HTTPHEADER,
{
"Content-Type: text/xml",
"content-length: " .. string.len(payload)
}
)
:setopt(curl.OPT_HTTPHEADER, queue_metadata.headers)

with the log_curl_command system, headers are already built before. Therefore, we can simplify this line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhance existing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants