| 21 | REGISTER_FUNCTION_NONCONST(Internal, ClusterCheck, &ClusterCheckTask::ScriptFunc, "checkable:cr:producer:resolvedMacros:useResolvedMacros"); |
| 22 | |
| 23 | void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, |
| 24 | const WaitGroup::Ptr& producer, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) |
| 25 | { |
| 26 | REQUIRE_NOT_NULL(checkable); |
| 27 | REQUIRE_NOT_NULL(cr); |
| 28 | |
| 29 | if (resolvedMacros && !useResolvedMacros) |
| 30 | return; |
| 31 | |
| 32 | CheckCommand::Ptr command = CheckCommand::ExecuteOverride ? CheckCommand::ExecuteOverride : checkable->GetCheckCommand(); |
| 33 | String commandName = command->GetName(); |
| 34 | |
| 35 | ApiListener::Ptr listener = ApiListener::GetInstance(); |
| 36 | if (!listener) { |
| 37 | String output = "No API listener is configured for this instance."; |
| 38 | |
| 39 | if (Checkable::ExecuteCommandProcessFinishedHandler) { |
| 40 | double now = Utility::GetTime(); |
| 41 | ProcessResult pr; |
| 42 | pr.PID = -1; |
| 43 | pr.ExecutionStart = now; |
| 44 | pr.ExecutionEnd = now; |
| 45 | pr.ExitStatus = 126; |
| 46 | pr.Output = output; |
| 47 | Checkable::ExecuteCommandProcessFinishedHandler(commandName, pr); |
| 48 | } else { |
| 49 | cr->SetOutput(output); |
| 50 | cr->SetState(ServiceUnknown); |
| 51 | checkable->ProcessCheckResult(cr, producer); |
| 52 | } |
| 53 | |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | std::pair<Dictionary::Ptr, Dictionary::Ptr> stats = listener->GetStatus(); |
| 58 | Dictionary::Ptr status = stats.first; |
| 59 | int numConnEndpoints = status->Get("num_conn_endpoints"); |
| 60 | int numNotConnEndpoints = status->Get("num_not_conn_endpoints"); |
| 61 | |
| 62 | ServiceState state; |
| 63 | String output = "Icinga 2 Cluster"; |
| 64 | |
| 65 | if (numNotConnEndpoints > 0) { |
| 66 | output += " Problem: " + Convert::ToString(numNotConnEndpoints) + " endpoints are not connected."; |
| 67 | output += "\n(" + FormatArray(status->Get("not_conn_endpoints")) + ")"; |
| 68 | |
| 69 | state = ServiceCritical; |
| 70 | } else { |
| 71 | output += " OK: " + Convert::ToString(numConnEndpoints) + " endpoints are connected."; |
| 72 | output += "\n(" + FormatArray(status->Get("conn_endpoints")) + ")"; |
| 73 | |
| 74 | state = ServiceOK; |
| 75 | } |
| 76 | |
| 77 | if (Checkable::ExecuteCommandProcessFinishedHandler) { |
| 78 | double now = Utility::GetTime(); |
| 79 | ProcessResult pr; |
| 80 | pr.PID = -1; |
nothing calls this directly
no test coverage detected