]> granicus.if.org Git - icinga2/commitdiff
Fix failed agent checks after restarts.
authorGunnar Beutner <gunnar@beutner.name>
Tue, 15 Apr 2014 13:56:41 +0000 (15:56 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 15 Apr 2014 13:56:53 +0000 (15:56 +0200)
Refs #4865

components/agent/agentchecktask.cpp
components/agent/agentchecktask.h

index 58ee20214337a9e35316f4d47c0956c8f77d22fe..674ea423772dffc5a9d225867e898b2383ed69fa 100644 (file)
@@ -58,7 +58,7 @@ void AgentCheckTask::AgentTimerHandler(void)
        double now = Utility::GetTime();
 
        BOOST_FOREACH(kv, l_PendingChecks) {
-               if (kv.second < now - 60 && kv.first->IsCheckPending()) {
+               if (kv.second < now - 60 && kv.first->IsCheckPending() && !SendResult(kv.first, false)) {
                        CheckResult::Ptr cr = make_shared<CheckResult>();
                        cr->SetOutput("Agent isn't responding.");
                        cr->SetState(ServiceCritical);
@@ -71,7 +71,7 @@ void AgentCheckTask::AgentTimerHandler(void)
        l_PendingChecks.swap(newmap);
 }
 
-void AgentCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
+bool AgentCheckTask::SendResult(const Checkable::Ptr& checkable, bool enqueue)
 {
        Host::Ptr host;
        Service::Ptr service;
@@ -90,14 +90,14 @@ void AgentCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu
 
        if (agent_identity.IsEmpty() || agent_host.IsEmpty()) {
                Log(LogWarning, "agent", "'agent_name' and 'agent_host' must be set for agent checks.");
-               return;
+               return false;
        }
 
        String agent_peer_host = MacroProcessor::ResolveMacros("$agent_peer_host$", resolvers, checkable->GetLastCheckResult());
        String agent_peer_port = MacroProcessor::ResolveMacros("$agent_peer_port$", resolvers, checkable->GetLastCheckResult());
-       
+
        double now = Utility::GetTime();
-       
+
        BOOST_FOREACH(const AgentListener::Ptr& al, DynamicType::GetObjects<AgentListener>()) {
                double seen = al->GetAgentSeen(agent_identity);
 
@@ -108,17 +108,26 @@ void AgentCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu
 
                if (cr) {
                        checkable->ProcessCheckResult(cr);
-                       return;
+                       return true;
                }
        }
-       
-       {
-               boost::mutex::scoped_lock lock(l_Mutex);
-               l_PendingChecks[checkable] = now;
-       }
 
-       BOOST_FOREACH(const AgentListener::Ptr& al, DynamicType::GetObjects<AgentListener>()) {
-               if (!agent_peer_host.IsEmpty() && !agent_peer_port.IsEmpty())
-                       al->AddConnection(agent_peer_host, agent_peer_port);
+       if (enqueue) {
+               {
+                       boost::mutex::scoped_lock lock(l_Mutex);
+                       l_PendingChecks[checkable] = now;
+               }
+
+               BOOST_FOREACH(const AgentListener::Ptr& al, DynamicType::GetObjects<AgentListener>()) {
+                       if (!agent_peer_host.IsEmpty() && !agent_peer_port.IsEmpty())
+                               al->AddConnection(agent_peer_host, agent_peer_port);
+               }
        }
+
+       return false;
+}
+
+void AgentCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
+{
+       SendResult(checkable, true);
 }
index 2102f2a9dcc5eeeda07017afb3d049ff24f77fb3..e35a34e5cd690c4d7a3e796e1ce9c5346a86fde3 100644 (file)
@@ -41,6 +41,8 @@ private:
        AgentCheckTask(void);
        
        static void AgentTimerHandler(void);
+
+       static bool SendResult(const Checkable::Ptr& checkable, bool enqueue);
 };
 
 }