From: Gunnar Beutner Date: Tue, 22 Jan 2013 08:33:57 +0000 (+0100) Subject: Refactor scheduling stuff from *CheckTask into the checker component X-Git-Tag: v0.0.2~693 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=989d7139f30b837c6f807673c4d05b3854913705;p=icinga2 Refactor scheduling stuff from *CheckTask into the checker component Fixes #3067 --- diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 744349b94..8160ab600 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -64,7 +64,9 @@ void CheckerComponent::CheckTimerHandler(void) CheckTimeView::iterator it = idx.begin(); Service::Ptr service = *it; - if (service->GetNextCheck() > now) + double next_check = service->GetNextCheck(); + + if (next_check > now) break; idx.erase(it); @@ -85,10 +87,15 @@ void CheckerComponent::CheckTimerHandler(void) 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(); + scheduleInfo->Set("schedule_start", next_check); + scheduleInfo->Set("execution_start", Utility::GetTime()); + vector arguments; arguments.push_back(service); 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 */ 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); + scheduleInfo->Set("execution_end", Utility::GetTime()); + scheduleInfo->Set("schedule_end", Utility::GetTime()); + try { Value vresult = task->GetResult(); if (vresult.IsObjectType()) { 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); RequestMessage rm; diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index 98a4ea92b..2d12b31da 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -69,7 +69,7 @@ private: void CheckTimerHandler(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); diff --git a/lib/icinga/nullchecktask.cpp b/lib/icinga/nullchecktask.cpp index 9d6e92c2a..5481baa94 100644 --- a/lib/icinga/nullchecktask.cpp +++ b/lib/icinga/nullchecktask.cpp @@ -31,10 +31,6 @@ void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector& double now = Utility::GetTime(); Dictionary::Ptr cr = boost::make_shared(); - cr->Set("schedule_start", now); - cr->Set("schedule_end", now); - cr->Set("execution_start", now); - cr->Set("execution_end", now); cr->Set("state", StateUnknown); task->FinishResult(cr); diff --git a/lib/icinga/pluginchecktask.cpp b/lib/icinga/pluginchecktask.cpp index e2ca0d1bb..c00650cf7 100644 --- a/lib/icinga/pluginchecktask.cpp +++ b/lib/icinga/pluginchecktask.cpp @@ -50,9 +50,6 @@ void PluginCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector(); - ct.m_Result->Set("schedule_start", Utility::GetTime()); - process->Start(boost::bind(&PluginCheckTask::ProcessFinishedHandler, ct)); } @@ -67,12 +64,13 @@ void PluginCheckTask::ProcessFinishedHandler(PluginCheckTask ct) return; } - ct.m_Result->Set("execution_start", pr.ExecutionStart); - ct.m_Result->Set("execution_end", pr.ExecutionEnd); + Dictionary::Ptr result = boost::make_shared(); + result->Set("execution_start", pr.ExecutionStart); + result->Set("execution_end", pr.ExecutionEnd); String output = pr.Output; output.Trim(); - ProcessCheckOutput(ct.m_Result, output); + ProcessCheckOutput(result, output); ServiceState state; @@ -91,11 +89,9 @@ void PluginCheckTask::ProcessFinishedHandler(PluginCheckTask ct) break; } - ct.m_Result->Set("state", state); - - ct.m_Result->Set("schedule_end", Utility::GetTime()); + result->Set("state", state); - ct.m_Task->FinishResult(ct.m_Result); + ct.m_Task->FinishResult(result); } void PluginCheckTask::ProcessCheckOutput(const Dictionary::Ptr& result, String& output) diff --git a/lib/icinga/pluginchecktask.h b/lib/icinga/pluginchecktask.h index b5b46e028..a8bc2846d 100644 --- a/lib/icinga/pluginchecktask.h +++ b/lib/icinga/pluginchecktask.h @@ -42,7 +42,6 @@ private: ScriptTask::Ptr m_Task; Process::Ptr m_Process; - Dictionary::Ptr m_Result; }; }