]> granicus.if.org Git - icinga2/commitdiff
Implement validator for the check_interval attribute
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 5 Dec 2014 11:59:57 +0000 (12:59 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 5 Dec 2014 12:00:41 +0000 (13:00 +0100)
fixes #7591

lib/icinga/checkable.cpp
lib/icinga/checkable.hpp
lib/icinga/icinga-type.conf

index 737b5e1f10da492c9a00aad90c2a1d0eb220c0db..c8f65ea9b9088168a488ea867d8d26045203eb91 100644 (file)
  ******************************************************************************/
 
 #include "icinga/checkable.hpp"
+#include "config/configcompilercontext.hpp"
 #include "base/objectlock.hpp"
 #include "base/utility.hpp"
+#include "base/scriptfunction.hpp"
 #include <boost/foreach.hpp>
 #include <boost/bind/apply.hpp>
 
 using namespace icinga;
 
 REGISTER_TYPE(Checkable);
+REGISTER_SCRIPTFUNCTION(ValidateCheckableCheckInterval, &Checkable::ValidateCheckInterval);
 
 boost::signals2::signal<void (const Checkable::Ptr&, bool, const MessageOrigin&)> Checkable::OnEnablePerfdataChanged;
 boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType, double, const MessageOrigin&)> Checkable::OnAcknowledgementSet;
@@ -263,3 +266,11 @@ Endpoint::Ptr Checkable::GetCommandEndpoint(void) const
 {
        return Endpoint::GetByName(GetCommandEndpointRaw());
 }
+
+void Checkable::ValidateCheckInterval(const String& location, const Checkable::Ptr& object)
+{
+       if (object->GetCheckInterval() <= 0) {
+               ConfigCompilerContext::GetInstance()->AddMessage(true, "Validation failed for " +
+                   location + ": check_interval must be greater than 0.");
+       }
+}
index 5f414539cef0e8f1d3e27d56459f31efa36b387d..9ea2bb10441894ee9235c58220940b34fa7d4c60 100644 (file)
@@ -276,6 +276,8 @@ public:
        void RemoveReverseDependency(const intrusive_ptr<Dependency>& dep);
        std::set<intrusive_ptr<Dependency> > GetReverseDependencies(void) const;
 
+       static void ValidateCheckInterval(const String& location, const Checkable::Ptr& object);
+
 protected:
        virtual void Start(void);
 
index 12e5945f208702ffba5a633cea55a7743c7ea325..948f4dc7d6a5d7d28e9414d68086172ec75cf69a 100644 (file)
@@ -26,6 +26,8 @@
 }
 
 %type Checkable {
+       %validator "ValidateCheckableCheckInterval",
+
        %attribute %string "display_name",
 
        %require "check_command",