From f282126bb4af4a933a343613951bf84a42c67b80 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 15 May 2017 10:14:19 +0200 Subject: [PATCH] Don't allow acknowledgement expire timestamps in the past fixes #5250 --- lib/icinga/apiactions.cpp | 7 +++++-- lib/icinga/externalcommandprocessor.cpp | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index dacd8fc71..d488cd599 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -203,9 +203,12 @@ Dictionary::Ptr ApiActions::AcknowledgeProblem(const ConfigObject::Ptr& object, notify = HttpUtility::GetLastParameter(params, "notify"); if (params->Contains("persistent")) persistent = HttpUtility::GetLastParameter(params, "persistent"); - if (params->Contains("expiry")) + if (params->Contains("expiry")) { timestamp = HttpUtility::GetLastParameter(params, "expiry"); - else + + if (timestamp <= Utility::GetTime()) + return ApiActions::CreateResult(409, "Acknowledgement 'expiry' timestamp must be in the future for object " + checkable->GetName()); + } else timestamp = 0; Host::Ptr host; diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index a7d97ad01..04977924f 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -653,6 +653,9 @@ void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const std::ve if (service->GetState() == ServiceOK) BOOST_THROW_EXCEPTION(std::invalid_argument("The service '" + arguments[1] + "' is OK.")); + if (timestamp != 0 && timestamp <= Utility::GetTime()) + BOOST_THROW_EXCEPTION(std::invalid_argument("Acknowledgement expire time must be in the future for service '" + arguments[1] + "' on host '" + arguments[0] + "'")); + Log(LogNotice, "ExternalCommandProcessor") << "Setting timed acknowledgement for service '" << service->GetName() << "'" << (notify ? "" : ". Disabled notification"); @@ -717,6 +720,9 @@ void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const std::v if (host->GetState() == HostUp) BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK.")); + if (timestamp != 0 && timestamp <= Utility::GetTime()) + BOOST_THROW_EXCEPTION(std::invalid_argument("Acknowledgement expire time must be in the future for host '" + arguments[0] + "'")); + Comment::AddComment(host, CommentAcknowledgement, arguments[5], arguments[6], persistent, timestamp); host->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, persistent, timestamp); }