mirror of https://github.com/Icinga/icinga2.git
IcingaDB: Remove GetObjectIdentifiersWithoutEnv()
Having the command type be a part of the command ID isn't needed anywhere. Removing this simplifies the way we generate IDs in general, because we don't need Prepend() anymore. The command type was only needed to prevent ID collisions within the command_envvar and command_argument tables. Those tables have since been separated into {check,event,notification}command_envvar and {check,event,notification}command_argument tables.
This commit is contained in:
parent
d892fc77f3
commit
0b9317a5bf
|
@ -629,7 +629,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String id = HashValue(new Array(Prepend(m_EnvironmentId, Prepend(kv.first, GetObjectIdentifiersWithoutEnv(object)))));
|
String id = HashValue(new Array({m_EnvironmentId, kv.first, object->GetName()}));
|
||||||
typeCvs.emplace_back(id);
|
typeCvs.emplace_back(id);
|
||||||
|
|
||||||
Dictionary::Ptr data = new Dictionary({{objectKeyName, objectKey}, {"environment_id", m_EnvironmentId}, {"customvar_id", kv.first}});
|
Dictionary::Ptr data = new Dictionary({{objectKeyName, objectKey}, {"environment_id", m_EnvironmentId}, {"customvar_id", kv.first}});
|
||||||
|
@ -719,7 +719,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
for (auto& group : groups) {
|
for (auto& group : groups) {
|
||||||
auto groupObj ((*getGroup)(group));
|
auto groupObj ((*getGroup)(group));
|
||||||
String groupId = GetObjectIdentifier(groupObj);
|
String groupId = GetObjectIdentifier(groupObj);
|
||||||
String id = HashValue(new Array(Prepend(m_EnvironmentId, Prepend(GetObjectIdentifiersWithoutEnv(groupObj), GetObjectIdentifiersWithoutEnv(object)))));
|
String id = HashValue(new Array({m_EnvironmentId, groupObj->GetName(), object->GetName()}));
|
||||||
members.emplace_back(id);
|
members.emplace_back(id);
|
||||||
Dictionary::Ptr data = new Dictionary({{objectKeyName, objectKey}, {"environment_id", m_EnvironmentId}, {typeName + "group_id", groupId}});
|
Dictionary::Ptr data = new Dictionary({{objectKeyName, objectKey}, {"environment_id", m_EnvironmentId}, {typeName + "group_id", groupId}});
|
||||||
members.emplace_back(JsonEncode(data));
|
members.emplace_back(JsonEncode(data));
|
||||||
|
@ -750,7 +750,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
String rangeId = HashValue(new Array({m_EnvironmentId, kv.first, kv.second}));
|
String rangeId = HashValue(new Array({m_EnvironmentId, kv.first, kv.second}));
|
||||||
rangeIds->Add(rangeId);
|
rangeIds->Add(rangeId);
|
||||||
|
|
||||||
String id = HashValue(new Array(Prepend(m_EnvironmentId, Prepend(kv.first, Prepend(kv.second, GetObjectIdentifiersWithoutEnv(object))))));
|
String id = HashValue(new Array({m_EnvironmentId, kv.first, kv.second, object->GetName()}));
|
||||||
typeRanges.emplace_back(id);
|
typeRanges.emplace_back(id);
|
||||||
Dictionary::Ptr data = new Dictionary({{"environment_id", m_EnvironmentId}, {"timeperiod_id", objectKey}, {"range_key", kv.first}, {"range_value", kv.second}});
|
Dictionary::Ptr data = new Dictionary({{"environment_id", m_EnvironmentId}, {"timeperiod_id", objectKey}, {"range_key", kv.first}, {"range_value", kv.second}});
|
||||||
typeRanges.emplace_back(JsonEncode(data));
|
typeRanges.emplace_back(JsonEncode(data));
|
||||||
|
@ -780,7 +780,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
String includeId = GetObjectIdentifier(includeTp);
|
String includeId = GetObjectIdentifier(includeTp);
|
||||||
includeChecksums->Add(includeId);
|
includeChecksums->Add(includeId);
|
||||||
|
|
||||||
String id = HashValue(new Array(Prepend(m_EnvironmentId, Prepend(GetObjectIdentifiersWithoutEnv(includeTp), GetObjectIdentifiersWithoutEnv(object)))));
|
String id = HashValue(new Array({m_EnvironmentId, includeTp->GetName(), object->GetName()}));
|
||||||
includs.emplace_back(id);
|
includs.emplace_back(id);
|
||||||
Dictionary::Ptr data = new Dictionary({{"environment_id", m_EnvironmentId}, {"timeperiod_id", objectKey}, {"include_id", includeId}});
|
Dictionary::Ptr data = new Dictionary({{"environment_id", m_EnvironmentId}, {"timeperiod_id", objectKey}, {"include_id", includeId}});
|
||||||
includs.emplace_back(JsonEncode(data));
|
includs.emplace_back(JsonEncode(data));
|
||||||
|
@ -810,7 +810,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
String excludeId = GetObjectIdentifier(excludeTp);
|
String excludeId = GetObjectIdentifier(excludeTp);
|
||||||
excludeChecksums->Add(excludeId);
|
excludeChecksums->Add(excludeId);
|
||||||
|
|
||||||
String id = HashValue(new Array(Prepend(m_EnvironmentId, Prepend(GetObjectIdentifiersWithoutEnv(excludeTp), GetObjectIdentifiersWithoutEnv(object)))));
|
String id = HashValue(new Array({m_EnvironmentId, excludeTp->GetName(), object->GetName()}));
|
||||||
excluds.emplace_back(id);
|
excluds.emplace_back(id);
|
||||||
Dictionary::Ptr data = new Dictionary({{"environment_id", m_EnvironmentId}, {"timeperiod_id", objectKey}, {"exclude_id", excludeId}});
|
Dictionary::Ptr data = new Dictionary({{"environment_id", m_EnvironmentId}, {"timeperiod_id", objectKey}, {"exclude_id", excludeId}});
|
||||||
excluds.emplace_back(JsonEncode(data));
|
excluds.emplace_back(JsonEncode(data));
|
||||||
|
@ -843,7 +843,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
for (auto& group : groups) {
|
for (auto& group : groups) {
|
||||||
auto groupObj ((*getGroup)(group));
|
auto groupObj ((*getGroup)(group));
|
||||||
String groupId = GetObjectIdentifier(groupObj);
|
String groupId = GetObjectIdentifier(groupObj);
|
||||||
String id = HashValue(new Array(Prepend(m_EnvironmentId, Prepend(GetObjectIdentifiersWithoutEnv(groupObj), GetObjectIdentifiersWithoutEnv(object)))));
|
String id = HashValue(new Array({m_EnvironmentId, groupObj->GetName(), object->GetName()}));
|
||||||
members.emplace_back(id);
|
members.emplace_back(id);
|
||||||
Dictionary::Ptr data = new Dictionary({{"user_id", objectKey}, {"environment_id", m_EnvironmentId}, {"usergroup_id", groupId}});
|
Dictionary::Ptr data = new Dictionary({{"user_id", objectKey}, {"environment_id", m_EnvironmentId}, {"usergroup_id", groupId}});
|
||||||
members.emplace_back(JsonEncode(data));
|
members.emplace_back(JsonEncode(data));
|
||||||
|
@ -878,7 +878,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
|
|
||||||
for (auto& user : users) {
|
for (auto& user : users) {
|
||||||
String userId = GetObjectIdentifier(user);
|
String userId = GetObjectIdentifier(user);
|
||||||
String id = HashValue(new Array(Prepend(m_EnvironmentId, Prepend(GetObjectIdentifiersWithoutEnv(user), GetObjectIdentifiersWithoutEnv(object)))));
|
String id = HashValue(new Array({m_EnvironmentId, user->GetName(), object->GetName()}));
|
||||||
usrs.emplace_back(id);
|
usrs.emplace_back(id);
|
||||||
Dictionary::Ptr data = new Dictionary({{"notification_id", objectKey}, {"environment_id", m_EnvironmentId}, {"user_id", userId}});
|
Dictionary::Ptr data = new Dictionary({{"notification_id", objectKey}, {"environment_id", m_EnvironmentId}, {"user_id", userId}});
|
||||||
usrs.emplace_back(JsonEncode(data));
|
usrs.emplace_back(JsonEncode(data));
|
||||||
|
@ -901,7 +901,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
auto groupMembers = usergroup->GetMembers();
|
auto groupMembers = usergroup->GetMembers();
|
||||||
std::copy(groupMembers.begin(), groupMembers.end(), std::inserter(allUsers, allUsers.begin()));
|
std::copy(groupMembers.begin(), groupMembers.end(), std::inserter(allUsers, allUsers.begin()));
|
||||||
|
|
||||||
String id = HashValue(new Array(Prepend(m_EnvironmentId, Prepend("usergroup", Prepend(GetObjectIdentifiersWithoutEnv(usergroup), GetObjectIdentifiersWithoutEnv(object))))));
|
String id = HashValue(new Array({m_EnvironmentId, "usergroup", usergroup->GetName(), object->GetName()}));
|
||||||
groups.emplace_back(id);
|
groups.emplace_back(id);
|
||||||
Dictionary::Ptr groupData = new Dictionary({{"notification_id", objectKey}, {"environment_id", m_EnvironmentId}, {"usergroup_id", usergroupId}});
|
Dictionary::Ptr groupData = new Dictionary({{"notification_id", objectKey}, {"environment_id", m_EnvironmentId}, {"usergroup_id", usergroupId}});
|
||||||
groups.emplace_back(JsonEncode(groupData));
|
groups.emplace_back(JsonEncode(groupData));
|
||||||
|
@ -920,7 +920,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
|
|
||||||
for (auto& user : allUsers) {
|
for (auto& user : allUsers) {
|
||||||
String userId = GetObjectIdentifier(user);
|
String userId = GetObjectIdentifier(user);
|
||||||
String id = HashValue(new Array(Prepend(m_EnvironmentId, Prepend("user", Prepend(GetObjectIdentifiersWithoutEnv(user), GetObjectIdentifiersWithoutEnv(object))))));
|
String id = HashValue(new Array({m_EnvironmentId, "user", user->GetName(), object->GetName()}));
|
||||||
notificationRecipients.emplace_back(id);
|
notificationRecipients.emplace_back(id);
|
||||||
Dictionary::Ptr data = new Dictionary({{"notification_id", objectKey}, {"environment_id", m_EnvironmentId}, {"user_id", userId}});
|
Dictionary::Ptr data = new Dictionary({{"notification_id", objectKey}, {"environment_id", m_EnvironmentId}, {"user_id", userId}});
|
||||||
notificationRecipients.emplace_back(JsonEncode(data));
|
notificationRecipients.emplace_back(JsonEncode(data));
|
||||||
|
@ -974,7 +974,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
values->Set("argument_key", kv.first);
|
values->Set("argument_key", kv.first);
|
||||||
values->Set("environment_id", m_EnvironmentId);
|
values->Set("environment_id", m_EnvironmentId);
|
||||||
|
|
||||||
String id = HashValue(new Array(Prepend(m_EnvironmentId, Prepend(kv.first, GetObjectIdentifiersWithoutEnv(object)))));
|
String id = HashValue(new Array({m_EnvironmentId, kv.first, object->GetName()}));
|
||||||
|
|
||||||
typeArgs.emplace_back(id);
|
typeArgs.emplace_back(id);
|
||||||
typeArgs.emplace_back(JsonEncode(values));
|
typeArgs.emplace_back(JsonEncode(values));
|
||||||
|
@ -1023,7 +1023,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
values->Set("envvar_key", kv.first);
|
values->Set("envvar_key", kv.first);
|
||||||
values->Set("environment_id", m_EnvironmentId);
|
values->Set("environment_id", m_EnvironmentId);
|
||||||
|
|
||||||
String id = HashValue(new Array(Prepend(m_EnvironmentId, Prepend(kv.first, GetObjectIdentifiersWithoutEnv(object)))));
|
String id = HashValue(new Array({m_EnvironmentId, kv.first, object->GetName()}));
|
||||||
|
|
||||||
typeVars.emplace_back(id);
|
typeVars.emplace_back(id);
|
||||||
typeVars.emplace_back(JsonEncode(values));
|
typeVars.emplace_back(JsonEncode(values));
|
||||||
|
@ -1543,7 +1543,7 @@ void IcingaDB::SendStateChange(const ConfigObject::Ptr& object, const CheckResul
|
||||||
auto eventTime (cr->GetExecutionEnd());
|
auto eventTime (cr->GetExecutionEnd());
|
||||||
auto eventTs (TimestampToMilliseconds(eventTime));
|
auto eventTs (TimestampToMilliseconds(eventTime));
|
||||||
|
|
||||||
Array::Ptr rawId = new Array(Prepend(m_EnvironmentId, GetObjectIdentifiersWithoutEnv(object)));
|
Array::Ptr rawId = new Array({m_EnvironmentId, object->GetName()});
|
||||||
rawId->Add(eventTs);
|
rawId->Add(eventTs);
|
||||||
|
|
||||||
std::vector<String> xAdd ({
|
std::vector<String> xAdd ({
|
||||||
|
@ -1623,7 +1623,7 @@ void IcingaDB::SendSentNotification(
|
||||||
auto usersAmount (users.size());
|
auto usersAmount (users.size());
|
||||||
auto sendTs (TimestampToMilliseconds(sendTime));
|
auto sendTs (TimestampToMilliseconds(sendTime));
|
||||||
|
|
||||||
Array::Ptr rawId = new Array(Prepend(m_EnvironmentId, GetObjectIdentifiersWithoutEnv(notification)));
|
Array::Ptr rawId = new Array({m_EnvironmentId, notification->GetName()});
|
||||||
rawId->Add(GetNotificationTypeByEnum(type));
|
rawId->Add(GetNotificationTypeByEnum(type));
|
||||||
rawId->Add(sendTs);
|
rawId->Add(sendTs);
|
||||||
|
|
||||||
|
|
|
@ -60,19 +60,9 @@ String IcingaDB::FormatCommandLine(const Value& commandLine)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayData IcingaDB::GetObjectIdentifiersWithoutEnv(const ConfigObject::Ptr& object)
|
|
||||||
{
|
|
||||||
Type::Ptr type = object->GetReflectionType();
|
|
||||||
|
|
||||||
if (type == CheckCommand::TypeInstance || type == NotificationCommand::TypeInstance || type == EventCommand::TypeInstance)
|
|
||||||
return {type->GetName(), object->GetName()};
|
|
||||||
else
|
|
||||||
return {object->GetName()};
|
|
||||||
}
|
|
||||||
|
|
||||||
String IcingaDB::GetObjectIdentifier(const ConfigObject::Ptr& object)
|
String IcingaDB::GetObjectIdentifier(const ConfigObject::Ptr& object)
|
||||||
{
|
{
|
||||||
return HashValue(new Array(Prepend(m_EnvironmentId, GetObjectIdentifiersWithoutEnv(object))));
|
return HashValue(new Array({m_EnvironmentId, object->GetName()}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,7 +72,7 @@ String IcingaDB::GetObjectIdentifier(const ConfigObject::Ptr& object)
|
||||||
*/
|
*/
|
||||||
String IcingaDB::CalcEventID(const char* eventType, const ConfigObject::Ptr& object, double eventTime, NotificationType nt)
|
String IcingaDB::CalcEventID(const char* eventType, const ConfigObject::Ptr& object, double eventTime, NotificationType nt)
|
||||||
{
|
{
|
||||||
Array::Ptr rawId = new Array(GetObjectIdentifiersWithoutEnv(object));
|
Array::Ptr rawId = new Array({object->GetName()});
|
||||||
rawId->Insert(0, m_EnvironmentId);
|
rawId->Insert(0, m_EnvironmentId);
|
||||||
rawId->Insert(1, eventType);
|
rawId->Insert(1, eventType);
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,6 @@ private:
|
||||||
static long long TimestampToMilliseconds(double timestamp);
|
static long long TimestampToMilliseconds(double timestamp);
|
||||||
static String IcingaToStreamValue(const Value& value);
|
static String IcingaToStreamValue(const Value& value);
|
||||||
|
|
||||||
static ArrayData GetObjectIdentifiersWithoutEnv(const ConfigObject::Ptr& object);
|
|
||||||
static String GetObjectIdentifier(const ConfigObject::Ptr& object);
|
static String GetObjectIdentifier(const ConfigObject::Ptr& object);
|
||||||
static String CalcEventID(const char* eventType, const ConfigObject::Ptr& object, double eventTime = 0, NotificationType nt = NotificationType(0));
|
static String CalcEventID(const char* eventType, const ConfigObject::Ptr& object, double eventTime = 0, NotificationType nt = NotificationType(0));
|
||||||
static Dictionary::Ptr SerializeVars(const CustomVarObject::Ptr& object);
|
static Dictionary::Ptr SerializeVars(const CustomVarObject::Ptr& object);
|
||||||
|
@ -141,25 +140,6 @@ private:
|
||||||
|
|
||||||
void ExceptionHandler(boost::exception_ptr exp);
|
void ExceptionHandler(boost::exception_ptr exp);
|
||||||
|
|
||||||
template<class T>
|
|
||||||
static inline
|
|
||||||
std::vector<T> Prepend(std::vector<T>&& needle, std::vector<T>&& haystack)
|
|
||||||
{
|
|
||||||
for (auto& hay : haystack) {
|
|
||||||
needle.emplace_back(std::move(hay));
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::move(needle);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T, class Needle>
|
|
||||||
static inline
|
|
||||||
std::vector<T> Prepend(Needle&& needle, std::vector<T>&& haystack)
|
|
||||||
{
|
|
||||||
haystack.emplace(haystack.begin(), std::forward<Needle>(needle));
|
|
||||||
return std::move(haystack);
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::vector<Type::Ptr> GetTypes();
|
static std::vector<Type::Ptr> GetTypes();
|
||||||
|
|
||||||
Timer::Ptr m_StatsTimer;
|
Timer::Ptr m_StatsTimer;
|
||||||
|
|
Loading…
Reference in New Issue