mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 07:34:15 +02:00
Use ExecuteCommand::ExecuteOverride also for ido check
This commit is contained in:
parent
df2b82f7fe
commit
80dc908fca
@ -20,7 +20,8 @@ REGISTER_FUNCTION_NONCONST(Internal, IdoCheck, &IdoCheckTask::ScriptFunc, "check
|
|||||||
void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
||||||
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
||||||
{
|
{
|
||||||
CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
|
ServiceState state;
|
||||||
|
CheckCommand::Ptr commandObj = CheckCommand::ExecuteOverride ? CheckCommand::ExecuteOverride : checkable->GetCheckCommand();
|
||||||
Value raw_command = commandObj->GetCommandLine();
|
Value raw_command = commandObj->GetCommandLine();
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
@ -28,6 +29,9 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
|
|||||||
tie(host, service) = GetHostService(checkable);
|
tie(host, service) = GetHostService(checkable);
|
||||||
|
|
||||||
MacroProcessor::ResolverList resolvers;
|
MacroProcessor::ResolverList resolvers;
|
||||||
|
if (MacroResolver::OverrideMacros)
|
||||||
|
resolvers.emplace_back("override", MacroResolver::OverrideMacros);
|
||||||
|
|
||||||
if (service)
|
if (service)
|
||||||
resolvers.emplace_back("service", service);
|
resolvers.emplace_back("service", service);
|
||||||
resolvers.emplace_back("host", host);
|
resolvers.emplace_back("host", host);
|
||||||
@ -61,25 +65,70 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (idoType.IsEmpty()) {
|
if (idoType.IsEmpty()) {
|
||||||
cr->SetOutput("Attribute 'ido_type' must be set.");
|
String output = "Attribute 'ido_type' must be set.";
|
||||||
cr->SetState(ServiceUnknown);
|
state = ServiceUnknown;
|
||||||
|
|
||||||
|
if (Checkable::ExecuteCommandProcessFinishedHandler) {
|
||||||
|
double now = Utility::GetTime();
|
||||||
|
ProcessResult pr;
|
||||||
|
pr.PID = -1;
|
||||||
|
pr.Output = output;
|
||||||
|
pr.ExecutionStart = now;
|
||||||
|
pr.ExecutionEnd = now;
|
||||||
|
pr.ExitStatus = state;
|
||||||
|
|
||||||
|
Checkable::ExecuteCommandProcessFinishedHandler(commandObj->GetName(), pr);
|
||||||
|
} else {
|
||||||
|
cr->SetState(state);
|
||||||
|
cr->SetOutput(output);
|
||||||
checkable->ProcessCheckResult(cr);
|
checkable->ProcessCheckResult(cr);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idoName.IsEmpty()) {
|
if (idoName.IsEmpty()) {
|
||||||
cr->SetOutput("Attribute 'ido_name' must be set.");
|
String output = "Attribute 'ido_name' must be set.";
|
||||||
cr->SetState(ServiceUnknown);
|
state = ServiceUnknown;
|
||||||
|
|
||||||
|
if (Checkable::ExecuteCommandProcessFinishedHandler) {
|
||||||
|
double now = Utility::GetTime();
|
||||||
|
ProcessResult pr;
|
||||||
|
pr.PID = -1;
|
||||||
|
pr.Output = output;
|
||||||
|
pr.ExecutionStart = now;
|
||||||
|
pr.ExecutionEnd = now;
|
||||||
|
pr.ExitStatus = state;
|
||||||
|
|
||||||
|
Checkable::ExecuteCommandProcessFinishedHandler(commandObj->GetName(), pr);
|
||||||
|
} else {
|
||||||
|
cr->SetState(state);
|
||||||
|
cr->SetOutput(output);
|
||||||
checkable->ProcessCheckResult(cr);
|
checkable->ProcessCheckResult(cr);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type::Ptr type = Type::GetByName(idoType);
|
Type::Ptr type = Type::GetByName(idoType);
|
||||||
|
|
||||||
if (!type || !DbConnection::TypeInstance->IsAssignableFrom(type)) {
|
if (!type || !DbConnection::TypeInstance->IsAssignableFrom(type)) {
|
||||||
cr->SetOutput("DB IDO type '" + idoType + "' is invalid.");
|
String output = "DB IDO type '" + idoType + "' is invalid.";
|
||||||
cr->SetState(ServiceUnknown);
|
state = ServiceUnknown;
|
||||||
|
|
||||||
|
if (Checkable::ExecuteCommandProcessFinishedHandler) {
|
||||||
|
double now = Utility::GetTime();
|
||||||
|
ProcessResult pr;
|
||||||
|
pr.PID = -1;
|
||||||
|
pr.Output = output;
|
||||||
|
pr.ExecutionStart = now;
|
||||||
|
pr.ExecutionEnd = now;
|
||||||
|
pr.ExitStatus = state;
|
||||||
|
|
||||||
|
Checkable::ExecuteCommandProcessFinishedHandler(commandObj->GetName(), pr);
|
||||||
|
} else {
|
||||||
|
cr->SetState(state);
|
||||||
|
cr->SetOutput(output);
|
||||||
checkable->ProcessCheckResult(cr);
|
checkable->ProcessCheckResult(cr);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,34 +138,78 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
|
|||||||
DbConnection::Ptr conn = static_pointer_cast<DbConnection>(dtype->GetObject(idoName));
|
DbConnection::Ptr conn = static_pointer_cast<DbConnection>(dtype->GetObject(idoName));
|
||||||
|
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
cr->SetOutput("DB IDO connection '" + idoName + "' does not exist.");
|
String output = "DB IDO connection '" + idoName + "' does not exist.";
|
||||||
cr->SetState(ServiceUnknown);
|
state = ServiceUnknown;
|
||||||
|
|
||||||
|
if (Checkable::ExecuteCommandProcessFinishedHandler) {
|
||||||
|
double now = Utility::GetTime();
|
||||||
|
ProcessResult pr;
|
||||||
|
pr.PID = -1;
|
||||||
|
pr.Output = output;
|
||||||
|
pr.ExecutionStart = now;
|
||||||
|
pr.ExecutionEnd = now;
|
||||||
|
pr.ExitStatus = state;
|
||||||
|
|
||||||
|
Checkable::ExecuteCommandProcessFinishedHandler(commandObj->GetName(), pr);
|
||||||
|
} else {
|
||||||
|
cr->SetState(state);
|
||||||
|
cr->SetOutput(output);
|
||||||
checkable->ProcessCheckResult(cr);
|
checkable->ProcessCheckResult(cr);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double qps = conn->GetQueryCount(60) / 60.0;
|
double qps = conn->GetQueryCount(60) / 60.0;
|
||||||
|
|
||||||
if (conn->IsPaused()) {
|
if (conn->IsPaused()) {
|
||||||
cr->SetOutput("DB IDO connection is temporarily disabled on this cluster instance.");
|
String output = "DB IDO connection is temporarily disabled on this cluster instance.";
|
||||||
cr->SetState(ServiceOK);
|
state = ServiceOK;
|
||||||
|
|
||||||
|
if (Checkable::ExecuteCommandProcessFinishedHandler) {
|
||||||
|
double now = Utility::GetTime();
|
||||||
|
ProcessResult pr;
|
||||||
|
pr.PID = -1;
|
||||||
|
pr.Output = output;
|
||||||
|
pr.ExecutionStart = now;
|
||||||
|
pr.ExecutionEnd = now;
|
||||||
|
pr.ExitStatus = state;
|
||||||
|
|
||||||
|
Checkable::ExecuteCommandProcessFinishedHandler(commandObj->GetName(), pr);
|
||||||
|
} else {
|
||||||
|
cr->SetState(state);
|
||||||
|
cr->SetOutput(output);
|
||||||
checkable->ProcessCheckResult(cr);
|
checkable->ProcessCheckResult(cr);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double pendingQueries = conn->GetPendingQueryCount();
|
double pendingQueries = conn->GetPendingQueryCount();
|
||||||
|
|
||||||
if (!conn->GetConnected()) {
|
if (!conn->GetConnected()) {
|
||||||
|
String output;
|
||||||
if (conn->GetShouldConnect()) {
|
if (conn->GetShouldConnect()) {
|
||||||
cr->SetOutput("Could not connect to the database server.");
|
output ="Could not connect to the database server.";
|
||||||
cr->SetState(ServiceCritical);
|
state = ServiceCritical;
|
||||||
} else {
|
} else {
|
||||||
cr->SetOutput("Not currently enabled: Another cluster instance is responsible for the IDO database.");
|
output = "Not currently enabled: Another cluster instance is responsible for the IDO database.";
|
||||||
cr->SetState(ServiceOK);
|
state = ServiceOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkable->ProcessCheckResult(cr);
|
if (Checkable::ExecuteCommandProcessFinishedHandler) {
|
||||||
|
double now = Utility::GetTime();
|
||||||
|
ProcessResult pr;
|
||||||
|
pr.PID = -1;
|
||||||
|
pr.Output = output;
|
||||||
|
pr.ExecutionStart = now;
|
||||||
|
pr.ExecutionEnd = now;
|
||||||
|
pr.ExitStatus = state;
|
||||||
|
|
||||||
|
Checkable::ExecuteCommandProcessFinishedHandler(commandObj->GetName(), pr);
|
||||||
|
} else {
|
||||||
|
cr->SetState(state);
|
||||||
|
cr->SetOutput(output);
|
||||||
|
checkable->ProcessCheckResult(cr);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,13 +223,13 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
|
|||||||
<< " Queries per second: " << std::fixed << std::setprecision(3) << qps
|
<< " Queries per second: " << std::fixed << std::setprecision(3) << qps
|
||||||
<< " Pending queries: " << std::fixed << std::setprecision(3) << pendingQueries << ".";
|
<< " Pending queries: " << std::fixed << std::setprecision(3) << pendingQueries << ".";
|
||||||
|
|
||||||
cr->SetState(ServiceWarning);
|
state = ServiceWarning;
|
||||||
} else {
|
} else {
|
||||||
msgbuf << "Connected to the database server (Schema version: '" << schema_version << "')."
|
msgbuf << "Connected to the database server (Schema version: '" << schema_version << "')."
|
||||||
<< " Queries per second: " << std::fixed << std::setprecision(3) << qps
|
<< " Queries per second: " << std::fixed << std::setprecision(3) << qps
|
||||||
<< " Pending queries: " << std::fixed << std::setprecision(3) << pendingQueries << ".";
|
<< " Pending queries: " << std::fixed << std::setprecision(3) << pendingQueries << ".";
|
||||||
|
|
||||||
cr->SetState(ServiceOK);
|
state = ServiceOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conn->GetEnableHa()) {
|
if (conn->GetEnableHa()) {
|
||||||
@ -149,26 +242,40 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
|
|||||||
if (missingQueriesCritical.IsEmpty() && qps < queriesCritical) {
|
if (missingQueriesCritical.IsEmpty() && qps < queriesCritical) {
|
||||||
msgbuf << " " << qps << " queries/s lower than critical threshold (" << queriesCritical << " queries/s).";
|
msgbuf << " " << qps << " queries/s lower than critical threshold (" << queriesCritical << " queries/s).";
|
||||||
|
|
||||||
cr->SetState(ServiceCritical);
|
state= ServiceCritical;
|
||||||
} else if (missingQueriesWarning.IsEmpty() && qps < queriesWarning) {
|
} else if (missingQueriesWarning.IsEmpty() && qps < queriesWarning) {
|
||||||
msgbuf << " " << qps << " queries/s lower than warning threshold (" << queriesWarning << " queries/s).";
|
msgbuf << " " << qps << " queries/s lower than warning threshold (" << queriesWarning << " queries/s).";
|
||||||
|
|
||||||
cr->SetState(ServiceWarning);
|
state = ServiceWarning;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (missingPendingQueriesCritical.IsEmpty() && pendingQueries > pendingQueriesCritical) {
|
if (missingPendingQueriesCritical.IsEmpty() && pendingQueries > pendingQueriesCritical) {
|
||||||
msgbuf << " " << pendingQueries << " pending queries greater than critical threshold ("
|
msgbuf << " " << pendingQueries << " pending queries greater than critical threshold ("
|
||||||
<< pendingQueriesCritical << " queries).";
|
<< pendingQueriesCritical << " queries).";
|
||||||
|
|
||||||
cr->SetState(ServiceCritical);
|
state = ServiceCritical;
|
||||||
} else if (missingPendingQueriesWarning.IsEmpty() && pendingQueries > pendingQueriesWarning) {
|
} else if (missingPendingQueriesWarning.IsEmpty() && pendingQueries > pendingQueriesWarning) {
|
||||||
msgbuf << " " << pendingQueries << " pending queries greater than warning threshold ("
|
msgbuf << " " << pendingQueries << " pending queries greater than warning threshold ("
|
||||||
<< pendingQueriesWarning << " queries).";
|
<< pendingQueriesWarning << " queries).";
|
||||||
|
|
||||||
cr->SetState(ServiceWarning);
|
state = ServiceWarning;
|
||||||
}
|
}
|
||||||
|
|
||||||
cr->SetOutput(msgbuf.str());
|
String output = msgbuf.str();
|
||||||
|
|
||||||
|
if (Checkable::ExecuteCommandProcessFinishedHandler) {
|
||||||
|
double now = Utility::GetTime();
|
||||||
|
ProcessResult pr;
|
||||||
|
pr.PID = -1;
|
||||||
|
pr.Output = output;
|
||||||
|
pr.ExecutionStart = now;
|
||||||
|
pr.ExecutionEnd = now;
|
||||||
|
pr.ExitStatus = state;
|
||||||
|
|
||||||
|
Checkable::ExecuteCommandProcessFinishedHandler(commandObj->GetName(), pr);
|
||||||
|
} else {
|
||||||
|
cr->SetState(state);
|
||||||
|
cr->SetOutput(output);
|
||||||
|
|
||||||
cr->SetPerformanceData(new Array({
|
cr->SetPerformanceData(new Array({
|
||||||
{ new PerfdataValue("queries", qps, false, "", queriesWarning, queriesCritical) },
|
{ new PerfdataValue("queries", qps, false, "", queriesWarning, queriesCritical) },
|
||||||
@ -179,4 +286,5 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
checkable->ProcessCheckResult(cr);
|
checkable->ProcessCheckResult(cr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user