mirror of https://github.com/Icinga/icinga2.git
Improve validation for times.{begin,end} in notification objects
fixes #6939
This commit is contained in:
parent
aa88271d5a
commit
8ae206cd5d
|
@ -720,6 +720,35 @@ void Notification::ValidateTypes(const Lazy<Array::Ptr>& lvalue, const Validatio
|
||||||
BOOST_THROW_EXCEPTION(ValidationError(this, { "types" }, "Type filter is invalid."));
|
BOOST_THROW_EXCEPTION(ValidationError(this, { "types" }, "Type filter is invalid."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Notification::ValidateTimes(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils)
|
||||||
|
{
|
||||||
|
ObjectImpl<Notification>::ValidateTimes(lvalue, utils);
|
||||||
|
|
||||||
|
Dictionary::Ptr times = lvalue();
|
||||||
|
|
||||||
|
if (!times)
|
||||||
|
return;
|
||||||
|
|
||||||
|
double begin;
|
||||||
|
double end;
|
||||||
|
|
||||||
|
try {
|
||||||
|
begin = Convert::ToDouble(times->Get("begin"));
|
||||||
|
} catch (const std::exception&) {
|
||||||
|
BOOST_THROW_EXCEPTION(ValidationError(this, { "times" }, "'begin' is invalid, must be duration or number." ));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
end = Convert::ToDouble(times->Get("end"));
|
||||||
|
} catch (const std::exception&) {
|
||||||
|
BOOST_THROW_EXCEPTION(ValidationError(this, { "times" }, "'end' is invalid, must be duration or number." ));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Also solve logical errors where begin > end. */
|
||||||
|
if (begin > 0 && end > 0 && begin > end)
|
||||||
|
BOOST_THROW_EXCEPTION(ValidationError(this, { "times" }, "'begin' must be smaller than 'end'."));
|
||||||
|
}
|
||||||
|
|
||||||
Endpoint::Ptr Notification::GetCommandEndpoint() const
|
Endpoint::Ptr Notification::GetCommandEndpoint() const
|
||||||
{
|
{
|
||||||
return Endpoint::GetByName(GetCommandEndpointRaw());
|
return Endpoint::GetByName(GetCommandEndpointRaw());
|
||||||
|
|
|
@ -95,6 +95,7 @@ public:
|
||||||
|
|
||||||
void ValidateStates(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils) override;
|
void ValidateStates(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils) override;
|
||||||
void ValidateTypes(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils) override;
|
void ValidateTypes(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils) override;
|
||||||
|
void ValidateTimes(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils) override;
|
||||||
|
|
||||||
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
||||||
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
|
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
|
||||||
|
|
Loading…
Reference in New Issue