From 6de9f58810fe255e9401cd7f35730d02ea906128 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Thu, 8 Apr 2021 11:23:26 +0200 Subject: [PATCH 1/5] Add WindowsEventLogLogger --- doc/09-object-types.md | 17 +++++ doc/14-features.md | 11 +-- etc/CMakeLists.txt | 2 + .../features-available/windowseventlog.conf | 8 +++ icinga-installer/icinga2.wixpatch.cmake | 14 ++++ lib/base/CMakeLists.txt | 27 +++++++ lib/base/windowseventloglogger-provider.mc | 5 ++ lib/base/windowseventloglogger.cpp | 71 +++++++++++++++++++ lib/base/windowseventloglogger.hpp | 35 +++++++++ lib/base/windowseventloglogger.ti | 15 ++++ tools/syntax/vim/syntax/icinga2.vim | 2 +- 11 files changed, 201 insertions(+), 6 deletions(-) create mode 100644 etc/icinga2/features-available/windowseventlog.conf create mode 100644 lib/base/windowseventloglogger-provider.mc create mode 100644 lib/base/windowseventloglogger.cpp create mode 100644 lib/base/windowseventloglogger.hpp create mode 100644 lib/base/windowseventloglogger.ti diff --git a/doc/09-object-types.md b/doc/09-object-types.md index 85b397ece..950a843a7 100644 --- a/doc/09-object-types.md +++ b/doc/09-object-types.md @@ -1864,4 +1864,21 @@ Facility Constants: FacilityUucp | LOG\_UUCP | The UUCP system. +### WindowsEventLogLogger +Specifies Icinga 2 logging to the Windows Event Log. +This configuration object is available as `windowseventlog` [logging feature](14-features.md#logging). + +Example: + +``` +object WindowsEventLogLogger "windowseventlog" { + severity = "warning" +} +``` + +Configuration Attributes: + + Name | Type | Description + --------------------------|-----------------------|---------------------------------- + severity | String | **Optional.** The minimum severity for this log. Can be "debug", "notice", "information", "warning" or "critical". Defaults to "warning". diff --git a/doc/14-features.md b/doc/14-features.md index 823d4149a..2b5a30c62 100644 --- a/doc/14-features.md +++ b/doc/14-features.md @@ -11,11 +11,12 @@ Icinga 2 supports three different types of logging: You can enable additional loggers using the `icinga2 feature enable` and `icinga2 feature disable` commands to configure loggers: -Feature | Description ----------|------------ -debuglog | Debug log (path: `/var/log/icinga2/debug.log`, severity: `debug` or higher) -mainlog | Main log (path: `/var/log/icinga2/icinga2.log`, severity: `information` or higher) -syslog | Syslog (severity: `warning` or higher) +Feature | Description +----------------|------------ +debuglog | Debug log (path: `/var/log/icinga2/debug.log`, severity: `debug` or higher) +mainlog | Main log (path: `/var/log/icinga2/icinga2.log`, severity: `information` or higher) +syslog | Syslog (severity: `warning` or higher) +windowseventlog | Windows Event Log (severity: `warning` or higher) By default file the `mainlog` feature is enabled. When running Icinga 2 on a terminal log messages with severity `information` or higher are diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt index f693bbcd4..47c8a40e2 100644 --- a/etc/CMakeLists.txt +++ b/etc/CMakeLists.txt @@ -39,6 +39,8 @@ install_if_not_exists(icinga2/features-available/debuglog.conf ${ICINGA2_CONFIGD install_if_not_exists(icinga2/features-available/mainlog.conf ${ICINGA2_CONFIGDIR}/features-available) if(NOT WIN32) install_if_not_exists(icinga2/features-available/syslog.conf ${ICINGA2_CONFIGDIR}/features-available) +else() + install_if_not_exists(icinga2/features-available/windowseventlog.conf ${ICINGA2_CONFIGDIR}/features-available) endif() install_if_not_exists(icinga2/scripts/mail-host-notification.sh ${ICINGA2_CONFIGDIR}/scripts) install_if_not_exists(icinga2/scripts/mail-service-notification.sh ${ICINGA2_CONFIGDIR}/scripts) diff --git a/etc/icinga2/features-available/windowseventlog.conf b/etc/icinga2/features-available/windowseventlog.conf new file mode 100644 index 000000000..ddd5716ee --- /dev/null +++ b/etc/icinga2/features-available/windowseventlog.conf @@ -0,0 +1,8 @@ +/** + * The WindowsEventLogLogger type writes log information to the Windows Event Log. + */ + +object WindowsEventLogLogger "windowseventlog" { + severity = "warning" +} + diff --git a/icinga-installer/icinga2.wixpatch.cmake b/icinga-installer/icinga2.wixpatch.cmake index 5ee6361ae..eee4027ca 100644 --- a/icinga-installer/icinga2.wixpatch.cmake +++ b/icinga-installer/icinga2.wixpatch.cmake @@ -20,6 +20,20 @@ $CM_CP_sbin.icinga2_installer.exe=2 AND NOT SUPPRESS_XTRA + + + + + + + + + diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index 2a5391818..9707d2935 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -85,6 +85,33 @@ set(base_SOURCES workqueue.cpp workqueue.hpp ) +if(WIN32) + mkclass_target(windowseventloglogger.ti windowseventloglogger-ti.cpp windowseventloglogger-ti.hpp) + list(APPEND base_SOURCES windowseventloglogger.cpp windowseventloglogger.hpp windowseventloglogger-ti.hpp) + + # Generate a DLL containing message definitions for the Windows Event Viewer. + # See also: https://docs.microsoft.com/en-us/windows/win32/eventlog/reporting-an-event + add_custom_command( + OUTPUT windowseventloglogger-provider.rc windowseventloglogger-provider.h + COMMAND mc ARGS -U ${CMAKE_CURRENT_SOURCE_DIR}/windowseventloglogger-provider.mc + DEPENDS windowseventloglogger-provider.mc + ) + + list(APPEND base_SOURCES windowseventloglogger-provider.h) + + add_custom_command( + OUTPUT windowseventloglogger-provider.res + COMMAND rc ARGS windowseventloglogger-provider.rc + DEPENDS windowseventloglogger-provider.rc + ) + + add_library(eventprovider MODULE windowseventloglogger-provider.res windowseventloglogger-provider.rc) + set_target_properties(eventprovider PROPERTIES LINKER_LANGUAGE CXX) + target_link_libraries(eventprovider PRIVATE -noentry) + + install(TARGETS eventprovider LIBRARY DESTINATION ${CMAKE_INSTALL_SBINDIR}) +endif() + set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/application-version.cpp PROPERTY EXCLUDE_UNITY_BUILD TRUE) if(ICINGA2_UNITY_BUILD) diff --git a/lib/base/windowseventloglogger-provider.mc b/lib/base/windowseventloglogger-provider.mc new file mode 100644 index 000000000..09e65ba57 --- /dev/null +++ b/lib/base/windowseventloglogger-provider.mc @@ -0,0 +1,5 @@ +MessageId=0x1 +SymbolicName=MSG_PLAIN_LOG_ENTRY +Language=English +%1 +. diff --git a/lib/base/windowseventloglogger.cpp b/lib/base/windowseventloglogger.cpp new file mode 100644 index 000000000..8c9582351 --- /dev/null +++ b/lib/base/windowseventloglogger.cpp @@ -0,0 +1,71 @@ +/* Icinga 2 | (c) 2021 Icinga GmbH | GPLv2+ */ + +#ifdef _WIN32 +#include "base/windowseventloglogger.hpp" +#include "base/windowseventloglogger-ti.cpp" +#include "base/windowseventloglogger-provider.h" +#include "base/configtype.hpp" +#include "base/statsfunction.hpp" +#include + +using namespace icinga; + +REGISTER_TYPE(WindowsEventLogLogger); + +REGISTER_STATSFUNCTION(WindowsEventLogLogger, &WindowsEventLogLogger::StatsFunc); + +INITIALIZE_ONCE(&WindowsEventLogLogger::StaticInitialize); + +static HANDLE l_EventLog = nullptr; + +void WindowsEventLogLogger::StaticInitialize() +{ + l_EventLog = RegisterEventSourceA(nullptr, "Icinga 2"); +} + +void WindowsEventLogLogger::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&) +{ + DictionaryData nodes; + + for (const WindowsEventLogLogger::Ptr& logger : ConfigType::GetObjectsByType()) { + nodes.emplace_back(logger->GetName(), 1); + } + + status->Set("windowseventloglogger", new Dictionary(std::move(nodes))); +} + +/** + * Processes a log entry and outputs it to the Windows Event Log. + * + * @param entry The log entry. + */ +void WindowsEventLogLogger::ProcessLogEntry(const LogEntry& entry) +{ + if (l_EventLog != nullptr) { + std::string message = Logger::SeverityToString(entry.Severity) + "/" + entry.Facility + ": " + entry.Message; + std::array strings{ + message.c_str() + }; + + WORD eventType; + switch (entry.Severity) { + case LogCritical: + eventType = EVENTLOG_ERROR_TYPE; + break; + case LogWarning: + eventType = EVENTLOG_WARNING_TYPE; + break; + default: + eventType = EVENTLOG_INFORMATION_TYPE; + } + + ReportEventA(l_EventLog, eventType, 0, MSG_PLAIN_LOG_ENTRY, NULL, strings.size(), 0, strings.data(), NULL); + } +} + +void WindowsEventLogLogger::Flush() +{ + /* Nothing to do here. */ +} + +#endif /* _WIN32 */ diff --git a/lib/base/windowseventloglogger.hpp b/lib/base/windowseventloglogger.hpp new file mode 100644 index 000000000..7b8b03e91 --- /dev/null +++ b/lib/base/windowseventloglogger.hpp @@ -0,0 +1,35 @@ +/* Icinga 2 | (c) 2021 Icinga GmbH | GPLv2+ */ + +#ifndef WINDOWSEVENTLOGLOGGER_H +#define WINDOWSEVENTLOGLOGGER_H + +#ifdef _WIN32 +#include "base/i2-base.hpp" +#include "base/windowseventloglogger-ti.hpp" + +namespace icinga +{ + +/** + * A logger that logs to the Windows Event Log. + * + * @ingroup base + */ +class WindowsEventLogLogger final : public ObjectImpl +{ +public: + DECLARE_OBJECT(WindowsEventLogLogger); + DECLARE_OBJECTNAME(WindowsEventLogLogger); + + static void StaticInitialize(); + static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata); + +protected: + void ProcessLogEntry(const LogEntry& entry) override; + void Flush() override; +}; + +} +#endif /* _WIN32 */ + +#endif /* WINDOWSEVENTLOGLOGGER_H */ diff --git a/lib/base/windowseventloglogger.ti b/lib/base/windowseventloglogger.ti new file mode 100644 index 000000000..edf65fc06 --- /dev/null +++ b/lib/base/windowseventloglogger.ti @@ -0,0 +1,15 @@ +/* Icinga 2 | (c) 2021 Icinga GmbH | GPLv2+ */ + +#include "base/logger.hpp" + +library base; + +namespace icinga +{ + +class WindowsEventLogLogger : Logger +{ + activation_priority -100; +}; + +} diff --git a/tools/syntax/vim/syntax/icinga2.vim b/tools/syntax/vim/syntax/icinga2.vim index 0374c7b5a..59ff202f1 100644 --- a/tools/syntax/vim/syntax/icinga2.vim +++ b/tools/syntax/vim/syntax/icinga2.vim @@ -60,7 +60,7 @@ syn keyword icinga2ObjType IcingaApplication IdoMysqlConnection IdoPgsqlConnec syn keyword icinga2ObjType InfluxdbWriter LivestatusListener Notification NotificationCommand syn keyword icinga2ObjType NotificationComponent OpenTsdbWriter PerfdataWriter syn keyword icinga2ObjType ScheduledDowntime Service ServiceGroup SyslogLogger -syn keyword icinga2ObjType TimePeriod User UserGroup Zone +syn keyword icinga2ObjType TimePeriod User UserGroup WindowsEventLogLogger Zone " Object/Template marker (simplified) syn match icinga2ObjDef "\(object\|template\)[ \t]\+.*" From 05ca30a6a0e8f2485da22ae0d3da9774a7c97f9b Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Thu, 8 Apr 2021 13:49:53 +0200 Subject: [PATCH 2/5] Write early log messages to the Windows Event Log When Icinga 2 is started as a service, the early log messages generated until the FileLogger object is activated are lost and make it really hard to debug issues that (only) occur when Icinga 2 reloads. With this commit, these early log messages are written to the Windows Event Log. --- lib/base/logger.cpp | 18 ++++++++++++++++++ lib/base/logger.hpp | 3 +++ lib/base/windowseventloglogger.cpp | 14 +++++++++++++- lib/base/windowseventloglogger.hpp | 2 ++ lib/config/configitem.cpp | 14 ++++++++++++++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index 53698bf3c..fe5668779 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -9,6 +9,9 @@ #include "base/objectlock.hpp" #include "base/context.hpp" #include "base/scriptglobal.hpp" +#ifdef _WIN32 +#include "base/windowseventloglogger.hpp" +#endif /* _WIN32 */ #include #include @@ -29,6 +32,7 @@ REGISTER_TYPE(Logger); std::set Logger::m_Loggers; std::mutex Logger::m_Mutex; bool Logger::m_ConsoleLogEnabled = true; +std::atomic Logger::m_EarlyLoggingEnabled (true); bool Logger::m_TimestampEnabled = true; LogSeverity Logger::m_ConsoleLogSeverity = LogInformation; @@ -157,6 +161,14 @@ LogSeverity Logger::GetConsoleLogSeverity() return m_ConsoleLogSeverity; } +void Logger::DisableEarlyLogging() { + m_EarlyLoggingEnabled = false; +} + +bool Logger::IsEarlyLoggingEnabled() { + return m_EarlyLoggingEnabled; +} + void Logger::DisableTimestamp() { m_TimestampEnabled = false; @@ -242,6 +254,12 @@ Log::~Log() * then cout will not flush lines automatically. */ std::cout << std::flush; } + +#ifdef _WIN32 + if (Logger::IsEarlyLoggingEnabled() && entry.Severity >= Logger::GetConsoleLogSeverity()) { + WindowsEventLogLogger::WriteToWindowsEventLog(entry); + } +#endif /* _WIN32 */ } Log& Log::operator<<(const char *val) diff --git a/lib/base/logger.hpp b/lib/base/logger.hpp index 9a53e13cf..6d87c29b7 100644 --- a/lib/base/logger.hpp +++ b/lib/base/logger.hpp @@ -67,6 +67,8 @@ public: static void DisableConsoleLog(); static void EnableConsoleLog(); static bool IsConsoleLogEnabled(); + static void DisableEarlyLogging(); + static bool IsEarlyLoggingEnabled(); static void DisableTimestamp(); static void EnableTimestamp(); static bool IsTimestampEnabled(); @@ -84,6 +86,7 @@ private: static std::mutex m_Mutex; static std::set m_Loggers; static bool m_ConsoleLogEnabled; + static std::atomic m_EarlyLoggingEnabled; static bool m_TimestampEnabled; static LogSeverity m_ConsoleLogSeverity; }; diff --git a/lib/base/windowseventloglogger.cpp b/lib/base/windowseventloglogger.cpp index 8c9582351..cc28358f9 100644 --- a/lib/base/windowseventloglogger.cpp +++ b/lib/base/windowseventloglogger.cpp @@ -37,9 +37,21 @@ void WindowsEventLogLogger::StatsFunc(const Dictionary::Ptr& status, const Array /** * Processes a log entry and outputs it to the Windows Event Log. * + * This function implements the interface expected by the Logger base class and passes + * the log entry to WindowsEventLogLogger::WriteToWindowsEventLog(). + * * @param entry The log entry. */ -void WindowsEventLogLogger::ProcessLogEntry(const LogEntry& entry) +void WindowsEventLogLogger::ProcessLogEntry(const LogEntry& entry) { + WindowsEventLogLogger::WriteToWindowsEventLog(entry); +} + +/** + * Writes a LogEntry object to the Windows Event Log. + * + * @param entry The log entry. + */ +void WindowsEventLogLogger::WriteToWindowsEventLog(const LogEntry& entry) { if (l_EventLog != nullptr) { std::string message = Logger::SeverityToString(entry.Severity) + "/" + entry.Facility + ": " + entry.Message; diff --git a/lib/base/windowseventloglogger.hpp b/lib/base/windowseventloglogger.hpp index 7b8b03e91..cefc245c7 100644 --- a/lib/base/windowseventloglogger.hpp +++ b/lib/base/windowseventloglogger.hpp @@ -24,6 +24,8 @@ public: static void StaticInitialize(); static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata); + static void WriteToWindowsEventLog(const LogEntry& entry); + protected: void ProcessLogEntry(const LogEntry& entry) override; void Flush() override; diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index da91efc58..cb241eb8c 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -675,6 +675,14 @@ bool ConfigItem::ActivateItems(const std::vector& newItems, boo return false; }); + /* Find the last logger type to be activated. */ + Type::Ptr lastLoggerType = nullptr; + for (const Type::Ptr& type : types) { + if (Logger::TypeInstance->IsAssignableFrom(type)) { + lastLoggerType = type; + } + } + for (const Type::Ptr& type : types) { for (const ConfigItem::Ptr& item : newItems) { if (!item->m_Object) @@ -695,6 +703,12 @@ bool ConfigItem::ActivateItems(const std::vector& newItems, boo object->Activate(runtimeCreated, cookie); } + + // TODO: find a better name for silent + if (!silent && type == lastLoggerType) { + /* Disable early logging configuration once the last logger type was activated. */ + Logger::DisableEarlyLogging(); + } } if (!silent) From 23aa628665f2230b7ae45033b2e57114c183f784 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Fri, 4 Jun 2021 11:17:48 +0200 Subject: [PATCH 3/5] Windows: automatically migrate from mainlog to windowseventlog --- etc/CMakeLists.txt | 2 +- etc/icinga2/features-enabled/mainlog.conf | 1 - .../features-enabled/windowseventlog.conf | 1 + icinga-installer/icinga-installer.cpp | 29 ++++++++++++++++++- 4 files changed, 30 insertions(+), 3 deletions(-) delete mode 100644 etc/icinga2/features-enabled/mainlog.conf create mode 100644 etc/icinga2/features-enabled/windowseventlog.conf diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt index 47c8a40e2..ff138bd4c 100644 --- a/etc/CMakeLists.txt +++ b/etc/CMakeLists.txt @@ -56,7 +56,7 @@ if(NOT WIN32) install(FILES bash_completion.d/icinga2 DESTINATION ${BASHCOMPLETION_DIR}) else() - install_if_not_exists(icinga2/features-enabled/mainlog.conf ${ICINGA2_CONFIGDIR}/features-enabled) + install_if_not_exists(icinga2/features-enabled/windowseventlog.conf ${ICINGA2_CONFIGDIR}/features-enabled) endif() if(${CMAKE_SYSTEM_NAME} MATCHES "(Linux|Solaris|SunOS)") diff --git a/etc/icinga2/features-enabled/mainlog.conf b/etc/icinga2/features-enabled/mainlog.conf deleted file mode 100644 index 6d7a47f06..000000000 --- a/etc/icinga2/features-enabled/mainlog.conf +++ /dev/null @@ -1 +0,0 @@ -include "../features-available/mainlog.conf" diff --git a/etc/icinga2/features-enabled/windowseventlog.conf b/etc/icinga2/features-enabled/windowseventlog.conf new file mode 100644 index 000000000..8e5787339 --- /dev/null +++ b/etc/icinga2/features-enabled/windowseventlog.conf @@ -0,0 +1 @@ +include "../features-available/windowseventlog.conf" diff --git a/icinga-installer/icinga-installer.cpp b/icinga-installer/icinga-installer.cpp index 233f90cab..4dc050de6 100644 --- a/icinga-installer/icinga-installer.cpp +++ b/icinga-installer/icinga-installer.cpp @@ -213,10 +213,11 @@ static int UpgradeNSIS(void) static int InstallIcinga(void) { std::string installDir = GetIcingaInstallPath(); + std::string skelDir = installDir + "\\share\\skel"; std::string dataDir = GetIcingaDataPath(); if (!PathExists(dataDir)) { - std::string sourceDir = installDir + "\\share\\skel" + std::string(1, '\0'); + std::string sourceDir = skelDir + std::string(1, '\0'); std::string destinationDir = dataDir + std::string(1, '\0'); SHFILEOPSTRUCT fop; @@ -243,6 +244,32 @@ static int InstallIcinga(void) MkDirP(dataDir + "/var/spool/icinga2/tmp"); } + // Upgrade from versions older than 2.13 by making the windowseventlog feature available, + // enable it by default and disable the old mainlog feature. + if (!PathExists(dataDir + "/etc/icinga2/features-available/windowseventlog.conf")) { + // Disable the old mainlog feature as it is replaced by windowseventlog by default. + std::string mainlogEnabledFile = dataDir + "/etc/icinga2/features-enabled/mainlog.conf"; + if (PathExists(mainlogEnabledFile)) { + if (DeleteFileA(mainlogEnabledFile.c_str()) == 0) { + throw std::runtime_error("deleting '" + mainlogEnabledFile + "' failed"); + } + } + + // Install the new windowseventlog feature. As features-available/windowseventlog.conf is used as a marker file, + // copy it as the last step, so that this is run again should the upgrade be interrupted. + for (const std::string& d : {"features-enabled", "features-available"}) { + std::string sourceFile = skelDir + "/etc/icinga2/" + d + "/windowseventlog.conf"; + std::string destinationFile = dataDir + "/etc/icinga2/" + d + "/windowseventlog.conf"; + + if (CopyFileA(sourceFile.c_str(), destinationFile.c_str(), false) == 0) { + throw std::runtime_error("copying '" + sourceFile + "' to '" + destinationFile + "' failed"); + } + } + } + + // TODO: In Icinga 2.14, rename features-available/mainlog.conf to mainlog.conf.deprecated + // so that it's no longer listed as an available feature. + ExecuteCommand("icacls", "\"" + dataDir + "\" /grant *S-1-5-20:(oi)(ci)m"); ExecuteCommand("icacls", "\"" + dataDir + "\\etc\" /inheritance:r /grant:r *S-1-5-20:(oi)(ci)m *S-1-5-32-544:(oi)(ci)f"); From 36ce7d961f18dd5273cbb38b6ca7b1ecec644eeb Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Mon, 21 Jun 2021 16:07:36 +0200 Subject: [PATCH 4/5] Rename silent parameter of ConfigItem::ActivateItems() As silent now no longer only controls the generation of log messages, a better name is required. This changes its name, inverts its value to reflect the new name and adds a documentation comment. --- lib/cli/daemoncommand.cpp | 2 +- lib/config/configitem.cpp | 21 +++++++++++++++------ lib/config/configitem.hpp | 2 +- lib/remote/configobjectutility.cpp | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index e25048c1b..30ce74f6c 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -276,7 +276,7 @@ int RunWorker(const std::vector& configs, bool closeConsoleLog = fa } // activate config only after daemonization: it starts threads and that is not compatible with fork() - if (!ConfigItem::ActivateItems(newItems, false, false, true)) { + if (!ConfigItem::ActivateItems(newItems, false, true, true)) { Log(LogCritical, "cli", "Error activating configuration."); return EXIT_FAILURE; } diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index cb241eb8c..8e6ab0e91 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -624,8 +624,18 @@ bool ConfigItem::CommitItems(const ActivationContext::Ptr& context, WorkQueue& u return true; } +/** + * ActivateItems activates new config items. + * + * @param newItems Vector of items to be activated + * @param runtimeCreated Whether the objects were created by a runtime object + * @param mainConfigActivation Whether this is the call for activating the main configuration during startup + * @param withModAttrs Whether this call shall read the modified attributes file + * @param cookie Cookie for preventing message loops + * @return Whether the config activation was successful (in case of errors, exceptions are thrown) + */ bool ConfigItem::ActivateItems(const std::vector& newItems, bool runtimeCreated, - bool silent, bool withModAttrs, const Value& cookie) + bool mainConfigActivation, bool withModAttrs, const Value& cookie) { static std::mutex mtx; std::unique_lock lock(mtx); @@ -663,7 +673,7 @@ bool ConfigItem::ActivateItems(const std::vector& newItems, boo object->PreActivate(); } - if (!silent) + if (mainConfigActivation) Log(LogInformation, "ConfigItem", "Triggering Start signal for config items"); /* Activate objects in priority order. */ @@ -704,14 +714,13 @@ bool ConfigItem::ActivateItems(const std::vector& newItems, boo object->Activate(runtimeCreated, cookie); } - // TODO: find a better name for silent - if (!silent && type == lastLoggerType) { + if (mainConfigActivation && type == lastLoggerType) { /* Disable early logging configuration once the last logger type was activated. */ Logger::DisableEarlyLogging(); } } - if (!silent) + if (mainConfigActivation) Log(LogInformation, "ConfigItem", "Activated all objects."); return true; @@ -734,7 +743,7 @@ bool ConfigItem::RunWithActivationContext(const Function::Ptr& function) if (!CommitItems(scope.GetContext(), upq, newItems, true)) return false; - if (!ActivateItems(newItems, false, true)) + if (!ActivateItems(newItems, false, false)) return false; return true; diff --git a/lib/config/configitem.hpp b/lib/config/configitem.hpp index b3e4ca35d..b99cd08e5 100644 --- a/lib/config/configitem.hpp +++ b/lib/config/configitem.hpp @@ -54,7 +54,7 @@ public: static bool CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector& newItems, bool silent = false); static bool ActivateItems(const std::vector& newItems, bool runtimeCreated = false, - bool silent = false, bool withModAttrs = false, const Value& cookie = Empty); + bool mainConfigActivation = false, bool withModAttrs = false, const Value& cookie = Empty); static bool RunWithActivationContext(const Function::Ptr& function); diff --git a/lib/remote/configobjectutility.cpp b/lib/remote/configobjectutility.cpp index 6ba0e0ecc..e086ca3fb 100644 --- a/lib/remote/configobjectutility.cpp +++ b/lib/remote/configobjectutility.cpp @@ -224,7 +224,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full * uq, items, runtimeCreated, silent, withModAttrs, cookie * IMPORTANT: Forward the cookie aka origin in order to prevent sync loops in the same zone! */ - if (!ConfigItem::ActivateItems(newItems, true, true, false, cookie)) { + if (!ConfigItem::ActivateItems(newItems, true, false, false, cookie)) { if (errors) { Log(LogNotice, "ConfigObjectUtility") << "Failed to activate config object '" << fullName << "'. Aborting and removing config path '" << path << "'."; From aa423d80acb9dbfa18917d3720a463dded401d75 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Wed, 23 Jun 2021 17:05:05 +0200 Subject: [PATCH 5/5] Change WindowsEventLogLogger default severity to information As this is intended to replace the mainlog feature which logged severity information, this should be the default for this logger. --- doc/09-object-types.md | 4 ++-- doc/14-features.md | 2 +- etc/icinga2/features-available/windowseventlog.conf | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/09-object-types.md b/doc/09-object-types.md index 950a843a7..041e8f1c2 100644 --- a/doc/09-object-types.md +++ b/doc/09-object-types.md @@ -1873,7 +1873,7 @@ Example: ``` object WindowsEventLogLogger "windowseventlog" { - severity = "warning" + severity = "information" } ``` @@ -1881,4 +1881,4 @@ Configuration Attributes: Name | Type | Description --------------------------|-----------------------|---------------------------------- - severity | String | **Optional.** The minimum severity for this log. Can be "debug", "notice", "information", "warning" or "critical". Defaults to "warning". + severity | String | **Optional.** The minimum severity for this log. Can be "debug", "notice", "information", "warning" or "critical". Defaults to "information". diff --git a/doc/14-features.md b/doc/14-features.md index 2b5a30c62..64a651534 100644 --- a/doc/14-features.md +++ b/doc/14-features.md @@ -16,7 +16,7 @@ Feature | Description debuglog | Debug log (path: `/var/log/icinga2/debug.log`, severity: `debug` or higher) mainlog | Main log (path: `/var/log/icinga2/icinga2.log`, severity: `information` or higher) syslog | Syslog (severity: `warning` or higher) -windowseventlog | Windows Event Log (severity: `warning` or higher) +windowseventlog | Windows Event Log (severity: `information` or higher) By default file the `mainlog` feature is enabled. When running Icinga 2 on a terminal log messages with severity `information` or higher are diff --git a/etc/icinga2/features-available/windowseventlog.conf b/etc/icinga2/features-available/windowseventlog.conf index ddd5716ee..8e5c0ae10 100644 --- a/etc/icinga2/features-available/windowseventlog.conf +++ b/etc/icinga2/features-available/windowseventlog.conf @@ -3,6 +3,6 @@ */ object WindowsEventLogLogger "windowseventlog" { - severity = "warning" + severity = "information" }