mirror of
https://github.com/Icinga/icinga2.git
synced 2025-06-14 18:50:31 +02:00
Merge pull request #9586 from Icinga/9363
icinga2 daemon: write icinga2.debug only if --dump-objects given
This commit is contained in:
commit
ae32b3cbbd
@ -430,6 +430,7 @@ Command options:
|
|||||||
-c [ --config ] arg parse a configuration file
|
-c [ --config ] arg parse a configuration file
|
||||||
-z [ --no-config ] start without a configuration file
|
-z [ --no-config ] start without a configuration file
|
||||||
-C [ --validate ] exit after validating the configuration
|
-C [ --validate ] exit after validating the configuration
|
||||||
|
--dump-objects write icinga2.debug cache file for icinga2 object list
|
||||||
-e [ --errorlog ] arg log fatal errors to the specified log file (only
|
-e [ --errorlog ] arg log fatal errors to the specified log file (only
|
||||||
works in combination with --daemonize or
|
works in combination with --daemonize or
|
||||||
--close-stdio)
|
--close-stdio)
|
||||||
@ -520,10 +521,9 @@ attributes. The command also shows where each of the attributes was modified and
|
|||||||
provides debug information for further configuration problem analysis.
|
provides debug information for further configuration problem analysis.
|
||||||
That way you can also identify which objects have been created from your [apply rules](17-language-reference.md#apply).
|
That way you can also identify which objects have been created from your [apply rules](17-language-reference.md#apply).
|
||||||
|
|
||||||
Runtime modifications via the [REST API](12-icinga2-api.md#icinga2-api-config-objects)
|
Configuration modifications are not immediately updated. Furthermore there is a known issue with
|
||||||
are not immediately updated. Furthermore there is a known issue with
|
|
||||||
[group assign expressions](17-language-reference.md#group-assign) which are not reflected in the host object output.
|
[group assign expressions](17-language-reference.md#group-assign) which are not reflected in the host object output.
|
||||||
You need to restart Icinga 2 in order to update the `icinga2.debug` cache file.
|
You need to run `icinga2 daemon -C --dump-objects` in order to update the `icinga2.debug` cache file.
|
||||||
|
|
||||||
More information can be found in the [troubleshooting](15-troubleshooting.md#troubleshooting-list-configuration-objects) section.
|
More information can be found in the [troubleshooting](15-troubleshooting.md#troubleshooting-list-configuration-objects) section.
|
||||||
|
|
||||||
|
@ -310,10 +310,9 @@ Found 1 Service objects.
|
|||||||
[2014-10-15 14:27:19 +0200] information/cli: Parsed 175 objects.
|
[2014-10-15 14:27:19 +0200] information/cli: Parsed 175 objects.
|
||||||
```
|
```
|
||||||
|
|
||||||
Runtime modifications via the [REST API](12-icinga2-api.md#icinga2-api-config-objects)
|
Configuration modifications are not immediately updated. Furthermore there is a known issue with
|
||||||
are not immediately updated. Furthermore there is a known issue with
|
|
||||||
[group assign expressions](17-language-reference.md#group-assign) which are not reflected in the host object output.
|
[group assign expressions](17-language-reference.md#group-assign) which are not reflected in the host object output.
|
||||||
You need to restart Icinga 2 in order to update the `icinga2.debug` cache file.
|
You need to `icinga2 daemon -C --dump-objects` in order to update the `icinga2.debug` cache file.
|
||||||
|
|
||||||
### Apply rules do not match <a id="apply-rules-do-not-match"></a>
|
### Apply rules do not match <a id="apply-rules-do-not-match"></a>
|
||||||
|
|
||||||
|
@ -176,6 +176,7 @@ void DaemonCommand::InitParameters(boost::program_options::options_description&
|
|||||||
("config,c", po::value<std::vector<std::string> >(), "parse a configuration file")
|
("config,c", po::value<std::vector<std::string> >(), "parse a configuration file")
|
||||||
("no-config,z", "start without a configuration file")
|
("no-config,z", "start without a configuration file")
|
||||||
("validate,C", "exit after validating the configuration")
|
("validate,C", "exit after validating the configuration")
|
||||||
|
("dump-objects", "write icinga2.debug cache file for icinga2 object list")
|
||||||
("errorlog,e", po::value<std::string>(), "log fatal errors to the specified log file (only works in combination with --daemonize or --close-stdio)")
|
("errorlog,e", po::value<std::string>(), "log fatal errors to the specified log file (only works in combination with --daemonize or --close-stdio)")
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
("daemonize,d", "detach from the controlling terminal")
|
("daemonize,d", "detach from the controlling terminal")
|
||||||
@ -218,6 +219,8 @@ static double GetDebugWorkerDelay()
|
|||||||
}
|
}
|
||||||
#endif /* I2_DEBUG */
|
#endif /* I2_DEBUG */
|
||||||
|
|
||||||
|
static String l_ObjectsPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do the actual work (config loading, ...)
|
* Do the actual work (config loading, ...)
|
||||||
*
|
*
|
||||||
@ -248,7 +251,7 @@ int RunWorker(const std::vector<std::string>& configs, bool closeConsoleLog = fa
|
|||||||
{
|
{
|
||||||
std::vector<ConfigItem::Ptr> newItems;
|
std::vector<ConfigItem::Ptr> newItems;
|
||||||
|
|
||||||
if (!DaemonUtility::LoadConfigFiles(configs, newItems, Configuration::ObjectsPath, Configuration::VarsPath)) {
|
if (!DaemonUtility::LoadConfigFiles(configs, newItems, l_ObjectsPath, Configuration::VarsPath)) {
|
||||||
Log(LogCritical, "cli", "Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.");
|
Log(LogCritical, "cli", "Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.");
|
||||||
NotifyStatus("Config validation failed.");
|
NotifyStatus("Config validation failed.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -626,12 +629,21 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector<std::strin
|
|||||||
configs.push_back(configDir + "/icinga2.conf");
|
configs.push_back(configDir + "/icinga2.conf");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (vm.count("dump-objects")) {
|
||||||
|
if (!vm.count("validate")) {
|
||||||
|
Log(LogCritical, "cli", "--dump-objects is not allowed without -C");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
l_ObjectsPath = Configuration::ObjectsPath;
|
||||||
|
}
|
||||||
|
|
||||||
if (vm.count("validate")) {
|
if (vm.count("validate")) {
|
||||||
Log(LogInformation, "cli", "Loading configuration file(s).");
|
Log(LogInformation, "cli", "Loading configuration file(s).");
|
||||||
|
|
||||||
std::vector<ConfigItem::Ptr> newItems;
|
std::vector<ConfigItem::Ptr> newItems;
|
||||||
|
|
||||||
if (!DaemonUtility::LoadConfigFiles(configs, newItems, Configuration::ObjectsPath, Configuration::VarsPath)) {
|
if (!DaemonUtility::LoadConfigFiles(configs, newItems, l_ObjectsPath, Configuration::VarsPath)) {
|
||||||
Log(LogCritical, "cli", "Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.");
|
Log(LogCritical, "cli", "Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
*
|
*
|
||||||
@ -55,7 +69,7 @@ int ObjectListCommand::Run(const boost::program_options::variables_map& vm, cons
|
|||||||
if (!Utility::PathExists(objectfile)) {
|
if (!Utility::PathExists(objectfile)) {
|
||||||
Log(LogCritical, "cli")
|
Log(LogCritical, "cli")
|
||||||
<< "Cannot open objects file '" << Configuration::ObjectsPath << "'.";
|
<< "Cannot open objects file '" << Configuration::ObjectsPath << "'.";
|
||||||
Log(LogCritical, "cli", "Run 'icinga2 daemon -C' to validate config and generate the cache file.");
|
Log(LogCritical, "cli", "Run 'icinga2 daemon -C --dump-objects' to validate config and generate the cache file.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,9 @@ void ConfigCompilerContext::WriteObject(const Dictionary::Ptr& object)
|
|||||||
|
|
||||||
void ConfigCompilerContext::CancelObjectsFile()
|
void ConfigCompilerContext::CancelObjectsFile()
|
||||||
{
|
{
|
||||||
|
if (!m_ObjectsFP)
|
||||||
|
return;
|
||||||
|
|
||||||
delete m_ObjectsFP;
|
delete m_ObjectsFP;
|
||||||
m_ObjectsFP = nullptr;
|
m_ObjectsFP = nullptr;
|
||||||
|
|
||||||
@ -60,6 +63,9 @@ void ConfigCompilerContext::CancelObjectsFile()
|
|||||||
|
|
||||||
void ConfigCompilerContext::FinishObjectsFile()
|
void ConfigCompilerContext::FinishObjectsFile()
|
||||||
{
|
{
|
||||||
|
if (!m_ObjectsFP)
|
||||||
|
return;
|
||||||
|
|
||||||
delete m_ObjectsFP;
|
delete m_ObjectsFP;
|
||||||
m_ObjectsFP = nullptr;
|
m_ObjectsFP = nullptr;
|
||||||
|
|
||||||
|
@ -22,6 +22,11 @@ public:
|
|||||||
void CancelObjectsFile();
|
void CancelObjectsFile();
|
||||||
void FinishObjectsFile();
|
void FinishObjectsFile();
|
||||||
|
|
||||||
|
inline bool IsOpen() const noexcept
|
||||||
|
{
|
||||||
|
return m_ObjectsFP;
|
||||||
|
}
|
||||||
|
|
||||||
static ConfigCompilerContext *GetInstance();
|
static ConfigCompilerContext *GetInstance();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -286,6 +286,7 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
|
|||||||
BOOST_THROW_EXCEPTION(ValidationError(dobj, ex.GetPath(), "Circular references are not allowed"));
|
BOOST_THROW_EXCEPTION(ValidationError(dobj, ex.GetPath(), "Circular references are not allowed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ConfigCompilerContext::GetInstance()->IsOpen()) {
|
||||||
Dictionary::Ptr persistentItem = new Dictionary({
|
Dictionary::Ptr persistentItem = new Dictionary({
|
||||||
{ "type", type->GetName() },
|
{ "type", type->GetName() },
|
||||||
{ "name", GetName() },
|
{ "name", GetName() },
|
||||||
@ -300,10 +301,10 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
|
|||||||
}) }
|
}) }
|
||||||
});
|
});
|
||||||
|
|
||||||
dhint.reset();
|
|
||||||
|
|
||||||
ConfigCompilerContext::GetInstance()->WriteObject(persistentItem);
|
ConfigCompilerContext::GetInstance()->WriteObject(persistentItem);
|
||||||
persistentItem.reset();
|
}
|
||||||
|
|
||||||
|
dhint.reset();
|
||||||
|
|
||||||
dobj->Register();
|
dobj->Register();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user