mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
icinga2 object list: warn on possibly outdated config
This commit is contained in:
parent
0767c6ef87
commit
f71612d8f3
@ -250,8 +250,6 @@ bool DaemonUtility::LoadConfigFiles(const std::vector<std::string>& configs,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigCompilerContext::GetInstance()->FinishObjectsFile();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ScriptGlobal::WriteToFile(varsfile);
|
ScriptGlobal::WriteToFile(varsfile);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
@ -259,5 +257,7 @@ bool DaemonUtility::LoadConfigFiles(const std::vector<std::string>& configs,
|
|||||||
Application::Exit(1);
|
Application::Exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigCompilerContext::GetInstance()->FinishObjectsFile();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
namespace po = boost::program_options;
|
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");
|
("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.
|
* 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")
|
Log(LogNotice, "cli")
|
||||||
<< "Parsed " << objects_count << " objects.";
|
<< "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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user