diff --git a/lib/icingadb/icingadb-utility.cpp b/lib/icingadb/icingadb-utility.cpp index 2c1f23ff9..078aee192 100644 --- a/lib/icingadb/icingadb-utility.cpp +++ b/lib/icingadb/icingadb-utility.cpp @@ -65,14 +65,34 @@ String IcingaDB::GetEnvironment() return ConfigType::GetObjectsByType()[0]->GetEnvironment(); } -String IcingaDB::GetObjectIdentifier(const ConfigObject::Ptr& object) +ArrayData IcingaDB::GetObjectIdentifiersWithoutEnv(const ConfigObject::Ptr& object) { Type::Ptr type = object->GetReflectionType(); if (type == CheckCommand::TypeInstance || type == NotificationCommand::TypeInstance || type == EventCommand::TypeInstance) - return HashValue((Array::Ptr)new Array({GetEnvironment(), type->GetName(), object->GetName()})); + return {type->GetName(), object->GetName()}; else - return HashValue((Array::Ptr)new Array({GetEnvironment(), object->GetName()})); + return {object->GetName()}; +} + +template +inline +std::vector Prepend(std::vector&& haystack) +{ + return std::move(haystack); +} + +template +inline +std::vector Prepend(Needles&&... needles, Needle&& needle, std::vector&& haystack) +{ + haystack.emplace(haystack.begin(), std::forward(needle)); + return Prepend(std::forward(needles)..., std::move(haystack)); +} + +String IcingaDB::GetObjectIdentifier(const ConfigObject::Ptr& object) +{ + return HashValue(new Array(Prepend(GetEnvironment(), GetObjectIdentifiersWithoutEnv(object)))); } static const std::set metadataWhitelist ({"package", "source_location", "templates"}); diff --git a/lib/icingadb/icingadb.hpp b/lib/icingadb/icingadb.hpp index 0ed792030..60709ed9d 100644 --- a/lib/icingadb/icingadb.hpp +++ b/lib/icingadb/icingadb.hpp @@ -81,6 +81,7 @@ private: static String FormatCommandLine(const Value& commandLine); static long long TimestampToMilliseconds(double timestamp); + static ArrayData GetObjectIdentifiersWithoutEnv(const ConfigObject::Ptr& object); static String GetObjectIdentifier(const ConfigObject::Ptr& object); static String GetEnvironment(); static Dictionary::Ptr SerializeVars(const CustomVarObject::Ptr& object);