mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-31 01:24:19 +02:00
Refactor scheduling stuff from *CheckTask into the checker component
Fixes #3067
This commit is contained in:
parent
02de634c12
commit
989d7139f3
@ -64,7 +64,9 @@ void CheckerComponent::CheckTimerHandler(void)
|
|||||||
CheckTimeView::iterator it = idx.begin();
|
CheckTimeView::iterator it = idx.begin();
|
||||||
Service::Ptr service = *it;
|
Service::Ptr service = *it;
|
||||||
|
|
||||||
if (service->GetNextCheck() > now)
|
double next_check = service->GetNextCheck();
|
||||||
|
|
||||||
|
if (next_check > now)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
idx.erase(it);
|
idx.erase(it);
|
||||||
@ -85,10 +87,15 @@ void CheckerComponent::CheckTimerHandler(void)
|
|||||||
|
|
||||||
m_PendingServices.insert(service);
|
m_PendingServices.insert(service);
|
||||||
|
|
||||||
|
/* keep track of scheduling info in case the check type doesn't provide its own information */
|
||||||
|
Dictionary::Ptr scheduleInfo = boost::make_shared<Dictionary>();
|
||||||
|
scheduleInfo->Set("schedule_start", next_check);
|
||||||
|
scheduleInfo->Set("execution_start", Utility::GetTime());
|
||||||
|
|
||||||
vector<Value> arguments;
|
vector<Value> arguments;
|
||||||
arguments.push_back(service);
|
arguments.push_back(service);
|
||||||
ScriptTask::Ptr task;
|
ScriptTask::Ptr task;
|
||||||
task = service->InvokeMethod("check", arguments, boost::bind(&CheckerComponent::CheckCompletedHandler, this, service, _1));
|
task = service->InvokeMethod("check", arguments, boost::bind(&CheckerComponent::CheckCompletedHandler, this, service, scheduleInfo, _1));
|
||||||
assert(task); /* TODO: gracefully handle missing methods */
|
assert(task); /* TODO: gracefully handle missing methods */
|
||||||
|
|
||||||
service->Set("current_task", task);
|
service->Set("current_task", task);
|
||||||
@ -111,16 +118,31 @@ void CheckerComponent::CheckTimerHandler(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckerComponent::CheckCompletedHandler(const Service::Ptr& service, const ScriptTask::Ptr& task)
|
void CheckerComponent::CheckCompletedHandler(const Service::Ptr& service, const Dictionary::Ptr& scheduleInfo, const ScriptTask::Ptr& task)
|
||||||
{
|
{
|
||||||
service->Set("current_task", Empty);
|
service->Set("current_task", Empty);
|
||||||
|
|
||||||
|
scheduleInfo->Set("execution_end", Utility::GetTime());
|
||||||
|
scheduleInfo->Set("schedule_end", Utility::GetTime());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Value vresult = task->GetResult();
|
Value vresult = task->GetResult();
|
||||||
|
|
||||||
if (vresult.IsObjectType<Dictionary>()) {
|
if (vresult.IsObjectType<Dictionary>()) {
|
||||||
Dictionary::Ptr result = vresult;
|
Dictionary::Ptr result = vresult;
|
||||||
|
|
||||||
|
if (!result->Contains("schedule_start"))
|
||||||
|
result->Set("schedule_start", scheduleInfo->Get("schedule_start"));
|
||||||
|
|
||||||
|
if (!result->Contains("schedule_end"))
|
||||||
|
result->Set("schedule_end", scheduleInfo->Get("schedule_end"));
|
||||||
|
|
||||||
|
if (!result->Contains("execution_start"))
|
||||||
|
result->Set("execution_start", scheduleInfo->Get("execution_start"));
|
||||||
|
|
||||||
|
if (!result->Contains("execution_end"))
|
||||||
|
result->Set("execution_end", scheduleInfo->Get("execution_end"));
|
||||||
|
|
||||||
service->ApplyCheckResult(result);
|
service->ApplyCheckResult(result);
|
||||||
|
|
||||||
RequestMessage rm;
|
RequestMessage rm;
|
||||||
|
@ -69,7 +69,7 @@ private:
|
|||||||
void CheckTimerHandler(void);
|
void CheckTimerHandler(void);
|
||||||
void ResultTimerHandler(void);
|
void ResultTimerHandler(void);
|
||||||
|
|
||||||
void CheckCompletedHandler(const Service::Ptr& service, const ScriptTask::Ptr& task);
|
void CheckCompletedHandler(const Service::Ptr& service, const Dictionary::Ptr& scheduleInfo, const ScriptTask::Ptr& task);
|
||||||
|
|
||||||
void AdjustCheckTimer(void);
|
void AdjustCheckTimer(void);
|
||||||
|
|
||||||
|
@ -31,10 +31,6 @@ void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>&
|
|||||||
double now = Utility::GetTime();
|
double now = Utility::GetTime();
|
||||||
|
|
||||||
Dictionary::Ptr cr = boost::make_shared<Dictionary>();
|
Dictionary::Ptr cr = boost::make_shared<Dictionary>();
|
||||||
cr->Set("schedule_start", now);
|
|
||||||
cr->Set("schedule_end", now);
|
|
||||||
cr->Set("execution_start", now);
|
|
||||||
cr->Set("execution_end", now);
|
|
||||||
cr->Set("state", StateUnknown);
|
cr->Set("state", StateUnknown);
|
||||||
|
|
||||||
task->FinishResult(cr);
|
task->FinishResult(cr);
|
||||||
|
@ -50,9 +50,6 @@ void PluginCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Value
|
|||||||
|
|
||||||
PluginCheckTask ct(task, process);
|
PluginCheckTask ct(task, process);
|
||||||
|
|
||||||
ct.m_Result = boost::make_shared<Dictionary>();
|
|
||||||
ct.m_Result->Set("schedule_start", Utility::GetTime());
|
|
||||||
|
|
||||||
process->Start(boost::bind(&PluginCheckTask::ProcessFinishedHandler, ct));
|
process->Start(boost::bind(&PluginCheckTask::ProcessFinishedHandler, ct));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,12 +64,13 @@ void PluginCheckTask::ProcessFinishedHandler(PluginCheckTask ct)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ct.m_Result->Set("execution_start", pr.ExecutionStart);
|
Dictionary::Ptr result = boost::make_shared<Dictionary>();
|
||||||
ct.m_Result->Set("execution_end", pr.ExecutionEnd);
|
result->Set("execution_start", pr.ExecutionStart);
|
||||||
|
result->Set("execution_end", pr.ExecutionEnd);
|
||||||
|
|
||||||
String output = pr.Output;
|
String output = pr.Output;
|
||||||
output.Trim();
|
output.Trim();
|
||||||
ProcessCheckOutput(ct.m_Result, output);
|
ProcessCheckOutput(result, output);
|
||||||
|
|
||||||
ServiceState state;
|
ServiceState state;
|
||||||
|
|
||||||
@ -91,11 +89,9 @@ void PluginCheckTask::ProcessFinishedHandler(PluginCheckTask ct)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ct.m_Result->Set("state", state);
|
result->Set("state", state);
|
||||||
|
|
||||||
ct.m_Result->Set("schedule_end", Utility::GetTime());
|
ct.m_Task->FinishResult(result);
|
||||||
|
|
||||||
ct.m_Task->FinishResult(ct.m_Result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginCheckTask::ProcessCheckOutput(const Dictionary::Ptr& result, String& output)
|
void PluginCheckTask::ProcessCheckOutput(const Dictionary::Ptr& result, String& output)
|
||||||
|
@ -42,7 +42,6 @@ private:
|
|||||||
|
|
||||||
ScriptTask::Ptr m_Task;
|
ScriptTask::Ptr m_Task;
|
||||||
Process::Ptr m_Process;
|
Process::Ptr m_Process;
|
||||||
Dictionary::Ptr m_Result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user