| 55 | } |
| 56 | |
| 57 | Dictionary::Ptr ApiActions::ProcessCheckResult( |
| 58 | const ConfigObject::Ptr& object, |
| 59 | const ApiUser::Ptr&, |
| 60 | const Dictionary::Ptr& params |
| 61 | ) |
| 62 | { |
| 63 | using Result = Checkable::ProcessingResult; |
| 64 | |
| 65 | Checkable::Ptr checkable = static_pointer_cast<Checkable>(object); |
| 66 | |
| 67 | if (!checkable) |
| 68 | return ApiActions::CreateResult(404, |
| 69 | "Cannot process passive check result for non-existent object."); |
| 70 | |
| 71 | if (!checkable->GetEnablePassiveChecks()) |
| 72 | return ApiActions::CreateResult(403, "Passive checks are disabled for object '" + checkable->GetName() + "'."); |
| 73 | |
| 74 | if (!checkable->IsReachable(DependencyCheckExecution)) |
| 75 | return ApiActions::CreateResult(200, "Ignoring passive check result for unreachable object '" + checkable->GetName() + "'."); |
| 76 | |
| 77 | Host::Ptr host; |
| 78 | Service::Ptr service; |
| 79 | tie(host, service) = GetHostService(checkable); |
| 80 | |
| 81 | if (!params->Contains("exit_status")) |
| 82 | return ApiActions::CreateResult(400, "Parameter 'exit_status' is required."); |
| 83 | |
| 84 | int exitStatus = HttpUtility::GetLastParameter(params, "exit_status"); |
| 85 | |
| 86 | ServiceState state; |
| 87 | |
| 88 | if (!service) { |
| 89 | if (exitStatus == 0) |
| 90 | state = ServiceOK; |
| 91 | else if (exitStatus == 1) |
| 92 | state = ServiceCritical; |
| 93 | else |
| 94 | return ApiActions::CreateResult(400, "Invalid 'exit_status' for Host " |
| 95 | + checkable->GetName() + "."); |
| 96 | } else { |
| 97 | state = PluginUtility::ExitStatusToState(exitStatus); |
| 98 | } |
| 99 | |
| 100 | if (!params->Contains("plugin_output")) |
| 101 | return ApiActions::CreateResult(400, "Parameter 'plugin_output' is required"); |
| 102 | |
| 103 | CheckResult::Ptr cr = new CheckResult(); |
| 104 | cr->SetOutput(HttpUtility::GetLastParameter(params, "plugin_output")); |
| 105 | cr->SetState(state); |
| 106 | |
| 107 | if (params->Contains("execution_start")) |
| 108 | cr->SetExecutionStart(HttpUtility::GetLastParameter(params, "execution_start")); |
| 109 | |
| 110 | if (params->Contains("execution_end")) |
| 111 | cr->SetExecutionEnd(HttpUtility::GetLastParameter(params, "execution_end")); |
| 112 | |
| 113 | cr->SetCheckSource(HttpUtility::GetLastParameter(params, "check_source")); |
| 114 | cr->SetSchedulingSource(HttpUtility::GetLastParameter(params, "scheduling_source")); |
no test coverage detected