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

fix(engine/test): Test inheritance contact group #1794

Merged
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
7 changes: 7 additions & 0 deletions engine/enginerpc/engine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ service Engine {
rpc GetService(ServiceIdentifier) returns (EngineService) {}
rpc GetHostGroup(NameIdentifier) returns (EngineHostGroup) {}
rpc GetServiceGroup(NameIdentifier) returns (EngineServiceGroup) {}
rpc GetContactGroup(NameIdentifier) returns (EngineContactGroup) {}
rpc GetHostsCount(google.protobuf.Empty) returns (GenericValue) {}
rpc GetContactsCount(google.protobuf.Empty) returns (GenericValue) {}
rpc GetServicesCount(google.protobuf.Empty) returns (GenericValue) {}
Expand Down Expand Up @@ -697,6 +698,12 @@ message EngineServiceGroup {
repeated string members = 7;
}

message EngineContactGroup {
string name = 1;
string alias = 2;
repeated string members = 3;
}

message EngineComment {
string host_name = 1;
string svc_desc = 2;
Expand Down
45 changes: 45 additions & 0 deletions engine/enginerpc/engine_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,51 @@ grpc::Status engine_impl::GetServiceGroup(grpc::ServerContext* context
return grpc::Status(grpc::INVALID_ARGUMENT, err);
}

/**
* @brief Return ContactGroup informations.
*
* @param context gRPC context
* @param request ContactGroup's identifier (by ContactGroup name)
* @param response The filled fields
*
*@return Status::OK
*/
grpc::Status engine_impl::GetContactGroup(grpc::ServerContext* context
[[maybe_unused]],
const NameIdentifier* request,
EngineContactGroup* response) {
std::string err;
auto fn = std::packaged_task<int(void)>([&err, request,
contactgroup =
response]() -> int32_t {
std::shared_ptr<com::centreon::engine::contactgroup> selectedcontactgroup;
auto itcontactgroup = contactgroup::contactgroups.find(request->name());
if (itcontactgroup != contactgroup::contactgroups.end())
selectedcontactgroup = itcontactgroup->second;
else {
err = fmt::format("could not find contactgroup '{}'", request->name());
return 1;
}

contactgroup->set_name(selectedcontactgroup->get_name());
contactgroup->set_alias(selectedcontactgroup->get_alias());

if (!selectedcontactgroup->get_members().empty())
for (const auto& [key, _] : selectedcontactgroup->get_members())
contactgroup->add_members(key);

return 0;
});

std::future<int32_t> result = fn.get_future();
command_manager::instance().enqueue(std::move(fn));

if (result.get() == 0)
return grpc::Status::OK;
else
return grpc::Status(grpc::INVALID_ARGUMENT, err);
}

/**
* @brief Return the total number of hosts.
*
Expand Down
3 changes: 3 additions & 0 deletions engine/inc/com/centreon/engine/engine_impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class engine_impl final : public Engine::Service {
grpc::Status GetServiceGroup(grpc::ServerContext* context,
const NameIdentifier* request,
EngineServiceGroup* response) override;
grpc::Status GetContactGroup(grpc::ServerContext* context,
const NameIdentifier* request,
EngineContactGroup* response) override;
grpc::Status AddHostComment(grpc::ServerContext* context,
const EngineComment* request,
CommandSuccess* response) override;
Expand Down
Loading