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

Mon 15407 add protobuf instance status message #405

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
MON-15246 add pb_custom_variable_status
  • Loading branch information
jean-christophe81 committed Oct 13, 2022
commit e11da54311dd7260544c94ccf934216cb8ad11af
134 changes: 69 additions & 65 deletions broker/neb/src/callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -967,75 +967,79 @@ int neb::callback_external_command(int callback_type, void* data) {
SPDLOG_LOGGER_INFO(
log_v2::neb(),
"callbacks: generating host custom variable update event");
std::list<std::string> l{absl::StrSplit(
misc::string::check_string_utf8(necd->command_args), ';')};
if (l.size() != 3)
SPDLOG_LOGGER_ERROR(
log_v2::neb(), "callbacks: invalid host custom variable command");
else {
std::list<std::string>::iterator it(l.begin());
std::string host{std::move(*it)};
++it;
std::string var_name{std::move(*it)};
++it;
std::string var_value{std::move(*it)};

// Find host ID.
uint64_t host_id = engine::get_host_id(host);
if (host_id != 0) {
// Fill custom variable.
auto cvs = std::make_shared<neb::custom_variable_status>();
cvs->host_id = host_id;
cvs->modified = true;
cvs->name = var_name;
cvs->service_id = 0;
cvs->update_time = necd->timestamp.tv_sec;
cvs->value = var_value;

// Send event.
gl_publisher.write(cvs);
// Split argument string.
if (necd->command_args) {
std::list<std::string> l{absl::StrSplit(
misc::string::check_string_utf8(necd->command_args), ';')};
if (l.size() != 3)
SPDLOG_LOGGER_ERROR(
log_v2::neb(),
"callbacks: invalid host custom variable command");
else {
std::list<std::string>::iterator it(l.begin());
std::string host{std::move(*it)};
++it;
std::string var_name{std::move(*it)};
++it;
std::string var_value{std::move(*it)};

// Find host ID.
uint64_t host_id = engine::get_host_id(host);
if (host_id != 0) {
// Fill custom variable.
auto cvs = std::make_shared<neb::custom_variable_status>();
cvs->host_id = host_id;
cvs->modified = true;
cvs->name = var_name;
cvs->service_id = 0;
cvs->update_time = necd->timestamp.tv_sec;
cvs->value = var_value;

// Send event.
gl_publisher.write(cvs);
}
}
}
}
}
else if (necd->command_type == CMD_CHANGE_CUSTOM_SVC_VAR) {
SPDLOG_LOGGER_INFO(
log_v2::neb(),
"callbacks: generating service custom variable update event");

// Split argument string.
if (necd->command_args) {
std::list<std::string> l{absl::StrSplit(
misc::string::check_string_utf8(necd->command_args), ';')};
if (l.size() != 4)
SPDLOG_LOGGER_ERROR(
log_v2::neb(),
"callbacks: invalid service custom variable command");
else {
std::list<std::string>::iterator it{l.begin()};
std::string host{std::move(*it)};
++it;
std::string service{std::move(*it)};
++it;
std::string var_name{std::move(*it)};
++it;
std::string var_value{std::move(*it)};

// Find host/service IDs.
std::pair<uint64_t, uint64_t> p{
engine::get_host_and_service_id(host, service)};
if (p.first && p.second) {
// Fill custom variable.
auto cvs{std::make_shared<neb::custom_variable_status>()};
cvs->host_id = p.first;
cvs->modified = true;
cvs->name = var_name;
cvs->service_id = p.second;
cvs->update_time = necd->timestamp.tv_sec;
cvs->value = var_value;
} else if (necd->command_type == CMD_CHANGE_CUSTOM_SVC_VAR) {
SPDLOG_LOGGER_INFO(
log_v2::neb(),
"callbacks: generating service custom variable update event");

// Send event.
gl_publisher.write(cvs);
// Split argument string.
if (necd->command_args) {
std::list<std::string> l{absl::StrSplit(
misc::string::check_string_utf8(necd->command_args), ';')};
if (l.size() != 4)
SPDLOG_LOGGER_ERROR(
log_v2::neb(),
"callbacks: invalid service custom variable command");
else {
std::list<std::string>::iterator it{l.begin()};
std::string host{std::move(*it)};
++it;
std::string service{std::move(*it)};
++it;
std::string var_name{std::move(*it)};
++it;
std::string var_value{std::move(*it)};

// Find host/service IDs.
std::pair<uint64_t, uint64_t> p{
engine::get_host_and_service_id(host, service)};
if (p.first && p.second) {
// Fill custom variable.
auto cvs{std::make_shared<neb::custom_variable_status>()};
cvs->host_id = p.first;
cvs->modified = true;
cvs->name = var_name;
cvs->service_id = p.second;
cvs->update_time = necd->timestamp.tv_sec;
cvs->value = var_value;

// Send event.
gl_publisher.write(cvs);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion broker/unified_sql/src/stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void (stream::*const stream::_neb_processing_table[])(
&stream::_process_acknowledgement,
&stream::_process_comment,
&stream::_process_custom_variable,
nullptr,
&stream::_process_custom_variable_status,
&stream::_process_downtime,
nullptr,
nullptr,
Expand Down