-
Notifications
You must be signed in to change notification settings - Fork 22
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
base: master
Are you sure you want to change the base?
(stream/refactoring) Upgrade BSM to api-v2 #91
Conversation
…ttps://github.com/centreon/centreon-stream-connector-scripts into feat(streamconnector)-add-refacto-bsm-v2-lua-files
There was a problem hiding this 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
Co-authored-by: tcharles <[email protected]>
There was a problem hiding this 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
|
||
local categories = self.sc_params.params.bbdo.categories | ||
local elements = self.sc_params.params.bbdo.elements | ||
|
There was a problem hiding this comment.
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
-- 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
[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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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') |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if xml_service_severity == false then | |
if not xml_service_severity then |
return payload | ||
end | ||
|
||
function EventQueue:send_data(payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return true | |
return true |
|
||
function EventQueue:send_data(payload) | ||
self.sc_logger:debug("[EventQueue:send_data]: Starting to send data") | ||
|
There was a problem hiding this comment.
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)
:setopt( | ||
curl.OPT_HTTPHEADER, | ||
{ | ||
"Content-Type: text/xml", | ||
"content-length: " .. string.len(payload) | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: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
Refacto streamconnector BSM to api-v2