mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-22 13:14:32 +02:00
Improve checksum checks for each file content
This commit is contained in:
parent
a6ddef17d9
commit
f92f6f7f8c
@ -336,17 +336,12 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D
|
|||||||
* Otherwise do the old timestamp dance for versions < 2.11.
|
* Otherwise do the old timestamp dance for versions < 2.11.
|
||||||
*/
|
*/
|
||||||
if (checksums) {
|
if (checksums) {
|
||||||
/* Calculate and compare the checksums. */
|
|
||||||
String productionConfigChecksum = GetGlobalChecksum(productionConfigInfo);
|
|
||||||
String newConfigChecksum = GetGlobalChecksum(newConfigInfo);
|
|
||||||
|
|
||||||
Log(LogInformation, "ApiListener")
|
Log(LogInformation, "ApiListener")
|
||||||
<< "Received configuration for zone '" << zoneName << "' from endpoint '"
|
<< "Received configuration for zone '" << zoneName << "' from endpoint '"
|
||||||
<< fromEndpointName << "' with checksum '" << newConfigChecksum << "'."
|
<< fromEndpointName << "'. Comparing the checksums.";
|
||||||
<< " Our production configuration has checksum '" << productionConfigChecksum << "'.";
|
|
||||||
|
|
||||||
/* TODO: Do this earlier in hello-handshakes. */
|
/* TODO: Do this earlier in hello-handshakes. */
|
||||||
if (newConfigChecksum != productionConfigChecksum)
|
if (CheckConfigChange(productionConfigInfo, newConfigInfo))
|
||||||
configChange = true;
|
configChange = true;
|
||||||
} else {
|
} else {
|
||||||
/* TODO: Figure out whether we always need to rely on the timestamp flags when there are checksums involved. */
|
/* TODO: Figure out whether we always need to rely on the timestamp flags when there are checksums involved. */
|
||||||
@ -608,17 +603,23 @@ String ApiListener::GetChecksum(const String& content)
|
|||||||
return SHA256(content);
|
return SHA256(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
String ApiListener::GetGlobalChecksum(const ConfigDirInformation& config)
|
bool ApiListener::CheckConfigChange(const ConfigDirInformation& oldConfig, const ConfigDirInformation& newConfig)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr checksums = config.Checksums;
|
Dictionary::Ptr oldChecksums = oldConfig.Checksums;
|
||||||
|
Dictionary::Ptr newChecksums = newConfig.Checksums;
|
||||||
|
|
||||||
String result;
|
Log(LogCritical, "Comparing old: '")
|
||||||
|
<< JsonEncode(oldChecksums)
|
||||||
|
<< "' to new '" << JsonEncode(newChecksums) << "'.";
|
||||||
|
|
||||||
ObjectLock olock(checksums);
|
/* Different length means that either one or the other side added or removed something. */
|
||||||
for (const Dictionary::Pair& kv : checksums) {
|
if (oldChecksums->GetLength() != newChecksums->GetLength())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
/* Both dictionaries have an equal size. */
|
||||||
|
ObjectLock olock(oldChecksums);
|
||||||
|
for (const Dictionary::Pair& kv : oldChecksums) {
|
||||||
String path = kv.first;
|
String path = kv.first;
|
||||||
String checksum = kv.second;
|
|
||||||
|
|
||||||
/* Only use configuration files for checksum calculation. */
|
/* Only use configuration files for checksum calculation. */
|
||||||
//if (!Utility::Match("*.conf", path))
|
//if (!Utility::Match("*.conf", path))
|
||||||
// continue;
|
// continue;
|
||||||
@ -630,11 +631,14 @@ String ApiListener::GetGlobalChecksum(const ConfigDirInformation& config)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
Log(LogCritical, "ApiListener")
|
Log(LogCritical, "ApiListener")
|
||||||
<< "Adding checksum for " << kv.first << ": " << kv.second;
|
<< "Checking " << path << " for checksum: " << kv.second;
|
||||||
result += kv.second;
|
|
||||||
|
/* Check whether our key exists in the new checksums, and they have an equal value. */
|
||||||
|
if (newChecksums->Get(path) != kv.second)
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetChecksum(result);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -186,7 +186,7 @@ private:
|
|||||||
static void AsyncTryActivateZonesStage(const std::vector<String>& relativePaths);
|
static void AsyncTryActivateZonesStage(const std::vector<String>& relativePaths);
|
||||||
|
|
||||||
static String GetChecksum(const String& content);
|
static String GetChecksum(const String& content);
|
||||||
static String GetGlobalChecksum(const ConfigDirInformation& config);
|
static bool CheckConfigChange(const ConfigDirInformation& oldConfig, const ConfigDirInformation& newConfig);
|
||||||
|
|
||||||
void UpdateLastFailedZonesStageValidation(const String& log);
|
void UpdateLastFailedZonesStageValidation(const String& log);
|
||||||
void ClearLastFailedZonesStageValidation();
|
void ClearLastFailedZonesStageValidation();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user