icinga2 object list: warn on possibly outdated config

This commit is contained in:
Alexander A. Klimov 2022-11-21 14:50:56 +01:00
parent 0767c6ef87
commit f71612d8f3
2 changed files with 25 additions and 2 deletions

View File

@ -250,8 +250,6 @@ bool DaemonUtility::LoadConfigFiles(const std::vector<std::string>& configs,
return false;
}
ConfigCompilerContext::GetInstance()->FinishObjectsFile();
try {
ScriptGlobal::WriteToFile(varsfile);
} catch (const std::exception& ex) {
@ -259,5 +257,7 @@ bool DaemonUtility::LoadConfigFiles(const std::vector<std::string>& configs,
Application::Exit(1);
}
ConfigCompilerContext::GetInstance()->FinishObjectsFile();
return true;
}

View File

@ -18,6 +18,7 @@
#include <fstream>
#include <iostream>
#include <iomanip>
#include <sys/stat.h>
using namespace icinga;
namespace po = boost::program_options;
@ -43,6 +44,19 @@ void ObjectListCommand::InitParameters(boost::program_options::options_descripti
("type,t", po::value<std::string>(), "filter by type matches");
}
static time_t GetCtime(const String& path)
{
#ifdef _WIN32
struct _stat statbuf;
int rc = _stat(path.CStr(), &statbuf);
#else /* _WIN32 */
struct stat statbuf;
int rc = stat(path.CStr(), &statbuf);
#endif /* _WIN32 */
return rc ? 0 : statbuf.st_ctime;
}
/**
* The entry point for the "object list" CLI command.
*
@ -104,6 +118,15 @@ int ObjectListCommand::Run(const boost::program_options::variables_map& vm, cons
Log(LogNotice, "cli")
<< "Parsed " << objects_count << " objects.";
auto objectsPathCtime (GetCtime(Configuration::ObjectsPath));
auto varsPathCtime (GetCtime(Configuration::VarsPath));
if (objectsPathCtime < varsPathCtime) {
Log(LogWarning, "cli")
<< "This data is " << Utility::FormatDuration(varsPathCtime - objectsPathCtime)
<< " older than the last Icinga config (re)load. It may be outdated. Consider running 'icinga2 daemon -C --dump-objects' first.";
}
return 0;
}