/******************************************************************************
* Icinga 2 *
- * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
+ * Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
******************************************************************************/
#include "icinga/checkable.hpp"
-#include "icinga/checkable.tcpp"
+#include "icinga/checkable-ti.cpp"
#include "icinga/host.hpp"
#include "icinga/service.hpp"
#include "base/objectlock.hpp"
if (endpoint) {
Zone::Ptr checkableZone = static_pointer_cast<Zone>(GetZone());
- if (!checkableZone)
- checkableZone = Zone::GetLocalZone();
+ if (checkableZone) {
+ Zone::Ptr cmdZone = endpoint->GetZone();
- Zone::Ptr cmdZone = endpoint->GetZone();
-
- if (checkableZone && cmdZone != checkableZone && cmdZone->GetParent() != checkableZone) {
+ if (cmdZone != checkableZone && cmdZone->GetParent() != checkableZone) {
+ BOOST_THROW_EXCEPTION(ValidationError(this, { "command_endpoint" },
+ "Command endpoint must be in zone '" + checkableZone->GetName() + "' or in a direct child zone thereof."));
+ }
+ } else {
BOOST_THROW_EXCEPTION(ValidationError(this, { "command_endpoint" },
- "Command endpoint must be in zone '" + checkableZone->GetName() + "' or in a direct child zone thereof."));
+ "Command endpoint must not be set."));
}
}
}
{
double now = Utility::GetTime();
- if (GetNextCheck() < now + 300)
- UpdateNextCheck();
+ if (GetNextCheck() < now + 60) {
+ double delta = std::min(GetCheckInterval(), 60.0);
+ delta *= (double)std::rand() / RAND_MAX;
+ SetNextCheck(now + delta);
+ }
ObjectImpl<Checkable>::Start(runtimeCreated);
}
OnNotificationsRequested(checkable, NotificationDowntimeEnd, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), nullptr);
}
-void Checkable::ValidateCheckInterval(double value, const ValidationUtils& utils)
+void Checkable::ValidateCheckInterval(const Lazy<double>& lvalue, const ValidationUtils& utils)
{
- ObjectImpl<Checkable>::ValidateCheckInterval(value, utils);
+ ObjectImpl<Checkable>::ValidateCheckInterval(lvalue, utils);
- if (value <= 0)
+ if (lvalue() <= 0)
BOOST_THROW_EXCEPTION(ValidationError(this, { "check_interval" }, "Interval must be greater than 0."));
}
-void Checkable::ValidateMaxCheckAttempts(int value, const ValidationUtils& utils)
+void Checkable::ValidateRetryInterval(const Lazy<double>& lvalue, const ValidationUtils& utils)
+{
+ ObjectImpl<Checkable>::ValidateRetryInterval(lvalue, utils);
+
+ if (lvalue() <= 0)
+ BOOST_THROW_EXCEPTION(ValidationError(this, { "retry_interval" }, "Interval must be greater than 0."));
+}
+
+void Checkable::ValidateMaxCheckAttempts(const Lazy<int>& lvalue, const ValidationUtils& utils)
{
- ObjectImpl<Checkable>::ValidateMaxCheckAttempts(value, utils);
+ ObjectImpl<Checkable>::ValidateMaxCheckAttempts(lvalue, utils);
- if (value <= 0)
+ if (lvalue() <= 0)
BOOST_THROW_EXCEPTION(ValidationError(this, { "max_check_attempts" }, "Value must be greater than 0."));
}