libcib_la_SOURCES = \
checkresult.cpp \
checkresult.h \
- checktask.cpp \
- checktask.h \
cib.cpp \
cib.h \
configobjectadapter.cpp \
+++ /dev/null
-/******************************************************************************
- * 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);
-}
+++ /dev/null
-/******************************************************************************
- * 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 */
#include "macroprocessor.h"
#include "checkresult.h"
-#include "checktask.h"
#include "nagioschecktask.h"
#include "servicestatusmessage.h"
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);
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)
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);