Skip to content
This repository was archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
Mon 6764 limit downtime date 20.10 (#478)
Browse files Browse the repository at this point in the history
* fix (downtime): Limit downtime start date, end date and duration
* chore(doc): release note updated
REFS: MON-6764
  • Loading branch information
rem31 authored Apr 2, 2021
1 parent 65ec79f commit db17837
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 63 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ restarted automatically. It is fixed now.
*Check commands*

When many commands are running, engine could crash when we stop it.

*Downtime*

Add Limit downtime start date, end date to 4102441200 (31/12/209 23:59) max and duration to 31622400 (366 days) max
## 20.10.2

`January 20, 2021`
Expand Down
73 changes: 48 additions & 25 deletions src/downtimes/downtime_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
*
*/

#include "com/centreon/engine/downtimes/downtime_manager.hh"
#include "com/centreon/engine/broker.hh"
#include "com/centreon/engine/configuration/applier/state.hh"
#include "com/centreon/engine/downtimes/downtime_manager.hh"
#include "com/centreon/engine/downtimes/host_downtime.hh"
#include "com/centreon/engine/downtimes/service_downtime.hh"
#include "com/centreon/engine/exceptions/error.hh"
#include "com/centreon/engine/events/loop.hh"
#include "com/centreon/engine/exceptions/error.hh"
#include "com/centreon/engine/globals.hh"
#include "com/centreon/engine/logging/logger.hh"

Expand All @@ -43,25 +43,25 @@ void downtime_manager::delete_downtime(downtime::type type,
uint64_t downtime_id) {
/* find the downtime we should remove */
for (auto it = _scheduled_downtimes.begin(), end = _scheduled_downtimes.end();
it != end;
++it) {
it != end; ++it) {
if (it->second->get_downtime_id() == downtime_id &&
it->second->get_type() == type) {
logger(dbg_downtime, basic)
<< "delete downtime(type:" << type << ", id: " << downtime_id << ")";
<< "delete downtime(type:" << type << ", id: " << downtime_id << ")";
_scheduled_downtimes.erase(it);
break;
}
}
}

/* unschedules a host or service downtime */
int downtime_manager::unschedule_downtime(downtime::type type, uint64_t downtime_id) {
int downtime_manager::unschedule_downtime(downtime::type type,
uint64_t downtime_id) {
std::shared_ptr<downtime> temp_downtime{find_downtime(type, downtime_id)};

logger(dbg_functions, basic) << "unschedule_downtime()";
logger(dbg_downtime, basic)
<< "unschedule downtime(type:" << type << ", id: " << downtime_id << ")";
<< "unschedule downtime(type:" << type << ", id: " << downtime_id << ")";

/* find the downtime entry in the list in memory */
if (!temp_downtime)
Expand All @@ -82,13 +82,13 @@ int downtime_manager::unschedule_downtime(downtime::type type, uint64_t downtime
/* unschedule all downtime entries that were triggered by this one */
std::list<uint64_t> lst;
for (auto it = _scheduled_downtimes.begin(), end = _scheduled_downtimes.end();
it != end; ++it) {
it != end; ++it) {
if (it->second->get_triggered_by() == downtime_id)
lst.push_back(it->second->get_downtime_id());
}
for (uint64_t id : lst) {
logger(dbg_downtime, basic)
<< "Unschedule triggered downtime (id: " << id << ")";
<< "Unschedule triggered downtime (id: " << id << ")";
unschedule_downtime(downtime::any_downtime, id);
}

Expand Down Expand Up @@ -131,8 +131,9 @@ int downtime_manager::check_pending_flex_host_downtime(host* hst) {
it{_scheduled_downtimes.begin()},
end{_scheduled_downtimes.end()};
it != end; ++it) {
if (it->second->get_type() != downtime::host_downtime || it->second->is_fixed() ||
it->second->is_in_effect() || it->second->get_triggered_by() != 0)
if (it->second->get_type() != downtime::host_downtime ||
it->second->is_fixed() || it->second->is_in_effect() ||
it->second->get_triggered_by() != 0)
continue;

/* this entry matches our host! */
Expand Down Expand Up @@ -178,8 +179,9 @@ int downtime_manager::check_pending_flex_service_downtime(service* svc) {
it{_scheduled_downtimes.begin()},
end{_scheduled_downtimes.end()};
it != end; ++it) {
if (it->second->get_type() != downtime::service_downtime || it->second->is_fixed() ||
it->second->is_in_effect() || it->second->get_triggered_by() != 0)
if (it->second->get_type() != downtime::service_downtime ||
it->second->is_fixed() || it->second->is_in_effect() ||
it->second->get_triggered_by() != 0)
continue;

service_downtime& dt(
Expand Down Expand Up @@ -264,9 +266,9 @@ int downtime_manager::
time_t start_time,
std::string const& comment) {
logger(dbg_downtime, basic)
<< "Delete downtimes (host: '" << hostname << "', service description: '"
<< service_description << "', start time: " << start_time
<< ", comment: '" << comment << "')";
<< "Delete downtimes (host: '" << hostname << "', service description: '"
<< service_description << "', start time: " << start_time
<< ", comment: '" << comment << "')";
int deleted{0};

/* Do not allow deletion of everything - must have at least 1 filter on. */
Expand Down Expand Up @@ -329,7 +331,7 @@ void downtime_manager::insert_downtime(std::shared_ptr<downtime> dt) {
*/
void downtime_manager::initialize_downtime_data() {
logger(dbg_functions, basic)
<< "downtime_manager::initialize_downtime_data()";
<< "downtime_manager::initialize_downtime_data()";
/* clean up the old downtime data */
xdddefault_validate_downtime_data();

Expand All @@ -341,8 +343,8 @@ int downtime_manager::xdddefault_validate_downtime_data() {
bool save = true;

/* remove stale downtimes */
for (auto it = _scheduled_downtimes.begin(), end = _scheduled_downtimes.end();
it != end; ) {
for (auto it = _scheduled_downtimes.begin(), end = _scheduled_downtimes.end();
it != end;) {
std::shared_ptr<com::centreon::engine::downtimes::downtime> temp_downtime(
it->second);

Expand All @@ -356,7 +358,7 @@ int downtime_manager::xdddefault_validate_downtime_data() {

/* remove triggered downtimes without valid parents */
for (auto it = _scheduled_downtimes.begin(), end = _scheduled_downtimes.end();
it != end; ) {
it != end;) {
save = true;
downtimes::downtime& temp_downtime(*it->second);

Expand All @@ -365,7 +367,8 @@ int downtime_manager::xdddefault_validate_downtime_data() {
continue;
}

if (!find_downtime(downtime::any_downtime, temp_downtime.get_triggered_by()))
if (!find_downtime(downtime::any_downtime,
temp_downtime.get_triggered_by()))
save = false;

/* delete the downtime */
Expand Down Expand Up @@ -424,9 +427,9 @@ downtime* downtime_manager::add_new_host_downtime(std::string const& host_name,

/* send data to event broker */
broker_downtime_data(NEBTYPE_DOWNTIME_ADD, NEBFLAG_NONE, NEBATTR_NONE,
downtime::host_downtime, host_name.c_str(), nullptr, entry_time,
author, comment_data, start_time, end_time, fixed,
triggered_by, duration, new_downtime_id, nullptr);
downtime::host_downtime, host_name.c_str(), nullptr,
entry_time, author, comment_data, start_time, end_time,
fixed, triggered_by, duration, new_downtime_id, nullptr);
return retval;
}

Expand Down Expand Up @@ -491,6 +494,26 @@ int downtime_manager::schedule_downtime(downtime::type type,
if (start_time >= end_time || end_time <= time(nullptr))
return ERROR;

if (start_time > 4102441200) {
logger(log_verification_error, basic)
<< "SCHEDULE DOWNTIME ALERT : start time is out of range and setted to "
"1/1/2100 00:00";
start_time = 4102441200;
}

if (end_time > 4102441200) {
logger(log_verification_error, basic)
<< "SCHEDULE DOWNTIME ALERT : end time is out of range and setted to "
"1/1/2100 00:00";
end_time = 4102441200;
}

if (duration > 31622400) {
logger(log_verification_error, basic)
<< "SCHEDULE DOWNTIME ALERT : is too long and setted to 366 days";
duration = 31622400;
}

/* add a new downtime entry */
if (type == downtime::host_downtime)
add_new_host_downtime(host_name, entry_time, author, comment_data,
Expand All @@ -515,7 +538,7 @@ int downtime_manager::register_downtime(downtime::type type,
uint64_t downtime_id) {
logger(dbg_functions, basic) << "downtime_manager::register_downtime()";
logger(dbg_downtime, basic)
<< "register downtime(type: " << type << ", id: " << downtime_id << ")";
<< "register downtime(type: " << type << ", id: " << downtime_id << ")";
/* find the downtime entry in memory */
std::shared_ptr<downtime> temp_downtime{find_downtime(type, downtime_id)};
if (!temp_downtime)
Expand Down
Loading

0 comments on commit db17837

Please sign in to comment.