/******************************************************************************
* Icinga 2 *
- * Copyright (C) 2012-2017 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"
boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType, bool, bool, double, const MessageOrigin::Ptr&)> Checkable::OnAcknowledgementSet;
boost::signals2::signal<void (const Checkable::Ptr&, const MessageOrigin::Ptr&)> Checkable::OnAcknowledgementCleared;
-void Checkable::StaticInitialize(void)
+void Checkable::StaticInitialize()
{
/* fixed downtime start */
- Downtime::OnDowntimeStarted.connect(boost::bind(&Checkable::NotifyFixedDowntimeStart, _1));
+ Downtime::OnDowntimeStarted.connect(std::bind(&Checkable::NotifyFixedDowntimeStart, _1));
/* flexible downtime start */
- Downtime::OnDowntimeTriggered.connect(boost::bind(&Checkable::NotifyFlexibleDowntimeStart, _1));
+ Downtime::OnDowntimeTriggered.connect(std::bind(&Checkable::NotifyFlexibleDowntimeStart, _1));
/* fixed/flexible downtime end */
- Downtime::OnDowntimeRemoved.connect(boost::bind(&Checkable::NotifyDowntimeEnd, _1));
+ Downtime::OnDowntimeRemoved.connect(std::bind(&Checkable::NotifyDowntimeEnd, _1));
}
-Checkable::Checkable(void)
- : m_CheckRunning(false)
+Checkable::Checkable()
{
SetSchedulingOffset(Utility::Random());
}
-void Checkable::OnAllConfigLoaded(void)
+void Checkable::OnAllConfigLoaded()
{
ObjectImpl<Checkable>::OnAllConfigLoaded();
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) {
- BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("command_endpoint"),
- "Command endpoint must be in zone '" + checkableZone->GetName() + "' or in a direct child zone thereof."));
+ 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 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);
}
boost::mutex::scoped_lock lock(m_CheckableMutex);
Array::Ptr groups;
- Host *host = dynamic_cast<Host *>(this);
+ auto *host = dynamic_cast<Host *>(this);
if (host)
groups = host->GetGroups();
groups->Add(name);
}
-AcknowledgementType Checkable::GetAcknowledgement(void)
+AcknowledgementType Checkable::GetAcknowledgement()
{
- AcknowledgementType avalue = static_cast<AcknowledgementType>(GetAcknowledgementRaw());
+ auto avalue = static_cast<AcknowledgementType>(GetAcknowledgementRaw());
if (avalue != AcknowledgementNone) {
double expiry = GetAcknowledgementExpiry();
return avalue;
}
-bool Checkable::IsAcknowledged(void) const
+bool Checkable::IsAcknowledged() const
{
return const_cast<Checkable *>(this)->GetAcknowledgement() != AcknowledgementNone;
}
SetAcknowledgementExpiry(expiry);
if (notify && !IsPaused())
- OnNotificationsRequested(this, NotificationAcknowledgement, GetLastCheckResult(), author, comment, MessageOrigin::Ptr());
+ OnNotificationsRequested(this, NotificationAcknowledgement, GetLastCheckResult(), author, comment, nullptr);
OnAcknowledgementSet(this, author, comment, type, notify, persistent, expiry, origin);
}
OnAcknowledgementCleared(this, origin);
}
-Endpoint::Ptr Checkable::GetCommandEndpoint(void) const
+Endpoint::Ptr Checkable::GetCommandEndpoint() const
{
return Endpoint::GetByName(GetCommandEndpointRaw());
}
-int Checkable::GetSeverity(void) const
+int Checkable::GetSeverity() const
{
/* overridden in Host/Service class. */
return 0;
Checkable::Ptr checkable = downtime->GetCheckable();
if (!checkable->IsPaused())
- OnNotificationsRequested(checkable, NotificationDowntimeStart, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), MessageOrigin::Ptr());
+ OnNotificationsRequested(checkable, NotificationDowntimeStart, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), nullptr);
}
void Checkable::NotifyDowntimeEnd(const Downtime::Ptr& downtime)
Checkable::Ptr checkable = downtime->GetCheckable();
if (!checkable->IsPaused())
- OnNotificationsRequested(checkable, NotificationDowntimeEnd, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), MessageOrigin::Ptr());
+ OnNotificationsRequested(checkable, NotificationDowntimeEnd, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), nullptr);
+}
+
+void Checkable::ValidateCheckInterval(const Lazy<double>& lvalue, const ValidationUtils& utils)
+{
+ ObjectImpl<Checkable>::ValidateCheckInterval(lvalue, utils);
+
+ if (lvalue() <= 0)
+ BOOST_THROW_EXCEPTION(ValidationError(this, { "check_interval" }, "Interval must be greater than 0."));
}
-void Checkable::ValidateCheckInterval(double value, const ValidationUtils& utils)
+void Checkable::ValidateRetryInterval(const Lazy<double>& lvalue, const ValidationUtils& utils)
{
- ObjectImpl<Checkable>::ValidateCheckInterval(value, utils);
+ ObjectImpl<Checkable>::ValidateRetryInterval(lvalue, utils);
- if (value <= 0)
- BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("check_interval"), "Interval must be greater than 0."));
+ if (lvalue() <= 0)
+ BOOST_THROW_EXCEPTION(ValidationError(this, { "retry_interval" }, "Interval must be greater than 0."));
}
-void Checkable::ValidateMaxCheckAttempts(int value, const ValidationUtils& utils)
+void Checkable::ValidateMaxCheckAttempts(const Lazy<int>& lvalue, const ValidationUtils& utils)
{
- ObjectImpl<Checkable>::ValidateMaxCheckAttempts(value, utils);
+ ObjectImpl<Checkable>::ValidateMaxCheckAttempts(lvalue, utils);
- if (value <= 0)
- BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("max_check_attempts"), "Value must be greater than 0."));
+ if (lvalue() <= 0)
+ BOOST_THROW_EXCEPTION(ValidationError(this, { "max_check_attempts" }, "Value must be greater than 0."));
}