mirror of https://github.com/Icinga/icinga2.git
parent
60d5959ba4
commit
22f3c5082d
|
@ -246,6 +246,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
%type ScheduledDowntime %inherits CustomVarObject {
|
%type ScheduledDowntime %inherits CustomVarObject {
|
||||||
|
%validator "ValidateScheduledDowntimeRanges",
|
||||||
|
|
||||||
%require "host_name",
|
%require "host_name",
|
||||||
%attribute %name(Host) "host_name",
|
%attribute %name(Host) "host_name",
|
||||||
%attribute %string "service_name",
|
%attribute %string "service_name",
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
REGISTER_TYPE(ScheduledDowntime);
|
REGISTER_TYPE(ScheduledDowntime);
|
||||||
|
REGISTER_SCRIPTFUNCTION(ValidateScheduledDowntimeRanges, &ScheduledDowntime::ValidateRanges);
|
||||||
|
|
||||||
INITIALIZE_ONCE(&ScheduledDowntime::StaticInitialize);
|
INITIALIZE_ONCE(&ScheduledDowntime::StaticInitialize);
|
||||||
|
|
||||||
|
@ -179,3 +180,35 @@ void ScheduledDowntime::CreateNextDowntime(void)
|
||||||
Downtime::Ptr downtime = Checkable::GetDowntimeByID(uid);
|
Downtime::Ptr downtime = Checkable::GetDowntimeByID(uid);
|
||||||
downtime->SetConfigOwner(GetName());
|
downtime->SetConfigOwner(GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScheduledDowntime::ValidateRanges(const String& location, const ScheduledDowntime::Ptr& object)
|
||||||
|
{
|
||||||
|
Dictionary::Ptr ranges = object->GetRanges();
|
||||||
|
|
||||||
|
if (!ranges)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* create a fake time environment to validate the definitions */
|
||||||
|
time_t refts = Utility::GetTime();
|
||||||
|
tm reference = Utility::LocalTime(refts);
|
||||||
|
Array::Ptr segments = new Array();
|
||||||
|
|
||||||
|
ObjectLock olock(ranges);
|
||||||
|
BOOST_FOREACH(const Dictionary::Pair& kv, ranges) {
|
||||||
|
try {
|
||||||
|
tm begin_tm, end_tm;
|
||||||
|
int stride;
|
||||||
|
LegacyTimePeriod::ParseTimeRange(kv.first, &begin_tm, &end_tm, &stride, &reference);
|
||||||
|
} catch (std::exception&) {
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Validation failed for " +
|
||||||
|
location + ": Invalid time specification.", object->GetDebugInfo()));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
LegacyTimePeriod::ProcessTimeRanges(kv.second, &reference, segments);
|
||||||
|
} catch (std::exception&) {
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Validation failed for " +
|
||||||
|
location + ": Invalid time range definition.", object->GetDebugInfo()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -53,6 +53,8 @@ public:
|
||||||
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
||||||
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
|
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
|
||||||
|
|
||||||
|
static void ValidateRanges(const String& location, const ScheduledDowntime::Ptr& object);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void OnAllConfigLoaded(void);
|
virtual void OnAllConfigLoaded(void);
|
||||||
virtual void Start(void);
|
virtual void Start(void);
|
||||||
|
|
Loading…
Reference in New Issue