}
%type ScheduledDowntime %inherits CustomVarObject {
+ %validator "ValidateScheduledDowntimeRanges",
+
%require "host_name",
%attribute %name(Host) "host_name",
%attribute %string "service_name",
using namespace icinga;
REGISTER_TYPE(ScheduledDowntime);
+REGISTER_SCRIPTFUNCTION(ValidateScheduledDowntimeRanges, &ScheduledDowntime::ValidateRanges);
INITIALIZE_ONCE(&ScheduledDowntime::StaticInitialize);
Downtime::Ptr downtime = Checkable::GetDowntimeByID(uid);
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()));
+ }
+ }
+}
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
+ static void ValidateRanges(const String& location, const ScheduledDowntime::Ptr& object);
+
protected:
virtual void OnAllConfigLoaded(void);
virtual void Start(void);