Don't allow "managed" downtimes to be deleted by users.

Fixes #5980
This commit is contained in:
Michael Friedrich 2014-05-04 16:57:11 +02:00
parent 4f44ef13f1
commit cf2bdecfeb
5 changed files with 66 additions and 1 deletions

View 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);
{

View 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);
}
}

View File

@ -20,6 +20,7 @@ safe class Downtime
};
[state] int legacy_id;
[state] bool was_cancelled;
[state] String config_owner;
};
}

View 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());
}

50
test/config/5980.conf Normal file
View File

@ -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"
}