]> granicus.if.org Git - icinga2/commitdiff
InfluxdbWriter: clone less 7356/head
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Wed, 24 Jul 2019 08:43:45 +0000 (10:43 +0200)
committerAlexander A. Klimov <alexander.klimov@icinga.com>
Wed, 24 Jul 2019 08:43:45 +0000 (10:43 +0200)
lib/perfdata/influxdbwriter.cpp

index 39106c95f34f6041838ef7d9d5f517625020ba8a..86d8128de65b103da21cfa1283658ac4fac34dcd 100644 (file)
@@ -248,23 +248,26 @@ void InfluxdbWriter::CheckResultHandlerWQ(const Checkable::Ptr& checkable, const
 
        // Clone the template and perform an in-place macro expansion of measurement and tag values
        Dictionary::Ptr tmpl_clean = service ? GetServiceTemplate() : GetHostTemplate();
-       Dictionary::Ptr tmpl = static_pointer_cast<Dictionary>(tmpl_clean->Clone());
+       Dictionary::Ptr tmpl = static_pointer_cast<Dictionary>(tmpl_clean->ShallowClone());
        tmpl->Set("measurement", MacroProcessor::ResolveMacros(tmpl->Get("measurement"), resolvers, cr));
 
-       Dictionary::Ptr tags = tmpl->Get("tags");
-       if (tags) {
-               ObjectLock olock(tags);
-               for (const Dictionary::Pair& pair : tags) {
-                       String missing_macro;
-                       Value value = MacroProcessor::ResolveMacros(pair.second, resolvers, cr, &missing_macro);
+       Dictionary::Ptr tagsClean = tmpl->Get("tags");
+       if (tagsClean) {
+               Dictionary::Ptr tags = new Dictionary();
 
-                       if (!missing_macro.IsEmpty()) {
-                               tags->Remove(pair.first);
-                               continue;
-                       }
+               {
+                       ObjectLock olock(tagsClean);
+                       for (const Dictionary::Pair& pair : tagsClean) {
+                               String missing_macro;
+                               Value value = MacroProcessor::ResolveMacros(pair.second, resolvers, cr, &missing_macro);
 
-                       tags->Set(pair.first, value);
+                               if (missing_macro.IsEmpty()) {
+                                       tags->Set(pair.first, value);
+                               }
+                       }
                }
+
+               tmpl->Set("tags", tags);
        }
 
        CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();