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 Oct 29, 2024
1 parent aa4a605 commit b799302
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
11 changes: 11 additions & 0 deletions engine/enginerpc/engine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ service Engine {
rpc GetContact(ContactIdentifier) returns (EngineContact) {}
rpc GetService(ServiceIdentifier) returns (EngineService) {}
rpc GetHostGroup(HostGroupIdentifier) returns (EngineHostGroup) {}
rpc GetContactGroup(ContactGroupIdentifier) 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 @@ -690,6 +691,16 @@ message EngineHostGroup {
string action_url = 7;
}

message ContactGroupIdentifier {
string name = 1;
}

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 @@ -845,6 +845,51 @@ grpc::Status engine_impl::GetHostGroup(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 ContactGroupIdentifier* 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 @@ -60,6 +60,9 @@ class engine_impl final : public Engine::Service {
grpc::Status GetHostGroup(grpc::ServerContext* context,
const HostGroupIdentifier*,
EngineHostGroup*) override;
grpc::Status GetContactGroup(grpc::ServerContext* context,
const ContactGroupIdentifier* request,
EngineContactGroup* response) override;
grpc::Status AddHostComment(grpc::ServerContext* context,
const EngineComment* request,
CommandSuccess* response) override;
Expand Down

0 comments on commit b799302

Please sign in to comment.