mirror of https://github.com/Icinga/icinga2.git
parent
71ef1de964
commit
6fc4efccc7
|
@ -390,7 +390,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
configUpdates->emplace_back("customvar:" + kv.first);
|
configUpdates->emplace_back("customvar:" + kv.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
String id = CalculateCheckSumArray(new Array({envId, kv.first, objectKey}));
|
String id = HashValue(new Array({envId, kv.first, objectKey}));
|
||||||
typeCvs.emplace_back(id);
|
typeCvs.emplace_back(id);
|
||||||
typeCvs.emplace_back(JsonEncode(new Dictionary({{"object_id", objectKey}, {"environment_id", envId}, {"customvar_id", kv.first}})));
|
typeCvs.emplace_back(JsonEncode(new Dictionary({{"object_id", objectKey}, {"environment_id", envId}, {"customvar_id", kv.first}})));
|
||||||
|
|
||||||
|
@ -410,7 +410,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
String iconImage = checkable->GetIconImage();
|
String iconImage = checkable->GetIconImage();
|
||||||
if (!actionUrl.IsEmpty()) {
|
if (!actionUrl.IsEmpty()) {
|
||||||
auto& actionUrls (hMSets[m_PrefixConfigObject + "action_url"]);
|
auto& actionUrls (hMSets[m_PrefixConfigObject + "action_url"]);
|
||||||
actionUrls.emplace_back(CalculateCheckSumArray(new Array({envId, actionUrl})));
|
actionUrls.emplace_back(HashValue(new Array({envId, actionUrl})));
|
||||||
actionUrls.emplace_back(JsonEncode(new Dictionary({{"environment_id", envId}, {"action_url", actionUrl}})));
|
actionUrls.emplace_back(JsonEncode(new Dictionary({{"environment_id", envId}, {"action_url", actionUrl}})));
|
||||||
|
|
||||||
if (configUpdates) {
|
if (configUpdates) {
|
||||||
|
@ -419,7 +419,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
}
|
}
|
||||||
if (!notesUrl.IsEmpty()) {
|
if (!notesUrl.IsEmpty()) {
|
||||||
auto& notesUrls (hMSets[m_PrefixConfigObject + "notes_url"]);
|
auto& notesUrls (hMSets[m_PrefixConfigObject + "notes_url"]);
|
||||||
notesUrls.emplace_back(CalculateCheckSumArray(new Array({envId, notesUrl})));
|
notesUrls.emplace_back(HashValue(new Array({envId, notesUrl})));
|
||||||
notesUrls.emplace_back(JsonEncode(new Dictionary({{"environment_id", envId}, {"notes_url", notesUrl}})));
|
notesUrls.emplace_back(JsonEncode(new Dictionary({{"environment_id", envId}, {"notes_url", notesUrl}})));
|
||||||
|
|
||||||
if (configUpdates) {
|
if (configUpdates) {
|
||||||
|
@ -428,7 +428,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
}
|
}
|
||||||
if (!iconImage.IsEmpty()) {
|
if (!iconImage.IsEmpty()) {
|
||||||
auto& iconImages (hMSets[m_PrefixConfigObject + "icon_image"]);
|
auto& iconImages (hMSets[m_PrefixConfigObject + "icon_image"]);
|
||||||
iconImages.emplace_back(CalculateCheckSumArray(new Array({envId, iconImage})));
|
iconImages.emplace_back(HashValue(new Array({envId, iconImage})));
|
||||||
iconImages.emplace_back(JsonEncode(new Dictionary({{"environment_id", envId}, {"icon_image", iconImage}})));
|
iconImages.emplace_back(JsonEncode(new Dictionary({{"environment_id", envId}, {"icon_image", iconImage}})));
|
||||||
|
|
||||||
if (configUpdates) {
|
if (configUpdates) {
|
||||||
|
@ -460,7 +460,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
|
|
||||||
for (auto& group : groups) {
|
for (auto& group : groups) {
|
||||||
String groupId = GetObjectIdentifier((*getGroup)(group));
|
String groupId = GetObjectIdentifier((*getGroup)(group));
|
||||||
String id = CalculateCheckSumArray(new Array({envId, groupId, objectKey}));
|
String id = HashValue(new Array({envId, groupId, objectKey}));
|
||||||
members.emplace_back(id);
|
members.emplace_back(id);
|
||||||
members.emplace_back(JsonEncode(new Dictionary({{"object_id", objectKey}, {"environment_id", envId}, {"group_id", groupId}})));
|
members.emplace_back(JsonEncode(new Dictionary({{"object_id", objectKey}, {"environment_id", envId}, {"group_id", groupId}})));
|
||||||
|
|
||||||
|
@ -487,10 +487,10 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
rangeIds->Reserve(ranges->GetLength());
|
rangeIds->Reserve(ranges->GetLength());
|
||||||
|
|
||||||
for (auto& kv : ranges) {
|
for (auto& kv : ranges) {
|
||||||
String rangeId = CalculateCheckSumArray(new Array({envId, kv.first, kv.second}));
|
String rangeId = HashValue(new Array({envId, kv.first, kv.second}));
|
||||||
rangeIds->Add(rangeId);
|
rangeIds->Add(rangeId);
|
||||||
|
|
||||||
String id = CalculateCheckSumArray(new Array({envId, rangeId, objectKey}));
|
String id = HashValue(new Array({envId, rangeId, objectKey}));
|
||||||
typeRanges.emplace_back(id);
|
typeRanges.emplace_back(id);
|
||||||
typeRanges.emplace_back(JsonEncode(new Dictionary({{"environment_id", envId}, {"timeperiod_id", objectKey}, {"range_key", kv.first}, {"range_value", kv.second}})));
|
typeRanges.emplace_back(JsonEncode(new Dictionary({{"environment_id", envId}, {"timeperiod_id", objectKey}, {"range_key", kv.first}, {"range_value", kv.second}})));
|
||||||
|
|
||||||
|
@ -518,7 +518,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
String includeId = GetObjectIdentifier((*getInclude)(include.Get<String>()));
|
String includeId = GetObjectIdentifier((*getInclude)(include.Get<String>()));
|
||||||
includeChecksums->Add(includeId);
|
includeChecksums->Add(includeId);
|
||||||
|
|
||||||
String id = CalculateCheckSumArray(new Array({envId, includeId, objectKey}));
|
String id = HashValue(new Array({envId, includeId, objectKey}));
|
||||||
includs.emplace_back(id);
|
includs.emplace_back(id);
|
||||||
includs.emplace_back(JsonEncode(new Dictionary({{"environment_id", envId}, {"timeperiod_id", objectKey}, {"include_id", includeId}})));
|
includs.emplace_back(JsonEncode(new Dictionary({{"environment_id", envId}, {"timeperiod_id", objectKey}, {"include_id", includeId}})));
|
||||||
|
|
||||||
|
@ -546,7 +546,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
String excludeId = GetObjectIdentifier((*getExclude)(exclude.Get<String>()));
|
String excludeId = GetObjectIdentifier((*getExclude)(exclude.Get<String>()));
|
||||||
excludeChecksums->Add(excludeId);
|
excludeChecksums->Add(excludeId);
|
||||||
|
|
||||||
String id = CalculateCheckSumArray(new Array({envId, excludeId, objectKey}));
|
String id = HashValue(new Array({envId, excludeId, objectKey}));
|
||||||
excluds.emplace_back(id);
|
excluds.emplace_back(id);
|
||||||
excluds.emplace_back(JsonEncode(new Dictionary({{"environment_id", envId}, {"timeperiod_id", objectKey}, {"exclude_id", excludeId}})));
|
excluds.emplace_back(JsonEncode(new Dictionary({{"environment_id", envId}, {"timeperiod_id", objectKey}, {"exclude_id", excludeId}})));
|
||||||
|
|
||||||
|
@ -570,7 +570,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
|
|
||||||
for (auto& parent : parentsRaw) {
|
for (auto& parent : parentsRaw) {
|
||||||
String parentId = GetObjectIdentifier(parent);
|
String parentId = GetObjectIdentifier(parent);
|
||||||
String id = CalculateCheckSumArray(new Array({envId, parentId, objectKey}));
|
String id = HashValue(new Array({envId, parentId, objectKey}));
|
||||||
parnts.emplace_back(id);
|
parnts.emplace_back(id);
|
||||||
parnts.emplace_back(JsonEncode(new Dictionary({{"zone_id", objectKey}, {"environment_id", envId}, {"parent_id", parentId}})));
|
parnts.emplace_back(JsonEncode(new Dictionary({{"zone_id", objectKey}, {"environment_id", envId}, {"parent_id", parentId}})));
|
||||||
|
|
||||||
|
@ -603,7 +603,7 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S
|
||||||
|
|
||||||
for (auto& group : groups) {
|
for (auto& group : groups) {
|
||||||
String groupId = GetObjectIdentifier((*getGroup)(group));
|
String groupId = GetObjectIdentifier((*getGroup)(group));
|
||||||
String id = CalculateCheckSumArray(new Array({envId, groupId, objectKey}));
|
String id = HashValue(new Array({envId, groupId, objectKey}));
|
||||||
members.emplace_back(id);
|
members.emplace_back(id);
|
||||||
members.emplace_back(JsonEncode(new Dictionary({{"user_id", objectKey}, {"environment_id", envId}, {"group_id", groupId}})));
|
members.emplace_back(JsonEncode(new Dictionary({{"user_id", objectKey}, {"environment_id", envId}, {"group_id", groupId}})));
|
||||||
|
|
||||||
|
@ -637,7 +637,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 = CalculateCheckSumArray(new Array({envId, userId, objectKey}));
|
String id = HashValue(new Array({envId, userId, objectKey}));
|
||||||
usrs.emplace_back(id);
|
usrs.emplace_back(id);
|
||||||
usrs.emplace_back(JsonEncode(new Dictionary({{"notification_id", objectKey}, {"environment_id", envId}, {"user_id", userId}})));
|
usrs.emplace_back(JsonEncode(new Dictionary({{"notification_id", objectKey}, {"environment_id", envId}, {"user_id", userId}})));
|
||||||
|
|
||||||
|
@ -659,7 +659,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 = CalculateCheckSumArray(new Array({envId, "usergroup", usergroupId, objectKey}));
|
String id = HashValue(new Array({envId, "usergroup", usergroupId, objectKey}));
|
||||||
groups.emplace_back(id);
|
groups.emplace_back(id);
|
||||||
groups.emplace_back(JsonEncode(new Dictionary({{"notification_id", objectKey}, {"environment_id", envId}, {"usergroup_id", usergroupId}})));
|
groups.emplace_back(JsonEncode(new Dictionary({{"notification_id", objectKey}, {"environment_id", envId}, {"usergroup_id", usergroupId}})));
|
||||||
|
|
||||||
|
@ -675,7 +675,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 = CalculateCheckSumArray(new Array({envId, "user", userId, objectKey}));
|
String id = HashValue(new Array({envId, "user", userId, objectKey}));
|
||||||
notificationRecipients.emplace_back(id);
|
notificationRecipients.emplace_back(id);
|
||||||
notificationRecipients.emplace_back(JsonEncode(new Dictionary({{"notification_id", objectKey}, {"environment_id", envId}, {"user_id", userId}})));
|
notificationRecipients.emplace_back(JsonEncode(new Dictionary({{"notification_id", objectKey}, {"environment_id", envId}, {"user_id", userId}})));
|
||||||
|
|
||||||
|
@ -923,11 +923,11 @@ bool IcingaDB::PrepareObject(const ConfigObject::Ptr& object, Dictionary::Ptr& a
|
||||||
String notesUrl = checkable->GetNotesUrl();
|
String notesUrl = checkable->GetNotesUrl();
|
||||||
String iconImage = checkable->GetIconImage();
|
String iconImage = checkable->GetIconImage();
|
||||||
if (!actionUrl.IsEmpty())
|
if (!actionUrl.IsEmpty())
|
||||||
attributes->Set("action_url_id", CalculateCheckSumArray(new Array({CalculateCheckSumString(GetEnvironment()), actionUrl})));
|
attributes->Set("action_url_id", HashValue(new Array({CalculateCheckSumString(GetEnvironment()), actionUrl})));
|
||||||
if (!notesUrl.IsEmpty())
|
if (!notesUrl.IsEmpty())
|
||||||
attributes->Set("notes_url_id", CalculateCheckSumArray(new Array({CalculateCheckSumString(GetEnvironment()), notesUrl})));
|
attributes->Set("notes_url_id", HashValue(new Array({CalculateCheckSumString(GetEnvironment()), notesUrl})));
|
||||||
if (!iconImage.IsEmpty())
|
if (!iconImage.IsEmpty())
|
||||||
attributes->Set("icon_image_id", CalculateCheckSumArray(new Array({CalculateCheckSumString(GetEnvironment()), iconImage})));
|
attributes->Set("icon_image_id", HashValue(new Array({CalculateCheckSumString(GetEnvironment()), iconImage})));
|
||||||
|
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
|
|
|
@ -80,16 +80,6 @@ String IcingaDB::CalculateCheckSumString(const String& str)
|
||||||
return SHA1(str);
|
return SHA1(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
String IcingaDB::CalculateCheckSumArray(const Array::Ptr& arr)
|
|
||||||
{
|
|
||||||
/* Ensure that checksums happen in a defined order. */
|
|
||||||
Array::Ptr tmpArr = arr->ShallowClone();
|
|
||||||
|
|
||||||
tmpArr->Sort();
|
|
||||||
|
|
||||||
return SHA1(PackObject(tmpArr));
|
|
||||||
}
|
|
||||||
|
|
||||||
String IcingaDB::CalculateCheckSumProperties(const ConfigObject::Ptr& object, const std::set<String>& propertiesBlacklist)
|
String IcingaDB::CalculateCheckSumProperties(const ConfigObject::Ptr& object, const std::set<String>& propertiesBlacklist)
|
||||||
{
|
{
|
||||||
//TODO: consider precision of 6 for double values; use specific config fields for hashing?
|
//TODO: consider precision of 6 for double values; use specific config fields for hashing?
|
||||||
|
|
|
@ -84,7 +84,6 @@ private:
|
||||||
static String GetObjectIdentifier(const ConfigObject::Ptr& object);
|
static String GetObjectIdentifier(const ConfigObject::Ptr& object);
|
||||||
static String GetEnvironment();
|
static String GetEnvironment();
|
||||||
static String CalculateCheckSumString(const String& str);
|
static String CalculateCheckSumString(const String& str);
|
||||||
static String CalculateCheckSumArray(const Array::Ptr& arr);
|
|
||||||
static String CalculateCheckSumProperties(const ConfigObject::Ptr& object, const std::set<String>& propertiesBlacklist);
|
static String CalculateCheckSumProperties(const ConfigObject::Ptr& object, const std::set<String>& propertiesBlacklist);
|
||||||
static String CalculateCheckSumMetadata(const ConfigObject::Ptr& object);
|
static String CalculateCheckSumMetadata(const ConfigObject::Ptr& object);
|
||||||
static String CalculateCheckSumVars(const CustomVarObject::Ptr& object);
|
static String CalculateCheckSumVars(const CustomVarObject::Ptr& object);
|
||||||
|
|
Loading…
Reference in New Issue