mirror of
https://github.com/Icinga/icinga2.git
synced 2025-09-22 09:17:43 +02:00
Increment /var/lib/icinga2/api/zones/*/.timestamp only on config change
refs #8210
This commit is contained in:
parent
71e19c4d01
commit
ac1371a6f4
@ -13,6 +13,7 @@
|
|||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
#include "base/shared.hpp"
|
#include "base/shared.hpp"
|
||||||
#include "base/utility.hpp"
|
#include "base/utility.hpp"
|
||||||
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@ -61,11 +62,14 @@ void ApiListener::SyncLocalZoneDir(const Zone::Ptr& zone) const
|
|||||||
|
|
||||||
String zoneName = zone->GetName();
|
String zoneName = zone->GetName();
|
||||||
Dictionary::Ptr contents = new Dictionary();
|
Dictionary::Ptr contents = new Dictionary();
|
||||||
|
double ts = 0;
|
||||||
|
|
||||||
// Load registered zone paths, e.g. '_etc', '_api' and user packages.
|
// Load registered zone paths, e.g. '_etc', '_api' and user packages.
|
||||||
for (const ZoneFragment& zf : ConfigCompiler::GetZoneDirs(zoneName)) {
|
for (const ZoneFragment& zf : ConfigCompiler::GetZoneDirs(zoneName)) {
|
||||||
ConfigDirInformation newConfigPart = LoadConfigDir(zf.Path, contents);
|
ConfigDirInformation newConfigPart = LoadConfigDir(zf.Path, contents);
|
||||||
|
|
||||||
|
Utility::GlobRecursive(zf.Path, "*", [&ts](const String& path) { ts = std::max(ts, Utility::GetModTime(path)); }, GlobFile | GlobDirectory);
|
||||||
|
|
||||||
// Config files '*.conf'.
|
// Config files '*.conf'.
|
||||||
{
|
{
|
||||||
ObjectLock olock(newConfigPart.UpdateV1);
|
ObjectLock olock(newConfigPart.UpdateV1);
|
||||||
@ -89,6 +93,11 @@ void ApiListener::SyncLocalZoneDir(const Zone::Ptr& zone) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ts == 0) {
|
||||||
|
// Syncing an empty zone every time hurts less than not syncing it at all.
|
||||||
|
ts = Utility::GetTime();
|
||||||
|
}
|
||||||
|
|
||||||
size_t sumUpdates = newConfigInfo.UpdateV1->GetLength() + newConfigInfo.UpdateV2->GetLength();
|
size_t sumUpdates = newConfigInfo.UpdateV1->GetLength() + newConfigInfo.UpdateV2->GetLength();
|
||||||
|
|
||||||
// Return early if there are no updates.
|
// Return early if there are no updates.
|
||||||
@ -144,7 +153,7 @@ void ApiListener::SyncLocalZoneDir(const Zone::Ptr& zone) const
|
|||||||
if (!Utility::PathExists(tsPath)) {
|
if (!Utility::PathExists(tsPath)) {
|
||||||
std::ofstream fp(tsPath.CStr(), std::ofstream::out | std::ostream::trunc);
|
std::ofstream fp(tsPath.CStr(), std::ofstream::out | std::ostream::trunc);
|
||||||
|
|
||||||
fp << std::fixed << Utility::GetTime();
|
fp << std::fixed << ts;
|
||||||
fp.close();
|
fp.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user