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

enh(centengine) : adding DeleteDowntimByStartTimeComment #36

Merged
merged 1 commit into from
Jun 27, 2020
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
3 changes: 3 additions & 0 deletions include/com/centreon/engine/engine_impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class engine_impl final : public Engine::Service {
grpc::Status DeleteDowntimeByHostName(grpc::ServerContext* context,
const DowntimeHostIdentifier* request,
CommandSuccess* response) override;
grpc::Status DeleteDowntimeByStartTimeComment(grpc::ServerContext* context,
const DowntimeStartTimeIdentifier* request,
CommandSuccess* response) override;
grpc::Status DelayHostNotification(grpc::ServerContext* context,
const HostDelayIdentifier* request,
CommandSuccess* response) override;
Expand Down
57 changes: 34 additions & 23 deletions src/cce_rpc/engine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ service Engine {
rpc GetServiceGroupsCount(google.protobuf.Empty) returns (GenericValue) {}
rpc GetContactGroupsCount(google.protobuf.Empty) returns (GenericValue) {}
rpc GetHostGroupsCount(google.protobuf.Empty) returns (GenericValue) {}
rpc GetServiceDependenciesCount(google.protobuf.Empty) returns (GenericValue) {}
rpc GetServiceDependenciesCount(google.protobuf.Empty)
returns (GenericValue) {}
rpc GetHostDependenciesCount(google.protobuf.Empty) returns (GenericValue) {}
rpc ProcessServiceCheckResult(Check) returns (CommandSuccess) {}
rpc ProcessHostCheckResult(Check) returns (CommandSuccess) {}
Expand All @@ -50,14 +51,19 @@ service Engine {
rpc DeleteAllHostComments(HostIdentifier) returns (CommandSuccess) {}
rpc DeleteAllServiceComments(ServiceIdentifier) returns (CommandSuccess) {}
rpc RemoveHostAcknowledgement(HostIdentifier) returns (CommandSuccess) {}
rpc RemoveServiceAcknowledgement(ServiceIdentifier) returns (CommandSuccess) {}
rpc RemoveServiceAcknowledgement(ServiceIdentifier)
returns (CommandSuccess) {}
rpc DeleteHostDowntime(GenericValue) returns (CommandSuccess) {}
rpc DeleteServiceDowntime(GenericValue) returns (CommandSuccess) {}
rpc DeleteHostDowntimeFull(DowntimeCriterias) returns (CommandSuccess) {}
rpc DeleteServiceDowntimeFull(DowntimeCriterias) returns (CommandSuccess) {}
rpc DeleteDowntimeByHostName(DowntimeHostIdentifier) returns (CommandSuccess) {}
rpc DeleteDowntimeByHostName(DowntimeHostIdentifier)
returns (CommandSuccess) {}
rpc DeleteDowntimeByStartTimeComment(DowntimeStartTimeIdentifier)
returns (CommandSuccess) {}
rpc DelayHostNotification(HostDelayIdentifier) returns (CommandSuccess) {}
rpc DelayServiceNotification(ServiceDelayIdentifier) returns (CommandSuccess) {}
rpc DelayServiceNotification(ServiceDelayIdentifier)
returns (CommandSuccess) {}
}

message GenericString {
Expand Down Expand Up @@ -249,8 +255,8 @@ message ThresholdsFile {

message HostIdentifier {
oneof identifier {
string name = 1;
uint32 id = 2;
string name = 1;
uint32 id = 2;
}
}

Expand All @@ -261,9 +267,9 @@ message EngineHost {
string check_period = 4;
uint32 id = 5;
enum State {
UP = 0;
UP = 0;
DOWN = 1;
UNREACHABLE = 2;
UNREACHABLE = 2;
}
State current_state = 6;
}
Expand Down Expand Up @@ -302,37 +308,37 @@ message EngineService {
string description = 4;
string check_period = 5;
enum State {
OK = 0;
WARNING = 1;
CRITICAL = 2;
UNKNOWN = 3;
}
OK = 0;
WARNING = 1;
CRITICAL = 2;
UNKNOWN = 3;
}
State current_state = 6;
}

message EngineComment {
string host_name = 1;
string svc_desc = 2;
string user = 3;
string comment_data = 4;
bool persistent = 5;
uint32 entry_time = 6;
string host_name = 1;
string svc_desc = 2;
string user = 3;
string comment_data = 4;
bool persistent = 5;
uint32 entry_time = 6;
}

message HostDelayIdentifier {
oneof identifier {
string name = 1;
uint32 id = 2;
string name = 1;
uint32 id = 2;
}
uint32 delay_time = 3;
uint32 delay_time = 3;
}

message ServiceDelayIdentifier {
oneof identifier {
NameIdentifier names = 1;
IdIdentifier ids = 2;
}
uint32 delay_time = 3;
uint32 delay_time = 3;
}

message DowntimeCriterias {
Expand All @@ -353,3 +359,8 @@ message DowntimeHostIdentifier {
google.protobuf.UInt32Value start = 3;
string comment_data = 4;
}

message DowntimeStartTimeIdentifier {
google.protobuf.UInt32Value start = 1;
string comment_data = 2;
}
45 changes: 38 additions & 7 deletions src/centengine/engine_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -900,17 +900,16 @@ grpc::Status engine_impl::DeleteServiceDowntimeFull(
*
* @param context gRPC context
* @param request DowntimeHostIdentifier (it's a hostname and optionally other
* filter arguments like service description, start time and downtime's
* comment
* @param Command response
* filter arguments like service description, start time and downtime's
* comment
* @param Command response
*
* @return Status::OK
*/
grpc::Status engine_impl::DeleteDowntimeByHostName(
grpc::ServerContext* context __attribute__((unused)),
const DowntimeHostIdentifier* request,
CommandSuccess* response) {

/*hostname must be defined to delete the downtime but not others arguments*/
std::string const& host_name = request->host_name();
if (host_name.empty())
Expand All @@ -919,7 +918,6 @@ grpc::Status engine_impl::DeleteDowntimeByHostName(

auto fn = std::packaged_task<int32_t(void)>([&host_name,
request]() -> int32_t {

std::pair<bool, time_t> start_time;
std::string service_desc;
std::string comment_data;
Expand All @@ -935,8 +933,7 @@ grpc::Status engine_impl::DeleteDowntimeByHostName(
uint32_t deleted =
downtime_manager::instance()
.delete_downtime_by_hostname_service_description_start_time_comment(
host_name, service_desc, start_time,
comment_data);
host_name, service_desc, start_time, comment_data);
if (deleted == 0)
return 1;
return 0;
Expand All @@ -949,6 +946,40 @@ grpc::Status engine_impl::DeleteDowntimeByHostName(
return grpc::Status::OK;
}

grpc::Status engine_impl::DeleteDowntimeByStartTimeComment(
grpc::ServerContext* context __attribute__((unused)),
const DowntimeStartTimeIdentifier* request,
CommandSuccess* response) {
time_t start_time;
/*hostname must be defined to delete the downtime but not others arguments*/
if (!(request->has_start()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it is not optional, why using Uint32Value?
It would be easier to use uint32, wouldn't it?

return grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT,
"start_time must not be empty");
else
start_time = request->start().value();

std::string const& comment_data = request->comment_data();
if (comment_data.empty())
return grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT,
"comment_data must not be empty");

auto fn = std::packaged_task<int32_t(void)>([&comment_data,
&start_time]() -> int32_t {
uint32_t deleted =
downtime_manager::instance()
.delete_downtime_by_hostname_service_description_start_time_comment(
"", "", {true, start_time}, comment_data);
if (0 == deleted)
return 1;
return 0;
});
std::future<int32_t> result = fn.get_future();
command_manager::instance().enqueue(std::move(fn));

response->set_value(!result.get());
return grpc::Status::OK;
}

grpc::Status engine_impl::DelayHostNotification(
grpc::ServerContext* context __attribute__((unused)),
const HostDelayIdentifier* request,
Expand Down
1 change: 0 additions & 1 deletion src/external_command/commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "com/centreon/engine/string.hh"
#include "compatibility/mmap.h"


using namespace com::centreon::engine;
using namespace com::centreon::engine::configuration::applier;
using namespace com::centreon::engine::downtimes;
Expand Down
25 changes: 24 additions & 1 deletion tests/engine/enginerpc/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,23 @@ class EngineRPCClient {
return true;
}

bool DeleteDowntimeByStartTimeComment(uint32_t const start,
std::string const& commentdata,
CommandSuccess* response) {
DowntimeStartTimeIdentifier request;
grpc::ClientContext context;
request.set_comment_data(commentdata);
request.mutable_start()->set_value(start);

grpc::Status status =
_stub->DeleteDowntimeByStartTimeComment(&context, request, response);
if (!status.ok()) {
std::cout << "DeleteDowntimeByStartTimeComment rpc engine failed" << std::endl;
return false;
}
return true;
}

bool DelayHostNotificationByName(std::string const& hostname,
uint32_t& delaytime,
CommandSuccess* response) {
Expand Down Expand Up @@ -1117,7 +1134,13 @@ int main(int argc, char** argv) {
status = client.DeleteDowntimeByHostName(hostname, svcdsc, start,
commentdata, &response);
std::cout << "DeleteDowntimeByHostName" << std::endl;
} else if (strcmp(argv[1], "DeleteDowntimeByStartTimeComment") == 0) {
CommandSuccess response;
uint32_t start = atoi(argv[2]);
std::string commentdata = argv[3];

status = client.DeleteDowntimeByStartTimeComment(start, commentdata, &response);
std::cout << "DeleteDowntimeByStartTimeComment" << std::endl;
}

exit(status);
}
36 changes: 36 additions & 0 deletions tests/engine/enginerpc/enginerpc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,42 @@ TEST_F(EngineRpc, DeleteDowntimeByHostName) {
erpc.shutdown();
}

TEST_F(EngineRpc, DeleteDowntimeByStartTimeComment) {
enginerpc erpc("0.0.0.0", 40001);
std::unique_ptr<std::thread> th;
std::condition_variable condvar;
std::mutex mutex;
std::ostringstream oss;
bool continuerunning = false;

set_time(20000);

time_t now = time(nullptr);
std::stringstream s;
s << "test_host;test_svc;" << now << ";" << now + 1 << ";1;0;1;admin;host";
ASSERT_EQ(0u, downtime_manager::instance().get_scheduled_downtimes().size());

ASSERT_EQ(cmd_schedule_downtime(CMD_SCHEDULE_SVC_DOWNTIME, now,
const_cast<char*>(s.str().c_str())),
OK);
ASSERT_EQ(1u, downtime_manager::instance().get_scheduled_downtimes().size());
call_command_manager(th, &condvar, &mutex, &continuerunning);

/*hostname must be defined to delete the downtime but not others arguments*/
oss << "DeleteDowntimeByStartTimeComment " << now << " host";

auto output = execute(oss.str());
{
std::lock_guard<std::mutex> lock(mutex);
continuerunning = true;
}
condvar.notify_one();
th->join();

ASSERT_EQ(0u, downtime_manager::instance().get_scheduled_downtimes().size());
erpc.shutdown();
}

TEST_F(EngineRpc, DelayHostNotification) {
enginerpc erpc("0.0.0.0", 40001);
std::unique_ptr<std::thread> th;
Expand Down