mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-29 16:44:29 +02:00
parent
0ad1ab20aa
commit
fa61711c21
@ -12,11 +12,34 @@
|
|||||||
#include "base/perfdatavalue.hpp"
|
#include "base/perfdatavalue.hpp"
|
||||||
#include "base/configtype.hpp"
|
#include "base/configtype.hpp"
|
||||||
#include "base/convert.hpp"
|
#include "base/convert.hpp"
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
REGISTER_FUNCTION_NONCONST(Internal, IdoCheck, &IdoCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
|
REGISTER_FUNCTION_NONCONST(Internal, IdoCheck, &IdoCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
|
||||||
|
|
||||||
|
static void ReportIdoCheck(
|
||||||
|
const Checkable::Ptr& checkable, const CheckCommand::Ptr& commandObj,
|
||||||
|
const CheckResult::Ptr& cr, String output, ServiceState state = ServiceUnknown
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (Checkable::ExecuteCommandProcessFinishedHandler) {
|
||||||
|
double now = Utility::GetTime();
|
||||||
|
ProcessResult pr;
|
||||||
|
pr.PID = -1;
|
||||||
|
pr.Output = std::move(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
@ -66,70 +89,19 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (idoType.IsEmpty()) {
|
if (idoType.IsEmpty()) {
|
||||||
String output = "Attribute 'ido_type' must be set.";
|
ReportIdoCheck(checkable, commandObj, cr, "Attribute 'ido_type' must be set.");
|
||||||
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);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idoName.IsEmpty()) {
|
if (idoName.IsEmpty()) {
|
||||||
String output = "Attribute 'ido_name' must be set.";
|
ReportIdoCheck(checkable, commandObj, cr, "Attribute 'ido_name' must be set.");
|
||||||
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);
|
|
||||||
}
|
|
||||||
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)) {
|
||||||
String output = "DB IDO type '" + idoType + "' is invalid.";
|
ReportIdoCheck(checkable, commandObj, cr, "DB IDO type '" + idoType + "' is invalid.");
|
||||||
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);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,77 +111,27 @@ 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) {
|
||||||
String output = "DB IDO connection '" + idoName + "' does not exist.";
|
ReportIdoCheck(checkable, commandObj, cr, "DB IDO connection '" + idoName + "' does not exist.");
|
||||||
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);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double qps = conn->GetQueryCount(60) / 60.0;
|
double qps = conn->GetQueryCount(60) / 60.0;
|
||||||
|
|
||||||
if (conn->IsPaused()) {
|
if (conn->IsPaused()) {
|
||||||
String output = "DB IDO connection is temporarily disabled on this cluster instance.";
|
ReportIdoCheck(checkable, commandObj, cr, "DB IDO connection is temporarily disabled on this cluster instance.", 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);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double pendingQueries = conn->GetPendingQueryCount();
|
double pendingQueries = conn->GetPendingQueryCount();
|
||||||
|
|
||||||
if (!conn->GetConnected()) {
|
if (!conn->GetConnected()) {
|
||||||
String output;
|
|
||||||
if (conn->GetShouldConnect()) {
|
if (conn->GetShouldConnect()) {
|
||||||
output ="Could not connect to the database server.";
|
ReportIdoCheck(checkable, commandObj, cr, "Could not connect to the database server.", ServiceCritical);
|
||||||
state = ServiceCritical;
|
|
||||||
} else {
|
} else {
|
||||||
output = "Not currently enabled: Another cluster instance is responsible for the IDO database.";
|
ReportIdoCheck(
|
||||||
state = ServiceOK;
|
checkable, commandObj, cr,
|
||||||
}
|
"Not currently enabled: Another cluster instance is responsible for the IDO database.", 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);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -262,30 +184,13 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
|
|||||||
state = ServiceWarning;
|
state = ServiceWarning;
|
||||||
}
|
}
|
||||||
|
|
||||||
String output = msgbuf.str();
|
cr->SetPerformanceData(new Array({
|
||||||
|
{ new PerfdataValue("queries", qps, false, "", queriesWarning, queriesCritical) },
|
||||||
|
{ new PerfdataValue("queries_1min", conn->GetQueryCount(60)) },
|
||||||
|
{ new PerfdataValue("queries_5mins", conn->GetQueryCount(5 * 60)) },
|
||||||
|
{ new PerfdataValue("queries_15mins", conn->GetQueryCount(15 * 60)) },
|
||||||
|
{ new PerfdataValue("pending_queries", pendingQueries, false, "", pendingQueriesWarning, pendingQueriesCritical) }
|
||||||
|
}));
|
||||||
|
|
||||||
if (Checkable::ExecuteCommandProcessFinishedHandler) {
|
ReportIdoCheck(checkable, commandObj, cr, msgbuf.str(), state);
|
||||||
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({
|
|
||||||
{ new PerfdataValue("queries", qps, false, "", queriesWarning, queriesCritical) },
|
|
||||||
{ new PerfdataValue("queries_1min", conn->GetQueryCount(60)) },
|
|
||||||
{ new PerfdataValue("queries_5mins", conn->GetQueryCount(5 * 60)) },
|
|
||||||
{ new PerfdataValue("queries_15mins", conn->GetQueryCount(15 * 60)) },
|
|
||||||
{ new PerfdataValue("pending_queries", pendingQueries, false, "", pendingQueriesWarning, pendingQueriesCritical) }
|
|
||||||
}));
|
|
||||||
|
|
||||||
checkable->ProcessCheckResult(cr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user