Implement validator for the check_interval attribute

fixes #7591
This commit is contained in:
Gunnar Beutner 2014-12-05 12:59:57 +01:00
parent cc8fe684fe
commit ec99efbc28
3 changed files with 15 additions and 0 deletions

View File

@ -18,14 +18,17 @@
******************************************************************************/ ******************************************************************************/
#include "icinga/checkable.hpp" #include "icinga/checkable.hpp"
#include "config/configcompilercontext.hpp"
#include "base/objectlock.hpp" #include "base/objectlock.hpp"
#include "base/utility.hpp" #include "base/utility.hpp"
#include "base/scriptfunction.hpp"
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/bind/apply.hpp> #include <boost/bind/apply.hpp>
using namespace icinga; using namespace icinga;
REGISTER_TYPE(Checkable); 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&, bool, const MessageOrigin&)> Checkable::OnEnablePerfdataChanged;
boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType, double, const MessageOrigin&)> Checkable::OnAcknowledgementSet; 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()); 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.");
}
}

View File

@ -276,6 +276,8 @@ public:
void RemoveReverseDependency(const intrusive_ptr<Dependency>& dep); void RemoveReverseDependency(const intrusive_ptr<Dependency>& dep);
std::set<intrusive_ptr<Dependency> > GetReverseDependencies(void) const; std::set<intrusive_ptr<Dependency> > GetReverseDependencies(void) const;
static void ValidateCheckInterval(const String& location, const Checkable::Ptr& object);
protected: protected:
virtual void Start(void); virtual void Start(void);

View File

@ -26,6 +26,8 @@
} }
%type Checkable { %type Checkable {
%validator "ValidateCheckableCheckInterval",
%attribute %string "display_name", %attribute %string "display_name",
%require "check_command", %require "check_command",