Skip to content

Commit d2dea14

Browse files
committed
Require to pass CheckResultProducer::Ptr to several methods
Namely: Checkable#ProcessCheckResult() 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 9fe94fa commit d2dea14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+237
-216
lines changed

lib/checker/checkercomponent.cpp

Lines changed: 2 additions & 2 deletions
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);
@@ -246,7 +246,7 @@ void CheckerComponent::ExecuteCheckHelper(const Checkable::Ptr& checkable)
246246
cr->SetExecutionStart(now);
247247
cr->SetExecutionEnd(now);
248248

249-
checkable->ProcessCheckResult(cr);
249+
checkable->ProcessCheckResult(cr, this);
250250

251251
Log(LogCritical, "checker", output);
252252
}

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ Dictionary::Ptr ApiActions::ProcessCheckResult(const ConfigObject::Ptr& object,
126126
if (params->Contains("ttl"))
127127
cr->SetTtl(HttpUtility::GetLastParameter(params, "ttl"));
128128

129-
Result result = checkable->ProcessCheckResult(cr);
129+
Result result = checkable->ProcessCheckResult(cr, ApiListener::GetInstance());
130+
130131
switch (result) {
131132
case Result::Ok:
132133
return ApiActions::CreateResult(200, "Successfully processed check result for object '" + checkable->GetName() + "'.");
@@ -789,7 +790,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
789790
Defer resetCheckCommandOverride([]() {
790791
CheckCommand::ExecuteOverride = nullptr;
791792
});
792-
cmd->Execute(checkable, cr, execMacros, false);
793+
cmd->Execute(checkable, cr, listener, execMacros, false);
793794
}
794795
} else if (command_type == "EventCommand") {
795796
EventCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions(EventCommand::GetTypeName(), resolved_command, ActionsHandler::AuthenticatedApiUser);

lib/icinga/checkable-check.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ double Checkable::GetLastCheck() const
9494
return schedule_end;
9595
}
9696

97-
Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin)
97+
Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const CheckResultProducer::Ptr& producer, const MessageOrigin::Ptr& origin)
9898
{
9999
using Result = Checkable::ProcessingResult;
100100

@@ -539,7 +539,7 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
539539
return Result::Ok;
540540
}
541541

542-
void Checkable::ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros)
542+
void Checkable::ExecuteRemoteCheck(const CheckResultProducer::Ptr& producer, const Dictionary::Ptr& resolvedMacros)
543543
{
544544
CONTEXT("Executing remote check for object '" << GetName() << "'");
545545

@@ -550,10 +550,10 @@ void Checkable::ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros)
550550
cr->SetScheduleStart(scheduled_start);
551551
cr->SetExecutionStart(before_check);
552552

553-
GetCheckCommand()->Execute(this, cr, resolvedMacros, true);
553+
GetCheckCommand()->Execute(this, cr, producer, resolvedMacros, true);
554554
}
555555

556-
void Checkable::ExecuteCheck()
556+
void Checkable::ExecuteCheck(const CheckResultProducer::Ptr& producer)
557557
{
558558
CONTEXT("Executing check for object '" << GetName() << "'");
559559

@@ -594,10 +594,10 @@ void Checkable::ExecuteCheck()
594594
bool local = !endpoint || endpoint == Endpoint::GetLocalEndpoint();
595595

596596
if (local) {
597-
GetCheckCommand()->Execute(this, cr, nullptr, false);
597+
GetCheckCommand()->Execute(this, cr, producer, nullptr, false);
598598
} else {
599599
Dictionary::Ptr macros = new Dictionary();
600-
GetCheckCommand()->Execute(this, cr, macros, false);
600+
GetCheckCommand()->Execute(this, cr, producer, macros, false);
601601

602602
if (endpoint->GetConnected()) {
603603
/* perform check on remote endpoint */
@@ -658,7 +658,7 @@ void Checkable::ExecuteCheck()
658658

659659
cr->SetOutput(output);
660660

661-
ProcessCheckResult(cr);
661+
ProcessCheckResult(cr, producer);
662662
}
663663

664664
{

lib/icinga/checkable-script.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99

1010
using namespace icinga;
1111

12-
static void CheckableProcessCheckResult(const CheckResult::Ptr& cr)
12+
static void CheckableProcessCheckResult(const CheckResult::Ptr& cr, const CheckResultProducer::Ptr& producer)
1313
{
1414
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
1515
Checkable::Ptr self = vframe->Self;
1616
REQUIRE_NOT_NULL(self);
17-
self->ProcessCheckResult(cr);
17+
self->ProcessCheckResult(cr, producer);
1818
}
1919

2020
Object::Ptr Checkable::GetPrototype()
2121
{
2222
static Dictionary::Ptr prototype = new Dictionary({
23-
{ "process_check_result", new Function("Checkable#process_check_result", CheckableProcessCheckResult, { "cr" }, false) }
23+
{ "process_check_result", new Function("Checkable#process_check_result", CheckableProcessCheckResult, { "cr", "producer" }, false) }
2424
});
2525

2626
return prototype;

lib/icinga/checkable.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "icinga/notification.hpp"
1313
#include "icinga/comment.hpp"
1414
#include "icinga/downtime.hpp"
15+
#include "remote/crproducer.hpp"
1516
#include "remote/endpoint.hpp"
1617
#include "remote/messageorigin.hpp"
1718
#include <condition_variable>
@@ -110,16 +111,18 @@ class Checkable : public ObjectImpl<Checkable>
110111

111112
static void UpdateStatistics(const CheckResult::Ptr& cr, CheckableType type);
112113

113-
void ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros = nullptr);
114-
void ExecuteCheck();
114+
void ExecuteRemoteCheck(const CheckResultProducer::Ptr& producer, const Dictionary::Ptr& resolvedMacros = nullptr);
115+
void ExecuteCheck(const CheckResultProducer::Ptr& producer);
116+
115117
enum class ProcessingResult
116118
{
117119
Ok,
118120
NoCheckResult,
119121
CheckableInactive,
120122
NewerCheckResultPresent,
121123
};
122-
ProcessingResult ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin = nullptr);
124+
125+
ProcessingResult ProcessCheckResult(const CheckResult::Ptr& cr, const CheckResultProducer::Ptr& producer, const MessageOrigin::Ptr& origin = nullptr);
123126

124127
Endpoint::Ptr GetCommandEndpoint() const;
125128

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;

lib/icinga/clusterevents.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ Value ClusterEvents::CheckResultAPIHandler(const MessageOrigin::Ptr& origin, con
176176
}
177177

178178
if (!checkable->IsPaused() && Zone::GetLocalZone() == checkable->GetZone() && endpoint == checkable->GetCommandEndpoint())
179-
checkable->ProcessCheckResult(cr);
179+
checkable->ProcessCheckResult(cr, ApiListener::GetInstance());
180180
else
181-
checkable->ProcessCheckResult(cr, origin);
181+
checkable->ProcessCheckResult(cr, ApiListener::GetInstance(), origin);
182182

183183
return Empty;
184184
}

0 commit comments

Comments
 (0)