mirror of https://github.com/Icinga/icinga2.git
On ScheduledDowntime change: remove future downtimes created before change
refs #8309
This commit is contained in:
parent
bcc3870f3a
commit
666c5818bb
|
@ -98,6 +98,15 @@ void ScheduledDowntime::TimerProc()
|
|||
Log(LogCritical, "ScheduledDowntime")
|
||||
<< "Exception occurred during creation of next downtime for scheduled downtime '"
|
||||
<< sd->GetName() << "': " << DiagnosticInformation(ex, false);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
sd->RemoveObsoleteDowntimes();
|
||||
} catch (const std::exception& ex) {
|
||||
Log(LogCritical, "ScheduledDowntime")
|
||||
<< "Exception occurred during removal of obsolete downtime for scheduled downtime '"
|
||||
<< sd->GetName() << "': " << DiagnosticInformation(ex, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -301,6 +310,24 @@ void ScheduledDowntime::CreateNextDowntime()
|
|||
}
|
||||
}
|
||||
|
||||
void ScheduledDowntime::RemoveObsoleteDowntimes()
|
||||
{
|
||||
auto name (GetName());
|
||||
auto downtimeOptionsHash (HashDowntimeOptions());
|
||||
|
||||
// Just to be sure start and removal don't happen at the same time
|
||||
auto threshold (Utility::GetTime() + 5 * 60);
|
||||
|
||||
for (const Downtime::Ptr& downtime : GetCheckable()->GetDowntimes()) {
|
||||
if (downtime->GetScheduledBy() == name && downtime->GetStartTime() > threshold) {
|
||||
auto configOwnerHash (downtime->GetConfigOwnerHash());
|
||||
|
||||
if (!configOwnerHash.IsEmpty() && configOwnerHash != downtimeOptionsHash)
|
||||
Downtime::RemoveDowntime(downtime->GetName(), false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScheduledDowntime::ValidateRanges(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils)
|
||||
{
|
||||
ObjectImpl<ScheduledDowntime>::ValidateRanges(lvalue, utils);
|
||||
|
|
|
@ -47,6 +47,7 @@ private:
|
|||
std::pair<double, double> FindRunningSegment(double minEnd = 0);
|
||||
std::pair<double, double> FindNextSegment();
|
||||
void CreateNextDowntime();
|
||||
void RemoveObsoleteDowntimes();
|
||||
|
||||
static std::atomic<bool> m_AllConfigLoaded;
|
||||
|
||||
|
|
Loading…
Reference in New Issue