mirror of https://github.com/Icinga/icinga2.git
Merge pull request #9354 from WuerthPhoenix/feature/return-correct-status-in-process-check-result-api
Return correct status codes in process-check-result API
This commit is contained in:
commit
4184dcd62c
|
@ -55,6 +55,8 @@ Dictionary::Ptr ApiActions::CreateResult(int code, const String& status,
|
|||
Dictionary::Ptr ApiActions::ProcessCheckResult(const ConfigObject::Ptr& object,
|
||||
const Dictionary::Ptr& params)
|
||||
{
|
||||
using Result = Checkable::ProcessingResult;
|
||||
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
|
@ -123,9 +125,19 @@ Dictionary::Ptr ApiActions::ProcessCheckResult(const ConfigObject::Ptr& object,
|
|||
if (params->Contains("ttl"))
|
||||
cr->SetTtl(HttpUtility::GetLastParameter(params, "ttl"));
|
||||
|
||||
checkable->ProcessCheckResult(cr);
|
||||
Result result = checkable->ProcessCheckResult(cr);
|
||||
switch (result) {
|
||||
case Result::Ok:
|
||||
return ApiActions::CreateResult(200, "Successfully processed check result for object '" + checkable->GetName() + "'.");
|
||||
case Result::NoCheckResult:
|
||||
return ApiActions::CreateResult(400, "Could not process check result for object '" + checkable->GetName() + "' because no check result was passed.");
|
||||
case Result::CheckableInactive:
|
||||
return ApiActions::CreateResult(503, "Could not process check result for object '" + checkable->GetName() + "' because the object is inactive.");
|
||||
case Result::NewerCheckResultPresent:
|
||||
return ApiActions::CreateResult(409, "Newer check result already present. Check result for '" + checkable->GetName() + "' was discarded.");
|
||||
}
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully processed check result for object '" + checkable->GetName() + "'.");
|
||||
return ApiActions::CreateResult(500, "Unexpected result (" + std::to_string(static_cast<int>(result)) + ") for object '" + checkable->GetName() + "'. Please submit a bug report at https://github.com/Icinga/icinga2");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::RescheduleCheck(const ConfigObject::Ptr& object,
|
||||
|
|
|
@ -94,15 +94,17 @@ double Checkable::GetLastCheck() const
|
|||
return schedule_end;
|
||||
}
|
||||
|
||||
void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin)
|
||||
Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin)
|
||||
{
|
||||
using Result = Checkable::ProcessingResult;
|
||||
|
||||
{
|
||||
ObjectLock olock(this);
|
||||
m_CheckRunning = false;
|
||||
}
|
||||
|
||||
if (!cr)
|
||||
return;
|
||||
return Result::NoCheckResult;
|
||||
|
||||
double now = Utility::GetTime();
|
||||
|
||||
|
@ -142,12 +144,12 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
|
|||
listener->SyncSendMessage(command_endpoint, message);
|
||||
}
|
||||
|
||||
return;
|
||||
return Result::Ok;
|
||||
|
||||
}
|
||||
|
||||
if (!IsActive())
|
||||
return;
|
||||
return Result::CheckableInactive;
|
||||
|
||||
bool reachable = IsReachable();
|
||||
bool notification_reachable = IsReachable(DependencyNotification);
|
||||
|
@ -184,7 +186,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
|
|||
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", newCRTimestamp) << " (" << newCRTimestamp
|
||||
<< "). It is in the past compared to ours at "
|
||||
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", currentCRTimestamp) << " (" << currentCRTimestamp << ").";
|
||||
return;
|
||||
return Result::NewerCheckResultPresent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -526,6 +528,8 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
|
|||
/* update reachability for child objects */
|
||||
if ((stateChange || hardChange) && !children.empty())
|
||||
OnReachabilityChanged(this, cr, children, origin);
|
||||
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
void Checkable::ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros)
|
||||
|
|
|
@ -111,7 +111,14 @@ public:
|
|||
|
||||
void ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros = nullptr);
|
||||
void ExecuteCheck();
|
||||
void ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin = nullptr);
|
||||
enum class ProcessingResult
|
||||
{
|
||||
Ok,
|
||||
NoCheckResult,
|
||||
CheckableInactive,
|
||||
NewerCheckResultPresent,
|
||||
};
|
||||
ProcessingResult ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin = nullptr);
|
||||
|
||||
Endpoint::Ptr GetCommandEndpoint() const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue