]> granicus.if.org Git - icinga2/commitdiff
Silence config compiler logging for runtime created objects 6663/head
authorMichael Friedrich <michael.friedrich@icinga.com>
Tue, 9 Oct 2018 14:41:17 +0000 (16:41 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Tue, 9 Oct 2018 14:41:17 +0000 (16:41 +0200)
This is especially problematic with many single creation requests,
e.g. many downtimes created via Icinga Web 2 & the REST API.

In addition to the config compiler messages, apply rule matches are
also in there which are removed by this patch.

lib/config/applyrule.cpp
lib/config/applyrule.hpp
lib/config/configitem.cpp
lib/remote/configobjectutility.cpp

index c8f012e232934c43a8bb079c670f437abd50df1c..7bbb8d7e09a2dca0ea18c4ff7b3b27a7a9dfa7c6 100644 (file)
@@ -158,11 +158,11 @@ std::vector<ApplyRule>& ApplyRule::GetRules(const String& type)
        return it->second;
 }
 
-void ApplyRule::CheckMatches()
+void ApplyRule::CheckMatches(bool silent)
 {
        for (const RuleMap::value_type& kv : m_Rules) {
                for (const ApplyRule& rule : kv.second) {
-                       if (!rule.HasMatches())
+                       if (!rule.HasMatches() && !silent)
                                Log(LogWarning, "ApplyRule")
                                        << "Apply rule '" << rule.GetName() << "' (" << rule.GetDebugInfo() << ") for type '" << kv.first << "' does not match anywhere!";
                }
index 91623df7575eabb580219ce4c628f0da6757fa55..b57d6c565dd9825c5f164ec4dc55f73d4a2a7c5a 100644 (file)
@@ -62,7 +62,7 @@ public:
        static bool IsValidTargetType(const String& sourceType, const String& targetType);
        static std::vector<String> GetTargetTypes(const String& sourceType);
 
-       static void CheckMatches();
+       static void CheckMatches(bool silent);
 
 private:
        String m_TargetType;
index f435c94815fd8bd92864635982b7277862404636..503491b523b96b09f5b8578959712adf6ca9d657 100644 (file)
@@ -618,7 +618,7 @@ bool ConfigItem::CommitItems(const ActivationContext::Ptr& context, WorkQueue& u
                return false;
        }
 
-       ApplyRule::CheckMatches();
+       ApplyRule::CheckMatches(silent);
 
        if (!silent) {
                /* log stats for external parsers */
index fff206328b6594be84f3cd13c9bee80cdce546b9..7feb9e84f8757eb20e41b24f95fcfc2a48fc93bc 100644 (file)
@@ -143,7 +143,8 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
 
                std::vector<ConfigItem::Ptr> newItems;
 
-               if (!ConfigItem::CommitItems(ascope.GetContext(), upq, newItems) || !ConfigItem::ActivateItems(upq, newItems, true)) {
+               /* Disable logging for object creation, but do so ourselves later on. */
+               if (!ConfigItem::CommitItems(ascope.GetContext(), upq, newItems, true) || !ConfigItem::ActivateItems(upq, newItems, true, true)) {
                        if (errors) {
                                if (unlink(path.CStr()) < 0 && errno != ENOENT) {
                                        BOOST_THROW_EXCEPTION(posix_error()
@@ -164,6 +165,10 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
                }
 
                ApiListener::UpdateObjectAuthority();
+
+               Log(LogInformation, "ConfigObjectUtility")
+                       << "Created and activated object '" << fullName << "' of type '" << type->GetName() << "'.";
+
        } catch (const std::exception& ex) {
                if (unlink(path.CStr()) < 0 && errno != ENOENT) {
                        BOOST_THROW_EXCEPTION(posix_error()