]> granicus.if.org Git - icinga2/commitdiff
Don't allow "managed" downtimes to be deleted by users.
authorMichael Friedrich <Michael.Friedrich@netways.de>
Sun, 4 May 2014 14:57:11 +0000 (16:57 +0200)
committerMichael Friedrich <Michael.Friedrich@netways.de>
Sun, 4 May 2014 14:57:11 +0000 (16:57 +0200)
Fixes #5980

lib/icinga/checkable-downtime.cpp
lib/icinga/checkable.cpp
lib/icinga/downtime.ti
lib/icinga/scheduleddowntime.cpp
test/config/5980.conf [new file with mode: 0644]

index 70a143f1697827057412819d0594ebcca942fbba..2fea94069f2897da7bb597f2eb7096cc4950665f 100644 (file)
@@ -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);
 
        {
index d60ffaf440994c2ad9c4ac1aa1c62aa9d7075606..c1d1877359e636c58983a7fe16ee498e8d7f8da2 100644 (file)
@@ -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);
        }
 }
index b1d8ee658db20fd30e160ab9c1dba682e7ef45dc..4dc05382ea8c3d370ef082a056421ab78ce55eb2 100644 (file)
@@ -20,6 +20,7 @@ safe class Downtime
        };
        [state] int legacy_id;
        [state] bool was_cancelled;
+       [state] String config_owner;
 };
 
 }
index 8d46ba30972e21f097ed51e90aa06e9724ef5212..b1e9c81ae2d4d986a2ded7213ebe9bbb75841da5 100644 (file)
@@ -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 (file)
index 0000000..ea53c00
--- /dev/null
@@ -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"
+}
+