diff --git a/lib/icinga/checkable-downtime.cpp b/lib/icinga/checkable-downtime.cpp index 70a143f16..2fea94069 100644 --- a/lib/icinga/checkable-downtime.cpp +++ b/lib/icinga/checkable-downtime.cpp @@ -127,6 +127,13 @@ void Checkable::RemoveDowntime(const String& id, bool cancelled, const String& a int legacy_id = downtime->GetLegacyId(); + String config_owner = downtime->GetConfigOwner(); + + if (!config_owner.IsEmpty()) { + Log(LogWarning, "icinga", "Cannot remove downtime with ID '" + Convert::ToString(legacy_id) + "'. It is owned by scheduled downtime object '" + config_owner + "'"); + return; + } + downtimes->Remove(id); { diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp index d60ffaf44..c1d187735 100644 --- a/lib/icinga/checkable.cpp +++ b/lib/icinga/checkable.cpp @@ -84,6 +84,9 @@ void Checkable::OnStateLoaded(void) } BOOST_FOREACH(const String& id, ids) { + /* override config owner to clear downtimes once */ + Downtime::Ptr downtime = GetDowntimeByID(id); + downtime->SetConfigOwner(Empty); RemoveDowntime(id, true); } } diff --git a/lib/icinga/downtime.ti b/lib/icinga/downtime.ti index b1d8ee658..4dc05382e 100644 --- a/lib/icinga/downtime.ti +++ b/lib/icinga/downtime.ti @@ -20,6 +20,7 @@ safe class Downtime }; [state] int legacy_id; [state] bool was_cancelled; + [state] String config_owner; }; } diff --git a/lib/icinga/scheduleddowntime.cpp b/lib/icinga/scheduleddowntime.cpp index 8d46ba309..b1e9c81ae 100644 --- a/lib/icinga/scheduleddowntime.cpp +++ b/lib/icinga/scheduleddowntime.cpp @@ -19,6 +19,7 @@ #include "icinga/scheduleddowntime.h" #include "icinga/legacytimeperiod.h" +#include "icinga/downtime.h" #include "base/timer.h" #include "base/dynamictype.h" #include "base/initialize.h" @@ -153,7 +154,10 @@ void ScheduledDowntime::CreateNextDowntime(void) return; } - GetCheckable()->AddDowntime(GetAuthor(), GetComment(), + String uid = GetCheckable()->AddDowntime(GetAuthor(), GetComment(), segment.first, segment.second, GetFixed(), String(), GetDuration(), GetName()); + + Downtime::Ptr downtime = Checkable::GetDowntimeByID(uid); + downtime->SetConfigOwner(GetName()); } diff --git a/test/config/5980.conf b/test/config/5980.conf new file mode 100644 index 000000000..ea53c000f --- /dev/null +++ b/test/config/5980.conf @@ -0,0 +1,50 @@ + + +object Host "5980-host" { + import "test-generic-host" + address = "127.0.0.1" +} + +object Service "5980-service1" { + import "test-generic-service" + host_name = "5980-host" + check_command = "dummy" +} + +object Service "5980-service2" { + import "test-generic-service" + host_name = "5980-host" + check_command = "dummy" +} + + +template ScheduledDowntime "5980-test-downtime" { + author = "icingaadmin" + comment = "Scheduled downtime for tests" + + ranges = { + monday = "02:00-03:00" + tuesday = "02:00-03:00" + wednesday = "02:00-03:00" + thursday = "02:00-03:00" + friday = "02:00-03:00" + saturday = "02:00-03:00" + sunday = "02:00-03:00" + } +} + + +apply ScheduledDowntime "5980-test-service-downtime" to Host { + import "5980-test-downtime" + comment = "Scheduled host downtime for tests" + + assign where host.name == "5980-host" +} + +apply ScheduledDowntime "5980-test-service-downtime" to Service { + import "5980-test-downtime" + comment = "Scheduled service downtime for tests" + + assign where host.name == "5980-host" +} +