]> granicus.if.org Git - icinga2/blobdiff - lib/icinga/checkable.cpp
Merge pull request #6577 from Icinga/fix/setup-api-including-users-file
[icinga2] / lib / icinga / checkable.cpp
index 9b66eb2408818f58f6e5fa786738922d66fb96a5..c577848d59ed34ba93e08ec7be6e5d5f40a7f24b 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * 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                *
@@ -18,7 +18,7 @@
  ******************************************************************************/
 
 #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"
@@ -57,14 +57,16 @@ void 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) {
+                       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."));
                }
        }
 }
@@ -73,8 +75,11 @@ void Checkable::Start(bool runtimeCreated)
 {
        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);
 }
@@ -195,6 +200,14 @@ void Checkable::ValidateCheckInterval(const Lazy<double>& lvalue, const Validati
                BOOST_THROW_EXCEPTION(ValidationError(this, { "check_interval" }, "Interval must be greater than 0."));
 }
 
+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(lvalue, utils);