Skip to content

Commit 342b57a

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 d9481fd commit 342b57a

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
@@ -233,7 +233,7 @@ void CheckerComponent::CheckThreadProc()
233233
void CheckerComponent::ExecuteCheckHelper(const Checkable::Ptr& checkable)
234234
{
235235
try {
236-
checkable->ExecuteCheck();
236+
checkable->ExecuteCheck(this);
237237
} catch (const std::exception& ex) {
238238
CheckResult::Ptr cr = new CheckResult();
239239
cr->SetState(ServiceUnknown);
@@ -247,7 +247,7 @@ void CheckerComponent::ExecuteCheckHelper(const Checkable::Ptr& checkable)
247247
cr->SetExecutionStart(now);
248248
cr->SetExecutionEnd(now);
249249

250-
checkable->ProcessCheckResult(cr);
250+
checkable->ProcessCheckResult(cr, this);
251251

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

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() + "'.");
@@ -787,7 +788,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
787788
Defer resetCheckCommandOverride([]() {
788789
CheckCommand::ExecuteOverride = nullptr;
789790
});
790-
cmd->Execute(checkable, cr, execMacros, false);
791+
cmd->Execute(checkable, cr, listener, execMacros, false);
791792
}
792793
} else if (command_type == "EventCommand") {
793794
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
@@ -96,7 +96,7 @@ double Checkable::GetLastCheck() const
9696
return schedule_end;
9797
}
9898

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

@@ -544,7 +544,7 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
544544
return Result::Ok;
545545
}
546546

547-
void Checkable::ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros)
547+
void Checkable::ExecuteRemoteCheck(const CheckResultProducer::Ptr& producer, const Dictionary::Ptr& resolvedMacros)
548548
{
549549
CONTEXT("Executing remote check for object '" << GetName() << "'");
550550

@@ -555,10 +555,10 @@ void Checkable::ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros)
555555
cr->SetScheduleStart(scheduled_start);
556556
cr->SetExecutionStart(before_check);
557557

558-
GetCheckCommand()->Execute(this, cr, resolvedMacros, true);
558+
GetCheckCommand()->Execute(this, cr, producer, resolvedMacros, true);
559559
}
560560

561-
void Checkable::ExecuteCheck()
561+
void Checkable::ExecuteCheck(const CheckResultProducer::Ptr& producer)
562562
{
563563
CONTEXT("Executing check for object '" << GetName() << "'");
564564

@@ -599,10 +599,10 @@ void Checkable::ExecuteCheck()
599599
bool local = !endpoint || endpoint == Endpoint::GetLocalEndpoint();
600600

601601
if (local) {
602-
GetCheckCommand()->Execute(this, cr, nullptr, false);
602+
GetCheckCommand()->Execute(this, cr, producer, nullptr, false);
603603
} else {
604604
Dictionary::Ptr macros = new Dictionary();
605-
GetCheckCommand()->Execute(this, cr, macros, false);
605+
GetCheckCommand()->Execute(this, cr, producer, macros, false);
606606

607607
if (endpoint->GetConnected()) {
608608
/* perform check on remote endpoint */
@@ -663,7 +663,7 @@ void Checkable::ExecuteCheck()
663663

664664
cr->SetOutput(output);
665665

666-
ProcessCheckResult(cr);
666+
ProcessCheckResult(cr, producer);
667667
}
668668

669669
{

lib/icinga/checkable-script.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
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);
1717

1818
if (cr) {
19-
self->ProcessCheckResult(cr);
19+
self->ProcessCheckResult(cr, producer);
2020
}
2121
}
2222

2323
Object::Ptr Checkable::GetPrototype()
2424
{
2525
static Dictionary::Ptr prototype = new Dictionary({
26-
{ "process_check_result", new Function("Checkable#process_check_result", CheckableProcessCheckResult, { "cr" }, false) }
26+
{ "process_check_result", new Function("Checkable#process_check_result", CheckableProcessCheckResult, { "cr", "producer" }, false) }
2727
});
2828

2929
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>
@@ -114,15 +115,17 @@ class Checkable : public ObjectImpl<Checkable>
114115

115116
static void UpdateStatistics(const CheckResult::Ptr& cr, CheckableType type);
116117

117-
void ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros = nullptr);
118-
void ExecuteCheck();
118+
void ExecuteRemoteCheck(const CheckResultProducer::Ptr& producer, const Dictionary::Ptr& resolvedMacros = nullptr);
119+
void ExecuteCheck(const CheckResultProducer::Ptr& producer);
120+
119121
enum class ProcessingResult
120122
{
121123
Ok,
122124
CheckableInactive,
123125
NewerCheckResultPresent,
124126
};
125-
ProcessingResult ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin = nullptr);
127+
128+
ProcessingResult ProcessCheckResult(const CheckResult::Ptr& cr, const CheckResultProducer::Ptr& producer, const MessageOrigin::Ptr& origin = nullptr);
126129

127130
Endpoint::Ptr GetCommandEndpoint() const;
128131

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)