mirror of https://github.com/Icinga/icinga2.git
Sync ranges_checksum for timeperiods
Signed-off-by: Michael Friedrich <michael.friedrich@icinga.com>
This commit is contained in:
parent
3e0a2f59e2
commit
c70316a835
|
@ -28,6 +28,7 @@
|
||||||
#include "icinga/checkcommand.hpp"
|
#include "icinga/checkcommand.hpp"
|
||||||
#include "icinga/eventcommand.hpp"
|
#include "icinga/eventcommand.hpp"
|
||||||
#include "icinga/notificationcommand.hpp"
|
#include "icinga/notificationcommand.hpp"
|
||||||
|
#include "icinga/timeperiod.hpp"
|
||||||
#include "remote/zone.hpp"
|
#include "remote/zone.hpp"
|
||||||
#include "base/json.hpp"
|
#include "base/json.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
|
@ -158,6 +159,11 @@ static ConfigObject::Ptr GetUserGroup(const String& name)
|
||||||
return ConfigObject::GetObject<UserGroup>(name);
|
return ConfigObject::GetObject<UserGroup>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ConfigObject::Ptr GetClude(const String& name)
|
||||||
|
{
|
||||||
|
return ConfigObject::GetObject<TimePeriod>(name);
|
||||||
|
}
|
||||||
|
|
||||||
void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTransaction, bool runtimeUpdate)
|
void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTransaction, bool runtimeUpdate)
|
||||||
{
|
{
|
||||||
AssertOnWorkQueue();
|
AssertOnWorkQueue();
|
||||||
|
@ -217,7 +223,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
||||||
groups = user->GetGroups();
|
groups = user->GetGroups();
|
||||||
getGroup = &::GetUserGroup;
|
getGroup = &::GetUserGroup;
|
||||||
|
|
||||||
checkSums->Set("groups_checksum", CalculateCheckSumGroups(groups));
|
checkSums->Set("groups_checksum", CalculateCheckSumArray(groups));
|
||||||
|
|
||||||
Array::Ptr groupChecksums = new Array();
|
Array::Ptr groupChecksums = new Array();
|
||||||
|
|
||||||
|
@ -257,7 +263,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
||||||
getGroup = &::GetHostGroup;
|
getGroup = &::GetHostGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkSums->Set("groups_checksum", CalculateCheckSumGroups(groups));
|
checkSums->Set("groups_checksum", CalculateCheckSumArray(groups));
|
||||||
|
|
||||||
Array::Ptr groupChecksums = new Array();
|
Array::Ptr groupChecksums = new Array();
|
||||||
|
|
||||||
|
@ -310,7 +316,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
||||||
endpoints->Set(i++, endpointObject->GetName());
|
endpoints->Set(i++, endpointObject->GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
checkSums->Set("endpoints_checksum", CalculateCheckSumGroups(endpoints));
|
checkSums->Set("endpoints_checksum", CalculateCheckSumArray(endpoints));
|
||||||
|
|
||||||
Zone::Ptr parentZone = zone->GetParent();
|
Zone::Ptr parentZone = zone->GetParent();
|
||||||
|
|
||||||
|
@ -351,6 +357,55 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
|
||||||
checkSums->Set("envvars_checksum", HashValue(envvars));
|
checkSums->Set("envvars_checksum", HashValue(envvars));
|
||||||
checkSums->Set("envvar_checksums", envvarChecksums);
|
checkSums->Set("envvar_checksums", envvarChecksums);
|
||||||
propertiesBlacklist.emplace("env");
|
propertiesBlacklist.emplace("env");
|
||||||
|
} else {
|
||||||
|
auto timeperiod (dynamic_pointer_cast<TimePeriod>(object));
|
||||||
|
|
||||||
|
if (timeperiod) {
|
||||||
|
Dictionary::Ptr ranges = timeperiod->GetRanges();
|
||||||
|
|
||||||
|
checkSums->Set("ranges_checksum", HashValue(ranges));
|
||||||
|
propertiesBlacklist.emplace("ranges");
|
||||||
|
|
||||||
|
// Compute checksums for Includes (like groups)
|
||||||
|
Array::Ptr includes;
|
||||||
|
ConfigObject::Ptr (*getInclude)(const String& name);
|
||||||
|
|
||||||
|
includes = timeperiod->GetIncludes();
|
||||||
|
getInclude = &::GetClude;
|
||||||
|
|
||||||
|
checkSums->Set("includes_checksum", CalculateCheckSumArray(includes));
|
||||||
|
|
||||||
|
Array::Ptr includeChecksums = new Array();
|
||||||
|
|
||||||
|
ObjectLock includesLock (includes);
|
||||||
|
ObjectLock includeChecksumsLock (includeChecksums);
|
||||||
|
|
||||||
|
for (auto include : includes) {
|
||||||
|
includeChecksums->Add(GetIdentifier((*getInclude)(include.Get<String>())));
|
||||||
|
}
|
||||||
|
|
||||||
|
checkSums->Set("include_checksums", includeChecksums);
|
||||||
|
|
||||||
|
// Compute checksums for Excludes (like groups)
|
||||||
|
Array::Ptr excludes;
|
||||||
|
ConfigObject::Ptr (*getExclude)(const String& name);
|
||||||
|
|
||||||
|
excludes = timeperiod->GetExcludes();
|
||||||
|
getExclude = &::GetClude;
|
||||||
|
|
||||||
|
checkSums->Set("excludes_checksum", CalculateCheckSumArray(excludes));
|
||||||
|
|
||||||
|
Array::Ptr excludeChecksums = new Array();
|
||||||
|
|
||||||
|
ObjectLock excludesLock (excludes);
|
||||||
|
ObjectLock excludeChecksumsLock (excludeChecksums);
|
||||||
|
|
||||||
|
for (auto exclude : excludes) {
|
||||||
|
excludeChecksums->Add(GetIdentifier((*getExclude)(exclude.Get<String>())));
|
||||||
|
}
|
||||||
|
|
||||||
|
checkSums->Set("exclude_checksums", excludeChecksums);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,14 +59,14 @@ String RedisWriter::CalculateCheckSumString(const String& str)
|
||||||
return SHA1(str);
|
return SHA1(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
String RedisWriter::CalculateCheckSumGroups(const Array::Ptr& groups)
|
String RedisWriter::CalculateCheckSumArray(const Array::Ptr& arr)
|
||||||
{
|
{
|
||||||
/* Ensure that checksums happen in a defined order. */
|
/* Ensure that checksums happen in a defined order. */
|
||||||
Array::Ptr tmpGroups = groups->ShallowClone();
|
Array::Ptr tmpArr = arr->ShallowClone();
|
||||||
|
|
||||||
tmpGroups->Sort();
|
tmpArr->Sort();
|
||||||
|
|
||||||
return SHA1(PackObject(tmpGroups));
|
return SHA1(PackObject(tmpArr));
|
||||||
}
|
}
|
||||||
|
|
||||||
String RedisWriter::CalculateCheckSumProperties(const ConfigObject::Ptr& object, const std::set<String>& propertiesBlacklist)
|
String RedisWriter::CalculateCheckSumProperties(const ConfigObject::Ptr& object, const std::set<String>& propertiesBlacklist)
|
||||||
|
|
|
@ -80,7 +80,7 @@ private:
|
||||||
static String GetIdentifier(const ConfigObject::Ptr& object);
|
static String GetIdentifier(const ConfigObject::Ptr& object);
|
||||||
static String GetEnvironment();
|
static String GetEnvironment();
|
||||||
static String CalculateCheckSumString(const String& str);
|
static String CalculateCheckSumString(const String& str);
|
||||||
static String CalculateCheckSumGroups(const Array::Ptr& groups);
|
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