]> granicus.if.org Git - icinga2/commitdiff
Cleaned up NagiosCheckTask.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sun, 15 Jul 2012 15:48:58 +0000 (17:48 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sun, 15 Jul 2012 15:48:58 +0000 (17:48 +0200)
cib/nagioschecktask.cpp
cib/nagioschecktask.h

index 071329c7114d339ba033f7a42f06eceb8c93419a..c8493df6dc89eff03375893c35f06ec82e8d36e8 100644 (file)
@@ -47,19 +47,18 @@ void NagiosCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Varia
        macroDicts.push_back(IcingaApplication::GetInstance()->GetMacros());
        string command = MacroProcessor::ResolveMacros(checkCommand, macroDicts);
 
-       CheckResult result;
+       Process::Ptr process = boost::make_shared<Process>(command);
+
+       NagiosCheckTask ct(task, process);
 
        time_t now;
        time(&now);
-       result.SetScheduleStart(now);
+       ct.m_Result.SetScheduleStart(now);
 
-       Process::Ptr process = boost::make_shared<Process>(command);
-
-       NagiosCheckTask ct(task, process);
-       process->Start(boost::bind(&NagiosCheckTask::ProcessFinishedHandler, ct, result));
+       process->Start(boost::bind(&NagiosCheckTask::ProcessFinishedHandler, ct));
 }
 
-void NagiosCheckTask::ProcessFinishedHandler(NagiosCheckTask ct, CheckResult result)
+void NagiosCheckTask::ProcessFinishedHandler(NagiosCheckTask ct)
 {
        ProcessResult pr;
 
@@ -70,12 +69,12 @@ void NagiosCheckTask::ProcessFinishedHandler(NagiosCheckTask ct, CheckResult res
                return;
        }
 
-       result.SetExecutionStart(pr.ExecutionStart);
-       result.SetExecutionEnd(pr.ExecutionEnd);
+       ct.m_Result.SetExecutionStart(pr.ExecutionStart);
+       ct.m_Result.SetExecutionEnd(pr.ExecutionEnd);
 
        string output = pr.Output;
        boost::algorithm::trim(output);
-       ProcessCheckOutput(result, output);
+       ProcessCheckOutput(ct.m_Result, output);
 
        ServiceState state;
 
@@ -94,13 +93,13 @@ void NagiosCheckTask::ProcessFinishedHandler(NagiosCheckTask ct, CheckResult res
                        break;
        }
 
-       result.SetState(state);
+       ct.m_Result.SetState(state);
 
        time_t now;
        time(&now);
-       result.SetScheduleEnd(now);
+       ct.m_Result.SetScheduleEnd(now);
 
-       ct.m_Task->FinishResult(result.GetDictionary());
+       ct.m_Task->FinishResult(ct.m_Result.GetDictionary());
 }
 
 void NagiosCheckTask::ProcessCheckOutput(CheckResult& result, const string& output)
index 3b55ba32fe2a935ddf194afb7e98adfaf841ec08..decce4d14ca61da37c98379330adba080b13fdd6 100644 (file)
@@ -31,13 +31,14 @@ public:
        static void Register(void);
 
 private:
-       static void ProcessFinishedHandler(NagiosCheckTask ct, CheckResult result);
+       static void ProcessFinishedHandler(NagiosCheckTask ct);
        static void ProcessCheckOutput(CheckResult& result, const string& output);
 
        NagiosCheckTask(const ScriptTask::Ptr& task, const Process::Ptr& process);
 
        ScriptTask::Ptr m_Task;
        Process::Ptr m_Process;
+       CheckResult m_Result;
 };
 
 }