Skip to content

Commit 54f89c0

Browse files
committed
Require to pass CheckResultProducer::Ptr to several methods
Namely: ClusterCheckTask::ScriptFunc() ClusterZoneCheckTask::ScriptFunc() DummyCheckTask::ScriptFunc() ExceptionCheckTask::ScriptFunc() IcingaCheckTask::ScriptFunc() IfwApiCheckTask::ScriptFunc() NullCheckTask::ScriptFunc() PluginCheckTask::ScriptFunc() RandomCheckTask::ScriptFunc() SleepCheckTask::ScriptFunc() IdoCheckTask::ScriptFunc() IcingadbCheck::ScriptFunc() CheckCommand#Execute() Checkable#ExecuteCheck() ClusterEvents::ExecuteCheckFromQueue() ExternalCommandProcessor::Process*CheckResult() ExternalCommandCallback ExternalCommandProcessor::Execute() ExternalCommandProcessor::ExecuteFromFile() ExternalCommandProcessor::ProcessFile() LivestatusQuery#ExecuteCommandHelper() LivestatusQuery#Execute()
1 parent c124f4b commit 54f89c0

37 files changed

+131
-113
lines changed

lib/checker/checkercomponent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void CheckerComponent::CheckThreadProc()
232232
void CheckerComponent::ExecuteCheckHelper(const Checkable::Ptr& checkable)
233233
{
234234
try {
235-
checkable->ExecuteCheck();
235+
checkable->ExecuteCheck(this);
236236
} catch (const std::exception& ex) {
237237
CheckResult::Ptr cr = new CheckResult();
238238
cr->SetState(ServiceUnknown);

lib/compat/externalcommandlistener.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
139139
Log(LogInformation, "ExternalCommandListener")
140140
<< "Executing external command: " << command;
141141

142-
ExternalCommandProcessor::Execute(command);
142+
ExternalCommandProcessor::Execute(this, command);
143143
} catch (const std::exception& ex) {
144144
Log(LogWarning, "ExternalCommandListener")
145145
<< "External command failed: " << DiagnosticInformation(ex, false);

lib/db_ido/idochecktask.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
using namespace icinga;
1818

19-
REGISTER_FUNCTION_NONCONST(Internal, IdoCheck, &IdoCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
19+
REGISTER_FUNCTION_NONCONST(Internal, IdoCheck, &IdoCheckTask::ScriptFunc, "checkable:cr:producer:resolvedMacros:useResolvedMacros");
2020

2121
static void ReportIdoCheck(
22-
const Checkable::Ptr& checkable, const CheckCommand::Ptr& commandObj,
23-
const CheckResult::Ptr& cr, String output, ServiceState state = ServiceUnknown
22+
const Checkable::Ptr& checkable, const CheckCommand::Ptr& commandObj, const CheckResult::Ptr& cr,
23+
const CheckResultProducer::Ptr& producer, String output, ServiceState state = ServiceUnknown
2424
)
2525
{
2626
if (Checkable::ExecuteCommandProcessFinishedHandler) {
@@ -36,12 +36,12 @@ static void ReportIdoCheck(
3636
} else {
3737
cr->SetState(state);
3838
cr->SetOutput(output);
39-
checkable->ProcessCheckResult(cr);
39+
checkable->ProcessCheckResult(cr, producer);
4040
}
4141
}
4242

4343
void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
44-
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
44+
const CheckResultProducer::Ptr& producer, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
4545
{
4646
ServiceState state;
4747
CheckCommand::Ptr commandObj = CheckCommand::ExecuteOverride ? CheckCommand::ExecuteOverride : checkable->GetCheckCommand();
@@ -88,19 +88,19 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
8888
return;
8989

9090
if (idoType.IsEmpty()) {
91-
ReportIdoCheck(checkable, commandObj, cr, "Attribute 'ido_type' must be set.");
91+
ReportIdoCheck(checkable, commandObj, cr, producer, "Attribute 'ido_type' must be set.");
9292
return;
9393
}
9494

9595
if (idoName.IsEmpty()) {
96-
ReportIdoCheck(checkable, commandObj, cr, "Attribute 'ido_name' must be set.");
96+
ReportIdoCheck(checkable, commandObj, cr, producer, "Attribute 'ido_name' must be set.");
9797
return;
9898
}
9999

100100
Type::Ptr type = Type::GetByName(idoType);
101101

102102
if (!type || !DbConnection::TypeInstance->IsAssignableFrom(type)) {
103-
ReportIdoCheck(checkable, commandObj, cr, "DB IDO type '" + idoType + "' is invalid.");
103+
ReportIdoCheck(checkable, commandObj, cr, producer, "DB IDO type '" + idoType + "' is invalid.");
104104
return;
105105
}
106106

@@ -110,25 +110,25 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
110110
DbConnection::Ptr conn = static_pointer_cast<DbConnection>(dtype->GetObject(idoName));
111111

112112
if (!conn) {
113-
ReportIdoCheck(checkable, commandObj, cr, "DB IDO connection '" + idoName + "' does not exist.");
113+
ReportIdoCheck(checkable, commandObj, cr, producer, "DB IDO connection '" + idoName + "' does not exist.");
114114
return;
115115
}
116116

117117
double qps = conn->GetQueryCount(60) / 60.0;
118118

119119
if (conn->IsPaused()) {
120-
ReportIdoCheck(checkable, commandObj, cr, "DB IDO connection is temporarily disabled on this cluster instance.", ServiceOK);
120+
ReportIdoCheck(checkable, commandObj, cr, producer, "DB IDO connection is temporarily disabled on this cluster instance.", ServiceOK);
121121
return;
122122
}
123123

124124
double pendingQueries = conn->GetPendingQueryCount();
125125

126126
if (!conn->GetConnected()) {
127127
if (conn->GetShouldConnect()) {
128-
ReportIdoCheck(checkable, commandObj, cr, "Could not connect to the database server.", ServiceCritical);
128+
ReportIdoCheck(checkable, commandObj, cr, producer, "Could not connect to the database server.", ServiceCritical);
129129
} else {
130130
ReportIdoCheck(
131-
checkable, commandObj, cr,
131+
checkable, commandObj, cr, producer,
132132
"Not currently enabled: Another cluster instance is responsible for the IDO database.", ServiceOK
133133
);
134134
}
@@ -193,5 +193,5 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult
193193
{ new PerfdataValue("pending_queries", pendingQueries, false, "", pendingQueriesWarning, pendingQueriesCritical) }
194194
}));
195195

196-
ReportIdoCheck(checkable, commandObj, cr, msgbuf.str(), state);
196+
ReportIdoCheck(checkable, commandObj, cr, producer, msgbuf.str(), state);
197197
}

lib/db_ido/idochecktask.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class IdoCheckTask
1818
{
1919
public:
2020
static void ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr,
21-
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros);
21+
const CheckResultProducer::Ptr& producer, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros);
2222

2323
private:
2424
IdoCheckTask();

lib/icinga/apiactions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
790790
Defer resetCheckCommandOverride([]() {
791791
CheckCommand::ExecuteOverride = nullptr;
792792
});
793-
cmd->Execute(checkable, cr, execMacros, false);
793+
cmd->Execute(checkable, cr, listener, execMacros, false);
794794
}
795795
} else if (command_type == "EventCommand") {
796796
EventCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions(EventCommand::GetTypeName(), resolved_command, ActionsHandler::AuthenticatedApiUser);

lib/icinga/checkable-check.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
551551
return Result::Ok;
552552
}
553553

554-
void Checkable::ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros)
554+
void Checkable::ExecuteRemoteCheck(const CheckResultProducer::Ptr& producer, const Dictionary::Ptr& resolvedMacros)
555555
{
556556
CONTEXT("Executing remote check for object '" << GetName() << "'");
557557

@@ -562,10 +562,10 @@ void Checkable::ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros)
562562
cr->SetScheduleStart(scheduled_start);
563563
cr->SetExecutionStart(before_check);
564564

565-
GetCheckCommand()->Execute(this, cr, resolvedMacros, true);
565+
GetCheckCommand()->Execute(this, cr, producer, resolvedMacros, true);
566566
}
567567

568-
void Checkable::ExecuteCheck()
568+
void Checkable::ExecuteCheck(const CheckResultProducer::Ptr& producer)
569569
{
570570
CONTEXT("Executing check for object '" << GetName() << "'");
571571

@@ -606,10 +606,10 @@ void Checkable::ExecuteCheck()
606606
bool local = !endpoint || endpoint == Endpoint::GetLocalEndpoint();
607607

608608
if (local) {
609-
GetCheckCommand()->Execute(this, cr, nullptr, false);
609+
GetCheckCommand()->Execute(this, cr, producer, nullptr, false);
610610
} else {
611611
Dictionary::Ptr macros = new Dictionary();
612-
GetCheckCommand()->Execute(this, cr, macros, false);
612+
GetCheckCommand()->Execute(this, cr, producer, macros, false);
613613

614614
if (endpoint->GetConnected()) {
615615
/* perform check on remote endpoint */
@@ -670,7 +670,7 @@ void Checkable::ExecuteCheck()
670670

671671
cr->SetOutput(output);
672672

673-
ProcessCheckResult(cr);
673+
ProcessCheckResult(cr, producer);
674674
}
675675

676676
{

lib/icinga/checkable.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ class Checkable : public ObjectImpl<Checkable>
111111

112112
static void UpdateStatistics(const CheckResult::Ptr& cr, CheckableType type);
113113

114-
void ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros = nullptr);
115-
void ExecuteCheck();
114+
void ExecuteRemoteCheck(const CheckResultProducer::Ptr& producer, const Dictionary::Ptr& resolvedMacros = nullptr);
115+
void ExecuteCheck(const CheckResultProducer::Ptr& producer);
116+
116117
enum class ProcessingResult
117118
{
118119
Ok,

lib/icinga/checkcommand.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ REGISTER_TYPE(CheckCommand);
1111
thread_local CheckCommand::Ptr CheckCommand::ExecuteOverride;
1212

1313
void CheckCommand::Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
14-
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
14+
const CheckResultProducer::Ptr& producer, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
1515
{
1616
GetExecute()->Invoke({
1717
checkable,
1818
cr,
19+
producer,
1920
resolvedMacros,
2021
useResolvedMacros
2122
});

lib/icinga/checkcommand.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class CheckCommand final : public ObjectImpl<CheckCommand>
2323
static thread_local CheckCommand::Ptr ExecuteOverride;
2424

2525
void Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
26+
const CheckResultProducer::Ptr& producer,
2627
const Dictionary::Ptr& resolvedMacros = nullptr,
2728
bool useResolvedMacros = false);
2829
};

lib/icinga/clusterevents-check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ void ClusterEvents::ExecuteCheckFromQueue(const MessageOrigin::Ptr& origin, cons
279279

280280
if (command_type == "check_command") {
281281
try {
282-
host->ExecuteRemoteCheck(macros);
282+
host->ExecuteRemoteCheck(ApiListener::GetInstance(), macros);
283283
} catch (const std::exception& ex) {
284284
String output = "Exception occurred while checking '" + host->GetName() + "': " + DiagnosticInformation(ex);
285285
ServiceState state = ServiceUnknown;

0 commit comments

Comments
 (0)