]> granicus.if.org Git - icinga2/commitdiff
Bugfixes for the ScriptTask feature.
authorGunnar Beutner <gunnar@beutner.name>
Sat, 14 Jul 2012 14:49:21 +0000 (16:49 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Sat, 14 Jul 2012 14:49:21 +0000 (16:49 +0200)
cib/Makefile.am
cib/checktask.cpp [deleted file]
cib/checktask.h [deleted file]
cib/i2-cib.h
components/checker/checkercomponent.cpp
components/checker/checkercomponent.h

index 9a427408abf04c72fa4b2d404fe7fbdc058d0832..d87059a354d98d29def3bc430e5861b489c0b6cd 100644 (file)
@@ -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 (file)
index cab5ebe..0000000
+++ /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<string, CheckTaskType> 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<string, CheckTaskType>::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 (file)
index a7c43c5..0000000
+++ /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<CheckTask> Ptr;
-       typedef weak_ptr<CheckTask> WeakPtr;
-
-       typedef function<CheckTask::Ptr(const Service&, const CompletionCallback&)> 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<string, CheckTaskType> m_Types;
-};
-
-struct CheckTaskType
-{
-       CheckTask::Factory Factory;
-};
-
-}
-
-#endif /* CHECKTASK_H */
index 43a5c902f12b17ce51ab656791f9831863756e79..73ffe102d0a68e0b9ab9a3d7c4c12e2bceca7ba0 100644 (file)
@@ -44,7 +44,6 @@
 
 #include "macroprocessor.h"
 #include "checkresult.h"
-#include "checktask.h"
 #include "nagioschecktask.h"
 
 #include "servicestatusmessage.h"
index d4b88ea4a395bda8e859d23194bfe2e5c49bc5a3..f402125c6c4e33c361f4d95fb953930f4d950f04 100644 (file)
@@ -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<ScriptTask>(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<Dictionary>())
-               return;
+       bool hasResult = false;
+       if (vresult.IsObjectType<Dictionary>()) {
+               CheckResult result = CheckResult(static_cast<Dictionary::Ptr>(vresult));
+
+               /* update service state */
+               service.ApplyCheckResult(result);
 
-       CheckResult result = static_cast<Dictionary::Ptr>(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)
index fa26863a003b62e5a4368da96e58e457e80c6c6b..ccddc69b9602a9efe033dd6465679262e81f4e86 100644 (file)
@@ -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);