Skip to content

Commit

Permalink
feat(engine/gRPC): GetContactGroup return information about a contact…
Browse files Browse the repository at this point in the history
… group.
  • Loading branch information
sechkem committed Nov 1, 2024
1 parent ab5093b commit aa42a0e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
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

0 comments on commit aa42a0e

Please sign in to comment.