[icinga-checkins] icinga.org: icinga2/support/2.4: Remove commentsand downtimes with reference to deleted checkable objects

git at icinga.org git at icinga.org
Thu May 12 11:50:27 CEST 2016


Module: icinga2
Branch: support/2.4
Commit: 7c7a4c3a65a4850ef4536203f0bd8054671b5cab
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=7c7a4c3a65a4850ef4536203f0bd8054671b5cab

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Thu Mar 31 13:29:08 2016 +0200

Remove commentsand downtimes with reference to deleted checkable objects

Silence the warning message and change the log level to notice as well.

fixes #10717

---

 lib/cli/daemonutility.cpp |    4 ++++
 lib/config/configitem.cpp |   37 +++++++++++++++++++++++++++++++++----
 lib/config/configitem.hpp |    6 +++++-
 3 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/lib/cli/daemonutility.cpp b/lib/cli/daemonutility.cpp
index a6fe455..84470cf 100644
--- a/lib/cli/daemonutility.cpp
+++ b/lib/cli/daemonutility.cpp
@@ -24,6 +24,7 @@
 #include "config/configcompiler.hpp"
 #include "config/configcompilercontext.hpp"
 #include "config/configitembuilder.hpp"
+#include "remote/configobjectutility.hpp"
 
 
 using namespace icinga;
@@ -168,6 +169,9 @@ bool DaemonUtility::LoadConfigFiles(const std::vector<std::string>& configs,
 	WorkQueue upq(25000, Application::GetConcurrency());
 	bool result = ConfigItem::CommitItems(ascope.GetContext(), upq, newItems);
 
+	/* Remove ignored Downtime/Comment objects. */
+	ConfigItem::RemoveIgnoredItems(ConfigObjectUtility::GetConfigDir());
+
 	if (!result)
 		return false;
 
diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp
index 267328a..f767c4c 100644
--- a/lib/config/configitem.cpp
+++ b/lib/config/configitem.cpp
@@ -44,6 +44,7 @@ using namespace icinga;
 boost::mutex ConfigItem::m_Mutex;
 ConfigItem::TypeMap ConfigItem::m_Items;
 ConfigItem::ItemList ConfigItem::m_UnnamedItems;
+ConfigItem::IgnoredItemList ConfigItem::m_IgnoredItems;
 
 REGISTER_SCRIPTFUNCTION(__run_with_activation_context, &ConfigItem::RunWithActivationContext);
 
@@ -190,9 +191,11 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
 		m_Expression->Evaluate(frame, &debugHints);
 	} catch (const std::exception& ex) {
 		if (m_IgnoreOnError) {
-			Log(LogWarning, "ConfigObject")
+			Log(LogNotice, "ConfigObject")
 			    << "Ignoring config object '" << m_Name << "' of type '" << m_Type << "' due to errors: " << DiagnosticInformation(ex);
 
+			m_IgnoredItems.push_back(m_DebugInfo.Path);
+
 			return ConfigObject::Ptr();
 		}
 
@@ -234,9 +237,11 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
 		dobj->Validate(FAConfig, utils);
 	} catch (ValidationError& ex) {
 		if (m_IgnoreOnError) {
-			Log(LogWarning, "ConfigObject")
+			Log(LogNotice, "ConfigObject")
 			    << "Ignoring config object '" << m_Name << "' of type '" << m_Type << "' due to errors: " << DiagnosticInformation(ex);
 
+			m_IgnoredItems.push_back(m_DebugInfo.Path);
+
 			return ConfigObject::Ptr();
 		}
 
@@ -248,9 +253,11 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
 		dobj->OnConfigLoaded();
 	} catch (const std::exception& ex) {
 		if (m_IgnoreOnError) {
-			Log(LogWarning, "ConfigObject")
+			Log(LogNotice, "ConfigObject")
 			    << "Ignoring config object '" << m_Name << "' of type '" << m_Type << "' due to errors: " << DiagnosticInformation(ex);
 
+			m_IgnoredItems.push_back(m_DebugInfo.Path);
+
 			return ConfigObject::Ptr();
 		}
 
@@ -359,11 +366,13 @@ void ConfigItem::OnAllConfigLoadedHelper(void)
 		m_Object->OnAllConfigLoaded();
 	} catch (const std::exception& ex) {
 		if (m_IgnoreOnError) {
-			Log(LogWarning, "ConfigObject")
+			Log(LogNotice, "ConfigObject")
 			    << "Ignoring config object '" << m_Name << "' of type '" << m_Type << "' due to errors: " << DiagnosticInformation(ex);
 
 			Unregister();
 
+			m_IgnoredItems.push_back(m_DebugInfo.Path);
+
 			return;
 		}
 
@@ -630,3 +639,23 @@ std::vector<ConfigItem::Ptr> ConfigItem::GetItems(const String& type)
 
 	return items;
 }
+
+void ConfigItem::RemoveIgnoredItems(const String& allowedConfigPath)
+{
+	BOOST_FOREACH(const String& path, m_IgnoredItems) {
+		if (path.Find(allowedConfigPath) == String::NPos)
+			continue;
+
+		Log(LogNotice, "ConfigItem")
+		    << "Removing ignored item path '" << path << "'.";
+
+		if (unlink(path.CStr()) < 0) {
+			BOOST_THROW_EXCEPTION(posix_error()
+			    << boost::errinfo_api_function("unlink")
+			    << boost::errinfo_errno(errno)
+			    << boost::errinfo_file_name(path));
+		}
+	}
+
+	m_IgnoredItems.clear();
+}
diff --git a/lib/config/configitem.hpp b/lib/config/configitem.hpp
index 3bfb953..b9c23d0 100644
--- a/lib/config/configitem.hpp
+++ b/lib/config/configitem.hpp
@@ -75,6 +75,8 @@ public:
 
 	static std::vector<ConfigItem::Ptr> GetItems(const String& type);
 
+	static void RemoveIgnoredItems(const String& allowedConfigPath);
+
 private:
 	String m_Type; /**< The object type. */
 	String m_Name; /**< The name. */
@@ -99,7 +101,9 @@ private:
 
 	typedef std::vector<ConfigItem::Ptr> ItemList;
 	static ItemList m_UnnamedItems;
-	static ItemList m_CommittedItems;
+
+	typedef std::vector<String> IgnoredItemList;
+	static IgnoredItemList m_IgnoredItems;
 
 	static ConfigItem::Ptr GetObjectUnlocked(const String& type,
 	    const String& name);



More information about the icinga-checkins mailing list