Introduce IcingaDB#GetObjectIdentifiersWithoutEnv()

refs #7692
This commit is contained in:
Alexander A. Klimov 2019-12-06 11:46:42 +01:00
parent 783586978f
commit d69cb676a7
2 changed files with 24 additions and 3 deletions

View File

@ -65,14 +65,34 @@ String IcingaDB::GetEnvironment()
return ConfigType::GetObjectsByType<IcingaApplication>()[0]->GetEnvironment(); return ConfigType::GetObjectsByType<IcingaApplication>()[0]->GetEnvironment();
} }
String IcingaDB::GetObjectIdentifier(const ConfigObject::Ptr& object) ArrayData IcingaDB::GetObjectIdentifiersWithoutEnv(const ConfigObject::Ptr& object)
{ {
Type::Ptr type = object->GetReflectionType(); Type::Ptr type = object->GetReflectionType();
if (type == CheckCommand::TypeInstance || type == NotificationCommand::TypeInstance || type == EventCommand::TypeInstance) 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 else
return HashValue((Array::Ptr)new Array({GetEnvironment(), object->GetName()})); return {object->GetName()};
}
template<class T>
inline
std::vector<T> Prepend(std::vector<T>&& haystack)
{
return std::move(haystack);
}
template<class T, class Needle, class... Needles>
inline
std::vector<T> Prepend(Needles&&... needles, Needle&& needle, std::vector<T>&& haystack)
{
haystack.emplace(haystack.begin(), std::forward<Needle>(needle));
return Prepend(std::forward<Needles>(needles)..., std::move(haystack));
}
String IcingaDB::GetObjectIdentifier(const ConfigObject::Ptr& object)
{
return HashValue(new Array(Prepend(GetEnvironment(), GetObjectIdentifiersWithoutEnv(object))));
} }
static const std::set<String> metadataWhitelist ({"package", "source_location", "templates"}); static const std::set<String> metadataWhitelist ({"package", "source_location", "templates"});

View File

@ -81,6 +81,7 @@ private:
static String FormatCommandLine(const Value& commandLine); static String FormatCommandLine(const Value& commandLine);
static long long TimestampToMilliseconds(double timestamp); static long long TimestampToMilliseconds(double timestamp);
static ArrayData GetObjectIdentifiersWithoutEnv(const ConfigObject::Ptr& object);
static String GetObjectIdentifier(const ConfigObject::Ptr& object); static String GetObjectIdentifier(const ConfigObject::Ptr& object);
static String GetEnvironment(); static String GetEnvironment();
static Dictionary::Ptr SerializeVars(const CustomVarObject::Ptr& object); static Dictionary::Ptr SerializeVars(const CustomVarObject::Ptr& object);