]> granicus.if.org Git - icinga2/commitdiff
Fix auto-discovery info files.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sun, 13 Apr 2014 10:41:34 +0000 (12:41 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sun, 13 Apr 2014 10:41:34 +0000 (12:41 +0200)
Refs #6002

components/agent/agentlistener.cpp

index ed216cc4421a38dfc43e2c5799be0948efd94152..cf05ef42a7d841e327e8fec902661ce96b3bbc6f 100644 (file)
@@ -206,17 +206,39 @@ void AgentListener::MessageHandler(const TlsStream::Ptr& sender, const String& i
        }
 
        if (method == "push_crs") {
-               Host::Ptr host = Host::GetByName(identity);
+               Dictionary::Ptr params = message->Get("params");
 
-               if (!host) {
-                       Log(LogWarning, "agent", "Ignoring check results for host '" + identity + "'.");
+               if (!params)
                        return;
+
+               Dictionary::Ptr inventoryDescr = make_shared<Dictionary>();
+               inventoryDescr->Set("identity", identity);
+               inventoryDescr->Set("crs", params);
+
+               String inventoryFile = GetInventoryDir() + SHA256(identity);
+               String inventoryTempFile = inventoryFile + ".tmp";
+
+               std::ofstream fp(inventoryTempFile.CStr(), std::ofstream::out | std::ostream::trunc);
+               fp << JsonSerialize(inventoryDescr);
+               fp.close();
+
+#ifdef _WIN32
+               _unlink(inventoryFile.CStr());
+#endif /* _WIN32 */
+
+               if (rename(inventoryTempFile.CStr(), inventoryFile.CStr()) < 0) {
+                       BOOST_THROW_EXCEPTION(posix_error()
+                           << boost::errinfo_api_function("rename")
+                           << boost::errinfo_errno(errno)
+                           << boost::errinfo_file_name(inventoryTempFile));
                }
 
-               Dictionary::Ptr params = message->Get("params");
+               Host::Ptr host = Host::GetByName(identity);
 
-               if (!params)
+               if (!host) {
+                       Log(LogWarning, "agent", "Ignoring check results for host '" + identity + "'.");
                        return;
+               }
 
                Value hostcr = Deserialize(params->Get("host"), true);
 
@@ -252,28 +274,6 @@ void AgentListener::MessageHandler(const TlsStream::Ptr& sender, const String& i
                        CheckResult::Ptr cr = servicecr;
                        service->ProcessCheckResult(cr);
                }
-
-               Dictionary::Ptr inventoryDescr = make_shared<Dictionary>();
-               inventoryDescr->Set("identity", identity);
-               inventoryDescr->Set("crs", params);
-
-               String inventoryFile = GetInventoryDir() + SHA256(identity);
-               String inventoryTempFile = inventoryFile + ".tmp";
-
-               std::ofstream fp(inventoryTempFile.CStr(), std::ofstream::out | std::ostream::trunc);
-               fp << JsonSerialize(inventoryDescr);
-               fp.close();
-
-#ifdef _WIN32
-               _unlink(inventoryFile.CStr());
-#endif /* _WIN32 */
-
-               if (rename(inventoryTempFile.CStr(), inventoryFile.CStr()) < 0) {
-                       BOOST_THROW_EXCEPTION(posix_error()
-                           << boost::errinfo_api_function("rename")
-                           << boost::errinfo_errno(errno)
-                           << boost::errinfo_file_name(inventoryTempFile));
-               }
        }
 }