From: Gunnar Beutner Date: Sat, 14 Jul 2012 14:49:21 +0000 (+0200) Subject: Bugfixes for the ScriptTask feature. X-Git-Tag: v0.0.1~237 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fe237e01457777bede4c680d7c9df22b866cb309;p=icinga2 Bugfixes for the ScriptTask feature. --- diff --git a/cib/Makefile.am b/cib/Makefile.am index 9a427408a..d87059a35 100644 --- a/cib/Makefile.am +++ b/cib/Makefile.am @@ -6,8 +6,6 @@ pkglib_LTLIBRARIES = \ libcib_la_SOURCES = \ checkresult.cpp \ checkresult.h \ - checktask.cpp \ - checktask.h \ cib.cpp \ cib.h \ configobjectadapter.cpp \ diff --git a/cib/checktask.cpp b/cib/checktask.cpp deleted file mode 100644 index cab5ebeff..000000000 --- a/cib/checktask.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software Foundation * - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ******************************************************************************/ - -#include "i2-cib.h" - -using namespace icinga; - -map CheckTask::m_Types; - -CheckTask::CheckTask(const Service& service, const CompletionCallback& completionCallback) - : AsyncTask(completionCallback), m_Service(service) -{ } - -Service& CheckTask::GetService(void) -{ - return m_Service; -} - -CheckResult& CheckTask::GetResult(void) -{ - return m_Result; -} - -void CheckTask::RegisterType(string type, Factory factory) -{ - CheckTaskType ctt; - ctt.Factory = factory; - - m_Types[type] = ctt; -} - -CheckTask::Ptr CheckTask::CreateTask(const Service& service, const CompletionCallback& completionCallback) -{ - map::iterator it; - - it = m_Types.find(service.GetCheckType()); - - if (it == m_Types.end()) - throw runtime_error("Invalid check type specified for service '" + service.GetName() + "'"); - - return it->second.Factory(service, completionCallback); -} diff --git a/cib/checktask.h b/cib/checktask.h deleted file mode 100644 index a7c43c5a7..000000000 --- a/cib/checktask.h +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software Foundation * - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ******************************************************************************/ - -#ifndef CHECKTASK_H -#define CHECKTASK_H - -namespace icinga -{ - -struct CheckTaskType; - -class I2_CIB_API CheckTask : public AsyncTask -{ -public: - typedef shared_ptr Ptr; - typedef weak_ptr WeakPtr; - - typedef function Factory; - - Service& GetService(void); - CheckResult& GetResult(void); - - static void RegisterType(string type, Factory factory); - static CheckTask::Ptr CreateTask(const Service& service, const CompletionCallback& completionCallback); - - static int GetTaskHistogramSlots(void); - -protected: - CheckTask(const Service& service, const CompletionCallback& completionCallback); - - virtual void Run(void) = 0; - -private: - Service m_Service; - CheckResult m_Result; - - static map m_Types; -}; - -struct CheckTaskType -{ - CheckTask::Factory Factory; -}; - -} - -#endif /* CHECKTASK_H */ diff --git a/cib/i2-cib.h b/cib/i2-cib.h index 43a5c902f..73ffe102d 100644 --- a/cib/i2-cib.h +++ b/cib/i2-cib.h @@ -44,7 +44,6 @@ #include "macroprocessor.h" #include "checkresult.h" -#include "checktask.h" #include "nagioschecktask.h" #include "servicestatusmessage.h" diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index d4b88ea4a..f402125c6 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -99,7 +99,7 @@ void CheckerComponent::CheckTimerHandler(void) Logger::Write(LogInformation, "checker", msgbuf.str()); } -void CheckerComponent::CheckCompletedHandler(Service& service, const AsyncTask::Ptr& atask) +void CheckerComponent::CheckCompletedHandler(Service service, const AsyncTask::Ptr& atask) { ScriptTask::Ptr task = static_pointer_cast(atask); @@ -110,41 +110,38 @@ void CheckerComponent::CheckCompletedHandler(Service& service, const AsyncTask:: if (m_PendingServices.find(service.GetConfigObject()) == m_PendingServices.end()) return; - /* remove the service from the list of pending services */ - m_PendingServices.erase(service.GetConfigObject()); - m_Services.push(service); - Variant vresult = task->GetResult(); - if (!vresult.IsObjectType()) - return; + bool hasResult = false; + if (vresult.IsObjectType()) { + CheckResult result = CheckResult(static_cast(vresult)); + + /* update service state */ + service.ApplyCheckResult(result); - CheckResult result = static_cast(vresult); + RequestMessage rm; + rm.SetMethod("checker::CheckResult"); - Logger::Write(LogDebug, "checker", "Got result for service '" + service.GetName() + "'"); + ServiceStatusMessage params; + params.SetService(service.GetName()); + params.SetState(service.GetState()); + params.SetStateType(service.GetStateType()); + params.SetCurrentCheckAttempt(service.GetCurrentCheckAttempt()); + params.SetNextCheck(service.GetNextCheck()); + params.SetCheckResult(result); - long execution_time = result.GetExecutionEnd() - result.GetExecutionStart(); - long latency = (result.GetScheduleEnd() - result.GetScheduleStart()) - execution_time; + rm.SetParams(params); - /* update service state */ - service.ApplyCheckResult(result); + EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, rm); + } /* figure out when the next check is for this service */ service.UpdateNextCheck(); - RequestMessage rm; - rm.SetMethod("checker::CheckResult"); - - ServiceStatusMessage params; - params.SetService(service.GetName()); - params.SetState(service.GetState()); - params.SetStateType(service.GetStateType()); - params.SetCurrentCheckAttempt(service.GetCurrentCheckAttempt()); - params.SetNextCheck(service.GetNextCheck()); - params.SetCheckResult(result); - - rm.SetParams(params); + /* remove the service from the list of pending services */ + m_PendingServices.erase(service.GetConfigObject()); + m_Services.push(service); - EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, rm); + Logger::Write(LogDebug, "checker", "Check finished for service '" + service.GetName() + "'"); } void CheckerComponent::ResultTimerHandler(void) diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index fa26863a0..ccddc69b9 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -60,7 +60,7 @@ private: void CheckTimerHandler(void); void ResultTimerHandler(void); - void CheckCompletedHandler(Service& service, const AsyncTask::Ptr& atask); + void CheckCompletedHandler(Service service, const AsyncTask::Ptr& atask); void AdjustCheckTimer(void);