From 85b972822e3bd4897828813d63adef219d9c973f Mon Sep 17 00:00:00 2001 From: rem31 <73845199+rem31@users.noreply.github.com> Date: Tue, 18 Jan 2022 12:41:53 +0100 Subject: [PATCH] enh(log_v2): new logging engine in centengine enh(engine/log_v2): new possibility to enable/disabled old/new logs enh(log_v2): add broker sink log and unit test for new loggers enh(log_v2): change some logs info on debug enh(log_v2): duplicate hold log with new loggers enh(log_v2): add new test robot REFS: MON-11583 REFS: MON-11866 REFS: MON-11867 --- centreon-clib/test/logging.cc | 26 +- centreon-engine/CMakeLists.txt | 3 + .../centreon/engine/configuration/state.hh | 52 +- .../inc/com/centreon/engine/contact.hh | 6 - .../inc/com/centreon/engine/log_v2.hh | 71 ++ .../centreon/engine/logging/broker_sink.hh | 67 ++ .../inc/com/centreon/engine/logging/logger.hh | 2 +- .../inc/com/centreon/engine/nebstructs.hh | 2 +- .../modules/external_commands/src/commands.cc | 44 +- .../modules/external_commands/src/main.cc | 20 +- .../external_commands/src/processing.cc | 36 +- .../modules/external_commands/src/utils.cc | 55 +- centreon-engine/src/anomalydetection.cc | 200 ++++-- centreon-engine/src/broker.cc | 3 +- centreon-engine/src/broker/handle.cc | 10 +- centreon-engine/src/broker/loader.cc | 16 +- centreon-engine/src/checkable.cc | 4 +- centreon-engine/src/checks/checker.cc | 111 ++- centreon-engine/src/command_manager.cc | 19 +- centreon-engine/src/commands/connector.cc | 308 +++++--- centreon-engine/src/commands/raw.cc | 105 ++- centreon-engine/src/compatibility/logging.cc | 11 +- centreon-engine/src/config.cc | 33 +- .../src/configuration/anomalydetection.cc | 366 +++++++--- .../configuration/applier/anomalydetection.cc | 17 +- .../src/configuration/applier/command.cc | 10 +- .../src/configuration/applier/connector.cc | 10 +- .../src/configuration/applier/contact.cc | 13 +- .../src/configuration/applier/contactgroup.cc | 32 +- .../src/configuration/applier/host.cc | 13 +- .../configuration/applier/hostdependency.cc | 14 +- .../configuration/applier/hostescalation.cc | 21 +- .../src/configuration/applier/hostgroup.cc | 17 +- .../src/configuration/applier/logging.cc | 53 +- .../src/configuration/applier/scheduler.cc | 104 ++- .../src/configuration/applier/service.cc | 17 +- .../applier/servicedependency.cc | 15 +- .../applier/serviceescalation.cc | 25 +- .../src/configuration/applier/servicegroup.cc | 21 +- .../src/configuration/applier/state.cc | 289 ++++++-- .../src/configuration/applier/timeperiod.cc | 14 +- centreon-engine/src/configuration/host.cc | 11 +- .../src/configuration/hostdependency.cc | 7 +- .../src/configuration/hostgroup.cc | 33 +- centreon-engine/src/configuration/parser.cc | 10 +- centreon-engine/src/configuration/service.cc | 254 +++++-- .../src/configuration/servicedependency.cc | 4 +- .../src/configuration/serviceescalation.cc | 63 +- centreon-engine/src/configuration/state.cc | 618 +++++++++++++--- centreon-engine/src/contact.cc | 285 ++++---- centreon-engine/src/contactgroup.cc | 13 +- centreon-engine/src/dependency.cc | 5 +- centreon-engine/src/diagnostic.cc | 59 +- .../src/downtimes/downtime_manager.cc | 77 +- .../src/downtimes/host_downtime.cc | 55 +- .../src/downtimes/service_downtime.cc | 73 +- centreon-engine/src/escalation.cc | 14 +- centreon-engine/src/events/loop.cc | 152 ++-- centreon-engine/src/events/sched_info.cc | 219 +++--- centreon-engine/src/events/timed_event.cc | 86 ++- centreon-engine/src/flapping.cc | 7 +- centreon-engine/src/host.cc | 663 +++++++++++++----- centreon-engine/src/hostdependency.cc | 25 +- centreon-engine/src/hostescalation.cc | 13 +- centreon-engine/src/hostgroup.cc | 20 +- centreon-engine/src/log_v2.cc | 319 +++++++++ centreon-engine/src/logging/CMakeLists.txt | 1 + centreon-engine/src/macros.cc | 21 +- centreon-engine/src/macros/grab_host.cc | 5 +- centreon-engine/src/macros/grab_service.cc | 5 +- centreon-engine/src/macros/grab_value.cc | 16 +- centreon-engine/src/macros/process.cc | 65 +- centreon-engine/src/main.cc | 196 +++--- centreon-engine/src/nebmods.cc | 85 ++- centreon-engine/src/notification.cc | 4 +- centreon-engine/src/notifier.cc | 429 +++++++++--- centreon-engine/src/retention/dump.cc | 16 +- centreon-engine/src/retention/host.cc | 17 +- centreon-engine/src/retention/service.cc | 48 +- centreon-engine/src/sehandlers.cc | 181 +++-- centreon-engine/src/service.cc | 651 ++++++++++++----- centreon-engine/src/servicedependency.cc | 28 +- centreon-engine/src/serviceescalation.cc | 13 +- centreon-engine/src/servicegroup.cc | 20 +- centreon-engine/src/timeperiod.cc | 37 +- centreon-engine/src/timerange.cc | 9 +- centreon-engine/src/utils.cc | 29 +- centreon-engine/src/xpddefault.cc | 174 ++++- centreon-engine/src/xsddefault.cc | 19 +- .../test/configuration/applier/events.cc | 186 +++-- .../test/configuration/applier/xodtemplate.cc | 346 ++++----- .../test/configuration/applier/xrddefault.cc | 17 +- centreon-engine/tests/CMakeLists.txt | 1 + .../configuration/applier/applier-log.cc | 543 ++++++++++++++ .../broker-engine/log-v2_engine.robot | 338 +++++++++ centreon-tests/resources/Common.py | 29 + centreon-tests/resources/Engine.py | 16 + centreon-tests/resources/resources.robot | 1 + 98 files changed, 6770 insertions(+), 2116 deletions(-) create mode 100644 centreon-engine/inc/com/centreon/engine/log_v2.hh create mode 100644 centreon-engine/inc/com/centreon/engine/logging/broker_sink.hh mode change 100755 => 100644 centreon-engine/src/anomalydetection.cc mode change 100755 => 100644 centreon-engine/src/checks/checker.cc create mode 100644 centreon-engine/src/log_v2.cc mode change 100755 => 100644 centreon-engine/src/macros.cc mode change 100755 => 100644 centreon-engine/src/macros/grab_value.cc mode change 100755 => 100644 centreon-engine/src/macros/process.cc mode change 100755 => 100644 centreon-engine/src/sehandlers.cc mode change 100755 => 100644 centreon-engine/src/xpddefault.cc create mode 100644 centreon-engine/tests/configuration/applier/applier-log.cc create mode 100644 centreon-tests/broker-engine/log-v2_engine.robot diff --git a/centreon-clib/test/logging.cc b/centreon-clib/test/logging.cc index 8560e6632d9..7940fe04958 100644 --- a/centreon-clib/test/logging.cc +++ b/centreon-clib/test/logging.cc @@ -386,10 +386,10 @@ TEST(ClibLogging, TempLoggerCtor) { auto id = e.add(obj.get(), 3, 0); temp_logger(0, 0) << "Centreon Clib test"; - ASSERT_EQ(obj->get_nb_call(), 0); + ASSERT_EQ(obj->get_nb_call(), 0u); temp_logger(1, 0) << "Centreon Clib test"; - ASSERT_EQ(obj->get_nb_call(), 1); + ASSERT_EQ(obj->get_nb_call(), 1u); e.remove(id); } @@ -524,7 +524,7 @@ TEST(ClibLogging, TempLoggerLogChar) { auto id = e.add(obj.get(), 3, 0); temp_logger(1, 0) << 'c'; - ASSERT_EQ(obj->get_nb_call(), 1); + ASSERT_EQ(obj->get_nb_call(), 1u); e.remove(id); } @@ -534,7 +534,7 @@ TEST(ClibLogging, TempLoggerLogDouble) { auto id = e.add(obj.get(), 3, 0); temp_logger(1, 0) << double(42.42); - ASSERT_EQ(obj->get_nb_call(), 1); + ASSERT_EQ(obj->get_nb_call(), 1u); e.remove(id); } @@ -544,7 +544,7 @@ TEST(ClibLogging, TempLoggerLogInt) { auto id = e.add(obj.get(), 3, 0); temp_logger(1, 0) << int(42); - ASSERT_EQ(obj->get_nb_call(), 1); + ASSERT_EQ(obj->get_nb_call(), 1u); e.remove(id); } @@ -554,7 +554,7 @@ TEST(ClibLogging, TempLoggerLogLong) { auto id = e.add(obj.get(), 3, 0); temp_logger(1, 0) << 42L; - ASSERT_EQ(obj->get_nb_call(), 1); + ASSERT_EQ(obj->get_nb_call(), 1u); e.remove(id); } @@ -564,7 +564,7 @@ TEST(ClibLogging, TempLoggerLogLongLong) { auto id = e.add(obj.get(), 3, 0); temp_logger(1, 0) << 42LL; - ASSERT_EQ(obj->get_nb_call(), 1); + ASSERT_EQ(obj->get_nb_call(), 1u); e.remove(id); } @@ -574,7 +574,7 @@ TEST(ClibLogging, TempLoggerLogPVoid) { auto id = e.add(obj.get(), 3, 0); temp_logger(1, 0) << obj.get(); - ASSERT_EQ(obj->get_nb_call(), 1); + ASSERT_EQ(obj->get_nb_call(), 1u); e.remove(id); } @@ -584,7 +584,7 @@ TEST(ClibLogging, TempLoggerLogStdString) { auto id = e.add(obj.get(), 3, 0); temp_logger(1, 0) << std::string("Centreon Clib test"); - ASSERT_EQ(obj->get_nb_call(), 1); + ASSERT_EQ(obj->get_nb_call(), 1u); e.remove(id); } @@ -594,7 +594,7 @@ TEST(ClibLogging, TempLoggerLogString) { auto id = e.add(obj.get(), 3, 0); temp_logger(1, 0) << "Centreon Clib test"; - ASSERT_EQ(obj->get_nb_call(), 1); + ASSERT_EQ(obj->get_nb_call(), 1u); e.remove(id); } @@ -605,7 +605,7 @@ TEST(ClibLogging, TempLoggerLogUint) { unsigned int ui(42); temp_logger(1, 0) << ui; - ASSERT_EQ(obj->get_nb_call(), 1); + ASSERT_EQ(obj->get_nb_call(), 1u); e.remove(id); } @@ -616,7 +616,7 @@ TEST(ClibLogging, TempLoggerLogULong) { unsigned long ul(42); temp_logger(1, 0) << ul; - ASSERT_EQ(obj->get_nb_call(), 1); + ASSERT_EQ(obj->get_nb_call(), 1u); e.remove(id); } @@ -627,6 +627,6 @@ TEST(ClibLogging, TempLoggerLogULongLong) { unsigned long long ull(42); temp_logger(1, 0) << ull; - ASSERT_EQ(obj->get_nb_call(), 1); + ASSERT_EQ(obj->get_nb_call(), 1u); e.remove(id); } diff --git a/centreon-engine/CMakeLists.txt b/centreon-engine/CMakeLists.txt index 4cbbaa356b7..e02534266b2 100644 --- a/centreon-engine/CMakeLists.txt +++ b/centreon-engine/CMakeLists.txt @@ -440,6 +440,7 @@ set( "${SRC_DIR}/hostdependency.cc" "${SRC_DIR}/hostescalation.cc" "${SRC_DIR}/hostgroup.cc" + "${SRC_DIR}/log_v2.cc" "${SRC_DIR}/macros.cc" "${SRC_DIR}/nebmods.cc" "${SRC_DIR}/notification.cc" @@ -485,6 +486,7 @@ set( "${INC_DIR}/com/centreon/engine/hostdependency.hh" "${INC_DIR}/com/centreon/engine/hostescalation.hh" "${INC_DIR}/com/centreon/engine/hostgroup.hh" + "${INC_DIR}/com/centreon/engine/log_v2.hh" "${INC_DIR}/com/centreon/engine/logging.hh" "${INC_DIR}/com/centreon/engine/macros.hh" "${INC_DIR}/com/centreon/engine/nebcallbacks.hh" @@ -544,6 +546,7 @@ target_link_libraries(cce_core ${nlohmann_json_LIBS} ${SOCKET_LIBRARIES} centreon_clib ${fmt_LIBRARIES} + ${spdlog_LIBS} ) # centengine target. diff --git a/centreon-engine/inc/com/centreon/engine/configuration/state.hh b/centreon-engine/inc/com/centreon/engine/configuration/state.hh index 7fc93e413e2..b54bcf877e7 100644 --- a/centreon-engine/inc/com/centreon/engine/configuration/state.hh +++ b/centreon-engine/inc/com/centreon/engine/configuration/state.hh @@ -394,6 +394,38 @@ class state { void use_setpgid(bool value); bool use_syslog() const noexcept; void use_syslog(bool value); + bool log_v2_enabled() const noexcept; + void log_v2_enabled(bool value); + bool log_legacy_enabled() const noexcept; + void log_legacy_enabled(bool value); + std::string const& log_v2_logger() const noexcept; + void log_v2_logger(std::string const& value); + std::string const& log_level_functions() const noexcept; + void log_level_functions(std::string const& value); + std::string const& log_level_config() const noexcept; + void log_level_config(std::string const& value); + std::string const& log_level_events() const noexcept; + void log_level_events(std::string const& value); + std::string const& log_level_checks() const noexcept; + void log_level_checks(std::string const& value); + std::string const& log_level_notifications() const noexcept; + void log_level_notifications(std::string const& value); + std::string const& log_level_eventbroker() const noexcept; + void log_level_eventbroker(std::string const& value); + std::string const& log_level_external_command() const noexcept; + void log_level_external_command(std::string const& value); + std::string const& log_level_commands() const noexcept; + void log_level_commands(std::string const& value); + std::string const& log_level_downtimes() const noexcept; + void log_level_downtimes(std::string const& value); + std::string const& log_level_comments() const noexcept; + void log_level_comments(std::string const& value); + std::string const& log_level_macros() const noexcept; + void log_level_macros(std::string const& value); + std::string const& log_level_process() const noexcept; + void log_level_process(std::string const& value); + std::string const& log_level_runtime() const noexcept; + void log_level_runtime(std::string const& value); std::string const& use_timezone() const noexcept; void use_timezone(std::string const& value); bool use_true_regexp_matching() const noexcept; @@ -449,7 +481,7 @@ class state { return (false); (obj.*ptr)(val); } catch (std::exception const& e) { - logger(logging::log_config_error, logging::basic) << e.what(); + engine_logger(logging::log_config_error, logging::basic) << e.what(); return (false); } return (true); @@ -462,7 +494,7 @@ class state { try { (obj.*ptr)(value); } catch (std::exception const& e) { - logger(logging::log_config_error, logging::basic) << e.what(); + engine_logger(logging::log_config_error, logging::basic) << e.what(); return (false); } return (true); @@ -604,6 +636,22 @@ class state { bool _use_retained_scheduling_info; bool _use_setpgid; bool _use_syslog; + bool _log_v2_enabled; + bool _log_legacy_enabled; + std::string _log_v2_logger; + std::string _log_level_functions; + std::string _log_level_config; + std::string _log_level_events; + std::string _log_level_checks; + std::string _log_level_notifications; + std::string _log_level_eventbroker; + std::string _log_level_external_command; + std::string _log_level_commands; + std::string _log_level_downtimes; + std::string _log_level_comments; + std::string _log_level_macros; + std::string _log_level_process; + std::string _log_level_runtime; std::string _use_timezone; bool _use_true_regexp_matching; }; diff --git a/centreon-engine/inc/com/centreon/engine/contact.hh b/centreon-engine/inc/com/centreon/engine/contact.hh index 07b26a6564a..1ff20385126 100644 --- a/centreon-engine/inc/com/centreon/engine/contact.hh +++ b/centreon-engine/inc/com/centreon/engine/contact.hh @@ -211,12 +211,6 @@ std::shared_ptr add_contact( int retain_status_information, int retain_nonstatus_information); -// bool operator==( -// com::centreon::engine::contact const& obj1, -// com::centreon::engine::contact const& obj2) throw (); -// bool operator!=( -// com::centreon::engine::contact const& obj1, -// com::centreon::engine::contact const& obj2) throw (); std::ostream& operator<<(std::ostream& os, com::centreon::engine::contact const& obj); std::ostream& operator<<(std::ostream& os, contact_map_unsafe const& obj); diff --git a/centreon-engine/inc/com/centreon/engine/log_v2.hh b/centreon-engine/inc/com/centreon/engine/log_v2.hh new file mode 100644 index 00000000000..8469824e6ed --- /dev/null +++ b/centreon-engine/inc/com/centreon/engine/log_v2.hh @@ -0,0 +1,71 @@ +/* +** Copyright 2021 Centreon +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +** +** For more information : contact@centreon.com +*/ +#ifndef CCE_LOG_V2_HH +#define CCE_LOG_V2_HH + +#include +#include + +#include +#include +#include + +#include "com/centreon/engine/configuration/state.hh" +#include "com/centreon/engine/namespace.hh" + +CCE_BEGIN() +class log_v2 { + std::string _log_name; + std::shared_ptr _config_log; + std::shared_ptr _functions_log; + std::shared_ptr _events_log; + std::shared_ptr _checks_log; + std::shared_ptr _notifications_log; + std::shared_ptr _eventbroker_log; + std::shared_ptr _external_command_log; + std::shared_ptr _commands_log; + std::shared_ptr _downtimes_log; + std::shared_ptr _comments_log; + std::shared_ptr _macros_log; + std::shared_ptr _process_log; + std::shared_ptr _runtime_log; + + log_v2(); + ~log_v2() noexcept = default; + + public: + void apply(const configuration::state& config); + static bool contains_level(const std::string& level_name); + static log_v2& instance(); + static std::shared_ptr functions(); + static std::shared_ptr config(); + static std::shared_ptr events(); + static std::shared_ptr checks(); + static std::shared_ptr notifications(); + static std::shared_ptr eventbroker(); + static std::shared_ptr external_command(); + static std::shared_ptr commands(); + static std::shared_ptr downtimes(); + static std::shared_ptr comments(); + static std::shared_ptr macros(); + static std::shared_ptr process(); + static std::shared_ptr runtime(); +}; +CCE_END() + +#endif /* !CCE_LOG_V2_HH */ diff --git a/centreon-engine/inc/com/centreon/engine/logging/broker_sink.hh b/centreon-engine/inc/com/centreon/engine/logging/broker_sink.hh new file mode 100644 index 00000000000..2ae4f9964f0 --- /dev/null +++ b/centreon-engine/inc/com/centreon/engine/logging/broker_sink.hh @@ -0,0 +1,67 @@ +/* +** Copyright 2011-2021 Centreon +** +** This file is part of Centreon Engine. +** +** Centreon Engine is free software: you can redistribute it and/or +** modify it under the terms of the GNU General Public License version 2 +** as published by the Free Software Foundation. +** +** Centreon Engine is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Centreon Engine. If not, see +** . +*/ +#ifndef CCE_LOGGING_BROKER_SINK_HH +#define CCE_LOGGING_BROKER_SINK_HH +#include +#include +#include +#include "com/centreon/engine/broker.hh" +#include "com/centreon/engine/logging/broker.hh" +#include "com/centreon/engine/logging/logger.hh" +#include "com/centreon/engine/namespace.hh" +#include "com/centreon/engine/nebstructs.hh" +#include "com/centreon/unique_array_ptr.hh" +#include "spdlog/details/null_mutex.h" +CCE_BEGIN() + +namespace logging { +template +class broker_sink : public spdlog::sinks::base_sink { + protected: + void sink_it_(const spdlog::details::log_msg& msg) override { + // log_msg is a struct containing the log entry info like level, timestamp, + // thread id etc. msg.raw contains pre formatted log + + // If needed (very likely but not mandatory), the sink formats the message + // before sending it to its final destination: + if (this->should_log(msg.level)) { + std::string message{fmt::to_string(msg.payload)}; + nebstruct_log_data ds{.type = NEBTYPE_LOG_DATA, + .flags = NEBFLAG_NONE, + .attr = NEBATTR_NONE, + .timestamp = get_broker_timestamp(nullptr), + .entry_time = time(nullptr), + .data_type = logging::log_all, + .data = message.c_str()}; + + // Make callbacks. + neb_make_callbacks(NEBCALLBACK_LOG_DATA, &ds); + } + } + + void flush_() override {} +}; + +using broker_sink_mt = broker_sink; +using broker_sink_st = broker_sink; + +} // namespace logging +CCE_END() + +#endif // !CCE_LOGGING_BROKER_SINK_HH diff --git a/centreon-engine/inc/com/centreon/engine/logging/logger.hh b/centreon-engine/inc/com/centreon/engine/logging/logger.hh index ee0e265df23..55ce5e3e8d4 100644 --- a/centreon-engine/inc/com/centreon/engine/logging/logger.hh +++ b/centreon-engine/inc/com/centreon/engine/logging/logger.hh @@ -87,7 +87,7 @@ enum verbosity_level { basic = 0u, more = 1u, most = 2u }; CCE_END() -#define logger(type, verbose) \ +#define engine_logger(type, verbose) \ for (unsigned int __com_centreon_engine_logging_define_ui(0); \ !__com_centreon_engine_logging_define_ui && \ com::centreon::logging::engine::instance().is_log(type, verbose); \ diff --git a/centreon-engine/inc/com/centreon/engine/nebstructs.hh b/centreon-engine/inc/com/centreon/engine/nebstructs.hh index c9cdc103bbf..9d2da463b30 100644 --- a/centreon-engine/inc/com/centreon/engine/nebstructs.hh +++ b/centreon-engine/inc/com/centreon/engine/nebstructs.hh @@ -400,7 +400,7 @@ typedef struct nebstruct_log_struct { time_t entry_time; int data_type; - char* data; + const char* data; } nebstruct_log_data; /* Module data structure. */ diff --git a/centreon-engine/modules/external_commands/src/commands.cc b/centreon-engine/modules/external_commands/src/commands.cc index f771f788afb..9af292b4f26 100644 --- a/centreon-engine/modules/external_commands/src/commands.cc +++ b/centreon-engine/modules/external_commands/src/commands.cc @@ -37,6 +37,7 @@ #include "com/centreon/engine/events/loop.hh" #include "com/centreon/engine/flapping.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/modules/external_commands/internal.hh" #include "com/centreon/engine/modules/external_commands/processing.hh" @@ -57,7 +58,9 @@ using namespace com::centreon::engine::logging; /* checks for the existence of the external command file and processes all * commands found in it */ int check_for_external_commands() { - logger(dbg_functions, basic) << "check_for_external_commands()"; + engine_logger(dbg_functions, basic) << "check_for_external_commands()"; + + log_v2::functions()->trace("check_for_external_commands()"); /* bail out if we shouldn't be checking for external commands */ if (!config->check_external_commands()) @@ -119,20 +122,31 @@ int check_for_external_commands() { * @return OK on success. */ int process_external_commands_from_file(char const* file, int delete_file) { - logger(dbg_functions, basic) << "process_external_commands_from_file()"; + engine_logger(dbg_functions, basic) + << "process_external_commands_from_file()"; + + log_v2::functions()->trace("process_external_commands_from_file()"); if (!file) return ERROR; - logger(dbg_external_command, more) + engine_logger(dbg_external_command, more) << "Processing commands from file '" << file << "'. File will " << (delete_file ? "be" : "NOT be") << " deleted after processing."; + log_v2::external_command()->debug( + "Processing commands from file '{}'. File will {} deleted after " + "processing.", + file, delete_file ? "be" : "NOT be"); + /* open the config file for reading */ mmapfile* thefile(nullptr); if ((thefile = mmap_fopen(file)) == nullptr) { - logger(log_info_message, basic) << "Error: Cannot open file '" << file - << "' to process external commands!"; + engine_logger(log_info_message, basic) + << "Error: Cannot open file '" << file + << "' to process external commands!"; + log_v2::config()->info( + "Error: Cannot open file '{}' to process external commands!", file); return ERROR; } @@ -234,7 +248,7 @@ int cmd_add_comment(int cmd, time_t entry_time, char* args) { } /* removes a host or service comment from the status log */ -int cmd_delete_comment(int cmd [[maybe_unused]], char* args) { +int cmd_delete_comment(int cmd[[maybe_unused]], char* args) { uint64_t comment_id{0}; /* get the comment id we should delete */ @@ -544,10 +558,14 @@ int process_passive_service_check(time_t check_time, /* we couldn't find the host */ if (real_host_name == nullptr) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Passive check result was received for service '" << svc_description << "' on host '" << host_name << "', but the host could not be found!"; + log_v2::runtime()->warn( + "Warning: Passive check result was received for service '{}' on host " + "'{}', but the host could not be found!", + svc_description, host_name); return ERROR; } @@ -555,10 +573,14 @@ int process_passive_service_check(time_t check_time, service_map::const_iterator found( service::services.find({real_host_name, svc_description})); if (found == service::services.end() || !found->second) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Passive check result was received for service '" << svc_description << "' on host '" << host_name << "', but the service could not be found!"; + log_v2::runtime()->warn( + "Warning: Passive check result was received for service '{}' on host " + "'{}', but the service could not be found!", + svc_description, host_name); return ERROR; } @@ -664,9 +686,13 @@ int process_passive_host_check(time_t check_time, /* we couldn't find the host */ if (real_host_name == nullptr) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Passive check result was received for host '" << host_name << "', but the host could not be found!"; + log_v2::runtime()->warn( + "Warning: Passive check result was received for host '{}', but the " + "host could not be found!", + host_name); return ERROR; } diff --git a/centreon-engine/modules/external_commands/src/main.cc b/centreon-engine/modules/external_commands/src/main.cc index 90d8708e33d..78890241cc8 100644 --- a/centreon-engine/modules/external_commands/src/main.cc +++ b/centreon-engine/modules/external_commands/src/main.cc @@ -23,6 +23,7 @@ #include #include "com/centreon/engine/broker.hh" #include "com/centreon/engine/exceptions/error.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/modules/external_commands/commands.hh" #include "com/centreon/engine/modules/external_commands/utils.hh" @@ -31,6 +32,7 @@ #include "com/centreon/engine/nebstructs.hh" using namespace com::centreon::engine::logging; +using namespace com::centreon::engine; /************************************** * * @@ -109,11 +111,13 @@ extern "C" int nebmodule_deinit(int flags, int reason) { shutdown_command_file_worker_thread(); close_command_file(); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "external command runtime error `" << e.what() << "'."; + log_v2::runtime()->error("external command runtime error '{}'.", e.what()); } catch (...) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "external command runtime error `unknown'"; + log_v2::runtime()->error("external command runtime error `unknown'"); } return (0); } @@ -154,10 +158,14 @@ extern "C" int nebmodule_init(int flags, char const* args, void* handle) { try { // Open the command file (named pipe) for reading. if (open_command_file() != OK) { - logger(log_process_info | log_runtime_error, basic) + engine_logger(log_process_info | log_runtime_error, basic) << "Bailing out due to errors encountered while trying to " << "initialize the external command file ... " << "(PID=" << getpid() << ")"; + log_v2::process()->info( + "Bailing out due to errors encountered while trying to initialize " + "the external command file ... (PID={})", + getpid()); return (1); } @@ -167,12 +175,14 @@ extern "C" int nebmodule_init(int flags, char const* args, void* handle) { throw(engine_error() << "register callback failed"); } } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "external command runtime error `" << e.what() << "'."; + log_v2::runtime()->error("external command runtime error '{}'.", e.what()); return (1); } catch (...) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "external command runtime error `unknown'."; + log_v2::runtime()->error("external command runtime error `unknown'."); return (1); } diff --git a/centreon-engine/modules/external_commands/src/processing.cc b/centreon-engine/modules/external_commands/src/processing.cc index 804b121ad12..ab9f7f9ca41 100644 --- a/centreon-engine/modules/external_commands/src/processing.cc +++ b/centreon-engine/modules/external_commands/src/processing.cc @@ -22,6 +22,7 @@ #include "com/centreon/engine/broker.hh" #include "com/centreon/engine/flapping.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/modules/external_commands/commands.hh" #include "com/centreon/engine/retention/applier/state.hh" @@ -579,7 +580,8 @@ processing::processing() processing::~processing() noexcept {} bool processing::execute(const std::string& cmdstr) const { - logger(dbg_functions, basic) << "processing external command"; + engine_logger(dbg_functions, basic) << "processing external command"; + log_v2::functions()->trace("processing external command"); char const* cmd{cmdstr.c_str()}; size_t len{cmdstr.size()}; @@ -626,8 +628,10 @@ bool processing::execute(const std::string& cmdstr) const { command_id = it->second.id; else if (command_name[0] != '_') { lock.unlock(); - logger(log_external_command | log_runtime_warning, basic) + engine_logger(log_external_command | log_runtime_warning, basic) << "Warning: Unrecognized external command -> " << command_name; + log_v2::external_command()->warn( + "Warning: Unrecognized external command -> {}", command_name); return false; } @@ -639,16 +643,25 @@ bool processing::execute(const std::string& cmdstr) const { if (command_id == CMD_PROCESS_SERVICE_CHECK_RESULT || command_id == CMD_PROCESS_HOST_CHECK_RESULT) { // Passive checks are logged in checks.c. - if (config->log_passive_checks()) - logger(log_passive_check, basic) + if (config->log_passive_checks()) { + engine_logger(log_passive_check, basic) << "EXTERNAL COMMAND: " << command_name << ';' << args; - } else if (config->log_external_commands()) - logger(log_external_command, basic) + log_v2::checks()->info("EXTERNAL COMMAND: {};{}", command_name, args); + } + } else if (config->log_external_commands()) { + engine_logger(log_external_command, basic) << "EXTERNAL COMMAND: " << command_name << ';' << args; + log_v2::external_command()->info("EXTERNAL COMMAND: {};{}", command_name, + args); + } - logger(dbg_external_command, more) << "External command id: " << command_id - << "\nCommand entry time: " << entry_time - << "\nCommand arguments: " << args; + engine_logger(dbg_external_command, more) + << "External command id: " << command_id + << "\nCommand entry time: " << entry_time + << "\nCommand arguments: " << args; + log_v2::external_command()->debug("External command id: {}", command_id); + log_v2::external_command()->debug("Command entry time: {}", entry_time); + log_v2::external_command()->debug("Command arguments: {}", args); // Send data to event broker. broker_external_command(NEBTYPE_EXTERNALCOMMAND_START, NEBFLAG_NONE, @@ -695,10 +708,11 @@ void processing::_wrapper_read_state_information() { retention::applier::state app_state; app_state.apply(*config, state); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: could not load retention file: " << e.what(); + log_v2::runtime()->error("Error: could not load retention file: {}", + e.what()); } - return; } void processing::_wrapper_save_state_information() { diff --git a/centreon-engine/modules/external_commands/src/utils.cc b/centreon-engine/modules/external_commands/src/utils.cc index 86fa22496a8..090e7966516 100644 --- a/centreon-engine/modules/external_commands/src/utils.cc +++ b/centreon-engine/modules/external_commands/src/utils.cc @@ -31,6 +31,7 @@ #include #include "com/centreon/engine/common.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/modules/external_commands/internal.hh" #include "com/centreon/engine/string.hh" @@ -68,7 +69,7 @@ int open_command_file(void) { /* create the external command file as a named pipe (FIFO) */ if (mkfifo(config->command_file().c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) != 0) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Could not create external command file '" << config->command_file() << "' as named pipe: (" << errno << ") -> " << strerror(errno) @@ -76,6 +77,13 @@ int open_command_file(void) { "you are sure that another copy of Centreon Engine is not " "running, " "you should delete this file."; + log_v2::runtime()->error( + "Error: Could not create external command file '{}' as named pipe: " + "({}) -> {}. If this file already exists and " + "you are sure that another copy of Centreon Engine is not " + "running, " + "you should delete this file.", + config->command_file(), errno, strerror(errno)); return ERROR; } } @@ -85,10 +93,14 @@ int open_command_file(void) { /* NOTE: file must be opened read-write for poll() to work */ if ((command_file_fd = open(config->command_file().c_str(), O_RDWR | O_NONBLOCK)) < 0) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Could not open external command file for reading " "via open(): (" << errno << ") -> " << strerror(errno); + log_v2::runtime()->error( + "Error: Could not open external command file for reading " + "via open(): ({}) -> {}", + errno, strerror(errno)); return ERROR; } @@ -97,36 +109,49 @@ int open_command_file(void) { int flags; flags = fcntl(command_file_fd, F_GETFL); if (flags < 0) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Could not get file descriptor flags on external " "command via fcntl(): (" << errno << ") -> " << strerror(errno); + log_v2::runtime()->error( + "Error: Could not get file descriptor flags on external " + "command via fcntl(): ({}) -> {}", + errno, strerror(errno)); return ERROR; } flags |= FD_CLOEXEC; if (fcntl(command_file_fd, F_SETFL, flags) == -1) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Could not set close-on-exec flag on external " "command via fcntl(): (" << errno << ") -> " << strerror(errno); + log_v2::runtime()->error( + "Error: Could not set close-on-exec flag on external " + "command via fcntl(): ({}) -> {}", + errno, strerror(errno)); return ERROR; } } /* re-open the FIFO for use with fgets() */ if ((command_file_fp = (FILE*)fdopen(command_file_fd, "r")) == NULL) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Could not open external command file for " "reading via fdopen(): (" << errno << ") -> " << strerror(errno); + log_v2::runtime()->error( + "Error: Could not open external command file for " + "reading via fdopen(): ({}) -> {}", + errno, strerror(errno)); return ERROR; } /* initialize worker thread */ if (init_command_file_worker_thread() == ERROR) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Could not initialize command file worker thread."; - + log_v2::runtime()->error( + "Error: Could not initialize command file worker thread."); /* close the command file */ fclose(command_file_fp); @@ -202,18 +227,24 @@ static void command_file_worker_thread() { if (pollval == -1) { switch (errno) { case EBADF: - logger(logging_options, basic) + engine_logger(logging_options, basic) << "command_file_worker_thread(): poll(): EBADF"; + log_v2::external_command()->info( + "command_file_worker_thread(): poll(): EBADF"); break; case ENOMEM: - logger(logging_options, basic) + engine_logger(logging_options, basic) << "command_file_worker_thread(): poll(): ENOMEM"; + log_v2::external_command()->info( + "command_file_worker_thread(): poll(): ENOMEM"); break; case EFAULT: - logger(logging_options, basic) + engine_logger(logging_options, basic) << "command_file_worker_thread(): poll(): EFAULT"; + log_v2::external_command()->info( + "command_file_worker_thread(): poll(): EFAULT"); break; case EINTR: @@ -225,8 +256,10 @@ static void command_file_worker_thread() { break; default: - logger(logging_options, basic) + engine_logger(logging_options, basic) << "command_file_worker_thread(): poll(): Unknown errno value."; + log_v2::external_command()->info( + "command_file_worker_thread(): poll(): Unknown errno value."); break; } diff --git a/centreon-engine/src/anomalydetection.cc b/centreon-engine/src/anomalydetection.cc old mode 100755 new mode 100644 index 397b0b99f64..e03f8ae270f --- a/centreon-engine/src/anomalydetection.cc +++ b/centreon-engine/src/anomalydetection.cc @@ -1,5 +1,5 @@ /* -** Copyright 2020 Centreon +** Copyright 2020-2021 Centreon ** ** This file is part of Centreon Engine. ** @@ -27,6 +27,7 @@ #include "com/centreon/engine/checks/checker.hh" #include "com/centreon/engine/globals.hh" #include "com/centreon/engine/host.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" @@ -325,66 +326,94 @@ com::centreon::engine::anomalydetection* add_anomalydetection( std::string const& timezone) { // Make sure we have everything we need. if (!service_id) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Service comes from a database, therefore its service id " << "must not be null"; + log_v2::config()->error( + "Error: Service comes from a database, therefore its service id must " + "not be null"); return nullptr; } else if (description.empty()) { - logger(log_config_error, basic) << "Error: Service description is not set"; + engine_logger(log_config_error, basic) + << "Error: Service description is not set"; + log_v2::config()->error("Error: Service description is not set"); return nullptr; } else if (!host_name.empty()) { uint64_t hid = get_host_id(host_name); if (hid != host_id) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: host id (" << host_id << ") of host ('" << host_name << "') of anomaly detection service '" << description << "' has a conflict between config does not match with the config " "id (" << hid << ")"; + log_v2::config()->error( + "Error: host id ({}) of host ('{}') of anomaly detection service " + "'{}' has a conflict between config does not match with the config " + "id ({})", + host_id, host_name, description, hid); return nullptr; } } auto it = service::services_by_id.find({host_id, dependent_service_id}); if (it == service::services_by_id.end()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Dependent service " << dependent_service_id << " does not exist (anomaly detection " << service_id << ")"; + log_v2::config()->error( + "Error: Dependent service {} does not exist (anomaly detection {})", + dependent_service_id, service_id); return nullptr; } service* dependent_service = it->second.get(); if (metric_name.empty()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: metric name must be provided for an anomaly detection " "service (host_id:" << host_id << ", service_id:" << service_id << ")"; + log_v2::config()->error( + "Error: metric name must be provided for an anomaly detection " + "service (host_id:{}, service_id:{})", + host_id, service_id); return nullptr; } if (thresholds_file.empty()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: thresholds file must be provided for an anomaly detection " "service (host_id:" << host_id << ", service_id:" << service_id << ")"; + log_v2::config()->error( + "Error: thresholds file must be provided for an anomaly detection " + "service (host_id:{}, service_id:{})", + host_id, service_id); return nullptr; } // Check values. if (max_attempts <= 0 || check_interval < 0 || retry_interval <= 0 || notification_interval < 0) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid max_attempts, check_interval, retry_interval" ", or notification_interval value for service '" << description << "' on host '" << host_name << "'"; + log_v2::config()->error( + "Error: Invalid max_attempts, check_interval, retry_interval" + ", or notification_interval value for service '{}' on host '{}'", + description, host_name); return nullptr; } // Check if the service is already exist. std::pair id(std::make_pair(host_id, service_id)); if (is_service_exist(id)) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Service '" << description << "' on host '" << host_name << "' has already been defined"; + log_v2::config()->error( + "Error: Service '{}' on host '{}' has already been defined", + description, host_name); return nullptr; } @@ -479,15 +508,24 @@ int anomalydetection::run_async_check(int check_options, bool reschedule_check, bool* time_is_valid, time_t* preferred_time) noexcept { - logger(dbg_functions, basic) + engine_logger(dbg_functions, basic) << "anomalydetection::run_async_check, check_options=" << check_options << ", latency=" << latency << ", scheduled_check=" << scheduled_check << ", reschedule_check=" << reschedule_check; - logger(dbg_checks, basic) + log_v2::functions()->trace( + "anomalydetection::run_async_check, check_options={}, latency={}, " + "scheduled_check={}, reschedule_check={}", + check_options, latency, scheduled_check, reschedule_check); + + engine_logger(dbg_checks, basic) << "** Running async check of anomalydetection '" << get_description() << "' on host '" << get_hostname() << "'..."; + log_v2::checks()->trace( + "** Running async check of anomalydetection '{} ' on host '{}'...", + get_description(), get_hostname()); + // Check if the service is viable now. if (!verify_check_viability(check_options, time_is_valid, preferred_time)) return ERROR; @@ -506,24 +544,34 @@ int anomalydetection::run_async_check(int check_options, if (preferred_time != nullptr) *preferred_time += static_cast(get_check_interval() * config->interval_length()); - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Some broker module cancelled check of anomalydetection '" << get_description() << "' on host '" << get_hostname(); + log_v2::runtime()->error( + "Error: Some broker module cancelled check of anomalydetection '{}' on " + "host '{}'", + get_description(), get_hostname()); return ERROR; } // Anomalydetection check was override by NEB module. else if (NEBERROR_CALLBACKOVERRIDE == res) { - logger(dbg_functions, basic) + engine_logger(dbg_functions, basic) << "Some broker module overrode check of anomalydetection '" << get_description() << "' on host '" << get_hostname() << "' so we'll bail out"; + log_v2::functions()->trace( + "Some broker module overrode check of anomalydetection '{}' on host " + "'{}' so we'll bail out", + get_description(), get_hostname()); return OK; } // Checking starts. - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Checking anomalydetection '" << get_description() << "' on host '" << get_hostname() << "'..."; + log_v2::checks()->trace("Checking anomalydetection '{}' on host '{}'...", + get_description(), get_hostname()); // Clear check options. if (scheduled_check) @@ -546,9 +594,11 @@ int anomalydetection::run_async_check(int check_options, // Update the number of running service checks. ++currently_running_service_checks; - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Current running service checks: " << currently_running_service_checks; + log_v2::checks()->trace("Current running service checks: {}", + currently_running_service_checks); // Set the execution flag. set_is_executing(true); @@ -669,8 +719,9 @@ anomalydetection::parse_perfdata(std::string const& perfdata, size_t pos = perfdata.find_last_of("="); /* If the perfdata is wrong. */ if (pos == std::string::npos) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Unable to parse perfdata '" << perfdata << "'"; + log_v2::runtime()->error("Error: Unable to parse perfdata '{}'", perfdata); return std::make_tuple(service::state_unknown, NAN, "", NAN, NAN); } @@ -691,8 +742,12 @@ anomalydetection::parse_perfdata(std::string const& perfdata, if (!_thresholds_file_viable) { status = service::state_ok; if (_status_change) { - logger(log_info_message, basic) << "The thresholds file is not viable " - "(not available or not readable)."; + engine_logger(log_info_message, basic) + << "The thresholds file is not viable " + "(not available or not readable)."; + log_v2::checks()->info( + "The thresholds file is not viable " + "(not available or not readable)."); } return std::make_tuple(status, value, unit, NAN, NAN); } @@ -717,17 +772,25 @@ anomalydetection::parse_perfdata(std::string const& perfdata, auto it2 = _thresholds.upper_bound(check_time); auto it1 = it2; if (it2 == _thresholds.end()) { - logger(log_runtime_error, basic) << "Error: the thresholds file is too old " - "compared to the check timestamp " - << check_time; + engine_logger(log_runtime_error, basic) + << "Error: the thresholds file is too old " + "compared to the check timestamp " + << check_time; + log_v2::runtime()->error( + "Error: the thresholds file is too old " + "compared to the check timestamp {}", + check_time); return std::make_tuple(service::state_unknown, value, uom, NAN, NAN); } if (it1 != _thresholds.begin()) --it1; else { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: timestamp " << check_time << " too old compared with the thresholds file"; + log_v2::runtime()->error( + "Error: timestamp {} too old compared with the thresholds file", + check_time); return std::make_tuple(service::state_unknown, value, uom, NAN, NAN); } @@ -756,8 +819,10 @@ anomalydetection::parse_perfdata(std::string const& perfdata, void anomalydetection::init_thresholds() { std::lock_guard lock(_thresholds_m); - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "Trying to read thresholds file '" << _thresholds_file << "'"; + log_v2::checks()->info("Trying to read thresholds file '{}'", + _thresholds_file); std::ifstream t(_thresholds_file); if (!t) return; @@ -769,14 +834,21 @@ void anomalydetection::init_thresholds() { try { json = nlohmann::json::parse(buffer.str()); } catch (const nlohmann::json::parse_error& e) { - logger(log_config_error, basic) << "Error: the file '" << _thresholds_file - << "' contains errors: " << e.what(); + engine_logger(log_config_error, basic) + << "Error: the file '" << _thresholds_file + << "' contains errors: " << e.what(); + log_v2::config()->error("Error: the file '{}' contains errors: {}", + _thresholds_file, e.what()); return; } if (!json.is_array()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: the file '" << _thresholds_file << "' is not a thresholds file. Its global structure is not an array."; + log_v2::config()->error( + "Error: the file '{}' is not a thresholds file. Its global structure " + "is not an array.", + _thresholds_file); return; } @@ -788,17 +860,26 @@ void anomalydetection::init_thresholds() { host_id = stoull(item["host_id"].get()); service_id = stoull(item["service_id"].get()); } catch (std::exception const& e) { - logger(log_config_error, basic) << "Error: host_id and service_id must " - "be strings containing integers: " - << e.what(); + engine_logger(log_config_error, basic) + << "Error: host_id and service_id must " + "be strings containing integers: " + << e.what(); + log_v2::config()->error( + "Error: host_id and service_id must " + "be strings containing integers: {}", + e.what()); return; } if (host_id == get_host_id() && service_id == get_service_id() && item["metric_name"].get() == _metric_name) { - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "Filling thresholds in anomaly detection (host_id: " << get_host_id() << ", service_id: " << get_service_id() << ", metric: " << _metric_name << ")"; + log_v2::checks()->info( + "Filling thresholds in anomaly detection (host_id: {}, service_id: " + "{}, metric: {})", + get_host_id(), get_service_id(), _metric_name); auto predict = item["predict"]; _thresholds.clear(); for (auto& i : predict) { @@ -814,10 +895,14 @@ void anomalydetection::init_thresholds() { } } if (count > 1) { - logger(log_info_message, most) << "Number of rows in memory: " << count; + engine_logger(log_info_message, most) + << "Number of rows in memory: " << count; + log_v2::checks()->info("Number of rows in memory: {}", count); _thresholds_file_viable = true; - } else - logger(log_info_message, most) << "Nothing in memory"; + } else { + engine_logger(log_info_message, most) << "Nothing in memory"; + log_v2::checks()->info("Nothing in memory"); + } } /** @@ -827,12 +912,15 @@ void anomalydetection::init_thresholds() { * @param filename The fullname of the file to parse. */ int anomalydetection::update_thresholds(const std::string& filename) { - logger(log_info_message, most) + engine_logger(log_info_message, most) << "Reading thresholds file '" << filename << "'."; + log_v2::checks()->info("Reading thresholds file '{}'.", filename); std::ifstream t(filename); if (!t) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Unable to read the thresholds file '" << filename << "'."; + log_v2::config()->error("Error: Unable to read the thresholds file '{}'.", + filename); return -1; } @@ -842,16 +930,23 @@ int anomalydetection::update_thresholds(const std::string& filename) { try { json = nlohmann::json::parse(buffer.str()); } catch (const nlohmann::json::parse_error& e) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: The thresholds file '" << filename << "' should be a json file: " << e.what(); + log_v2::config()->error( + "Error: The thresholds file '{}' should be a json file: {}", filename, + e.what()); return -2; } if (!json.is_array()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: the file '" << filename << "' is not a thresholds file. Its global structure is not an array."; + log_v2::config()->error( + "Error: the file '{}' is not a thresholds file. Its global structure " + "is not an array.", + filename); return -3; } @@ -862,36 +957,55 @@ int anomalydetection::update_thresholds(const std::string& filename) { host_id = stoull(item["host_id"].get()); svc_id = stoull(item["service_id"].get()); } catch (std::exception const& e) { - logger(log_config_error, basic) << "Error: host_id and service_id must " - "be strings containing integers: " - << e.what(); + engine_logger(log_config_error, basic) + << "Error: host_id and service_id must " + "be strings containing integers: " + << e.what(); + log_v2::config()->error( + "Error: host_id and service_id must " + "be strings containing integers: {}", + e.what()); continue; } auto found = service::services_by_id.find({host_id, svc_id}); if (found == service::services_by_id.end()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: The thresholds file contains thresholds for the anomaly " "detection service (host_id: " << host_id << ", service_id: " << svc_id << ") that does not exist"; + log_v2::config()->error( + "Error: The thresholds file contains thresholds for the anomaly " + "detection service (host_id: {}, service_id: {}) that does not exist", + host_id, svc_id); continue; } std::shared_ptr ad = std::static_pointer_cast(found->second); const std::string& metric_name(item["metric_name"].get()); if (ad->get_metric_name() != metric_name) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: The thresholds file contains thresholds for the anomaly " "detection service (host_id: " << ad->get_host_id() << ", service_id: " << ad->get_service_id() << ") with metric_name='" << metric_name << "' whereas the configured metric name is '" << ad->get_metric_name() << "'"; + log_v2::config()->error( + "Error: The thresholds file contains thresholds for the anomaly " + "detection service (host_id: {}, service_id: {}) with " + "metric_name='{}' whereas the configured metric name is '{}'", + ad->get_host_id(), ad->get_service_id(), metric_name, + ad->get_metric_name()); continue; } - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "Filling thresholds in anomaly detection (host_id: " << ad->get_host_id() << ", service_id: " << ad->get_service_id() << ", metric: " << ad->get_metric_name() << ")"; + log_v2::checks()->info( + "Filling thresholds in anomaly detection (host_id: {}, service_id: {}, " + "metric: {})", + ad->get_host_id(), ad->get_service_id(), ad->get_metric_name()); auto predict = item["predict"]; std::map > thresholds; diff --git a/centreon-engine/src/broker.cc b/centreon-engine/src/broker.cc index 8e60d66117b..22c71ede405 100644 --- a/centreon-engine/src/broker.cc +++ b/centreon-engine/src/broker.cc @@ -1178,7 +1178,8 @@ void broker_log_data(int type, time_t entry_time, struct timeval const* timestamp) { // Config check. - if (!(config->event_broker_options() & BROKER_LOGGED_DATA)) + if (!(config->event_broker_options() & BROKER_LOGGED_DATA) || + !config->log_legacy_enabled()) return; // Fill struct with relevant data. diff --git a/centreon-engine/src/broker/handle.cc b/centreon-engine/src/broker/handle.cc index 42ba5f24b4f..2ef0f3379cc 100644 --- a/centreon-engine/src/broker/handle.cc +++ b/centreon-engine/src/broker/handle.cc @@ -21,6 +21,7 @@ #include "com/centreon/engine/broker/compatibility.hh" #include "com/centreon/engine/common.hh" #include "com/centreon/engine/exceptions/error.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/nebmodules.hh" @@ -110,11 +111,14 @@ void handle::close() { typedef int (*func_deinit)(int, int); func_deinit deinit( (func_deinit)_handle->resolve_proc("nebmodule_deinit")); - if (!deinit) - logger(log_info_message, basic) + if (!deinit) { + engine_logger(log_info_message, basic) << "Cannot resolve symbole 'nebmodule_deinit' in module '" << _filename << "'."; - else + log_v2::process()->error( + "Cannot resolve symbole 'nebmodule_deinit' in module '{}'.", + _filename); + } else deinit(NEBMODULE_FORCE_UNLOAD | NEBMODULE_ENGINE, NEBMODULE_NEB_SHUTDOWN); _handle->unload(); diff --git a/centreon-engine/src/broker/loader.cc b/centreon-engine/src/broker/loader.cc index ab73bd66e41..5d58b1d900b 100644 --- a/centreon-engine/src/broker/loader.cc +++ b/centreon-engine/src/broker/loader.cc @@ -22,6 +22,7 @@ #include #include #include "com/centreon/engine/exceptions/error.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/io/directory_entry.hh" #include "com/centreon/io/file_stream.hh" @@ -120,14 +121,19 @@ unsigned int loader::load_directory(std::string const& dir) { try { module = add_module(dir + "/" + f.file_name(), config_file); module->open(); - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "Event broker module '" << f.file_name() << "' initialized successfully."; + log_v2::events()->info( + "Event broker module '{}' initialized successfully.", f.file_name()); ++loaded; } catch (error const& e) { del_module(module); - logger(log_runtime_error, basic) << "Error: Could not load module '" - << f.file_name() << "' -> " << e.what(); + engine_logger(log_runtime_error, basic) + << "Error: Could not load module '" << f.file_name() << "' -> " + << e.what(); + log_v2::runtime()->error("Error: Could not load module '{}' -> {}", + f.file_name(), e.what()); } } return loaded; @@ -144,8 +150,10 @@ void loader::unload_modules() { (*it)->close(); } catch (...) { } - logger(dbg_eventbroker, basic) + engine_logger(dbg_eventbroker, basic) << "Module '" << (*it)->get_filename() << "' unloaded successfully."; + log_v2::eventbroker()->trace("Module '{}' unloaded successfully.", + (*it)->get_filename()); } _modules.clear(); } diff --git a/centreon-engine/src/checkable.cc b/centreon-engine/src/checkable.cc index 3aaf6cb0396..e52271ec415 100644 --- a/centreon-engine/src/checkable.cc +++ b/centreon-engine/src/checkable.cc @@ -20,6 +20,7 @@ #include "com/centreon/engine/checkable.hh" #include #include "com/centreon/engine/exceptions/error.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" using namespace com::centreon::engine; @@ -107,7 +108,8 @@ checkable::checkable(std::string const& display_name, oss << " - "; oss << "Invalid freshness_threshold: value should be positive or 0"; } - logger(log_config_error, basic) << oss.str(); + engine_logger(log_config_error, basic) << oss.str(); + log_v2::config()->error(oss.str()); throw engine_error() << "Could not register checkable '" << display_name << "'"; } diff --git a/centreon-engine/src/checks/checker.cc b/centreon-engine/src/checks/checker.cc old mode 100755 new mode 100644 index 3811574f6c6..d460e95d588 --- a/centreon-engine/src/checks/checker.cc +++ b/centreon-engine/src/checks/checker.cc @@ -26,6 +26,7 @@ #include "com/centreon/engine/broker.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/macros.hh" #include "com/centreon/engine/neberrors.hh" #include "com/centreon/engine/objects.hh" @@ -96,8 +97,11 @@ void checker::clear() noexcept { * Reap and process all results received by execution process. */ void checker::reap() { - logger(dbg_functions, basic) << "checker::reap"; - logger(dbg_checks, basic) << "Starting to reap check results."; + engine_logger(dbg_functions, basic) << "checker::reap"; + log_v2::functions()->trace("checker::reap()"); + + engine_logger(dbg_checks, basic) << "Starting to reap check results."; + log_v2::checks()->trace("Starting to reap check results."); // Time to start reaping. time_t reaper_start_time; @@ -135,8 +139,11 @@ void checker::reap() { // Process check results. while (!_to_reap.empty()) { // Get result host or service check. - logger(dbg_checks, basic) - << "Found a check result (#" << ++reaped_checks << ") to handle..."; + ++reaped_checks; + engine_logger(dbg_checks, basic) + << "Found a check result (#" << reaped_checks << ") to handle..."; + log_v2::checks()->trace("Found a check result (#{}) to handle...", + reaped_checks); check_result* result = _to_reap.front(); _to_reap.pop_front(); @@ -145,14 +152,19 @@ void checker::reap() { service* svc = static_cast(result->get_notifier()); try { // Check if the service exists. - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Handling check result for service " << svc->get_host_id() << "/" << svc->get_service_id() << "..."; + log_v2::checks()->debug("Handling check result for service {}/{}...", + svc->get_host_id(), svc->get_service_id()); svc->handle_async_check_result(result); } catch (std::exception const& e) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Check result queue errors for service " << svc->get_host_id() << "/" << svc->get_service_id() << " : " << e.what(); + log_v2::runtime()->warn( + "Check result queue errors for service {}/{} : {}", + svc->get_host_id(), svc->get_service_id(), e.what()); } } // Host check result-> @@ -160,13 +172,17 @@ void checker::reap() { host* hst = static_cast(result->get_notifier()); try { // Process the check result-> - logger(dbg_checks, more) << "Handling check result for host " - << hst->get_host_id() << "..."; + engine_logger(dbg_checks, more) << "Handling check result for host " + << hst->get_host_id() << "..."; + log_v2::checks()->debug("Handling check result for host {}...", + hst->get_host_id()); hst->handle_async_check_result_3x(result); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Check result queue errors for " << "host " << hst->get_host_id() << " : " << e.what(); + log_v2::runtime()->error("Check result queue errors for host {} : {}", + hst->get_host_id(), e.what()); } } @@ -177,23 +193,29 @@ void checker::reap() { time(¤t_time); if (current_time - reaper_start_time > static_cast(config->max_check_reaper_time())) { - logger(dbg_checks, basic) << "Breaking out of check result reaper: " - << "max reaper time exceeded"; + engine_logger(dbg_checks, basic) + << "Breaking out of check result reaper: " + << "max reaper time exceeded"; + log_v2::checks()->trace( + "Breaking out of check result reaper: max reaper time exceeded"); break; } // Caught signal, need to break. if (sigshutdown) { - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Breaking out of check result reaper: signal encountered"; + log_v2::checks()->trace( + "Breaking out of check result reaper: signal encountered"); break; } } } // Reaping finished. - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Finished reaping " << reaped_checks << " check results"; + log_v2::checks()->trace("Finished reaping {} check results", reaped_checks); } /** @@ -210,10 +232,15 @@ void checker::run_sync(host* hst, int check_options, int use_cached_result, unsigned long check_timestamp_horizon) { - logger(dbg_functions, basic) + engine_logger(dbg_functions, basic) << "checker::run: hst=" << hst << ", check_options=" << check_options << ", use_cached_result=" << use_cached_result << ", check_timestamp_horizon=" << check_timestamp_horizon; + log_v2::functions()->trace( + "checker::run: hst={:p}, check_options={}" + ", use_cached_result={}" + ", check_timestamp_horizon={}", + (void*)hst, check_options, use_cached_result, check_timestamp_horizon); // Preamble. if (!hst) @@ -222,14 +249,16 @@ void checker::run_sync(host* hst, throw engine_error() << "Attempt to run synchronous active check on host '" << hst->get_name() << "' with no check command"; - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "** Run sync check of host '" << hst->get_name() << "'..."; + log_v2::checks()->trace("** Run sync check of host '{}'...", hst->get_name()); // Check if the host is viable now. if (!hst->verify_check_viability(check_options, nullptr, nullptr)) { if (check_result_code) *check_result_code = hst->get_current_state(); - logger(dbg_checks, basic) << "Host check is not viable at this time"; + engine_logger(dbg_checks, basic) << "Host check is not viable at this time"; + log_v2::checks()->trace("Host check is not viable at this time"); return; } @@ -246,8 +275,10 @@ void checker::run_sync(host* hst, check_timestamp_horizon)) { if (check_result_code) *check_result_code = hst->get_current_state(); - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "* Using cached host state: " << hst->get_current_state(); + log_v2::checks()->debug("* Using cached host state: {}", + hst->get_current_state()); // Update statistics. update_check_stats(ACTIVE_ONDEMAND_HOST_CHECK_STATS, start_time.tv_sec); @@ -257,8 +288,10 @@ void checker::run_sync(host* hst, } // Checking starts. - logger(dbg_checks, more) << "* Running actual host check: old state=" - << hst->get_current_state(); + engine_logger(dbg_checks, more) + << "* Running actual host check: old state=" << hst->get_current_state(); + log_v2::checks()->debug("* Running actual host check: old state={}", + hst->get_current_state()); // Update statistics. update_check_stats(ACTIVE_ONDEMAND_HOST_CHECK_STATS, start_time.tv_sec); @@ -311,8 +344,10 @@ void checker::run_sync(host* hst, *check_result_code = hst->get_current_state(); // Synchronous check is done. - logger(dbg_checks, more) << "* Sync host check done: new state=" - << hst->get_current_state(); + engine_logger(dbg_checks, more) + << "* Sync host check done: new state=" << hst->get_current_state(); + log_v2::checks()->debug("* Sync host check done: new state={}", + hst->get_current_state()); // Get the end time of command. gettimeofday(&end_time, nullptr); @@ -354,13 +389,15 @@ checker::~checker() noexcept { */ void checker::finished(commands::result const& res) noexcept { // Debug message. - logger(dbg_functions, basic) << "checker::finished: res=" << &res; + engine_logger(dbg_functions, basic) << "checker::finished: res=" << &res; + log_v2::functions()->trace("checker::finished: res={:p}", (void*)&res); std::unique_lock lock(_mut_reap); auto it_id = _waiting_check_result.find(res.command_id); if (it_id == _waiting_check_result.end()) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "command ID '" << res.command_id << "' not found"; + log_v2::runtime()->warn("command ID '{}' not found", res.command_id); return; } @@ -394,7 +431,8 @@ void checker::finished(commands::result const& res) noexcept { * host::state_down). */ com::centreon::engine::host::host_state checker::_execute_sync(host* hst) { - logger(dbg_functions, basic) << "checker::_execute_sync: hst=" << hst; + engine_logger(dbg_functions, basic) << "checker::_execute_sync: hst=" << hst; + log_v2::functions()->trace("checker::_execute_sync: hst={:p}", (void*)hst); // Preamble. if (!hst) @@ -403,8 +441,10 @@ com::centreon::engine::host::host_state checker::_execute_sync(host* hst) { throw engine_error() << "Attempt to run synchronous active check on host '" << hst->get_name() << "' with no check command"; - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "** Executing sync check of host '" << hst->get_name() << "'..."; + log_v2::checks()->trace("** Executing sync check of host '{}'...", + hst->get_name()); // Send broker event. timeval start_time; @@ -452,11 +492,15 @@ com::centreon::engine::host::host_state checker::_execute_sync(host* hst) { const_cast(hst->get_perf_data().c_str()), nullptr); // Debug messages. - logger(dbg_commands, more) + engine_logger(dbg_commands, more) << "Raw host check command: " << hst->get_check_command_ptr()->get_command_line(); - logger(dbg_commands, more) + log_v2::commands()->trace("Raw host check command: {}", + hst->get_check_command_ptr()->get_command_line()); + + engine_logger(dbg_commands, more) << "Processed host check ommand: " << processed_cmd; + log_v2::commands()->trace("Processed host check ommand: {}", processed_cmd); // Cleanup. hst->set_plugin_output(""); @@ -486,9 +530,11 @@ com::centreon::engine::host::host_state checker::_execute_sync(host* hst) { res.output = "(Execute command failed)"; res.start_time = res.end_time; - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Error: Synchronous host check command execution failed: " << e.what(); + log_v2::runtime()->warn( + "Error: Synchronous host check command execution failed: {}", e.what()); } // Get output. @@ -522,10 +568,14 @@ com::centreon::engine::host::host_state checker::_execute_sync(host* hst) { oss << "Host check timed out after " << config->host_check_timeout() << " seconds"; res.output = oss.str(); - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Host check command '" << processed_cmd << "' for host '" << hst->get_name() << "' timed out after " << config->host_check_timeout() << " seconds"; + log_v2::runtime()->warn( + "Warning: Host check command '{}' for host '{}' timed out after {} " + "seconds", + processed_cmd, hst->get_name(), config->host_check_timeout()); } // Update values. @@ -582,8 +632,9 @@ com::centreon::engine::host::host_state checker::_execute_sync(host* hst) { const_cast(hst->get_perf_data().c_str()), nullptr); // Termination. - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "** Sync host check done: state=" << return_result; + log_v2::checks()->trace("** Sync host check done: state={}", return_result); return return_result; } diff --git a/centreon-engine/src/command_manager.cc b/centreon-engine/src/command_manager.cc index 84190f0d6d1..84945e52fb3 100644 --- a/centreon-engine/src/command_manager.cc +++ b/centreon-engine/src/command_manager.cc @@ -27,6 +27,7 @@ #include "com/centreon/engine/comment.hh" #include "com/centreon/engine/downtimes/downtime_manager.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" using namespace com::centreon::engine; @@ -109,10 +110,14 @@ int command_manager::process_passive_service_check( /* we couldn't find the host */ if (real_host_name == nullptr) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Passive check result was received for service '" << svc_description << "' on host '" << host_name << "', but the host could not be found!"; + log_v2::runtime()->warn( + "Warning: Passive check result was received for service '{}' on host " + "'{}', but the host could not be found!", + svc_description, host_name); return ERROR; } @@ -120,10 +125,14 @@ int command_manager::process_passive_service_check( service_map::const_iterator found( service::services.find({*real_host_name, svc_description})); if (found == service::services.end() || !found->second) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Passive check result was received for service '" << svc_description << "' on host '" << host_name << "', but the service could not be found!"; + log_v2::runtime()->warn( + "Warning: Passive check result was received for service '{}' on host " + "'{}', but the service could not be found!", + svc_description, host_name); return ERROR; } @@ -186,9 +195,13 @@ int command_manager::process_passive_host_check(time_t check_time, /* we couldn't find the host */ if (real_host_name == nullptr) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Passive check result was received for host '" << host_name << "', but the host could not be found!"; + log_v2::runtime()->warn( + "Warning: Passive check result was received for host '{}', but the " + "host could not be found!", + host_name); return ERROR; } diff --git a/centreon-engine/src/commands/connector.cc b/centreon-engine/src/commands/connector.cc index 27980fc58ca..bce4f509404 100644 --- a/centreon-engine/src/commands/connector.cc +++ b/centreon-engine/src/commands/connector.cc @@ -24,6 +24,7 @@ #include #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/my_lock.hh" #include "com/centreon/engine/version.hh" @@ -79,9 +80,12 @@ connector::connector(const std::string& connector_name, UNIQUE_LOCK(lck, _lock); _process.setpgid_on_exec(config->use_setpgid()); } - if (config->enable_environment_macros()) - logger(log_runtime_warning, basic) + if (config->enable_environment_macros()) { + engine_logger(log_runtime_warning, basic) << "Warning: Connector does not enable environment macros"; + log_v2::runtime()->warn( + "Warning: Connector does not enable environment macros"); + } } /** @@ -92,8 +96,10 @@ connector::~connector() noexcept { try { _connector_close(); } catch (const std::exception& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: could not stop connector properly: " << e.what(); + log_v2::runtime()->error("Error: could not stop connector properly: {}", + e.what()); } // Wait restart thread. @@ -120,9 +126,12 @@ uint64_t connector::run(const std::string& processed_cmd, uint32_t timeout) { (void)macros; - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "connector::run: connector='" << _name << "', cmd='" << processed_cmd << "', timeout=" << timeout; + log_v2::commands()->trace( + "connector::run: connector='{}', cmd='{}', timeout={}", _name, + processed_cmd, timeout); // Set query informations. uint64_t command_id(get_uniq_id()); @@ -132,8 +141,8 @@ uint64_t connector::run(const std::string& processed_cmd, info->timeout = timeout; info->waiting_result = false; - logger(dbg_commands, basic) << "connector::run: id=" << command_id; - + engine_logger(dbg_commands, basic) << "connector::run: id=" << command_id; + log_v2::commands()->trace("connector::run: id={}", command_id); try { { UNIQUE_LOCK(lock, _lock); @@ -155,11 +164,15 @@ uint64_t connector::run(const std::string& processed_cmd, _queries[command_id] = info; } - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "connector::run: start command success: id=" << command_id; + log_v2::commands()->trace("connector::run: start command success: id={}", + command_id); } catch (...) { - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "connector::run: start command failed: id=" << command_id; + log_v2::commands()->trace("connector::run: start command failed: id={}", + command_id); throw; } return command_id; @@ -179,9 +192,12 @@ void connector::run(const std::string& processed_cmd, result& res) { (void)macros; - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "connector::run: connector='" << _name << "', cmd='" << processed_cmd << "', timeout=" << timeout; + log_v2::commands()->trace( + "connector::run: connector='{}', cmd='{}', timeout={}", _name, + processed_cmd, timeout); // Set query informations. uint64_t command_id(get_uniq_id()); @@ -191,7 +207,8 @@ void connector::run(const std::string& processed_cmd, info->timeout = timeout; info->waiting_result = true; - logger(dbg_commands, basic) << "connector::run: id=" << command_id; + engine_logger(dbg_commands, basic) << "connector::run: id=" << command_id; + log_v2::commands()->trace("connector::run: id={}", command_id); try { { @@ -213,11 +230,15 @@ void connector::run(const std::string& processed_cmd, _queries[command_id] = info; } - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "connector::run: start command success: id=" << command_id; + log_v2::commands()->trace("connector::run: start command success: id={}", + command_id); } catch (...) { - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "connector::run: start command failed: id=" << command_id; + log_v2::commands()->trace("connector::run: start command failed: id={}", + command_id); throw; } @@ -269,8 +290,10 @@ void connector::data_is_available(process& p) noexcept { nullptr}; try { - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "connector::data_is_available: process=" << (void*)&p; + log_v2::commands()->trace("connector::data_is_available: process={}", + (void*)&p); // Read process output. std::string data; @@ -294,9 +317,11 @@ void connector::data_is_available(process& p) noexcept { } } - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "connector::data_is_available: responses.size=" << responses.size(); + log_v2::commands()->trace( + "connector::data_is_available: responses.size={}", responses.size()); } // Parse queries responses. @@ -304,21 +329,30 @@ void connector::data_is_available(process& p) noexcept { char const* data = str.c_str(); char* endptr(nullptr); uint32_t id(strtol(data, &endptr, 10)); - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "connector::data_is_available: request id=" << id; + log_v2::commands()->trace("connector::data_is_available: request id={}", + id); + // Invalid query. - if (data == endptr || id >= tab_recv_query.size() || !tab_recv_query[id]) - logger(log_runtime_warning, basic) << "Warning: Connector '" << _name - << "' " - "received bad request ID: " - << id; - // Valid query, so execute it. - else + if (data == endptr || id >= tab_recv_query.size() || + !tab_recv_query[id]) { + engine_logger(log_runtime_warning, basic) + << "Warning: Connector '" << _name + << "' " + "received bad request ID: " + << id; + log_v2::runtime()->warn( + "Warning: Connector '{}' received bad request ID: {}", _name, id); + // Valid query, so execute it. + } else (this->*tab_recv_query[id])(endptr + 1); } } catch (std::exception const& e) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Connector '" << _name << "' error: " << e.what(); + log_v2::runtime()->warn("Warning: Connector '{}' error: {}", _name, + e.what()); } } @@ -339,8 +373,8 @@ void connector::data_is_available_err(process& p) noexcept { */ void connector::finished(process& p) noexcept { try { - logger(dbg_commands, basic) << "connector::finished: process=" << &p; - + engine_logger(dbg_commands, basic) << "connector::finished: process=" << &p; + log_v2::commands()->trace("connector::finished: process={}", (void*)&p); UNIQUE_LOCK(lock, _lock); _is_running = false; _data_available.clear(); @@ -356,9 +390,12 @@ void connector::finished(process& p) noexcept { } } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Connector '" << _name << "' termination routine failed: " << e.what(); + log_v2::runtime()->error( + "Error: Connector '{}' termination routine failed: {}", _name, + e.what()); } } @@ -372,9 +409,10 @@ void connector::_connector_close() { if (!_is_running) return; - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "connector::_connector_close: process=" << &_process; - + log_v2::commands()->trace("connector::_connector_close: process={:p}", + (void*)&_process); // Set variable to dosn't restart connector. { LOCK_GUARD(lck, _thread_m); @@ -395,9 +433,12 @@ void connector::_connector_close() { std::cv_status::timeout}; if (is_timeout || !_query_quit_ok) { _process.kill(); - if (is_timeout) - logger(log_runtime_warning, basic) + if (is_timeout) { + engine_logger(log_runtime_warning, basic) << "Warning: Cannot close connector '" << _name << "': Timeout"; + log_v2::runtime()->warn("Warning: Cannot close connector '{}': Timeout", + _name); + } } UNLOCK(lock); @@ -409,9 +450,10 @@ void connector::_connector_close() { * Start connection with the process. */ void connector::_connector_start() { - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "connector::_connector_start: process=" << &_process; - + log_v2::commands()->trace("connector::_connector_start: process={:p}", + (void*)&_process); { LOCK_GUARD(lock, _lock); @@ -450,14 +492,18 @@ void connector::_connector_start() { _is_running = true; } - logger(log_info_message, basic) << "Connector '" << _name << "' has started"; + engine_logger(log_info_message, basic) + << "Connector '" << _name << "' has started"; + log_v2::runtime()->info("Connector '{}' has started", _name); { LOCK_GUARD(lock, _lock); - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "connector::_connector_start: resend queries: queries.size=" << _queries.size(); - + log_v2::commands()->trace( + "connector::_connector_start: resend queries: queries.size={}", + _queries.size()); // Resend commands. for (std::unordered_map >::iterator it(_queries.begin()), @@ -488,8 +534,8 @@ const std::string& connector::_query_ending() const noexcept { */ void connector::_recv_query_error(char const* data) { try { - logger(dbg_commands, basic) << "connector::_recv_query_error"; - + engine_logger(dbg_commands, basic) << "connector::_recv_query_error"; + log_v2::commands()->trace("connector::_recv_query_error"); char* endptr(nullptr); int code(strtol(data, &endptr, 10)); if (data == endptr) @@ -500,23 +546,27 @@ void connector::_recv_query_error(char const* data) { switch (code) { // Information message. case 0: - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "Info: Connector '" << _name << "': " << message; + log_v2::runtime()->info("Info: Connector '{}': {}", _name, message); break; // Warning message. case 1: - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Connector '" << _name << "': " << message; + log_v2::runtime()->warn("Warning: Connector '{}': {}", _name, message); break; // Error message. case 2: - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Connector '" << _name << "': " << message; + log_v2::runtime()->error("Error: Connector '{}': {}", _name, message); break; } } catch (std::exception const& e) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Connector '" << _name << "': " << e.what(); + log_v2::runtime()->warn("Warning: Connector '{}': {}", _name, e.what()); } } @@ -527,8 +577,8 @@ void connector::_recv_query_error(char const* data) { */ void connector::_recv_query_execute(char const* data) { try { - logger(dbg_commands, basic) << "connector::_recv_query_execute"; - + engine_logger(dbg_commands, basic) << "connector::_recv_query_execute"; + log_v2::commands()->trace("connector::_recv_query_execute"); // Get query informations. char* endptr(nullptr); uint64_t command_id(strtol(data, &endptr, 10)); @@ -545,9 +595,10 @@ void connector::_recv_query_execute(char const* data) { char const* std_err(endptr + 1); char const* std_out(std_err + strlen(std_err) + 1); - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "connector::_recv_query_execute: id=" << command_id; - + log_v2::commands()->trace("connector::_recv_query_execute: id={}", + command_id); std::shared_ptr info; { LOCK_GUARD(lock, _lock); @@ -556,10 +607,13 @@ void connector::_recv_query_execute(char const* data) { std::unordered_map >::iterator it( _queries.find(command_id)); if (it == _queries.end()) { - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "recv query failed: command_id(" << command_id << ") " "not found into queries"; + log_v2::commands()->trace( + "recv query failed: command_id({}) not found into queries", + command_id); return; } // Get data. @@ -592,24 +646,34 @@ void connector::_recv_query_execute(char const* data) { res.output = (is_executed ? std_out : std_err); } - logger(dbg_commands, basic) << "connector::_recv_query_execute: " - "id=" - << command_id - << ", " - "start_time=" - << res.start_time.to_mseconds() - << ", " - "end_time=" - << res.end_time.to_mseconds() - << ", " - "exit_code=" - << res.exit_code - << ", " - "exit_status=" - << res.exit_status - << ", " - "output='" - << res.output << "'"; + engine_logger(dbg_commands, basic) << "connector::_recv_query_execute: " + "id=" + << command_id + << ", " + "start_time=" + << res.start_time.to_mseconds() + << ", " + "end_time=" + << res.end_time.to_mseconds() + << ", " + "exit_code=" + << res.exit_code + << ", " + "exit_status=" + << res.exit_status + << ", " + "output='" + << res.output << "'"; + log_v2::commands()->trace( + "connector::_recv_query_execute: " + "id={}, " + "start_time={}, " + "end_time={}, " + "exit_code={}, " + "exit_status={}, " + "output='{}'", + command_id, res.start_time.to_mseconds(), res.end_time.to_mseconds(), + res.exit_code, res.exit_status, res.output); if (!info->waiting_result) { // Forward result to the listener. @@ -622,8 +686,9 @@ void connector::_recv_query_execute(char const* data) { _cv_query.notify_all(); } } catch (std::exception const& e) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Connector '" << _name << "': " << e.what(); + log_v2::runtime()->warn("Warning: Connector '{}': {}", _name, e.what()); } } @@ -634,8 +699,8 @@ void connector::_recv_query_execute(char const* data) { */ void connector::_recv_query_quit(char const* data) { (void)data; - logger(dbg_commands, basic) << "connector::_recv_query_quit"; - + engine_logger(dbg_commands, basic) << "connector::_recv_query_quit"; + log_v2::commands()->trace("connector::_recv_query_quit"); LOCK_GUARD(lock, _lock); _query_quit_ok = true; _cv_query.notify_all(); @@ -647,8 +712,8 @@ void connector::_recv_query_quit(char const* data) { * @param[in] data Has version of engine to use with the connector. */ void connector::_recv_query_version(char const* data) { - logger(dbg_commands, basic) << "connector::_recv_query_version"; - + engine_logger(dbg_commands, basic) << "connector::_recv_query_version"; + log_v2::commands()->trace("connector::_recv_query_version"); bool version_ok(false); try { // Parse query version response to get major and minor @@ -662,18 +727,23 @@ void connector::_recv_query_version(char const* data) { data = endptr + 1; } - logger(dbg_commands, basic) << "connector::_recv_query_version: " - "major=" - << version[0] << ", minor=" << version[1]; - + engine_logger(dbg_commands, basic) + << "connector::_recv_query_version: " + "major=" + << version[0] << ", minor=" << version[1]; + log_v2::commands()->trace( + "connector::_recv_query_version: " + "major={}, minor={}", + version[0], version[1]); // Check the version. if (version[0] < CENTREON_ENGINE_VERSION_MAJOR || (version[0] == CENTREON_ENGINE_VERSION_MAJOR && version[1] <= CENTREON_ENGINE_VERSION_MINOR)) version_ok = true; } catch (std::exception const& e) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Connector '" << _name << "': " << e.what(); + log_v2::runtime()->warn("Warning: Connector '{}': {}", _name, e.what()); } LOCK_GUARD(lock, _lock); @@ -694,19 +764,25 @@ void connector::_send_query_execute(const std::string& cmdline, uint64_t command_id, timestamp const& start, uint32_t timeout) { - logger(dbg_commands, basic) << "connector::_send_query_execute: " - "id=" - << command_id - << ", " - "cmd='" - << cmdline - << "', " - "start=" - << start.to_seconds() - << ", " - "timeout=" - << timeout; - + engine_logger(dbg_commands, basic) << "connector::_send_query_execute: " + "id=" + << command_id + << ", " + "cmd='" + << cmdline + << "', " + "start=" + << start.to_seconds() + << ", " + "timeout=" + << timeout; + log_v2::commands()->trace( + "connector::_send_query_execute: " + "id={}, " + "cmd='{}', " + "start={}, " + "timeout={}", + command_id, cmdline, start.to_seconds(), timeout); std::ostringstream oss; oss << "2" << '\0' << command_id << '\0' << timeout << '\0' << start.to_seconds() << '\0' << cmdline << '\0' << _query_ending(); @@ -718,8 +794,8 @@ void connector::_send_query_execute(const std::string& cmdline, * Send query quit. To ask connector to quit properly. */ void connector::_send_query_quit() { - logger(dbg_commands, basic) << "connector::_send_query_quit"; - + engine_logger(dbg_commands, basic) << "connector::_send_query_quit"; + log_v2::commands()->trace("connector::_send_query_quit"); std::string query("4\0", 2); _process.write(query + _query_ending()); } @@ -728,8 +804,8 @@ void connector::_send_query_quit() { * Send query verion. To ask connector version. */ void connector::_send_query_version() { - logger(dbg_commands, basic) << "connector::_send_query_version"; - + engine_logger(dbg_commands, basic) << "connector::_send_query_version"; + log_v2::commands()->trace("connector::_send_query_version"); std::string query("0\0", 2); query.append(_query_ending()); _process.write(query); @@ -774,8 +850,9 @@ void connector::_run_restart() { try { _connector_start(); } catch (std::exception const& e) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Connector '" << _name << "': " << e.what(); + log_v2::runtime()->warn("Warning: Connector '{}': {}", _name, e.what()); std::unordered_map > tmp_queries; { @@ -801,25 +878,34 @@ void connector::_run_restart() { res.start_time = info->start_time; res.output = "(Failed to execute command with connector '" + _name + "')"; - logger(dbg_commands, basic) << "connector::_recv_query_execute: " - "id=" - << command_id - << ", " - "start_time=" - << res.start_time.to_mseconds() - << ", " - "end_time=" - << res.end_time.to_mseconds() - << ", " - "exit_code=" - << res.exit_code - << ", " - "exit_status=" - << res.exit_status - << ", " - "output='" - << res.output << "'"; - + engine_logger(dbg_commands, basic) << "connector::_recv_query_execute: " + "id=" + << command_id + << ", " + "start_time=" + << res.start_time.to_mseconds() + << ", " + "end_time=" + << res.end_time.to_mseconds() + << ", " + "exit_code=" + << res.exit_code + << ", " + "exit_status=" + << res.exit_status + << ", " + "output='" + << res.output << "'"; + log_v2::commands()->trace( + "connector::_recv_query_execute: " + "id={}, " + "start_time={}, " + "end_time={}, " + "exit_code={}, " + "exit_status={}, " + "output='{}'", + command_id, res.start_time.to_mseconds(), res.end_time.to_mseconds(), + res.exit_code, res.exit_status, res.output); if (!info->waiting_result) { // Forward result to the listener. if (_listener) diff --git a/centreon-engine/src/commands/raw.cc b/centreon-engine/src/commands/raw.cc index e08bf84f1a9..1ec33928a68 100644 --- a/centreon-engine/src/commands/raw.cc +++ b/centreon-engine/src/commands/raw.cc @@ -21,6 +21,7 @@ #include "com/centreon/engine/commands/environment.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" @@ -61,8 +62,10 @@ raw::~raw() noexcept { delete p; } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Raw command destructor failed: " << e.what(); + log_v2::runtime()->error("Error: Raw command destructor failed: {}", + e.what()); } } @@ -78,8 +81,10 @@ raw::~raw() noexcept { uint64_t raw::run(std::string const& processed_cmd, nagios_macros& macros, uint32_t timeout) { - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "raw::run: cmd='" << processed_cmd << "', timeout=" << timeout; + log_v2::commands()->trace("raw::run: cmd='{}', timeout={}", processed_cmd, + timeout); // Get process and put into the busy list. process* p; @@ -90,8 +95,10 @@ uint64_t raw::run(std::string const& processed_cmd, _processes_busy[p] = command_id; } - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "raw::run: id=" << command_id << ", process=" << p; + log_v2::commands()->trace("raw::run: id={} , process={}", command_id, + (void*)p); // Setup environnement macros if is necessary. environment env; @@ -100,11 +107,15 @@ uint64_t raw::run(std::string const& processed_cmd, try { // Start process. p->exec(processed_cmd.c_str(), env.data(), timeout); - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "raw::run: start process success: id=" << command_id; + log_v2::commands()->trace("raw::run: start process success: id={}", + command_id); } catch (...) { - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "raw::run: start process failed: id=" << command_id; + log_v2::commands()->trace("raw::run: start process failed: id={}", + command_id); std::lock_guard lock(_lock); _processes_busy.erase(p); @@ -126,15 +137,19 @@ void raw::run(std::string const& processed_cmd, nagios_macros& macros, uint32_t timeout, result& res) { - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "raw::run: cmd='" << processed_cmd << "', timeout=" << timeout; + log_v2::commands()->trace("raw::run: cmd='{}', timeout={}", processed_cmd, + timeout); // Get process. process p; uint64_t command_id(get_uniq_id()); - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "raw::run: id=" << command_id << ", process=" << &p; + log_v2::commands()->trace("raw::run: id={}, process={}", command_id, + (void*)&p); // Setup environement macros if is necessary. environment env; @@ -143,11 +158,15 @@ void raw::run(std::string const& processed_cmd, // Start process. try { p.exec(processed_cmd.c_str(), env.data(), timeout); - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "raw::run: start process success: id=" << command_id; + log_v2::commands()->trace("raw::run: start process success: id={}", + command_id); } catch (...) { - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "raw::run: start process failed: id=" << command_id; + log_v2::commands()->trace("raw::run: start process failed: id={}", + command_id); throw; } @@ -171,24 +190,34 @@ void raw::run(std::string const& processed_cmd, res.exit_code > 3) res.exit_code = service::state_unknown; - logger(dbg_commands, basic) << "raw::run: end process: " - "id=" - << command_id - << ", " - "start_time=" - << res.start_time.to_mseconds() - << ", " - "end_time=" - << res.end_time.to_mseconds() - << ", " - "exit_code=" - << res.exit_code - << ", " - "exit_status=" - << res.exit_status - << ", " - "output='" - << res.output << "'"; + engine_logger(dbg_commands, basic) << "raw::run: end process: " + "id=" + << command_id + << ", " + "start_time=" + << res.start_time.to_mseconds() + << ", " + "end_time=" + << res.end_time.to_mseconds() + << ", " + "exit_code=" + << res.exit_code + << ", " + "exit_status=" + << res.exit_status + << ", " + "output='" + << res.output << "'"; + log_v2::commands()->trace( + "raw::run: end process: " + "id={}, " + "start_time={}, " + "end_time={}, " + "exit_code={}, " + "exit_status={}, " + "output='{}'", + command_id, res.start_time.to_mseconds(), res.end_time.to_mseconds(), + res.exit_code, res.exit_status, res.output); } /************************************** @@ -223,7 +252,8 @@ void raw::data_is_available_err(process& p) noexcept { */ void raw::finished(process& p) noexcept { try { - logger(dbg_commands, basic) << "raw::finished: process=" << &p; + engine_logger(dbg_commands, basic) << "raw::finished: process=" << &p; + log_v2::commands()->trace("raw::finished: process={}", (void*)&p); uint64_t command_id(0); { @@ -236,9 +266,12 @@ void raw::finished(process& p) noexcept { _processes_free.push_back(&p); lock.unlock(); - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Invalid process pointer: " "process not found into process busy list"; + log_v2::runtime()->warn( + "Warning: Invalid process pointer: " + "process not found into process busy list"); return; } // Get command_id and remove the process from the busy list. @@ -246,7 +279,8 @@ void raw::finished(process& p) noexcept { _processes_busy.erase(it); } - logger(dbg_commands, basic) << "raw::finished: id=" << command_id; + engine_logger(dbg_commands, basic) << "raw::finished: id=" << command_id; + log_v2::commands()->trace("raw::finished: id={}", command_id); // Build check result. result res; @@ -274,20 +308,27 @@ void raw::finished(process& p) noexcept { (res.exit_code > 3)) res.exit_code = service::state_unknown; - logger(dbg_commands, basic) + engine_logger(dbg_commands, basic) << "raw::finished: id=" << command_id << ", start_time=" << res.start_time.to_mseconds() << ", end_time=" << res.end_time.to_mseconds() << ", exit_code=" << res.exit_code << ", exit_status=" << res.exit_status << ", output='" << res.output << "'"; + log_v2::commands()->trace( + "raw::finished: id={}, start_time={}, end_time={}, exit_code={}, " + "exit_status={}, output='{}'", + command_id, res.start_time.to_mseconds(), res.end_time.to_mseconds(), + res.exit_code, res.exit_status, res.output); // Forward result to the listener. if (_listener) _listener->finished(res); } catch (std::exception const& e) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Raw process termination routine failed: " << e.what(); + log_v2::runtime()->warn( + "Warning: Raw process termination routine failed: {}", e.what()); // Release process, put into the free list. std::lock_guard lock(_lock); diff --git a/centreon-engine/src/compatibility/logging.cc b/centreon-engine/src/compatibility/logging.cc index 901df7b870f..98a88f862d8 100644 --- a/centreon-engine/src/compatibility/logging.cc +++ b/centreon-engine/src/compatibility/logging.cc @@ -26,6 +26,7 @@ #include "com/centreon/engine/common.hh" #include "com/centreon/engine/globals.hh" #include "com/centreon/engine/host.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/service.hh" #include "com/centreon/engine/statusdata.hh" @@ -50,10 +51,13 @@ void log_host_state(unsigned int type, com::centreon::engine::host* hst) { (unsigned int)hst->get_current_state() < host::tab_host_states.size()) state = host::tab_host_states[hst->get_current_state()].second.c_str(); std::string const& state_type{host::tab_state_type[hst->get_state_type()]}; - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << type_str << " HOST STATE: " << hst->get_name() << ";" << state << ";" << state_type << ";" << hst->get_current_attempt() << ";" << hst->get_plugin_output(); + log_v2::events()->info("{} HOST STATE: {};{};{};{};{}", type_str, + hst->get_name(), state, state_type, + hst->get_current_attempt(), hst->get_plugin_output()); } /** @@ -71,8 +75,11 @@ void log_service_state(unsigned int type, com::centreon::engine::service* svc) { service::tab_service_states[svc->get_current_state()].second.c_str(); std::string const& state_type(service::tab_state_type[svc->get_state_type()]); std::string const& output{svc->get_plugin_output()}; - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << type_str << " SERVICE STATE: " << svc->get_hostname() << ";" << svc->get_description() << ";" << state << ";" << state_type << ";" << svc->get_current_attempt() << ";" << output; + log_v2::events()->info("{} SERVICE STATE: {};{};{};{};{};{}", type_str, + svc->get_hostname(), svc->get_description(), state, + state_type, svc->get_current_attempt(), output); } diff --git a/centreon-engine/src/config.cc b/centreon-engine/src/config.cc index eae3af1a815..d9d0647db6b 100644 --- a/centreon-engine/src/config.cc +++ b/centreon-engine/src/config.cc @@ -28,6 +28,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/configuration/parser.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/string.hh" @@ -131,10 +132,14 @@ int pre_flight_circular_check(int* w, int* e) { for (host_map::iterator it(host::hosts.begin()), end(host::hosts.end()); it != end; ++it) { - if (dfs_get_status(it->second.get()) == DFS_LOOPY) - logger(log_verification_error, basic) + if (dfs_get_status(it->second.get()) == DFS_LOOPY) { + engine_logger(log_verification_error, basic) << "Error: The host '" << it->first << "' is part of a circular parent/child chain!"; + log_v2::config()->error( + "Error: The host '{}' is part of a circular parent/child chain!", + it->first); + } /* clean DFS status */ dfs_set_status(it->second.get(), DFS_UNCHECKED); } @@ -158,11 +163,15 @@ int pre_flight_circular_check(int* w, int* e) { found = it->second->check_for_circular_servicedependency_path( it->second.get(), dependency::execution); if (found) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: A circular execution dependency (which could result " "in a deadlock) exists for service '" << it->second->get_service_description() << "' on host '" << it->second->get_hostname() << "'!"; + log_v2::config()->error( + "Error: A circular execution dependency (which could result " + "in a deadlock) exists for service '{}' on host '{}'!", + it->second->get_service_description(), it->second->get_hostname()); errors++; } } @@ -182,11 +191,15 @@ int pre_flight_circular_check(int* w, int* e) { found = it->second->check_for_circular_servicedependency_path( it->second.get(), dependency::notification); if (found) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: A circular notification dependency (which could " "result in a deadlock) exists for service '" << it->second->get_service_description() << "' on host '" << it->second->get_hostname() << "'!"; + log_v2::config()->error( + "Error: A circular notification dependency (which could " + "result in a deadlock) exists for service '{}' on host '{}'!", + it->second->get_service_description(), it->second->get_hostname()); errors++; } } @@ -213,10 +226,14 @@ int pre_flight_circular_check(int* w, int* e) { found = it->second->check_for_circular_hostdependency_path( it->second.get(), dependency::execution); if (found) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: A circular execution dependency (which could " "result in a deadlock) exists for host '" << it->second->get_hostname() << "'!"; + log_v2::config()->error( + "Error: A circular execution dependency (which could " + "result in a deadlock) exists for host '{}'!", + it->second->get_hostname()); errors++; } } @@ -236,10 +253,14 @@ int pre_flight_circular_check(int* w, int* e) { found = it->second->check_for_circular_hostdependency_path( it->second.get(), dependency::notification); if (found) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: A circular notification dependency (which could " "result in a deadlock) exists for host '" << it->first << "'!"; + log_v2::config()->error( + "Error: A circular notification dependency (which could " + "result in a deadlock) exists for host '{}'!", + it->first); errors++; } } diff --git a/centreon-engine/src/configuration/anomalydetection.cc b/centreon-engine/src/configuration/anomalydetection.cc index cfddc0896d5..11c7c41ba4c 100644 --- a/centreon-engine/src/configuration/anomalydetection.cc +++ b/centreon-engine/src/configuration/anomalydetection.cc @@ -22,6 +22,7 @@ #include "com/centreon/engine/customvariable.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/host.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/string.hh" @@ -297,249 +298,411 @@ anomalydetection& anomalydetection::operator=(anomalydetection const& other) { * * @return True if is the same anomalydetection, otherwise false. */ -bool anomalydetection::operator==( - anomalydetection const& other) const noexcept { +bool anomalydetection::operator==(anomalydetection const& other) const + noexcept { if (!object::operator==(other)) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::anomalydetection::equality => object don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => object don't match"); return false; } if (_acknowledgement_timeout != other._acknowledgement_timeout) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "acknowledgement_timeout don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "acknowledgement_timeout don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "acknowledgement_timeout don't match"); return false; } if (_action_url != other._action_url) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "action_url don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => action_url don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => action_url don't match"); return false; } if (_status_change != other._status_change) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "status_change don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => status_change don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => status_change don't match"); return false; } if (_checks_active != other._checks_active) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "checks_active don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => checks_active don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => checks_active don't match"); return false; } if (_checks_passive != other._checks_passive) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "checks_passive don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => checks_passive don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => checks_passive don't match"); return false; } if (_metric_name != other._metric_name) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "metric_name don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => metric_name don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => metric_name don't match"); return false; } if (_thresholds_file != other._thresholds_file) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "thresholds_file don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => thresholds_file don't " + "match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => thresholds_file don't " + "match"); return false; } if (_check_freshness != other._check_freshness) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "check_freshness don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => check_freshness don't " + "match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => check_freshness don't " + "match"); return false; } if (_check_interval != other._check_interval) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "check_interval don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => check_interval don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => check_interval don't match"); return false; } if (_contactgroups != other._contactgroups) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "contactgroups don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => contactgroups don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => contactgroups don't match"); return false; } if (_contacts != other._contacts) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::anomalydetection::equality => contacts don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => contacts don't match"); return false; } if (std::operator!=(_customvariables, other._customvariables)) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "customvariables don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => customvariables don't " + "match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => customvariables don't " + "match"); return false; } if (_display_name != other._display_name) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "display_name don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => display_name don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => display_name don't match"); return false; } if (_event_handler != other._event_handler) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "event_handler don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => event_handler don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => event_handler don't match"); return false; } if (_event_handler_enabled != other._event_handler_enabled) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "event_handler don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => event_handler don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => event_handler don't match"); return false; } if (_first_notification_delay != other._first_notification_delay) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "first_notification_delay don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "first_notification_delay don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "first_notification_delay don't match"); return false; } if (_flap_detection_enabled != other._flap_detection_enabled) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "flap_detection_enabled don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "flap_detection_enabled don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "flap_detection_enabled don't match"); return false; } if (_flap_detection_options != other._flap_detection_options) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "flap_detection_options don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "flap_detection_options don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "flap_detection_options don't match"); return false; } if (_freshness_threshold != other._freshness_threshold) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "freshness_threshold don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "freshness_threshold don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "freshness_threshold don't match"); return false; } if (_high_flap_threshold != other._high_flap_threshold) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "high_flap_threshold don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "high_flap_threshold don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "high_flap_threshold don't match"); return false; } if (_host_name != other._host_name) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "_host_name don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => _host_name don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => _host_name don't match"); return false; } if (_icon_image != other._icon_image) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "icon_image don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => icon_image don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => icon_image don't match"); return false; } if (_icon_image_alt != other._icon_image_alt) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "icon_image_alt don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => icon_image_alt don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => icon_image_alt don't match"); return false; } if (_initial_state != other._initial_state) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "initial_state don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => initial_state don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => initial_state don't match"); return false; } if (_is_volatile != other._is_volatile) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "is_volatile don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => is_volatile don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => is_volatile don't match"); return false; } if (_low_flap_threshold != other._low_flap_threshold) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "low_flap_threshold don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => low_flap_threshold " + "don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => low_flap_threshold " + "don't match"); return false; } if (_max_check_attempts != other._max_check_attempts) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "max_check_attempts don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => max_check_attempts " + "don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => max_check_attempts " + "don't match"); return false; } if (_notes != other._notes) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::anomalydetection::equality => notes don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => notes don't match"); return false; } if (_notes_url != other._notes_url) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::anomalydetection::equality => notes_url don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => notes_url don't match"); return false; } if (_notifications_enabled != other._notifications_enabled) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "notifications_enabled don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "notifications_enabled don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "notifications_enabled don't match"); return false; } if (_notification_interval != other._notification_interval) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "notification_interval don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "notification_interval don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "notification_interval don't match"); return false; } if (_notification_options != other._notification_options) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "notification_options don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "notification_options don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "notification_options don't match"); return false; } if (_notification_period != other._notification_period) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "notification_period don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "notification_period don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "notification_period don't match"); return false; } if (_obsess_over_service != other._obsess_over_service) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "obsess_over_service don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "obsess_over_service don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "obsess_over_service don't match"); return false; } if (_process_perf_data != other._process_perf_data) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "process_perf_data don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => process_perf_data " + "don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => process_perf_data " + "don't match"); return false; } if (_retain_nonstatus_information != other._retain_nonstatus_information) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "retain_nonstatus_information don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "retain_nonstatus_information don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "retain_nonstatus_information don't match"); return false; } if (_retain_status_information != other._retain_status_information) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "retain_status_information don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "retain_status_information don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "retain_status_information don't match"); return false; } if (_retry_interval != other._retry_interval) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "retry_interval don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => retry_interval don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => retry_interval don't match"); return false; } if (_recovery_notification_delay != other._recovery_notification_delay) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "recovery_notification_delay don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "recovery_notification_delay don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "recovery_notification_delay don't match"); return false; } if (_servicegroups != other._servicegroups) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "servicegroups don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => servicegroups don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => servicegroups don't match"); return false; } if (_service_description != other._service_description) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "service_description don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => " + "service_description don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => " + "service_description don't match"); return false; } if (_host_id != other._host_id) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::anomalydetection::equality => host_id don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => host_id don't match"); return false; } if (_host_id != other._host_id) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::anomalydetection::equality => host_id don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => host_id don't match"); return false; } if (_service_id != other._service_id) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "service_id don't match"; + engine_logger(dbg_config, more) << "configuration::anomalydetection::" + "equality => service_id don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::" + "equality => service_id don't match"); return false; } if (_dependent_service_id != other._dependent_service_id) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "dependent_service_id don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => dependent_service_id " + "don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => dependent_service_id " + "don't match"); return false; } if (_stalking_options != other._stalking_options) { - logger(dbg_config, more) << "configuration::anomalydetection::equality => " - "stalking_options don't match"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => stalking_options " + "don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => stalking_options " + "don't match"); return false; } if (_timezone != other._timezone) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::anomalydetection::equality => timezone don't match"; + log_v2::config()->debug( + "configuration::anomalydetection::equality => timezone don't match"); return false; } - logger(dbg_config, more) << "configuration::anomalydetection::equality => OK"; + engine_logger(dbg_config, more) + << "configuration::anomalydetection::equality => OK"; + log_v2::config()->debug("configuration::anomalydetection::equality => OK"); return true; } @@ -550,8 +713,8 @@ bool anomalydetection::operator==( * * @return True if is not the same anomalydetection, otherwise false. */ -bool anomalydetection::operator!=( - anomalydetection const& other) const noexcept { +bool anomalydetection::operator!=(anomalydetection const& other) const + noexcept { return !operator==(other); } @@ -1514,9 +1677,12 @@ bool anomalydetection::_set_event_handler_enabled(bool value) { */ bool anomalydetection::_set_failure_prediction_enabled(bool value) { (void)value; - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: anomalydetection failure_prediction_enabled is deprecated." << " This option will not be supported in 20.04."; + log_v2::config()->warn( + "Warning: anomalydetection failure_prediction_enabled is deprecated. " + "This option will not be supported in 20.04."); ++config_warnings; return true; } @@ -1531,9 +1697,12 @@ bool anomalydetection::_set_failure_prediction_enabled(bool value) { bool anomalydetection::_set_failure_prediction_options( std::string const& value) { (void)value; - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: anomalydetection failure_prediction_options is deprecated." << " This option will not be supported in 20.04."; + log_v2::config()->warn( + "Warning: anomalydetection failure_prediction_options is deprecated. " + "This option will not be supported in 20.04."); ++config_warnings; return true; } @@ -1834,9 +2003,12 @@ bool anomalydetection::_set_obsess_over_service(bool value) { */ bool anomalydetection::_set_parallelize_check(bool value) { (void)value; - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: anomalydetection parallelize_check is deprecated" << " This option will not be supported in 20.04."; + log_v2::config()->warn( + "Warning: anomalydetection parallelize_check is deprecated This option " + "will not be supported in 20.04."); ++config_warnings; return true; } diff --git a/centreon-engine/src/configuration/applier/anomalydetection.cc b/centreon-engine/src/configuration/applier/anomalydetection.cc index 71be60aa660..d7d2ae45517 100644 --- a/centreon-engine/src/configuration/applier/anomalydetection.cc +++ b/centreon-engine/src/configuration/applier/anomalydetection.cc @@ -27,6 +27,7 @@ #include "com/centreon/engine/downtimes/downtime_manager.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" using namespace com::centreon; using namespace com::centreon::engine; @@ -98,9 +99,11 @@ void applier::anomalydetection::add_object( << obj.service_description() << "'"; // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new anomalydetection '" << obj.service_description() << "' of host '" << obj.host_name() << "'."; + log_v2::config()->debug("Creating new anomalydetection '{}' of host '{}'.", + obj.service_description(), obj.host_name()); // Add anomalydetection to the global configuration set. config->anomalydetections().insert(obj); @@ -234,9 +237,11 @@ void applier::anomalydetection::modify_object( std::string const& service_description(obj.service_description()); // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Modifying new anomalydetection '" << service_description << "' of host '" << host_name << "'."; + log_v2::config()->debug("Modifying new anomalydetection '{}' of host '{}'.", + service_description, host_name); // Find the configuration object. set_anomalydetection::iterator it_cfg( @@ -441,9 +446,11 @@ void applier::anomalydetection::remove_object( assert(obj.key().first); // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Removing anomalydetection '" << service_description << "' of host '" << host_name << "'."; + log_v2::config()->debug("Removing anomalydetection '{}' of host '{}'.", + service_description, host_name); // Find anomalydetection. service_id_map::iterator it(engine::service::services_by_id.find(obj.key())); @@ -490,9 +497,11 @@ void applier::anomalydetection::remove_object( void applier::anomalydetection::resolve_object( configuration::anomalydetection const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Resolving anomalydetection '" << obj.service_description() << "' of host '" << obj.host_name() << "'."; + log_v2::config()->debug("Resolving anomalydetection '{}' of host '{}'.", + obj.service_description(), obj.host_name()); // Find anomalydetection. service_id_map::iterator it( diff --git a/centreon-engine/src/configuration/applier/command.cc b/centreon-engine/src/configuration/applier/command.cc index faf26f9b4b0..3726f23ea54 100644 --- a/centreon-engine/src/configuration/applier/command.cc +++ b/centreon-engine/src/configuration/applier/command.cc @@ -27,6 +27,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" using namespace com::centreon::engine; @@ -49,8 +50,9 @@ applier::command::~command() throw() {} */ void applier::command::add_object(configuration::command const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new command '" << obj.command_name() << "'."; + log_v2::config()->debug("Creating new command '{}'.", obj.command_name()); // Add command to the global configuration set. config->commands().insert(obj); @@ -94,8 +96,9 @@ void applier::command::expand_objects(configuration::state& s) { */ void applier::command::modify_object(configuration::command const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Modifying command '" << obj.command_name() << "'."; + log_v2::config()->debug("Modifying command '{}'.", obj.command_name()); // Find old configuration. set_command::iterator it_cfg(config->commands_find(obj.key())); @@ -154,8 +157,9 @@ void applier::command::modify_object(configuration::command const& obj) { */ void applier::command::remove_object(configuration::command const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Removing command '" << obj.command_name() << "'."; + log_v2::config()->debug("Removing command '{}'.", obj.command_name()); // Find command. std::unordered_map >::iterator diff --git a/centreon-engine/src/configuration/applier/connector.cc b/centreon-engine/src/configuration/applier/connector.cc index 81479c38a32..3a2b22e3c26 100644 --- a/centreon-engine/src/configuration/applier/connector.cc +++ b/centreon-engine/src/configuration/applier/connector.cc @@ -23,6 +23,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/macros/misc.hh" #include "com/centreon/engine/macros/process.hh" @@ -45,8 +46,9 @@ applier::connector::~connector() noexcept {} */ void applier::connector::add_object(configuration::connector const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new connector '" << obj.connector_name() << "'."; + log_v2::config()->debug("Creating new connector '{}'.", obj.connector_name()); // Expand command line. nagios_macros* macros(get_global_macros()); @@ -82,8 +84,9 @@ void applier::connector::expand_objects(configuration::state& s) { */ void applier::connector::modify_object(configuration::connector const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Modifying connector '" << obj.connector_name() << "'."; + log_v2::config()->debug("Modifying connector '{}'.", obj.connector_name()); // Find old configuration. set_connector::iterator it_cfg(config->connectors_find(obj.key())); @@ -122,8 +125,9 @@ void applier::connector::modify_object(configuration::connector const& obj) { */ void applier::connector::remove_object(configuration::connector const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Removing connector '" << obj.connector_name() << "'."; + log_v2::config()->debug("Removing connector '{}'.", obj.connector_name()); // Find connector. connector_map::iterator it(commands::connector::connectors.find(obj.key())); diff --git a/centreon-engine/src/configuration/applier/contact.cc b/centreon-engine/src/configuration/applier/contact.cc index 34420dbeb80..7024fad4cc8 100644 --- a/centreon-engine/src/configuration/applier/contact.cc +++ b/centreon-engine/src/configuration/applier/contact.cc @@ -25,6 +25,7 @@ #include "com/centreon/engine/deleter/listmember.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" using namespace com::centreon; using namespace com::centreon::engine; @@ -77,8 +78,9 @@ applier::contact::~contact() throw() {} */ void applier::contact::add_object(configuration::contact const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new contact '" << obj.contact_name() << "'."; + log_v2::config()->debug("Creating new contact '{}'.", obj.contact_name()); // Add contact to the global configuration set. config->contacts().insert(obj); @@ -191,8 +193,9 @@ void applier::contact::expand_objects(configuration::state& s) { */ void applier::contact::modify_object(configuration::contact const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Modifying contact '" << obj.contact_name() << "'."; + log_v2::config()->debug("Modifying contact '{}'.", obj.contact_name()); // Find old configuration. set_contact::iterator it_cfg(config->contacts_find(obj.key())); @@ -352,8 +355,9 @@ void applier::contact::modify_object(configuration::contact const& obj) { */ void applier::contact::remove_object(configuration::contact const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Removing contact '" << obj.contact_name() << "'."; + log_v2::config()->debug("Removing contact '{}'.", obj.contact_name()); // Find contact. contact_map::iterator it{engine::contact::contacts.find(obj.key())}; @@ -385,8 +389,9 @@ void applier::contact::remove_object(configuration::contact const& obj) { */ void applier::contact::resolve_object(configuration::contact const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Resolving contact '" << obj.contact_name() << "'."; + log_v2::config()->debug("Resolving contact '{}'.", obj.contact_name()); // Find contact. contact_map::const_iterator ct_it{ diff --git a/centreon-engine/src/configuration/applier/contactgroup.cc b/centreon-engine/src/configuration/applier/contactgroup.cc index 7e733949cbe..dc7d3021e43 100644 --- a/centreon-engine/src/configuration/applier/contactgroup.cc +++ b/centreon-engine/src/configuration/applier/contactgroup.cc @@ -24,6 +24,7 @@ #include "com/centreon/engine/deleter/listmember.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" using namespace com::centreon::engine::configuration; @@ -70,8 +71,9 @@ void applier::contactgroup::add_object(configuration::contactgroup const& obj) { std::string const& name(obj.contactgroup_name()); // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new contactgroup '" << name << "'."; + log_v2::config()->debug("Creating new contactgroup '{}'.", name); if (engine::contactgroup::contactgroups.find(name) != engine::contactgroup::contactgroups.end()) @@ -89,9 +91,13 @@ void applier::contactgroup::add_object(configuration::contactgroup const& obj) { it != end; ++it) { contact_map::iterator ct_it{engine::contact::contacts.find(*it)}; if (ct_it == engine::contact::contacts.end()) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Contact '" << *it << "' specified in contact group '" << cg->get_name() << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Contact '{}' specified in contact group '{}' is not defined " + "anywhere!", + *it, cg->get_name()); throw engine_error() << "Error: Cannot resolve contact group " << obj.contactgroup_name() << "'"; } else { @@ -134,8 +140,10 @@ void applier::contactgroup::expand_objects(configuration::state& s) { void applier::contactgroup::modify_object( configuration::contactgroup const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Modifying contactgroup '" << obj.contactgroup_name() << "'"; + log_v2::config()->debug("Modifying contactgroup '{}'", + obj.contactgroup_name()); // Find old configuration. set_contactgroup::iterator it_cfg(config->contactgroups_find(obj.key())); @@ -170,9 +178,13 @@ void applier::contactgroup::modify_object( it != end; ++it) { contact_map::const_iterator ct_it{engine::contact::contacts.find(*it)}; if (ct_it == engine::contact::contacts.end()) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Contact '" << *it << "' specified in contact group '" << it_obj->second->get_name() << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Contact '{}' specified in contact group '{}' is not " + "defined anywhere!", + *it, it_obj->second->get_name()); throw engine_error() << "Error: Cannot resolve contact group " << obj.contactgroup_name() << "'"; } else { @@ -200,8 +212,10 @@ void applier::contactgroup::modify_object( void applier::contactgroup::remove_object( configuration::contactgroup const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Removing contactgroup '" << obj.contactgroup_name() << "'"; + log_v2::config()->debug("Removing contactgroup '{}'", + obj.contactgroup_name()); // Find contact group. contactgroup_map::iterator it( @@ -231,8 +245,10 @@ void applier::contactgroup::remove_object( void applier::contactgroup::resolve_object( configuration::contactgroup const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Resolving contact group '" << obj.contactgroup_name() << "'"; + log_v2::config()->debug("Resolving contact group '{}'", + obj.contactgroup_name()); // Find contact group. contactgroup_map::iterator it{ @@ -257,9 +273,11 @@ void applier::contactgroup::_resolve_members( // Only process if contactgroup has not been resolved already. if (_resolved.find(obj.key()) == _resolved.end()) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Resolving members of contact group '" << obj.contactgroup_name() << "'"; + log_v2::config()->debug("Resolving members of contact group '{}'", + obj.contactgroup_name()); // Mark object as resolved. configuration::contactgroup& resolved_obj(_resolved[obj.key()]); diff --git a/centreon-engine/src/configuration/applier/host.cc b/centreon-engine/src/configuration/applier/host.cc index 80b31e43747..38d4f22d25d 100644 --- a/centreon-engine/src/configuration/applier/host.cc +++ b/centreon-engine/src/configuration/applier/host.cc @@ -29,6 +29,7 @@ #include "com/centreon/engine/downtimes/downtime_manager.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" using namespace com::centreon; using namespace com::centreon::engine; @@ -51,8 +52,9 @@ applier::host::~host() throw() {} */ void applier::host::add_object(configuration::host const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new host '" << obj.host_name() << "'."; + log_v2::config()->debug("Creating new host '{}'.", obj.host_name()); // Add host to the global configuration set. config->hosts().insert(obj); @@ -198,8 +200,9 @@ void applier::host::expand_objects(configuration::state& s) { */ void applier::host::modify_object(configuration::host const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Modifying host '" << obj.host_name() << "'."; + log_v2::config()->debug("Modifying host '{}'.", obj.host_name()); // Find the configuration object. set_host::iterator it_cfg(config->hosts_find(obj.key())); @@ -409,8 +412,9 @@ void applier::host::modify_object(configuration::host const& obj) { */ void applier::host::remove_object(configuration::host const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Removing host '" << obj.host_name() << "'."; + log_v2::config()->debug("Removing host '{}'.", obj.host_name()); // Find host. host_id_map::iterator it(engine::host::hosts_by_id.find(obj.key())); @@ -459,8 +463,9 @@ void applier::host::remove_object(configuration::host const& obj) { */ void applier::host::resolve_object(configuration::host const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Resolving host '" << obj.host_name() << "'."; + log_v2::config()->debug("Resolving host '{}'.", obj.host_name()); // If it is the very first host to be resolved, // remove all the child backlinks of all the hosts. diff --git a/centreon-engine/src/configuration/applier/hostdependency.cc b/centreon-engine/src/configuration/applier/hostdependency.cc index 1d012adb3af..ca3c1d281ea 100644 --- a/centreon-engine/src/configuration/applier/hostdependency.cc +++ b/centreon-engine/src/configuration/applier/hostdependency.cc @@ -23,6 +23,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" using namespace com::centreon::engine::configuration; @@ -60,10 +61,13 @@ void applier::hostdependency::add_object( << *obj.hosts().begin() << "'"; // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new host dependency of host '" << *obj.dependent_hosts().begin() << "' on host '" << *obj.hosts().begin() << "'."; + log_v2::config()->debug( + "Creating new host dependency of host '{}' on host '{}'.", + *obj.dependent_hosts().begin(), *obj.hosts().begin()); // Add dependency to the global configuration set. config->hostdependencies().insert(obj); @@ -201,7 +205,9 @@ void applier::hostdependency::modify_object( void applier::hostdependency::remove_object( configuration::hostdependency const& obj) { // Logging. - logger(logging::dbg_config, logging::more) << "Removing a host dependency."; + engine_logger(logging::dbg_config, logging::more) + << "Removing a host dependency."; + log_v2::config()->debug("Removing a host dependency."); // Find host dependency. hostdependency_mmap::iterator it( @@ -230,7 +236,9 @@ void applier::hostdependency::remove_object( void applier::hostdependency::resolve_object( configuration::hostdependency const& obj) { // Logging. - logger(logging::dbg_config, logging::more) << "Resolving a host dependency."; + engine_logger(logging::dbg_config, logging::more) + << "Resolving a host dependency."; + log_v2::config()->debug("Resolving a host dependency."); // Find host escalation hostdependency_mmap::iterator it{ diff --git a/centreon-engine/src/configuration/applier/hostescalation.cc b/centreon-engine/src/configuration/applier/hostescalation.cc index f253cf51ada..564b692541f 100644 --- a/centreon-engine/src/configuration/applier/hostescalation.cc +++ b/centreon-engine/src/configuration/applier/hostescalation.cc @@ -23,6 +23,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" using namespace com::centreon::engine::configuration; @@ -50,8 +51,10 @@ void applier::hostescalation::add_object( << "Could not create host escalation with multiple hosts / host groups"; // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new escalation for host '" << *obj.hosts().begin() << "'."; + log_v2::config()->debug("Creating new escalation for host '{}'.", + *obj.hosts().begin()); // Add escalation to the global configuration set. config->hostescalations().insert(obj); @@ -149,7 +152,9 @@ void applier::hostescalation::modify_object( void applier::hostescalation::remove_object( configuration::hostescalation const& obj) { // Logging. - logger(logging::dbg_config, logging::more) << "Removing a host escalation."; + engine_logger(logging::dbg_config, logging::more) + << "Removing a host escalation."; + log_v2::config()->debug("Removing a host escalation."); // Find host escalation. std::string const& host_name{*obj.hosts().begin()}; @@ -161,8 +166,10 @@ void applier::hostescalation::remove_object( host_map::iterator hit{engine::host::hosts.find(host_name)}; /* ... and its escalations */ if (hit == engine::host::hosts.end()) { - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Cannot find host '" << host_name << "' - already removed."; + log_v2::config()->debug("Cannot find host '{}' - already removed.", + host_name); host_exists = false; } else host_exists = true; @@ -194,9 +201,11 @@ void applier::hostescalation::remove_object( it->second.get(), &tv); if (host_exists) { - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Host '" << host_name << "' found - removing escalation from it."; + log_v2::config()->debug( + "Host '{}' found - removing escalation from it.", host_name); std::list& escalations(hit->second->get_escalations()); /* We need also to remove the escalation from the host */ for (std::list::iterator heit{escalations.begin()}, @@ -226,7 +235,9 @@ void applier::hostescalation::remove_object( void applier::hostescalation::resolve_object( configuration::hostescalation const& obj) { // Logging. - logger(logging::dbg_config, logging::more) << "Resolving a host escalation."; + engine_logger(logging::dbg_config, logging::more) + << "Resolving a host escalation."; + log_v2::config()->debug("Resolving a host escalation."); // Find host escalation bool found{false}; diff --git a/centreon-engine/src/configuration/applier/hostgroup.cc b/centreon-engine/src/configuration/applier/hostgroup.cc index 88dcd8cd1d1..568f0143f12 100644 --- a/centreon-engine/src/configuration/applier/hostgroup.cc +++ b/centreon-engine/src/configuration/applier/hostgroup.cc @@ -25,6 +25,7 @@ #include "com/centreon/engine/deleter/listmember.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" using namespace com::centreon::engine::configuration; @@ -55,8 +56,9 @@ applier::hostgroup::~hostgroup() throw() {} */ void applier::hostgroup::add_object(configuration::hostgroup const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new hostgroup '" << obj.hostgroup_name() << "'."; + log_v2::config()->debug("Creating new hostgroup '{}'.", obj.hostgroup_name()); // Add host group to the global configuration state. config->hostgroups().insert(obj); @@ -109,8 +111,9 @@ void applier::hostgroup::expand_objects(configuration::state& s) { */ void applier::hostgroup::modify_object(configuration::hostgroup const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Modifying hostgroup '" << obj.hostgroup_name() << "'"; + log_v2::config()->debug("Modifying hostgroup '{}'", obj.hostgroup_name()); // Find old configuration. set_hostgroup::iterator it_cfg(config->hostgroups_find(obj.key())); @@ -168,8 +171,9 @@ void applier::hostgroup::modify_object(configuration::hostgroup const& obj) { */ void applier::hostgroup::remove_object(configuration::hostgroup const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Removing host group '" << obj.hostgroup_name() << "'"; + log_v2::config()->debug("Removing host group '{}'", obj.hostgroup_name()); // Find host group. hostgroup_map::iterator it{engine::hostgroup::hostgroups.find(obj.key())}; @@ -196,8 +200,9 @@ void applier::hostgroup::remove_object(configuration::hostgroup const& obj) { */ void applier::hostgroup::resolve_object(configuration::hostgroup const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Resolving host group '" << obj.hostgroup_name() << "'"; + log_v2::config()->debug("Resolving host group '{}'", obj.hostgroup_name()); // Find host group. hostgroup_map::iterator it{engine::hostgroup::hostgroups.find(obj.key())}; @@ -221,8 +226,10 @@ void applier::hostgroup::_resolve_members(configuration::state& s // Only process if hostgroup has not been resolved already. if (_resolved.find(obj.key()) == _resolved.end()) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Resolving members of host group '" << obj.hostgroup_name() << "'"; + log_v2::config()->debug("Resolving members of host group '{}'", + obj.hostgroup_name()); // Mark object as resolved. configuration::hostgroup& resolved_obj(_resolved[obj.key()]); diff --git a/centreon-engine/src/configuration/applier/logging.cc b/centreon-engine/src/configuration/applier/logging.cc index 3475332bb8c..5d61ac633a6 100644 --- a/centreon-engine/src/configuration/applier/logging.cc +++ b/centreon-engine/src/configuration/applier/logging.cc @@ -37,33 +37,40 @@ void applier::logging::apply(state& config) { if (verify_config || test_scheduling) return; - // Syslog. - if (config.use_syslog() && !_syslog) - _add_syslog(); - else if (!config.use_syslog() && _syslog) - _del_syslog(); + if (config.log_legacy_enabled()) { + // Syslog. + if (config.use_syslog() && !_syslog) + _add_syslog(); + else if (!config.use_syslog() && _syslog) + _del_syslog(); - // Standard log file. - if (config.log_file() == "") - _del_log_file(); - else if (!_log || config.log_file() != _log->filename()) { - _add_log_file(config); + // Standard log file. + + if (config.log_file() == "") + _del_log_file(); + else if (!_log || config.log_file() != _log->filename()) { + _add_log_file(config); + _del_stdout(); + _del_stderr(); + } + + // Debug file. + if ((config.debug_file() == "") || !config.debug_level() || + !config.debug_verbosity()) { + _del_debug(); + _debug_level = config.debug_level(); + _debug_verbosity = config.debug_verbosity(); + _debug_max_size = config.max_debug_file_size(); + } else if (!_debug || config.debug_file() != _debug->filename() || + config.debug_level() != _debug_level || + config.debug_verbosity() != _debug_verbosity || + config.max_debug_file_size() != _debug_max_size) + _add_debug(config); + } else { _del_stdout(); _del_stderr(); - } - - // Debug file. - if ((config.debug_file() == "") || !config.debug_level() || - !config.debug_verbosity()) { _del_debug(); - _debug_level = config.debug_level(); - _debug_verbosity = config.debug_verbosity(); - _debug_max_size = config.max_debug_file_size(); - } else if (!_debug || config.debug_file() != _debug->filename() || - config.debug_level() != _debug_level || - config.debug_verbosity() != _debug_verbosity || - config.max_debug_file_size() != _debug_max_size) - _add_debug(config); + } } /** diff --git a/centreon-engine/src/configuration/applier/scheduler.cc b/centreon-engine/src/configuration/applier/scheduler.cc index 8ace54e2799..0d426a09900 100644 --- a/centreon-engine/src/configuration/applier/scheduler.cc +++ b/centreon-engine/src/configuration/applier/scheduler.cc @@ -26,6 +26,7 @@ #include "com/centreon/engine/deleter/listmember.hh" #include "com/centreon/engine/events/loop.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/statusdata.hh" #include "com/centreon/engine/timezone_locker.hh" @@ -515,16 +516,25 @@ void applier::scheduler::_calculate_host_inter_check_delay( } else scheduling_info.host_inter_check_delay = 0.0; - logger(dbg_events, most) << "Total scheduled host checks: " - << scheduling_info.total_scheduled_hosts; - logger(dbg_events, most) << "Host check interval total: " - << scheduling_info.host_check_interval_total; - logger(dbg_events, most) + engine_logger(dbg_events, most) << "Total scheduled host checks: " + << scheduling_info.total_scheduled_hosts; + log_v2::events()->debug("Total scheduled host checks: {}", + scheduling_info.total_scheduled_hosts); + engine_logger(dbg_events, most) + << "Host check interval total: " + << scheduling_info.host_check_interval_total; + log_v2::events()->debug("Host check interval total: {}", + scheduling_info.host_check_interval_total); + engine_logger(dbg_events, most) << setprecision(2) << "Average host check interval: " << scheduling_info.average_host_check_interval << " sec"; - logger(dbg_events, most) + log_v2::events()->debug("Average host check interval: {:.2f} sec", + scheduling_info.average_host_check_interval); + engine_logger(dbg_events, most) << setprecision(2) << "Host inter-check delay: " << scheduling_info.host_inter_check_delay << " sec"; + log_v2::events()->debug("Host inter-check delay: {:.2f} sec", + scheduling_info.host_inter_check_delay); } } @@ -532,7 +542,9 @@ void applier::scheduler::_calculate_host_inter_check_delay( * Calculate host scheduling params. */ void applier::scheduler::_calculate_host_scheduling_params() { - logger(dbg_events, most) << "Determining host scheduling parameters..."; + engine_logger(dbg_events, most) + << "Determining host scheduling parameters..."; + log_v2::events()->debug("Determining host scheduling parameters..."); // get current time. time_t const now(time(NULL)); @@ -563,8 +575,10 @@ void applier::scheduler::_calculate_host_scheduling_params() { static_cast(hst.get_check_interval()); } else { hst.set_should_be_scheduled(false); - logger(dbg_events, more) + engine_logger(dbg_events, more) << "Host " << hst.get_name() << " should not be scheduled."; + log_v2::events()->debug("Host {} should not be scheduled.", + hst.get_name()); } ++scheduling_info.total_hosts; @@ -628,14 +642,21 @@ void applier::scheduler::_calculate_service_inter_check_delay( } else scheduling_info.service_inter_check_delay = 0.0; - logger(dbg_events, more) << "Total scheduled service checks: " - << scheduling_info.total_scheduled_services; - logger(dbg_events, more) + engine_logger(dbg_events, more) + << "Total scheduled service checks: " + << scheduling_info.total_scheduled_services; + log_v2::events()->debug("Total scheduled service checks: {}", + scheduling_info.total_scheduled_services); + engine_logger(dbg_events, more) << setprecision(2) << "Average service check interval: " << scheduling_info.average_service_check_interval << " sec"; - logger(dbg_events, more) + log_v2::events()->debug("Average service check interval: {:.2f} sec", + scheduling_info.average_service_check_interval); + engine_logger(dbg_events, more) << setprecision(2) << "Service inter-check delay: " << scheduling_info.service_inter_check_delay << " sec"; + log_v2::events()->debug("Service inter-check delay: {:.2f} sec", + scheduling_info.service_inter_check_delay); } } @@ -656,12 +677,20 @@ void applier::scheduler::_calculate_service_interleave_factor( scheduling_info.service_interleave_factor = (int)(ceil(scheduling_info.average_scheduled_services_per_host)); - logger(dbg_events, more) << "Total scheduled service checks: " - << scheduling_info.total_scheduled_services; - logger(dbg_events, more) + engine_logger(dbg_events, more) + << "Total scheduled service checks: " + << scheduling_info.total_scheduled_services; + log_v2::events()->debug("Total scheduled service checks: {}", + scheduling_info.total_scheduled_services); + engine_logger(dbg_events, more) << "Total hosts: " << scheduling_info.total_hosts; - logger(dbg_events, more) << "Service Interleave factor: " - << scheduling_info.service_interleave_factor; + log_v2::events()->debug("Total hosts: {}", + scheduling_info.total_hosts); + engine_logger(dbg_events, more) + << "Service Interleave factor: " + << scheduling_info.service_interleave_factor; + log_v2::events()->debug("Service Interleave factor: {}", + scheduling_info.service_interleave_factor); } } @@ -669,7 +698,9 @@ void applier::scheduler::_calculate_service_interleave_factor( * Calculate service scheduling params. */ void applier::scheduler::_calculate_service_scheduling_params() { - logger(dbg_events, most) << "Determining service scheduling parameters..."; + engine_logger(dbg_events, most) + << "Determining service scheduling parameters..."; + log_v2::events()->debug("Determining service scheduling parameters..."); // get current time. time_t const now(time(NULL)); @@ -702,9 +733,11 @@ void applier::scheduler::_calculate_service_scheduling_params() { static_cast(svc.get_check_interval()); } else { svc.set_should_be_scheduled(false); - logger(dbg_events, more) + engine_logger(dbg_events, more) << "Service " << svc.get_description() << " on host " << svc.get_hostname() << " should not be scheduled."; + log_v2::events()->debug("Service {} on host {} should not be scheduled.", + svc.get_description(), svc.get_hostname()); } ++scheduling_info.total_services; } @@ -866,7 +899,8 @@ void applier::scheduler::_remove_misc_event(timed_event*& evt) { */ void applier::scheduler::_schedule_host_events( std::vector const& hosts) { - logger(dbg_events, most) << "Scheduling host checks..."; + engine_logger(dbg_events, most) << "Scheduling host checks..."; + log_v2::events()->debug("Scheduling host checks..."); // get current time. time_t const now(time(NULL)); @@ -878,11 +912,13 @@ void applier::scheduler::_schedule_host_events( for (unsigned int i(0); i < end; ++i) { com::centreon::engine::host& hst(*hosts[i]); - logger(dbg_events, most) << "Host '" << hst.get_name() << "'"; + engine_logger(dbg_events, most) << "Host '" << hst.get_name() << "'"; + log_v2::events()->debug("Host '{}'", hst.get_name()); // skip hosts that shouldn't be scheduled. if (!hst.get_should_be_scheduled()) { - logger(dbg_events, most) << "Host check should not be scheduled."; + engine_logger(dbg_events, most) << "Host check should not be scheduled."; + log_v2::events()->debug("Host check should not be scheduled."); continue; } @@ -891,8 +927,11 @@ void applier::scheduler::_schedule_host_events( (time_t)(now + (mult_factor * scheduling_info.host_inter_check_delay))); time_t time = hst.get_next_check(); - logger(dbg_events, most) << "Preferred Check Time: " << hst.get_next_check() - << " --> " << my_ctime(&time); + engine_logger(dbg_events, most) + << "Preferred Check Time: " << hst.get_next_check() << " --> " + << my_ctime(&time); + log_v2::events()->debug("Preferred Check Time: {} --> {}", + hst.get_next_check(), my_ctime(&time)); // Make sure the host can actually be scheduled at this time. { @@ -907,8 +946,11 @@ void applier::scheduler::_schedule_host_events( } time = hst.get_next_check(); - logger(dbg_events, most) << "Actual Check Time: " << hst.get_next_check() - << " --> " << my_ctime(&time); + engine_logger(dbg_events, most) + << "Actual Check Time: " << hst.get_next_check() << " --> " + << my_ctime(&time); + log_v2::events()->debug("Actual Check Time: {} --> {}", + hst.get_next_check(), my_ctime(&time)); if (!scheduling_info.first_host_check || (hst.get_next_check() < scheduling_info.first_host_check)) @@ -955,7 +997,9 @@ void applier::scheduler::_schedule_host_events( } // Schedule acknowledgement expirations. - logger(dbg_events, most) << "Scheduling host acknowledgement expirations..."; + engine_logger(dbg_events, most) + << "Scheduling host acknowledgement expirations..."; + log_v2::events()->debug("Scheduling host acknowledgement expirations..."); for (int i(0), end(hosts.size()); i < end; ++i) if (hosts[i]->get_problem_has_been_acknowledged()) hosts[i]->schedule_acknowledgement_expiration(); @@ -968,7 +1012,8 @@ void applier::scheduler::_schedule_host_events( */ void applier::scheduler::_schedule_service_events( std::vector const& services) { - logger(dbg_events, most) << "Scheduling service checks..."; + engine_logger(dbg_events, most) << "Scheduling service checks..."; + log_v2::events()->debug("Scheduling service checks..."); // get current time. time_t const now(time(NULL)); @@ -1061,8 +1106,9 @@ void applier::scheduler::_schedule_service_events( } // Schedule acknowledgement expirations. - logger(dbg_events, most) + engine_logger(dbg_events, most) << "Scheduling service acknowledgement expirations..."; + log_v2::events()->debug("Scheduling service acknowledgement expirations..."); for (int i(0), end(services.size()); i < end; ++i) if (services[i]->get_problem_has_been_acknowledged()) services[i]->schedule_acknowledgement_expiration(); diff --git a/centreon-engine/src/configuration/applier/service.cc b/centreon-engine/src/configuration/applier/service.cc index c1b1a13e2fd..27dc953ebe6 100644 --- a/centreon-engine/src/configuration/applier/service.cc +++ b/centreon-engine/src/configuration/applier/service.cc @@ -27,6 +27,7 @@ #include "com/centreon/engine/downtimes/downtime_manager.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" using namespace com::centreon; using namespace com::centreon::engine; @@ -107,9 +108,11 @@ void applier::service::add_object(configuration::service const& obj) { << obj.service_description() << "'"; // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new service '" << obj.service_description() << "' of host '" << *obj.hosts().begin() << "'."; + log_v2::config()->debug("Creating new service '{}' of host '{}'.", + obj.service_description(), *obj.hosts().begin()); // Add service to the global configuration set. config->services().insert(obj); @@ -288,9 +291,11 @@ void applier::service::modify_object(configuration::service const& obj) { std::string const& service_description(obj.service_description()); // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Modifying new service '" << service_description << "' of host '" << host_name << "'."; + log_v2::config()->debug("Modifying new service '{}' of host '{}'.", + service_description, host_name); // Find the configuration object. set_service::iterator it_cfg(config->services_find(obj.key())); @@ -490,9 +495,11 @@ void applier::service::remove_object(configuration::service const& obj) { assert(obj.key().first); // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Removing service '" << service_description << "' of host '" << host_name << "'."; + log_v2::config()->debug("Removing service '{}' of host '{}'.", + service_description, host_name); // Find anomaly detections depending on this service set_anomalydetection sad = config->anomalydetections(); @@ -547,9 +554,11 @@ void applier::service::remove_object(configuration::service const& obj) { */ void applier::service::resolve_object(configuration::service const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Resolving service '" << obj.service_description() << "' of host '" << *obj.hosts().begin() << "'."; + log_v2::config()->debug("Resolving service '{}' of host '{}'.", + obj.service_description(), *obj.hosts().begin()); // Find service. service_id_map::iterator it(engine::service::services_by_id.find(obj.key())); diff --git a/centreon-engine/src/configuration/applier/servicedependency.cc b/centreon-engine/src/configuration/applier/servicedependency.cc index 998d062b4a3..0ef6874caeb 100644 --- a/centreon-engine/src/configuration/applier/servicedependency.cc +++ b/centreon-engine/src/configuration/applier/servicedependency.cc @@ -25,6 +25,7 @@ #include "com/centreon/engine/configuration/servicedependency.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" using namespace com::centreon::engine::configuration; @@ -71,12 +72,18 @@ void applier::servicedependency::add_object( << obj.hosts().front() << "'"; // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new service dependency of service '" << obj.dependent_service_description().front() << "' of host '" << obj.dependent_hosts().front() << "' on service '" << obj.service_description().front() << "' of host '" << obj.hosts().front() << "'."; + log_v2::config()->debug( + "Creating new service dependency of service '{}' of host '{}' on service " + "'{}' of host '{}'.", + obj.dependent_service_description().front(), + obj.dependent_hosts().front(), obj.service_description().front(), + obj.hosts().front()); // Add dependency to the global configuration set. config->servicedependencies().insert(obj); @@ -242,8 +249,9 @@ void applier::servicedependency::modify_object( void applier::servicedependency::remove_object( configuration::servicedependency const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Removing a service dependency."; + log_v2::config()->debug("Removing a service dependency."); // Find service dependency. servicedependency_mmap::iterator it( @@ -271,8 +279,9 @@ void applier::servicedependency::remove_object( void applier::servicedependency::resolve_object( configuration::servicedependency const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Resolving a service dependency."; + log_v2::config()->debug("Resolving a service dependency."); // Find service dependency. servicedependency_mmap::iterator it( diff --git a/centreon-engine/src/configuration/applier/serviceescalation.cc b/centreon-engine/src/configuration/applier/serviceescalation.cc index ca99f075572..25b2ee61de5 100644 --- a/centreon-engine/src/configuration/applier/serviceescalation.cc +++ b/centreon-engine/src/configuration/applier/serviceescalation.cc @@ -23,6 +23,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" using namespace com::centreon::engine::configuration; @@ -51,10 +52,13 @@ void applier::serviceescalation::add_object( "hosts / host groups / services / service groups"; // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new escalation for service '" << obj.service_description().front() << "' of host '" << obj.hosts().front() << "'"; + log_v2::config()->debug( + "Creating new escalation for service '{}' of host '{}'", + obj.service_description().front(), obj.hosts().front()); // Add escalation to the global configuration set. config->serviceescalations().insert(obj); @@ -104,7 +108,9 @@ void applier::serviceescalation::add_object( */ void applier::serviceescalation::expand_objects(configuration::state& s) { // Browse all escalations. - logger(logging::dbg_config, logging::more) << "Expanding service escalations"; + engine_logger(logging::dbg_config, logging::more) + << "Expanding service escalations"; + log_v2::config()->debug("Expanding service escalations"); configuration::set_serviceescalation expanded; for (configuration::set_serviceescalation::const_iterator @@ -167,8 +173,9 @@ void applier::serviceescalation::modify_object( void applier::serviceescalation::remove_object( configuration::serviceescalation const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Removing a service escalation."; + log_v2::config()->debug("Removing a service escalation."); // Find service escalation. std::string const& host_name{obj.hosts().front()}; @@ -184,9 +191,11 @@ void applier::serviceescalation::remove_object( engine::service::services.find({host_name, description})}; /* ... and its escalations */ if (sit == engine::service::services.end()) { - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Cannot find service '" << host_name << "/" << description << "' - already removed."; + log_v2::config()->debug("Cannot find service '{}/{}' - already removed.", + host_name, description); service_exists = false; } else service_exists = true; @@ -203,9 +212,12 @@ void applier::serviceescalation::remove_object( it->second.get(), &tv); if (service_exists) { - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Service '" << host_name << "/" << description << "' found - removing escalation from it."; + log_v2::config()->debug( + "Service '{}/{}' found - removing escalation from it.", host_name, + description); std::list& srv_escalations(sit->second->get_escalations()); /* We need also to remove the escalation from the service */ for (std::list::iterator @@ -237,8 +249,9 @@ void applier::serviceescalation::remove_object( void applier::serviceescalation::resolve_object( configuration::serviceescalation const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Resolving a service escalation."; + log_v2::config()->debug("Resolving a service escalation."); // Find service escalation bool found{false}; diff --git a/centreon-engine/src/configuration/applier/servicegroup.cc b/centreon-engine/src/configuration/applier/servicegroup.cc index a41feee8305..d2ea1d162d5 100644 --- a/centreon-engine/src/configuration/applier/servicegroup.cc +++ b/centreon-engine/src/configuration/applier/servicegroup.cc @@ -23,6 +23,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" using namespace com::centreon::engine::configuration; @@ -67,8 +68,10 @@ applier::servicegroup& applier::servicegroup::operator=( */ void applier::servicegroup::add_object(configuration::servicegroup const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new servicegroup '" << obj.servicegroup_name() << "'"; + log_v2::config()->debug("Creating new servicegroup '{}'", + obj.servicegroup_name()); // Add service group to the global configuration set. config->servicegroups().insert(obj); @@ -126,8 +129,10 @@ void applier::servicegroup::expand_objects(configuration::state& s) { void applier::servicegroup::modify_object( configuration::servicegroup const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Modifying servicegroup '" << obj.servicegroup_name() << "'"; + log_v2::config()->debug("Modifying servicegroup '{}'", + obj.servicegroup_name()); // Find old configuration. set_servicegroup::iterator it_cfg(config->servicegroups_find(obj.key())); @@ -192,8 +197,10 @@ void applier::servicegroup::modify_object( void applier::servicegroup::remove_object( configuration::servicegroup const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Removing servicegroup '" << obj.servicegroup_name() << "'"; + log_v2::config()->debug("Removing servicegroup '{}'", + obj.servicegroup_name()); // Find service group. servicegroup_map::iterator it{ @@ -220,8 +227,10 @@ void applier::servicegroup::remove_object( void applier::servicegroup::resolve_object( configuration::servicegroup const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Removing service group '" << obj.servicegroup_name() << "'"; + log_v2::config()->debug("Removing service group '{}'", + obj.servicegroup_name()); // Find service group. servicegroup_map::const_iterator it{ @@ -246,9 +255,11 @@ void applier::servicegroup::_resolve_members( // Only process if servicegroup has not been resolved already. if (_resolved.find(obj.key()) == _resolved.end()) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Resolving members of service group '" << obj.servicegroup_name() << "'"; + log_v2::config()->debug("Resolving members of service group '{}'", + obj.servicegroup_name()); // Mark object as resolved. configuration::servicegroup& resolved_obj(_resolved[obj.key()]); diff --git a/centreon-engine/src/configuration/applier/state.cc b/centreon-engine/src/configuration/applier/state.cc index 5e62aa9337f..f29996c32c1 100644 --- a/centreon-engine/src/configuration/applier/state.cc +++ b/centreon-engine/src/configuration/applier/state.cc @@ -23,8 +23,8 @@ #include #include +#include #include - #include "com/centreon/engine/broker.hh" #include "com/centreon/engine/commands/connector.hh" #include "com/centreon/engine/config.hh" @@ -49,6 +49,7 @@ #include "com/centreon/engine/configuration/command.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/objects.hh" @@ -83,13 +84,17 @@ void applier::state::apply(configuration::state& new_cfg) { throw; // If is not the first time, we can restore the old one. - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not apply new configuration: " << e.what(); + log_v2::config()->error("Error: Could not apply new configuration: {}", + e.what()); // Check if we need to restore old configuration. if (_processing_state == state_error) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration: try to restore old configuration"; + log_v2::config()->debug( + "configuration: try to restore old configuration"); _processing(save); } } @@ -114,13 +119,16 @@ void applier::state::apply(configuration::state& new_cfg, throw; // If is not the first time, we can restore the old one. - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Cannot apply new configuration: " << e.what(); + log_v2::config()->error("Cannot apply new configuration: {}", e.what()); // Check if we need to restore old configuration. if (_processing_state == state_error) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration: try to restore old configuration"; + log_v2::config()->debug( + "configuration: try to restore old configuration"); _processing(save, &state); } } @@ -242,30 +250,38 @@ void applier::state::_apply(configuration::state const& new_cfg) { // Check variables should not be change after the first execution. if (has_already_been_loaded) { if (config->broker_module() != new_cfg.broker_module()) { - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Broker modules cannot be changed nor reloaded"; + log_v2::config()->warn( + "Warning: Broker modules cannot be changed nor reloaded"); ++config_warnings; } if (config->broker_module_directory() != new_cfg.broker_module_directory()) { - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Broker module directory cannot be changed"; + log_v2::config()->warn( + "Warning: Broker module directory cannot be changed"); ++config_warnings; } if (config->command_file() != new_cfg.command_file()) { - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Command file cannot be changed"; + log_v2::config()->warn("Warning: Command file cannot be changed"); ++config_warnings; } if (config->external_command_buffer_slots() != new_cfg.external_command_buffer_slots()) { - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: External command buffer slots cannot be changed"; + log_v2::config()->warn( + "Warning: External command buffer slots cannot be changed"); ++config_warnings; } if (config->use_timezone() != new_cfg.use_timezone()) { - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Timezone can not be changed"; + log_v2::config()->warn("Warning: Timezone can not be changed"); ++config_warnings; } } @@ -434,6 +450,20 @@ void applier::state::_apply(configuration::state const& new_cfg) { config->use_retained_scheduling_info(new_cfg.use_retained_scheduling_info()); config->use_setpgid(new_cfg.use_setpgid()); config->use_syslog(new_cfg.use_syslog()); + config->log_v2_enabled(new_cfg.log_v2_enabled()); + config->log_legacy_enabled(new_cfg.log_legacy_enabled()); + config->log_v2_logger(new_cfg.log_v2_logger()); + config->log_level_functions(new_cfg.log_level_functions()); + config->log_level_config(new_cfg.log_level_config()); + config->log_level_events(new_cfg.log_level_events()); + config->log_level_checks(new_cfg.log_level_checks()); + config->log_level_notifications(new_cfg.log_level_notifications()); + config->log_level_eventbroker(new_cfg.log_level_eventbroker()); + config->log_level_external_command(new_cfg.log_level_external_command()); + config->log_level_commands(new_cfg.log_level_commands()); + config->log_level_downtimes(new_cfg.log_level_downtimes()); + config->log_level_comments(new_cfg.log_level_comments()); + config->log_level_macros(new_cfg.log_level_macros()); config->use_true_regexp_matching(new_cfg.use_true_regexp_matching()); config->user(new_cfg.user()); @@ -454,8 +484,11 @@ void applier::state::_apply(configuration::state const& new_cfg) { xpddefault_initialize_performance_data(); // Check global event handler commands... - if (verify_config) - logger(log_info_message, basic) << "Checking global event handlers..."; + if (verify_config) { + engine_logger(log_info_message, basic) + << "Checking global event handlers..."; + log_v2::events()->info("Checking global event handlers..."); + } if (!config->global_host_event_handler().empty()) { // Check the event handler command. std::string temp_command_name(config->global_host_event_handler().substr( @@ -463,9 +496,13 @@ void applier::state::_apply(configuration::state const& new_cfg) { command_map::iterator found{ commands::command::commands.find(temp_command_name)}; if (found == commands::command::commands.end() || !found->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Global host event handler command '" << temp_command_name << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Global host event handler command '{}' is not defined " + "anywhere!", + temp_command_name); ++config_errors; global_host_event_handler_ptr = nullptr; } else @@ -478,9 +515,13 @@ void applier::state::_apply(configuration::state const& new_cfg) { command_map::iterator found{ commands::command::commands.find(temp_command_name)}; if (found == commands::command::commands.end() || !found->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Global service event handler command '" << temp_command_name << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Global service event handler command '{}' is not defined " + "anywhere!", + temp_command_name); ++config_errors; global_service_event_handler_ptr = nullptr; } else @@ -488,18 +529,25 @@ void applier::state::_apply(configuration::state const& new_cfg) { } // Check obsessive processor commands... - if (verify_config) - logger(log_info_message, basic) + if (verify_config) { + engine_logger(log_info_message, basic) << "Checking obsessive compulsive processor commands..."; + log_v2::events()->info( + "Checking obsessive compulsive processor commands..."); + } if (!config->ocsp_command().empty()) { std::string temp_command_name(config->ocsp_command().substr( 0, config->ocsp_command().find_first_of('!'))); command_map::iterator found{ commands::command::commands.find(temp_command_name)}; if (found == commands::command::commands.end() || !found->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Obsessive compulsive service processor command '" << temp_command_name << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Obsessive compulsive service processor command '{}' is not " + "defined anywhere!", + temp_command_name); ++config_errors; ocsp_command_ptr = nullptr; } else @@ -511,9 +559,13 @@ void applier::state::_apply(configuration::state const& new_cfg) { command_map::iterator found{ commands::command::commands.find(temp_command_name)}; if (found == commands::command::commands.end() || !found->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Obsessive compulsive host processor command '" << temp_command_name << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Obsessive compulsive host processor command '{}' is not " + "defined anywhere!", + temp_command_name); ++config_errors; ochp_command_ptr = nullptr; } else @@ -556,7 +608,8 @@ void applier::state::_apply( aplyr.remove_object(*it_delete); } catch (std::exception const& e) { ++config_errors; - logger(log_info_message, basic) << e.what(); + engine_logger(log_info_message, basic) << e.what(); + log_v2::events()->info(e.what()); } } } @@ -572,7 +625,8 @@ void applier::state::_apply( aplyr.add_object(*it_create); } catch (std::exception const& e) { ++config_errors; - logger(log_info_message, basic) << e.what(); + engine_logger(log_info_message, basic) << e.what(); + log_v2::events()->info(e.what()); } } } @@ -588,7 +642,8 @@ void applier::state::_apply( aplyr.modify_object(*it_modify); } catch (std::exception const& e) { ++config_errors; - logger(log_info_message, basic) << e.what(); + engine_logger(log_info_message, basic) << e.what(); + log_v2::events()->info(e.what()); } } } @@ -616,20 +671,29 @@ void applier::state::_check_serviceescalations() const { } } if (!found) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on serviceescalation !!! The service " << srv->get_hostname() << "/" << srv->get_description() << " contains a non existing service escalation"; + log_v2::config()->error( + "Error on serviceescalation !!! The service {}/{} contains a non " + "existing service escalation", + srv->get_hostname(), srv->get_description()); throw engine_error() << "This is a bug"; } } if (s.size() != srv->get_escalations().size()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on serviceescalation !!! Some escalations are stored " "several times in service " << srv->get_hostname() << "/" << srv->get_description() << "set size: " << s.size() << " ; list size: " << srv->get_escalations().size(); + log_v2::config()->error( + "Error on serviceescalation !!! Some escalations are stored " + "several times in service {}/{} set size: {} ; list size: {}", + srv->get_hostname(), srv->get_description(), s.size(), + srv->get_escalations().size()); throw engine_error() << "This is a bug"; } } @@ -642,33 +706,49 @@ void applier::state::_check_serviceescalations() const { if (p.second.get() == se->notifier_ptr) { found = true; if (se->get_hostname() != p.second->get_hostname()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on serviceescalation !!! The notifier seen by the " "escalation is wrong. " << "Host name given by the escalation is " << se->get_hostname() << " whereas the hostname from the notifier is " << p.second->get_hostname() << "."; + log_v2::config()->error( + "Error on serviceescalation !!! The notifier seen by the " + "escalation is wrong. Host name given by the escalation is {} " + "whereas the hostname from the notifier is {}.", + se->get_hostname(), p.second->get_hostname()); throw engine_error() << "This is a bug"; } if (se->get_description() != p.second->get_description()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on serviceescalation !!! The notifier seen by the " "escalation is wrong. " << "Service description given by the escalation is " << se->get_description() << " whereas the service description from the notifier is " << p.second->get_description() << "."; + log_v2::config()->error( + "Error on serviceescalation !!! The notifier seen by the " + "escalation is wrong. Service description given by the " + "escalation is {} whereas the service description from the " + "notifier is {}.", + se->get_description(), p.second->get_description()); throw engine_error() << "This is a bug"; } break; } } if (!found) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on serviceescalation !!! The notifier seen by the " "escalation is wrong " << "The bug is detected on escalation concerning host " << se->get_hostname() << " and service " << se->get_description(); + log_v2::config()->error( + "Error on serviceescalation !!! The notifier seen by the " + "escalation is wrong The bug is detected on escalation concerning " + "host {} and service {}", + se->get_hostname(), se->get_description()); throw engine_error() << "This is a bug"; } } @@ -693,9 +773,13 @@ void applier::state::_check_hostescalations() const { } } if (!found) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on hostescalation !!! The host " << hst->get_name() << " contains a non existing host escalation"; + log_v2::config()->error( + "Error on hostescalation !!! The host {} contains a non existing " + "host escalation", + hst->get_name()); throw engine_error() << "This is a bug"; } } @@ -709,23 +793,32 @@ void applier::state::_check_hostescalations() const { if (p.second.get() == he->notifier_ptr) { found = true; if (he->get_hostname() != p.second->get_name()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on hostescalation !!! The notifier seen by the " "escalation is wrong. " << "Host name given by the escalation is " << he->get_hostname() << " whereas the hostname from the notifier is " << p.second->get_name() << "."; + log_v2::config()->error( + "Error on hostescalation !!! The notifier seen by the escalation " + "is wrong. Host name given by the escalation is {} whereas the " + "hostname from the notifier is {}.", + he->get_hostname(), p.second->get_name()); throw engine_error() << "This is a bug"; } break; } } if (!found) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on hostescalation !!! The notifier seen by the escalation " "is wrong " << "The bug is detected on escalation concerning host " << he->get_hostname(); + log_v2::config()->error( + "Error on hostescalation !!! The notifier seen by the escalation is " + "wrong The bug is detected on escalation concerning host {}", + he->get_hostname()); throw engine_error() << "This is a bug"; } } @@ -744,10 +837,14 @@ void applier::state::_check_contacts() const { contact_map::iterator found{engine::contact::contacts.find(pp.first)}; if (found == engine::contact::contacts.end() || found->second.get() != pp.second) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on contact !!! The contact " << pp.first << " used in contactgroup " << p.first << " is not or badly defined"; + log_v2::config()->error( + "Error on contact !!! The contact {} used in contactgroup {} is " + "not or badly defined", + pp.first, p.first); throw engine_error() << "This is a bug"; } } @@ -758,10 +855,14 @@ void applier::state::_check_contacts() const { contact_map::iterator found{engine::contact::contacts.find(pp.first)}; if (found == engine::contact::contacts.end() || found->second.get() != pp.second) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on contact !!! The contact " << pp.first << " used in service " << p.second->get_hostname() << '/' << p.second->get_description() << " is not or badly defined"; + log_v2::config()->error( + "Error on contact !!! The contact {} used in service {}/{} is not " + "or badly defined", + pp.first, p.second->get_hostname(), p.second->get_description()); throw engine_error() << "This is a bug"; } } @@ -772,10 +873,14 @@ void applier::state::_check_contacts() const { contact_map::iterator found{engine::contact::contacts.find(pp.first)}; if (found == engine::contact::contacts.end() || found->second.get() != pp.second) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on contact !!! The contact " << pp.first << " used in service " << p.second->get_name() << " is not or badly defined"; + log_v2::config()->error( + "Error on contact !!! The contact {} used in service {} is not or " + "badly defined", + pp.first, p.second->get_name()); throw engine_error() << "This is a bug"; } } @@ -796,10 +901,14 @@ void applier::state::_check_contactgroups() const { engine::contactgroup::contactgroups.find(pp.first)}; if (found == engine::contactgroup::contactgroups.end() || found->second.get() != pp.second) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on contactgroup !!! The contactgroup " << pp.first << " used in service " << p.first.first << '/' << p.first.second << " is not or badly defined"; + log_v2::config()->error( + "Error on contactgroup !!! The contactgroup {} used in service " + "{}/{} is not or badly defined", + pp.first, p.first.first, p.first.second); throw engine_error() << "This is a bug"; } } @@ -811,9 +920,13 @@ void applier::state::_check_contactgroups() const { engine::contactgroup::contactgroups.find(pp.first)}; if (found == engine::contactgroup::contactgroups.end() || found->second.get() != pp.second) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on contactgroup !!! The contactgroup " << pp.first << " used in host " << p.first << " is not or badly defined"; + log_v2::config()->error( + "Error on contactgroup !!! The contactgroup {} used in host {} is " + "not or badly defined", + pp.first, p.first); throw engine_error() << "This is a bug"; } } @@ -825,10 +938,14 @@ void applier::state::_check_contactgroups() const { engine::contactgroup::contactgroups.find(pp.first)}; if (found == engine::contactgroup::contactgroups.end() || found->second.get() != pp.second) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on contactgroup !!! The contactgroup " << pp.first << " used in serviceescalation " << p.second->get_uuid().to_string() << " is not or badly defined"; + log_v2::config()->error( + "Error on contactgroup !!! The contactgroup {} used in " + "serviceescalation {} is not or badly defined", + pp.first, p.second->get_uuid().to_string()); throw engine_error() << "This is a bug"; } } @@ -840,10 +957,14 @@ void applier::state::_check_contactgroups() const { engine::contactgroup::contactgroups.find(pp.first)}; if (found == engine::contactgroup::contactgroups.end() || found->second.get() != pp.second) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on contactgroup !!! The contactgroup " << pp.first << " used in hostescalation " << p.second->get_uuid().to_string() << " is not or badly defined"; + log_v2::config()->error( + "Error on contactgroup !!! The contactgroup {} used in " + "hostescalation {} is not or badly defined", + pp.first, p.second->get_uuid().to_string()); throw engine_error() << "This is a bug"; } } @@ -866,10 +987,14 @@ void applier::state::_check_services() const { {svc->get_host_id(), svc->get_service_id()})}; if (found == engine::service::services_by_id.end() || found->second.get() != svc) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on service !!! The service " << p.first.first << '/' << p.first.second << " used in service dependency " << p.first.first << '/' << p.first.second << " is not or badly defined"; + log_v2::config()->error( + "Error on service !!! The service {}/{} used in service dependency " + "{}/{} is not or badly defined", + p.first.first, p.first.second, p.first.first, p.first.second); throw engine_error() << "This is a bug"; } } @@ -880,10 +1005,14 @@ void applier::state::_check_services() const { {p.second->get_hostname(), p.second->get_description()})}; if (found == engine::service::services.end() || found->second.get() != p.second.get()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on service !!! The service " << p.first.first << '/' << p.first.second << " defined in services is not defined in services_by_id"; + log_v2::config()->error( + "Error on service !!! The service {}/{} defined in services is not " + "defined in services_by_id", + p.first.first, p.first.second); throw engine_error() << "This is a bug"; } } @@ -903,10 +1032,14 @@ void applier::state::_check_services() const { } } if (!found) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on service !!! The service " << p.first.first << '/' << p.first.second << " defined in services has a wrong check command"; + log_v2::config()->error( + "Error on service !!! The service {}/{} defined in services has " + "a wrong check command", + p.first.first, p.first.second); throw engine_error() << "This is a bug"; } } @@ -915,11 +1048,15 @@ void applier::state::_check_services() const { if (engine::service::services_by_id.size() != engine::service::services.size()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on service !!! services_by_id contains ices that are not in " "services. The first one size is " << engine::service::services.size() << " the second size is " << engine::service::services.size(); + log_v2::config()->error( + "Error on service !!! services_by_id contains ices that are not in " + "services. The first one size is {} the second size is {}", + engine::service::services.size(), engine::service::services.size()); throw engine_error() << "This is a bug"; } } @@ -935,9 +1072,13 @@ void applier::state::_check_hosts() const { std::string const& where) { host_map::const_iterator found{engine::host::hosts.find(hst->get_name())}; if (found == engine::host::hosts.end() || found->second.get() != hst) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on host !!! The host " << hst->get_name() << " used in " << where << " is not defined or badly defined in hosts"; + log_v2::config()->error( + "Error on host !!! The host {} used in {} is not defined or badly " + "defined in hosts", + hst->get_name(), where); throw engine_error() << "This is a bug"; } }; @@ -968,9 +1109,13 @@ void applier::state::_check_hosts() const { } } if (!found) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on host !!! The host " << p.first << " defined in hosts has a wrong check command"; + log_v2::config()->error( + "Error on host !!! The host {} defined in hosts has a wrong " + "check command", + p.first); throw engine_error() << "This is a bug"; } } @@ -978,11 +1123,15 @@ void applier::state::_check_hosts() const { } if (engine::host::hosts_by_id.size() != engine::host::hosts.size()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error on host !!! hosts_by_id contains hosts that are not in " "hosts. The first one size is " << engine::service::services.size() << " whereas the second size is " << engine::service::services.size(); + log_v2::config()->error( + "Error on host !!! hosts_by_id contains hosts that are not in " + "hosts. The first one size is {} whereas the second size is {}", + engine::service::services.size(), engine::service::services.size()); throw engine_error() << "This is a bug"; } @@ -1008,7 +1157,7 @@ void applier::state::_apply(configuration::state& new_cfg, app_state.apply(new_cfg, state); } catch (std::exception const& e) { ++config_errors; - logger(log_info_message, basic) << e.what(); + std::cout << e.what(); } } } @@ -1027,7 +1176,7 @@ void applier::state::_expand(configuration::state& new_state) { } catch (std::exception const& e) { if (verify_config) { ++config_errors; - logger(log_info_message, basic) << e.what(); + std::cout << e.what(); } else throw; } @@ -1170,8 +1319,11 @@ void applier::state::_processing(configuration::state& new_cfg, std::lock_guard locker(_apply_lock); // Apply logging configurations. + applier::logging::instance().apply(new_cfg); + log_v2::instance().apply(new_cfg); + // Apply globals configurations. applier::globals::instance().apply(new_cfg); @@ -1184,15 +1336,19 @@ void applier::state::_processing(configuration::state& new_cfg, if (!has_already_been_loaded && !verify_config && !test_scheduling) { // This must be logged after we read config data, // as user may have changed location of main log file. - logger(log_process_info, basic) + engine_logger(log_process_info, basic) << "Centreon Engine " << CENTREON_ENGINE_VERSION_STRING << " starting ... (PID=" << getpid() << ")"; + log_v2::process()->info("Centreon Engine {} starting ... (PID={})", + CENTREON_ENGINE_VERSION_STRING, getpid()); // Log the local time - may be different than clock // time due to timezone offset. - logger(log_process_info, basic) + engine_logger(log_process_info, basic) << "Local time is " << string::ctime(program_start) << "\n" << "LOG VERSION: " << LOG_VERSION_2; + log_v2::process()->info("Local time is {}", string::ctime(program_start)); + log_v2::process()->info("LOG VERSION: {}", LOG_VERSION_2); } // @@ -1277,9 +1433,9 @@ void applier::state::_processing(configuration::state& new_cfg, config->serviceescalations()); #ifdef DEBUG_CONFIG - logger(log_config_error, basic) << "WARNING!! You are using a version of " - "centreon engine for developers!!!" - " This is not a production version."; + std::cout << "WARNING!! You are using a version of " + "centreon engine for developers!!!" + " This is not a production version."; // Checks on configuration _check_serviceescalations(); _check_hostescalations(); @@ -1306,7 +1462,8 @@ void applier::state::_processing(configuration::state& new_cfg, _apply(new_cfg); } catch (std::exception const& e) { ++config_errors; - logger(log_info_message, basic) << e.what(); + engine_logger(log_info_message, basic) << e.what(); + log_v2::events()->info(e.what()); } } @@ -1356,19 +1513,27 @@ void applier::state::_processing(configuration::state& new_cfg, (tv[i + 1].tv_usec - tv[i].tv_usec) / 1000000.0; runtimes[4] += runtimes[i]; } - logger(log_info_message, basic) + std::cout << "\nTiming information on configuration verification is listed " "below.\n\n" - << "CONFIG VERIFICATION TIMES (* = Potential for speedup " + "CONFIG VERIFICATION TIMES (* = Potential for speedup " "with -x option)\n" - << "----------------------------------\n" - << "Template Resolutions: " << runtimes[0] << " sec\n" - << "Object Relationships: " << runtimes[2] << " sec\n" - << "Circular Paths: " << runtimes[3] << " sec *\n" - << "Misc: " << runtimes[1] << " sec\n" - << " ============\n" - << "TOTAL: " << runtimes[4] - << " sec * = " << runtimes[3] << " sec (" + "----------------------------------\n" + "Template Resolutions: " + << runtimes[0] + << " sec\n" + "Object Relationships: " + << runtimes[2] + << " sec\n" + "Circular Paths: " + << runtimes[3] + << " sec *\n" + "Misc: " + << runtimes[1] + << " sec\n" + " ============\n" + "TOTAL: " + << runtimes[4] << " sec * = " << runtimes[3] << " sec (" << (runtimes[3] * 100.0 / runtimes[4]) << "%) estimated savings\n"; } } catch (...) { @@ -1396,7 +1561,7 @@ void applier::state::_resolve(std::set& cfg) { } catch (std::exception const& e) { if (verify_config) { ++config_errors; - logger(log_info_message, basic) << e.what(); + std::cout << e.what() << std::endl; } else throw; } diff --git a/centreon-engine/src/configuration/applier/timeperiod.cc b/centreon-engine/src/configuration/applier/timeperiod.cc index 764b8d72254..b1c7fd008f3 100644 --- a/centreon-engine/src/configuration/applier/timeperiod.cc +++ b/centreon-engine/src/configuration/applier/timeperiod.cc @@ -24,6 +24,7 @@ #include "com/centreon/engine/deleter/listmember.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" using namespace com::centreon::engine::configuration; @@ -64,8 +65,10 @@ applier::timeperiod& applier::timeperiod::operator=( */ void applier::timeperiod::add_object(configuration::timeperiod const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Creating new time period '" << obj.timeperiod_name() << "'."; + log_v2::config()->debug("Creating new time period '{}'.", + obj.timeperiod_name()); // Add time period to the global configuration set. config->timeperiods().insert(obj); @@ -106,8 +109,9 @@ void applier::timeperiod::expand_objects(configuration::state& s) { */ void applier::timeperiod::modify_object(configuration::timeperiod const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Modifying time period '" << obj.timeperiod_name() << "'."; + log_v2::config()->debug("Modifying time period '{}'.", obj.timeperiod_name()); // Find old configuration. set_timeperiod::iterator it_cfg(config->timeperiods_find(obj.key())); @@ -173,8 +177,9 @@ void applier::timeperiod::modify_object(configuration::timeperiod const& obj) { */ void applier::timeperiod::remove_object(configuration::timeperiod const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Removing time period '" << obj.timeperiod_name() << "'."; + log_v2::config()->debug("Removing time period '{}'.", obj.timeperiod_name()); // Find time period. timeperiod_map::iterator it(engine::timeperiod::timeperiods.find(obj.key())); @@ -203,8 +208,9 @@ void applier::timeperiod::remove_object(configuration::timeperiod const& obj) { */ void applier::timeperiod::resolve_object(configuration::timeperiod const& obj) { // Logging. - logger(logging::dbg_config, logging::more) + engine_logger(logging::dbg_config, logging::more) << "Resolving time period '" << obj.timeperiod_name() << "'."; + log_v2::config()->debug("Resolving time period '{}'.", obj.timeperiod_name()); // Find time period. timeperiod_map::iterator it{engine::timeperiod::timeperiods.find(obj.key())}; diff --git a/centreon-engine/src/configuration/host.cc b/centreon-engine/src/configuration/host.cc index 12c5ed96624..837dbe0badd 100644 --- a/centreon-engine/src/configuration/host.cc +++ b/centreon-engine/src/configuration/host.cc @@ -21,6 +21,7 @@ #include "com/centreon/engine/configuration/hostextinfo.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/host.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/string.hh" @@ -1259,9 +1260,12 @@ bool host::_set_event_handler_enabled(bool value) { */ bool host::_set_failure_prediction_enabled(bool value) { (void)value; - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: host failure_prediction_enabled is deprecated" << " This option will not be supported in 20.04."; + log_v2::config()->warn( + "Warning: host failure_prediction_enabled is deprecated This option will " + "not be supported in 20.04."); ++config_warnings; return true; } @@ -1275,9 +1279,12 @@ bool host::_set_failure_prediction_enabled(bool value) { */ bool host::_set_failure_prediction_options(std::string const& value) { (void)value; - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: service failure_prediction_options is deprecated" << " This option will not be supported in 20.04."; + log_v2::config()->warn( + "Warning: service failure_prediction_options is deprecated This option " + "will not be supported in 20.04."); ++config_warnings; return (true); } diff --git a/centreon-engine/src/configuration/hostdependency.cc b/centreon-engine/src/configuration/hostdependency.cc index 3ca7e63fbd8..5c30263a5f3 100644 --- a/centreon-engine/src/configuration/hostdependency.cc +++ b/centreon-engine/src/configuration/hostdependency.cc @@ -19,6 +19,7 @@ #include "com/centreon/engine/configuration/hostdependency.hh" #include "com/centreon/engine/exceptions/error.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/string.hh" @@ -195,9 +196,13 @@ void hostdependency::check_validity() const { std::string dependend_host_name(!_dependent_hosts->empty() ? *_dependent_hosts->begin() : *_dependent_hostgroups->begin()); - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Ignoring lame host dependency of '" << dependend_host_name << "' on host/hostgroups '" << host_name << "'."; + log_v2::config()->warn( + "Warning: Ignoring lame host dependency of '{}' on host/hostgroups " + "'{}'.", + dependend_host_name, host_name); } return; diff --git a/centreon-engine/src/configuration/hostgroup.cc b/centreon-engine/src/configuration/hostgroup.cc index e7d7cdfe66f..05420d7bf3a 100644 --- a/centreon-engine/src/configuration/hostgroup.cc +++ b/centreon-engine/src/configuration/hostgroup.cc @@ -19,6 +19,7 @@ #include "com/centreon/engine/configuration/hostgroup.hh" #include "com/centreon/engine/exceptions/error.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" using namespace com::centreon; @@ -90,43 +91,59 @@ hostgroup& hostgroup::operator=(hostgroup const& right) { */ bool hostgroup::operator==(hostgroup const& right) const throw() { if (!object::operator==(right)) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::hostgroup::equality => object don't match"; + log_v2::config()->debug( + "configuration::hostgroup::equality => object don't match"); return false; } if (_action_url != right._action_url) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::hostgroup::equality => action url don't match"; + log_v2::config()->debug( + "configuration::hostgroup::equality => action url don't match"); return false; } if (_alias != right._alias) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::hostgroup::equality => alias don't match"; + log_v2::config()->debug( + "configuration::hostgroup::equality => alias don't match"); return false; } if (_hostgroup_id != right._hostgroup_id) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::hostgroup::equality => hostgroup id don't match"; + log_v2::config()->debug( + "configuration::hostgroup::equality => hostgroup id don't match"); return false; } if (_hostgroup_name != right._hostgroup_name) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::hostgroup::equality => hostgroup name don't match"; + log_v2::config()->debug( + "configuration::hostgroup::equality => hostgroup name don't match"); return false; } if (_members != right._members) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::hostgroup::equality => members don't match"; + log_v2::config()->debug( + "configuration::hostgroup::equality => members don't match"); return false; } if (_notes != right._notes) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::hostgroup::equality => notes don't match"; + log_v2::config()->debug( + "configuration::hostgroup::equality => notes don't match"); return false; } if (_notes_url != right._notes_url) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::hostgroup::equality => notes url don't match"; + log_v2::config()->debug( + "configuration::hostgroup::equality => notes url don't match"); return false; } return true; diff --git a/centreon-engine/src/configuration/parser.cc b/centreon-engine/src/configuration/parser.cc index cf04f4d6989..dcfe88dd730 100644 --- a/centreon-engine/src/configuration/parser.cc +++ b/centreon-engine/src/configuration/parser.cc @@ -20,6 +20,7 @@ #include "com/centreon/engine/configuration/parser.hh" #include #include "com/centreon/engine/exceptions/error.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/string.hh" #include "com/centreon/io/directory_entry.hh" @@ -360,8 +361,9 @@ void parser::_parse_directory_configuration(std::string const& path) { * @param[in] path The configuration path. */ void parser::_parse_global_configuration(std::string const& path) { - logger(logging::log_info_message, logging::most) + engine_logger(logging::log_info_message, logging::most) << "Reading main configuration file '" << path << "'."; + log_v2::config()->info("Reading main configuration file '{}'.", path); std::ifstream stream(path.c_str(), std::ios::binary); if (!stream.is_open()) @@ -392,8 +394,9 @@ void parser::_parse_global_configuration(std::string const& path) { * @param[in] path The object definitions path. */ void parser::_parse_object_definitions(std::string const& path) { - logger(logging::log_info_message, logging::basic) + engine_logger(logging::log_info_message, logging::basic) << "Processing object config file '" << path << "'"; + log_v2::config()->info("Processing object config file '{}'", path); std::ifstream stream(path.c_str(), std::ios::binary); if (!stream.is_open()) @@ -469,8 +472,9 @@ void parser::_parse_object_definitions(std::string const& path) { * @param[in] path The resource file path. */ void parser::_parse_resource_file(std::string const& path) { - logger(logging::log_info_message, logging::most) + engine_logger(logging::log_info_message, logging::most) << "Reading resource file '" << path << "'"; + log_v2::config()->info("Reading resource file '{}'", path); std::ifstream stream(path.c_str(), std::ios::binary); if (!stream.is_open()) diff --git a/centreon-engine/src/configuration/service.cc b/centreon-engine/src/configuration/service.cc index 0e45d7ade68..947a7bd2bf2 100644 --- a/centreon-engine/src/configuration/service.cc +++ b/centreon-engine/src/configuration/service.cc @@ -22,6 +22,7 @@ #include "com/centreon/engine/customvariable.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/host.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/string.hh" @@ -295,241 +296,353 @@ service& service::operator=(service const& other) { */ bool service::operator==(service const& other) const throw() { if (!object::operator==(other)) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => object don't match"; + log_v2::config()->debug( + "configuration::service::equality => object don't match"); return false; } if (_acknowledgement_timeout != other._acknowledgement_timeout) { - logger(dbg_config, more) << "configuration::service::equality => " - "acknowledgement_timeout don't match"; + engine_logger(dbg_config, more) << "configuration::service::equality => " + "acknowledgement_timeout don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "acknowledgement_timeout don't match"); return false; } if (_action_url != other._action_url) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => action_url don't match"; + log_v2::config()->debug( + "configuration::service::equality => action_url don't match"); return false; } if (_checks_active != other._checks_active) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => checks_active don't match"; + log_v2::config()->debug( + "configuration::service::equality => checks_active don't match"); return false; } if (_checks_passive != other._checks_passive) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => checks_passive don't match"; + log_v2::config()->debug( + "configuration::service::equality => checks_passive don't match"); return false; } if (_check_command != other._check_command) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => checks_passive don't match"; + log_v2::config()->debug( + "configuration::service::equality => checks_passive don't match"); return false; } if (_check_command_is_important != other._check_command_is_important) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => check_command don't match"; + log_v2::config()->debug( + "configuration::service::equality => check_command don't match"); return false; } if (_check_freshness != other._check_freshness) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => check_freshness don't match"; + log_v2::config()->debug( + "configuration::service::equality => check_freshness don't match"); return false; } if (_check_interval != other._check_interval) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => check_interval don't match"; + log_v2::config()->debug( + "configuration::service::equality => check_interval don't match"); return false; } if (_check_period != other._check_period) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => check_period don't match"; + log_v2::config()->debug( + "configuration::service::equality => check_period don't match"); return false; } if (_contactgroups != other._contactgroups) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => contactgroups don't match"; + log_v2::config()->debug( + "configuration::service::equality => contactgroups don't match"); return false; } if (_contacts != other._contacts) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => contacts don't match"; + log_v2::config()->debug( + "configuration::service::equality => contacts don't match"); return false; } if (std::operator!=(_customvariables, other._customvariables)) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => customvariables don't match"; + log_v2::config()->debug( + "configuration::service::equality => customvariables don't match"); return false; } if (_display_name != other._display_name) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => display_name don't match"; + log_v2::config()->debug( + "configuration::service::equality => display_name don't match"); return false; } if (_event_handler != other._event_handler) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => event_handler don't match"; + log_v2::config()->debug( + "configuration::service::equality => event_handler don't match"); return false; } if (_event_handler_enabled != other._event_handler_enabled) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => event_handler don't match"; + log_v2::config()->debug( + "configuration::service::equality => event_handler don't match"); return false; } if (_first_notification_delay != other._first_notification_delay) { - logger(dbg_config, more) << "configuration::service::equality => " - "first_notification_delay don't match"; + engine_logger(dbg_config, more) << "configuration::service::equality => " + "first_notification_delay don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "first_notification_delay don't match"); return false; } if (_flap_detection_enabled != other._flap_detection_enabled) { - logger(dbg_config, more) << "configuration::service::equality => " - "flap_detection_enabled don't match"; + engine_logger(dbg_config, more) << "configuration::service::equality => " + "flap_detection_enabled don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "flap_detection_enabled don't match"); return false; } if (_flap_detection_options != other._flap_detection_options) { - logger(dbg_config, more) << "configuration::service::equality => " - "flap_detection_options don't match"; + engine_logger(dbg_config, more) << "configuration::service::equality => " + "flap_detection_options don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "flap_detection_options don't match"); return false; } if (_freshness_threshold != other._freshness_threshold) { - logger(dbg_config, more) << "configuration::service::equality => " - "freshness_threshold don't match"; + engine_logger(dbg_config, more) << "configuration::service::equality => " + "freshness_threshold don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "freshness_threshold don't match"); return false; } if (_high_flap_threshold != other._high_flap_threshold) { - logger(dbg_config, more) << "configuration::service::equality => " - "high_flap_threshold don't match"; + engine_logger(dbg_config, more) << "configuration::service::equality => " + "high_flap_threshold don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "high_flap_threshold don't match"); return false; } if (_hostgroups != other._hostgroups) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => hostgroups don't match"; + log_v2::config()->debug( + "configuration::service::equality => hostgroups don't match"); return false; } if (_hosts != other._hosts) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => _hosts don't match"; + log_v2::config()->debug( + "configuration::service::equality => _hosts don't match"); return false; } if (_icon_image != other._icon_image) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => icon_image don't match"; + log_v2::config()->debug( + "configuration::service::equality => icon_image don't match"); return false; } if (_icon_image_alt != other._icon_image_alt) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => icon_image_alt don't match"; + log_v2::config()->debug( + "configuration::service::equality => icon_image_alt don't match"); return false; } if (_initial_state != other._initial_state) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => initial_state don't match"; + log_v2::config()->debug( + "configuration::service::equality => initial_state don't match"); return false; } if (_is_volatile != other._is_volatile) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => is_volatile don't match"; + log_v2::config()->debug( + "configuration::service::equality => is_volatile don't match"); return false; } if (_low_flap_threshold != other._low_flap_threshold) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => low_flap_threshold don't match"; + log_v2::config()->debug( + "configuration::service::equality => low_flap_threshold don't match"); return false; } if (_max_check_attempts != other._max_check_attempts) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => max_check_attempts don't match"; + log_v2::config()->debug( + "configuration::service::equality => max_check_attempts don't match"); return false; } if (_notes != other._notes) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => notes don't match"; + log_v2::config()->debug( + "configuration::service::equality => notes don't match"); return false; } if (_notes_url != other._notes_url) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => notes_url don't match"; + log_v2::config()->debug( + "configuration::service::equality => notes_url don't match"); return false; } if (_notifications_enabled != other._notifications_enabled) { - logger(dbg_config, more) << "configuration::service::equality => " - "notifications_enabled don't match"; + engine_logger(dbg_config, more) << "configuration::service::equality => " + "notifications_enabled don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "notifications_enabled don't match"); return false; } if (_notification_interval != other._notification_interval) { - logger(dbg_config, more) << "configuration::service::equality => " - "notification_interval don't match"; + engine_logger(dbg_config, more) << "configuration::service::equality => " + "notification_interval don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "notification_interval don't match"); return false; } if (_notification_options != other._notification_options) { - logger(dbg_config, more) << "configuration::service::equality => " - "notification_options don't match"; + engine_logger(dbg_config, more) << "configuration::service::equality => " + "notification_options don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "notification_options don't match"); return false; } if (_notification_period != other._notification_period) { - logger(dbg_config, more) << "configuration::service::equality => " - "notification_period don't match"; + engine_logger(dbg_config, more) << "configuration::service::equality => " + "notification_period don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "notification_period don't match"); return false; } if (_obsess_over_service != other._obsess_over_service) { - logger(dbg_config, more) << "configuration::service::equality => " - "obsess_over_service don't match"; + engine_logger(dbg_config, more) << "configuration::service::equality => " + "obsess_over_service don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "obsess_over_service don't match"); return false; } if (_process_perf_data != other._process_perf_data) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => process_perf_data don't match"; + log_v2::config()->debug( + "configuration::service::equality => process_perf_data don't match"); return false; } if (_retain_nonstatus_information != other._retain_nonstatus_information) { - logger(dbg_config, more) << "configuration::service::equality => " - "retain_nonstatus_information don't match"; + engine_logger(dbg_config, more) + << "configuration::service::equality => " + "retain_nonstatus_information don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "retain_nonstatus_information don't match"); return false; } if (_retain_status_information != other._retain_status_information) { - logger(dbg_config, more) << "configuration::service::equality => " - "retain_status_information don't match"; + engine_logger(dbg_config, more) << "configuration::service::equality => " + "retain_status_information don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "retain_status_information don't match"); return false; } if (_retry_interval != other._retry_interval) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => retry_interval don't match"; + log_v2::config()->debug( + "configuration::service::equality => retry_interval don't match"); return false; } if (_recovery_notification_delay != other._recovery_notification_delay) { - logger(dbg_config, more) << "configuration::service::equality => " - "recovery_notification_delay don't match"; + engine_logger(dbg_config, more) + << "configuration::service::equality => " + "recovery_notification_delay don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "recovery_notification_delay don't match"); return false; } if (_servicegroups != other._servicegroups) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => servicegroups don't match"; + log_v2::config()->debug( + "configuration::service::equality => servicegroups don't match"); return false; } if (_service_description != other._service_description) { - logger(dbg_config, more) << "configuration::service::equality => " - "service_description don't match"; + engine_logger(dbg_config, more) << "configuration::service::equality => " + "service_description don't match"; + log_v2::config()->debug( + "configuration::service::equality => " + "service_description don't match"); return false; } if (_host_id != other._host_id) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => host_id don't match"; + log_v2::config()->debug( + "configuration::service::equality => host_id don't match"); return false; } if (_service_id != other._service_id) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => service_id don't match"; + log_v2::config()->debug( + "configuration::service::equality => service_id don't match"); return false; } if (_stalking_options != other._stalking_options) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => stalking_options don't match"; + log_v2::config()->debug( + "configuration::service::equality => stalking_options don't match"); return false; } if (_timezone != other._timezone) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::service::equality => timezone don't match"; + log_v2::config()->debug( + "configuration::service::equality => timezone don't match"); return false; } - logger(dbg_config, more) << "configuration::service::equality => OK"; + engine_logger(dbg_config, more) << "configuration::service::equality => OK"; + log_v2::config()->debug("configuration::service::equality => OK"); return true; } @@ -1496,9 +1609,12 @@ bool service::_set_event_handler_enabled(bool value) { */ bool service::_set_failure_prediction_enabled(bool value) { (void)value; - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: service failure_prediction_enabled is deprecated." << " This option will not be supported in 20.04."; + log_v2::config()->warn( + "Warning: service failure_prediction_enabled is deprecated. This option " + "will not be supported in 20.04."); ++config_warnings; return true; } @@ -1512,9 +1628,12 @@ bool service::_set_failure_prediction_enabled(bool value) { */ bool service::_set_failure_prediction_options(std::string const& value) { (void)value; - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: service failure_prediction_options is deprecated." << " This option will not be supported in 20.04."; + log_v2::config()->warn( + "Warning: service failure_prediction_options is deprecated. This option " + "will not be supported in 20.04."); ++config_warnings; return true; } @@ -1827,9 +1946,12 @@ bool service::_set_obsess_over_service(bool value) { */ bool service::_set_parallelize_check(bool value) { (void)value; - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: service parallelize_check is deprecated" << " This option will not be supported in 20.04."; + log_v2::config()->warn( + "Warning: service parallelize_check is deprecated This option will not " + "be supported in 20.04."); ++config_warnings; return true; } diff --git a/centreon-engine/src/configuration/servicedependency.cc b/centreon-engine/src/configuration/servicedependency.cc index ef20ebd7ddf..1fb1dadacec 100644 --- a/centreon-engine/src/configuration/servicedependency.cc +++ b/centreon-engine/src/configuration/servicedependency.cc @@ -19,6 +19,7 @@ #include "com/centreon/engine/configuration/servicedependency.hh" #include "com/centreon/engine/exceptions/error.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/string.hh" @@ -276,7 +277,8 @@ void servicedependency::check_validity() const { else msg << "host '" << _hosts->front() << "'"; } - logger(log_config_warning, basic) << msg.str(); + engine_logger(log_config_warning, basic) << msg.str(); + log_v2::config()->warn(msg.str()); } return; diff --git a/centreon-engine/src/configuration/serviceescalation.cc b/centreon-engine/src/configuration/serviceescalation.cc index 17e4e154918..4e922c971ea 100644 --- a/centreon-engine/src/configuration/serviceescalation.cc +++ b/centreon-engine/src/configuration/serviceescalation.cc @@ -19,6 +19,7 @@ #include "com/centreon/engine/configuration/serviceescalation.hh" #include "com/centreon/engine/exceptions/error.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/string.hh" @@ -123,68 +124,100 @@ bool serviceescalation::operator==(serviceescalation const& right) const * constructor in almost all cases, we can have two equal escalations * with different uuid.*/ if (!object::operator==(right)) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::serviceescalation::equality => object don't match"; + log_v2::config()->debug( + "configuration::serviceescalation::equality => object don't match"); return false; } if (_contactgroups != right._contactgroups) { - logger(dbg_config, more) << "configuration::serviceescalation::" - "equality => contact groups don't match"; + engine_logger(dbg_config, more) << "configuration::serviceescalation::" + "equality => contact groups don't match"; + log_v2::config()->debug( + "configuration::serviceescalation::" + "equality => contact groups don't match"); return false; } if (_escalation_options != right._escalation_options) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::serviceescalation::equality => escalation options " "don't match"; + log_v2::config()->debug( + "configuration::serviceescalation::equality => escalation options " + "don't match"); return false; } if (_escalation_period != right._escalation_period) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::serviceescalation::equality => escalation periods " "don't match"; + log_v2::config()->debug( + "configuration::serviceescalation::equality => escalation periods " + "don't match"); return false; } if (_first_notification != right._first_notification) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::serviceescalation::equality => first notifications " "don't match"; + log_v2::config()->debug( + "configuration::serviceescalation::equality => first notifications " + "don't match"); return false; } if (_hostgroups != right._hostgroups) { - logger(dbg_config, more) << "configuration::serviceescalation::" - "equality => host groups don't match"; + engine_logger(dbg_config, more) << "configuration::serviceescalation::" + "equality => host groups don't match"; + log_v2::config()->debug( + "configuration::serviceescalation::" + "equality => host groups don't match"); return false; } if (_hosts != right._hosts) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::serviceescalation::equality => hosts don't match"; + log_v2::config()->debug( + "configuration::serviceescalation::equality => hosts don't match"); return false; } if (_last_notification != right._last_notification) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::serviceescalation::equality => last notification " "don't match"; + log_v2::config()->debug( + "configuration::serviceescalation::equality => last notification " + "don't match"); return false; } if (_notification_interval != right._notification_interval) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::serviceescalation::equality => notification " "interval don't match"; + log_v2::config()->debug( + "configuration::serviceescalation::equality => notification " + "interval don't match"); return false; } if (_servicegroups != right._servicegroups) { - logger(dbg_config, more) << "configuration::serviceescalation::" - "equality => service groups don't match"; + engine_logger(dbg_config, more) << "configuration::serviceescalation::" + "equality => service groups don't match"; + log_v2::config()->debug( + "configuration::serviceescalation::" + "equality => service groups don't match"); return false; } if (_service_description != right._service_description) { - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::serviceescalation::equality => service descriptions " "don't match"; + log_v2::config()->debug( + "configuration::serviceescalation::equality => service descriptions " + "don't match"); return false; } - logger(dbg_config, more) + engine_logger(dbg_config, more) << "configuration::serviceescalation::equality => OK"; + log_v2::config()->debug("configuration::serviceescalation::equality => OK"); return true; } diff --git a/centreon-engine/src/configuration/state.cc b/centreon-engine/src/configuration/state.cc index 3224cc717dc..61cca493c32 100644 --- a/centreon-engine/src/configuration/state.cc +++ b/centreon-engine/src/configuration/state.cc @@ -1,5 +1,5 @@ /* -** Copyright 2011-2013,2015-2017 Centreon +** Copyright 2011-2013,2015-2017, 2021 Centreon ** ** This file is part of Centreon Engine. ** @@ -24,6 +24,7 @@ #include "com/centreon/engine/broker.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/string.hh" #include "com/centreon/io/file_entry.hh" #include "compatibility/locations.h" @@ -239,6 +240,25 @@ std::unordered_map const state::_setters{ SETTER(bool, use_retained_scheduling_info)}, {"use_setpgid", SETTER(bool, use_setpgid)}, {"use_syslog", SETTER(bool, use_syslog)}, + {"log_v2_enabled", SETTER(bool, log_v2_enabled)}, + {"log_legacy_enabled", SETTER(bool, log_legacy_enabled)}, + {"log_v2_logger", SETTER(std::string const&, log_v2_logger)}, + {"log_level_functions", SETTER(std::string const&, log_level_functions)}, + {"log_level_config", SETTER(std::string const&, log_level_config)}, + {"log_level_events", SETTER(std::string const&, log_level_events)}, + {"log_level_checks", SETTER(std::string const&, log_level_checks)}, + {"log_level_notifications", + SETTER(std::string const&, log_level_notifications)}, + {"log_level_eventbroker", + SETTER(std::string const&, log_level_eventbroker)}, + {"log_level_external_command", + SETTER(std::string const&, log_level_external_command)}, + {"log_level_commands", SETTER(std::string const&, log_level_commands)}, + {"log_level_downtimes", SETTER(std::string const&, log_level_downtimes)}, + {"log_level_comments", SETTER(std::string const&, log_level_comments)}, + {"log_level_macros", SETTER(std::string const&, log_level_macros)}, + {"log_level_process", SETTER(std::string const&, log_level_process)}, + {"log_level_runtime", SETTER(std::string const&, log_level_runtime)}, {"use_timezone", SETTER(std::string const&, use_timezone)}, {"use_true_regexp_matching", SETTER(bool, use_true_regexp_matching)}, {"xcddefault_comment_file", SETTER(std::string const&, _set_comment_file)}, @@ -360,6 +380,22 @@ static bool const default_use_retained_program_state(true); static bool const default_use_retained_scheduling_info(false); static bool const default_use_setpgid(true); static bool const default_use_syslog(true); +static bool const default_log_v2_enabled(true); +static bool const default_log_legacy_enabled(true); +static std::string const default_log_v2_logger("file"); +static std::string const default_log_level_functions("error"); +static std::string const default_log_level_config("info"); +static std::string const default_log_level_events("info"); +static std::string const default_log_level_checks("info"); +static std::string const default_log_level_notifications("error"); +static std::string const default_log_level_eventbroker("error"); +static std::string const default_log_level_external_command("error"); +static std::string const default_log_level_commands("error"); +static std::string const default_log_level_downtimes("error"); +static std::string const default_log_level_comments("error"); +static std::string const default_log_level_macros("error"); +static std::string const default_log_level_process("info"); +static std::string const default_log_level_runtime("error"); static std::string const default_use_timezone(""); static bool const default_use_true_regexp_matching(false); @@ -484,6 +520,22 @@ state::state() _use_retained_scheduling_info(default_use_retained_scheduling_info), _use_setpgid(default_use_setpgid), _use_syslog(default_use_syslog), + _log_v2_enabled(default_log_v2_enabled), + _log_legacy_enabled(default_log_legacy_enabled), + _log_v2_logger(default_log_v2_logger), + _log_level_functions(default_log_level_functions), + _log_level_config(default_log_level_config), + _log_level_events(default_log_level_events), + _log_level_checks(default_log_level_checks), + _log_level_notifications(default_log_level_notifications), + _log_level_eventbroker(default_log_level_eventbroker), + _log_level_external_command(default_log_level_external_command), + _log_level_commands(default_log_level_commands), + _log_level_downtimes(default_log_level_downtimes), + _log_level_comments(default_log_level_comments), + _log_level_macros(default_log_level_macros), + _log_level_process(default_log_level_process), + _log_level_runtime(default_log_level_runtime), _use_timezone(default_use_timezone), _use_true_regexp_matching(default_use_true_regexp_matching) {} @@ -647,6 +699,22 @@ state& state::operator=(state const& right) { _use_retained_scheduling_info = right._use_retained_scheduling_info; _use_setpgid = right._use_setpgid; _use_syslog = right._use_syslog; + _log_v2_enabled = right._log_v2_enabled; + _log_legacy_enabled = right._log_legacy_enabled; + _log_v2_logger = right._log_v2_logger; + _log_level_functions = right._log_level_functions; + _log_level_config = right._log_level_config; + _log_level_events = right._log_level_events; + _log_level_checks = right._log_level_checks; + _log_level_notifications = right._log_level_notifications; + _log_level_eventbroker = right._log_level_eventbroker; + _log_level_external_command = right._log_level_external_command; + _log_level_commands = right._log_level_commands; + _log_level_downtimes = right._log_level_downtimes; + _log_level_comments = right._log_level_comments; + _log_level_macros = right._log_level_macros; + _log_level_process = right._log_level_process; + _log_level_runtime = right._log_level_runtime; _use_timezone = right._use_timezone; _use_true_regexp_matching = right._use_true_regexp_matching; } @@ -798,6 +866,22 @@ bool state::operator==(state const& right) const noexcept { _use_retained_program_state == right._use_retained_program_state && _use_retained_scheduling_info == right._use_retained_scheduling_info && _use_setpgid == right._use_setpgid && _use_syslog == right._use_syslog && + _log_v2_enabled == right._log_v2_enabled && + _log_legacy_enabled == right._log_legacy_enabled && + _log_v2_logger == right._log_v2_logger && + _log_level_functions == right._log_level_functions && + _log_level_config == right._log_level_config && + _log_level_events == right._log_level_events && + _log_level_checks == right._log_level_checks && + _log_level_notifications == right._log_level_notifications && + _log_level_eventbroker == right._log_level_eventbroker && + _log_level_external_command == right._log_level_external_command && + _log_level_commands == right._log_level_commands && + _log_level_downtimes == right._log_level_downtimes && + _log_level_comments == right._log_level_comments && + _log_level_macros == right._log_level_macros && + _log_level_process == right._log_level_process && + _log_level_runtime == right._log_level_runtime && _use_timezone == right._use_timezone && _use_true_regexp_matching == right._use_true_regexp_matching); } @@ -955,7 +1039,7 @@ unsigned int state::auto_rescheduling_interval() const noexcept { */ void state::auto_rescheduling_interval(unsigned int value) { if (!value) - throw(engine_error() << "auto_rescheduling_interval cannot be 0"); + throw engine_error() << "auto_rescheduling_interval cannot be 0"; _auto_rescheduling_interval = value; } @@ -975,7 +1059,7 @@ unsigned int state::auto_rescheduling_window() const noexcept { */ void state::auto_rescheduling_window(unsigned int value) { if (!value) - throw(engine_error() << "auto_rescheduling_window cannot be 0"); + throw engine_error() << "auto_rescheduling_window cannot be 0"; _auto_rescheduling_window = value; } @@ -1181,7 +1265,7 @@ unsigned int state::check_reaper_interval() const noexcept { */ void state::check_reaper_interval(unsigned int value) { if (!value) - throw(engine_error() << "check_reaper_interval cannot be 0"); + throw engine_error() << "check_reaper_interval cannot be 0"; _check_reaper_interval = value; } @@ -1274,9 +1358,9 @@ int state::command_check_interval() const noexcept { */ void state::command_check_interval(int value) { if (value < -1 || !value) - throw(engine_error() - << "command_check_interval must be either positive or -1 (" << value - << " provided)"); + throw engine_error() + << "command_check_interval must be either positive or -1 (" << value + << " provided)"; _command_check_interval = value; @@ -1710,7 +1794,7 @@ unsigned int state::event_handler_timeout() const noexcept { */ void state::event_handler_timeout(unsigned int value) { if (!value) - throw(engine_error() << "event_handler_timeout cannot be 0"); + throw engine_error() << "event_handler_timeout cannot be 0"; _event_handler_timeout = value; } @@ -1820,8 +1904,8 @@ float state::high_host_flap_threshold() const noexcept { */ void state::high_host_flap_threshold(float value) { if (value <= 0.0 || value >= 100.0) - throw(engine_error() << "high_host_flap_threshold must " - << "be between 0.0 and 100.0, both excluded"); + throw engine_error() << "high_host_flap_threshold must " + << "be between 0.0 and 100.0, both excluded"; _high_host_flap_threshold = value; } @@ -1841,8 +1925,8 @@ float state::high_service_flap_threshold() const noexcept { */ void state::high_service_flap_threshold(float value) { if (value <= 0.0 || value >= 100.0) - throw(engine_error() << "high_service_flap_threshold " - << "must be between 0.0 and 100.0, both excluded"); + throw engine_error() << "high_service_flap_threshold " + << "must be between 0.0 and 100.0, both excluded"; _high_service_flap_threshold = value; } @@ -2014,7 +2098,7 @@ unsigned int state::host_check_timeout() const noexcept { */ void state::host_check_timeout(unsigned int value) { if (!value) - throw(engine_error() << "host_check_timeout cannot be 0"); + throw engine_error() << "host_check_timeout cannot be 0"; _host_check_timeout = value; } @@ -2113,8 +2197,8 @@ void state::host_perfdata_file_mode(perfdata_file_mode value) { * * @return The host_perfdata_file_processing_command value. */ -std::string const& state::host_perfdata_file_processing_command() - const noexcept { +std::string const& state::host_perfdata_file_processing_command() const + noexcept { return _host_perfdata_file_processing_command; } @@ -2215,7 +2299,7 @@ unsigned int state::interval_length() const noexcept { */ void state::interval_length(unsigned int value) { if (!value) - throw(engine_error() << "interval_length cannot be 0"); + throw engine_error() << "interval_length cannot be 0"; if (!_command_check_interval_is_seconds && _command_check_interval != -1) { _command_check_interval /= _interval_length; @@ -2385,8 +2469,8 @@ float state::low_host_flap_threshold() const noexcept { */ void state::low_host_flap_threshold(float value) { if (value <= 0.0 || value >= 100.0) - throw(engine_error() << "low_host_flap_threshold " - << "must be between 0.0 and 100.0, both excluded"); + throw engine_error() << "low_host_flap_threshold " + << "must be between 0.0 and 100.0, both excluded"; _low_host_flap_threshold = value; } @@ -2406,8 +2490,8 @@ float state::low_service_flap_threshold() const noexcept { */ void state::low_service_flap_threshold(float value) { if (value <= 0.0 || value >= 100.0) - throw(engine_error() << "low_service_flap_threshold " - << "must be between 0.0 and 100.0, both excluded"); + throw engine_error() << "low_service_flap_threshold " + << "must be between 0.0 and 100.0, both excluded"; _low_service_flap_threshold = value; } @@ -2427,7 +2511,7 @@ unsigned int state::max_check_reaper_time() const noexcept { */ void state::max_check_reaper_time(unsigned int value) { if (!value) - throw(engine_error() << "max_check_reaper_time cannot be 0"); + throw engine_error() << "max_check_reaper_time cannot be 0"; _max_check_reaper_time = value; } @@ -2465,7 +2549,7 @@ unsigned int state::max_host_check_spread() const noexcept { */ void state::max_host_check_spread(unsigned int value) { if (!value) - throw(engine_error() << "max_host_check_spread cannot be 0"); + throw engine_error() << "max_host_check_spread cannot be 0"; _max_host_check_spread = value; } @@ -2521,7 +2605,7 @@ unsigned int state::max_service_check_spread() const noexcept { */ void state::max_service_check_spread(unsigned int value) { if (!value) - throw(engine_error() << "max_service_check_spread cannot be 0"); + throw engine_error() << "max_service_check_spread cannot be 0"; _max_service_check_spread = value; } @@ -2541,7 +2625,7 @@ unsigned int state::notification_timeout() const noexcept { */ void state::notification_timeout(unsigned int value) { if (!value) - throw(engine_error() << "notification_timeout cannot be 0"); + throw engine_error() << "notification_timeout cannot be 0"; _notification_timeout = value; } @@ -2615,7 +2699,7 @@ unsigned int state::ochp_timeout() const noexcept { */ void state::ochp_timeout(unsigned int value) { if (!value) - throw(engine_error() << "ochp_timeout cannot be 0"); + throw engine_error() << "ochp_timeout cannot be 0"; _ochp_timeout = value; } @@ -2653,7 +2737,7 @@ unsigned int state::ocsp_timeout() const noexcept { */ void state::ocsp_timeout(unsigned int value) { if (!value) - throw(engine_error() << "ocsp_timeout cannot be 0"); + throw engine_error() << "ocsp_timeout cannot be 0"; _ocsp_timeout = value; } @@ -2889,7 +2973,7 @@ unsigned int state::retention_scheduling_horizon() const noexcept { */ void state::retention_scheduling_horizon(unsigned int value) { if (!value) - throw(engine_error() << "retention_scheduling_horizon cannot be 0"); + throw engine_error() << "retention_scheduling_horizon cannot be 0"; _retention_scheduling_horizon = value; } @@ -2909,7 +2993,7 @@ unsigned int state::retention_update_interval() const noexcept { */ void state::retention_update_interval(unsigned int value) { if (!value) - throw(engine_error() << "retention_update_interval cannot be 0"); + throw engine_error() << "retention_update_interval cannot be 0"; _retention_update_interval = value; } @@ -3114,7 +3198,7 @@ unsigned int state::service_check_timeout() const noexcept { */ void state::service_check_timeout(unsigned int value) { if (!value) - throw(engine_error() << "service_check_timeout cannot be 0"); + throw engine_error() << "service_check_timeout cannot be 0"; _service_check_timeout = value; } @@ -3134,7 +3218,7 @@ unsigned int state::service_freshness_check_interval() const noexcept { */ void state::service_freshness_check_interval(unsigned int value) { if (!value) - throw(engine_error() << "service_freshness_check_interval cannot be 0"); + throw engine_error() << "service_freshness_check_interval cannot be 0"; _service_freshness_check_interval = value; } @@ -3143,8 +3227,8 @@ void state::service_freshness_check_interval(unsigned int value) { * * @return The service_inter_check_delay_method value. */ -state::inter_check_delay state::service_inter_check_delay_method() - const noexcept { +state::inter_check_delay state::service_inter_check_delay_method() const + noexcept { return _service_inter_check_delay_method; } @@ -3162,8 +3246,8 @@ void state::service_inter_check_delay_method(inter_check_delay value) { * * @return The service_interleave_factor_method value. */ -state::interleave_factor state::service_interleave_factor_method() - const noexcept { +state::interleave_factor state::service_interleave_factor_method() const + noexcept { return _service_interleave_factor_method; } @@ -3235,8 +3319,8 @@ void state::service_perfdata_file_mode(perfdata_file_mode value) { * * @return The service_perfdata_file_processing_command value. */ -std::string const& state::service_perfdata_file_processing_command() - const noexcept { +std::string const& state::service_perfdata_file_processing_command() const + noexcept { return _service_perfdata_file_processing_command; } @@ -3301,8 +3385,8 @@ float state::sleep_time() const noexcept { */ void state::sleep_time(float value) { if (value <= 0.0) - throw(engine_error() << "sleep_time cannot be less or equal to 0 (" << value - << " provided)"); + throw engine_error() << "sleep_time cannot be less or equal to 0 (" << value + << " provided)"; _sleep_time = value; } @@ -3382,8 +3466,8 @@ unsigned int state::status_update_interval() const noexcept { */ void state::status_update_interval(unsigned int value) { if (value < 2) - throw(engine_error() << "status_update_interval cannot be less than 2 (" - << value << " provided)"); + throw engine_error() << "status_update_interval cannot be less than 2 (" + << value << " provided)"; _status_update_interval = value; } @@ -3402,7 +3486,8 @@ bool state::set(char const* key, char const* value) { if (it != _setters.end()) return (it->second)(*this, value); } catch (std::exception const& e) { - logger(log_config_error, basic) << e.what(); + engine_logger(log_config_error, basic) << e.what(); + log_v2::config()->error(e.what()); return false; } return true; @@ -3480,8 +3565,8 @@ unsigned int state::time_change_threshold() const noexcept { */ void state::time_change_threshold(unsigned int value) { if (value < 6) - throw(engine_error() << "time_change_threshold cannot be less than 6 (" - << value << " provided)"); + throw engine_error() << "time_change_threshold cannot be less than 6 (" + << value << " provided)"; _time_change_threshold = value; } @@ -3508,8 +3593,8 @@ void state::translate_passive_host_checks(bool value) { * * @return The users resources list. */ -std::unordered_map const& state::user() - const noexcept { +std::unordered_map const& state::user() const + noexcept { return _users; } @@ -3530,7 +3615,7 @@ void state::user(std::unordered_map const& value) { */ void state::user(std::string const& key, std::string const& value) { if (key.size() < 3 || key[0] != '$' || key[key.size() - 1] != '$') - throw(engine_error() << "Invalid user key '" << key << "'"); + throw engine_error() << "Invalid user key '" << key << "'"; std::string new_key = key; new_key.erase(new_key.begin(), new_key.begin() + 1); new_key.erase(new_key.end() - 1, new_key.end()); @@ -3554,9 +3639,12 @@ void state::user(unsigned int key, std::string const& value) { * @param[in] value The new use_aggressive_host_checking value. */ void state::use_aggressive_host_checking(bool value __attribute__((unused))) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: use_aggressive_host_checking is deprecated." " This option is no more supported since version 21.04."; + log_v2::config()->warn( + "Warning: use_aggressive_host_checking is deprecated. This option is no " + "more supported since version 21.04."); ++config_warnings; } @@ -3687,6 +3775,338 @@ void state::use_syslog(bool value) { _use_syslog = value; } +/** + * Get log_v2_enabled value. + * + * @return The log_v2_enabled value. + */ +bool state::log_v2_enabled() const noexcept { + return _log_v2_enabled; +} + +/** + * Set log_v2_enabled value. + * + * @param[in] value The new log_v2_enabled value. + */ +void state::log_v2_enabled(bool value) { + _log_v2_enabled = value; +} + +/** + * Get log_legacy_enabled value. + * + * @return The log_legacy_enabled value. + */ +bool state::log_legacy_enabled() const noexcept { + return _log_legacy_enabled; +} + +/** + * Set log_legacy_enabled value. + * + * @param[in] value The new log_legacy_enabled value. + */ +void state::log_legacy_enabled(bool value) { + _log_legacy_enabled = value; +} + +/** + * Get log_v2_logger value. + * + * @return The log_v2_logger value. + */ +std::string const& state::log_v2_logger() const noexcept { + return _log_v2_logger; +} + +/** + * Set log_v2_logger value. + * + * @param[in] value The new log_v2_logger value. + */ +void state::log_v2_logger(std::string const& value) { + if (value.empty()) + throw engine_error() << "log_v2_logger cannot be empty"; + _log_v2_logger = value; +} + +/** + * Get log_level_functions value. + * + * @return The log_level_functions value. + */ +std::string const& state::log_level_functions() const noexcept { + return _log_level_functions; +} + +/** + * Set log_level_functions value. + * + * @param[in] value The new log_level_functions value. + */ +void state::log_level_functions(std::string const& value) { + if (log_v2::contains_level(value)) + _log_level_functions = value; + else + throw engine_error() << "error wrong level setted for log_level_functions"; +} + +/** + * Get log_level_config value. + * + * @return The log_level_config value. + */ +std::string const& state::log_level_config() const noexcept { + return _log_level_config; +} + +/** + * Set log_level_config value. + * + * @param[in] value The new log_level_config value. + */ +void state::log_level_config(std::string const& value) { + if (log_v2::contains_level(value)) + _log_level_config = value; + else + throw engine_error() << "error wrong level setted for log_level_config"; +} + +/** + * Get log_level_events value. + * + * @return The log_level_events value. + */ +std::string const& state::log_level_events() const noexcept { + return _log_level_events; +} + +/** + * Set log_level_events value. + * + * @param[in] value The new log_level_events value. + */ +void state::log_level_events(std::string const& value) { + if (log_v2::contains_level(value)) + _log_level_events = value; + else + throw engine_error() << "error wrong level setted for log_level_events"; +} + +/** + * Get log_level_checks value. + * + * @return The log_level_checks value. + */ +std::string const& state::log_level_checks() const noexcept { + return _log_level_checks; +} + +/** + * Set log_level_checks value. + * + * @param[in] value The new log_level_checks value. + */ +void state::log_level_checks(std::string const& value) { + if (log_v2::contains_level(value)) + _log_level_checks = value; + else + throw engine_error() << "error wrong level setted for log_level_checks"; +} + +/** + * Get log_level_notifications value. + * + * @return The log_level_notifications value. + */ +std::string const& state::log_level_notifications() const noexcept { + return _log_level_notifications; +} + +/** + * Set log_level_notifications value. + * + * @param[in] value The new log_level_notifications value. + */ +void state::log_level_notifications(std::string const& value) { + if (log_v2::contains_level(value)) + _log_level_notifications = value; + else + throw engine_error() + << "error wrong level setted for log_level_notifications"; +} + +/** + * Get log_level_eventbroker value. + * + * @return The log_level_eventbroker value. + */ +std::string const& state::log_level_eventbroker() const noexcept { + return _log_level_eventbroker; +} + +/** + * Set log_level_eventbroker value. + * + * @param[in] value The new log_level_eventbroker value. + */ +void state::log_level_eventbroker(std::string const& value) { + if (log_v2::contains_level(value)) + _log_level_eventbroker = value; + else + throw engine_error() + << "error wrong level setted for log_level_eventbroker"; +} + +/** + * Get log_level_external_command value. + * + * @return The log_level_external_command value. + */ +std::string const& state::log_level_external_command() const noexcept { + return _log_level_external_command; +} + +/** + * Set log_level_external_command value. + * + * @param[in] value The new log_level_external_command value. + */ +void state::log_level_external_command(std::string const& value) { + if (log_v2::contains_level(value)) + _log_level_external_command = value; + else + throw engine_error() + << "error wrong level setted for log_level_external_command"; +} + +/** + * Get log_level_commands value. + * + * @return The log_level_commands value. + */ +std::string const& state::log_level_commands() const noexcept { + return _log_level_commands; +} + +/** + * Set log_level_commands value. + * + * @param[in] value The new log_level_commands value. + */ +void state::log_level_commands(std::string const& value) { + if (log_v2::contains_level(value)) + _log_level_commands = value; + else + throw engine_error() << "error wrong level setted for log_level_commands"; +} + +/** + * Get log_level_downtimes value. + * + * @return The log_level_downtimes value. + */ +std::string const& state::log_level_downtimes() const noexcept { + return _log_level_downtimes; +} + +/** + * Set log_level_downtimes value. + * + * @param[in] value The new log_level_downtimes value. + */ +void state::log_level_downtimes(std::string const& value) { + if (log_v2::contains_level(value)) + _log_level_downtimes = value; + else + throw engine_error() << "error wrong level setted for log_level_downtimes"; +} + +/** + * Get log_level_comments value. + * + * @return The log_level_comments value. + */ +std::string const& state::log_level_comments() const noexcept { + return _log_level_comments; +} + +/** + * Set log_level_comments value. + * + * @param[in] value The new log_level_comments value. + */ +void state::log_level_comments(std::string const& value) { + if (log_v2::contains_level(value)) + _log_level_comments = value; + else + throw engine_error() << "error wrong level setted for log_level_comments"; +} + +/** + * Get log_level_macros value. + * + * @return The log_level_macros value. + */ +std::string const& state::log_level_macros() const noexcept { + return _log_level_macros; +} + +/** + * Set log_level_macros value. + * + * @param[in] value The new log_level_macros value. + */ +void state::log_level_macros(std::string const& value) { + if (log_v2::contains_level(value)) + _log_level_macros = value; + else + throw engine_error() << "error wrong level setted for log_level_macros"; +} + +/** + * Get log_level_process value. + * + * @return The log_level_process value. + */ +std::string const& state::log_level_process() const noexcept { + return _log_level_process; +} + +/** + * Set log_level_process value. + * + * @param[in] value The new log_level_process value. + */ +void state::log_level_process(std::string const& value) { + if (log_v2::contains_level(value)) + _log_level_process = value; + else + throw engine_error() << "error wrong level setted for log_level_process"; +} + +/** + * Get log_level_runtime value. + * + * @return The log_level_runtime value. + */ +std::string const& state::log_level_runtime() const noexcept { + return _log_level_runtime; +} + +/** + * Set log_level_runtime value. + * + * @param[in] value The new log_level_runtime value. + */ +void state::log_level_runtime(std::string const& value) { + if (log_v2::contains_level(value)) + _log_level_runtime = value; + else + throw engine_error() << "error wrong level setted for log_level_runtime"; +} + /** * Get use_timezone value. * @@ -3730,8 +4150,9 @@ void state::use_true_regexp_matching(bool value) { */ void state::_set_aggregate_status_updates(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: aggregate_status_updates variable ignored"; + log_v2::config()->warn("Warning: aggregate_status_updates variable ignored"); ++config_warnings; } @@ -3742,7 +4163,9 @@ void state::_set_aggregate_status_updates(std::string const& value) { */ void state::_set_auth_file(std::string const& value) { (void)value; - logger(log_config_warning, basic) << "Warning: auth_file variable ignored"; + engine_logger(log_config_warning, basic) + << "Warning: auth_file variable ignored"; + log_v2::config()->warn("Warning: auth_file variable ignored"); ++config_warnings; } @@ -3753,8 +4176,9 @@ void state::_set_auth_file(std::string const& value) { */ void state::_set_bare_update_check(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: bare_update_check variable ignored"; + log_v2::config()->warn("Warning: bare_update_check variable ignored"); ++config_warnings; } @@ -3804,8 +4228,9 @@ void state::_set_cfg_file(std::string const& value) { */ void state::_set_check_for_updates(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: check_for_updates variable ignored"; + log_v2::config()->warn("Warning: check_for_updates variable ignored"); ++config_warnings; } @@ -3816,8 +4241,10 @@ void state::_set_check_for_updates(std::string const& value) { */ void state::_set_child_processes_fork_twice(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: child_processes_fork_twice variable ignored"; + log_v2::config()->warn( + "Warning: child_processes_fork_twice variable ignored"); ++config_warnings; } @@ -3845,7 +4272,9 @@ void state::_set_command_check_interval(std::string const& value) { */ void state::_set_comment_file(std::string const& value) { (void)value; - logger(log_config_warning, basic) << "Warning: comment_file variable ignored"; + engine_logger(log_config_warning, basic) + << "Warning: comment_file variable ignored"; + log_v2::config()->warn("Warning: comment_file variable ignored"); ++config_warnings; } @@ -3856,8 +4285,9 @@ void state::_set_comment_file(std::string const& value) { */ void state::_set_daemon_dumps_core(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: daemon_dumps_core variable ignored"; + log_v2::config()->warn("Warning: daemon_dumps_core variable ignored"); ++config_warnings; } @@ -3884,8 +4314,9 @@ void state::_set_date_format(std::string const& value) { */ void state::_set_downtime_file(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: downtime_file variable ignored"; + log_v2::config()->warn("Warning: downtime_file variable ignored"); ++config_warnings; } @@ -3896,8 +4327,9 @@ void state::_set_downtime_file(std::string const& value) { */ void state::_set_enable_embedded_perl(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: enable_embedded_perl variable ignored"; + log_v2::config()->warn("Warning: enable_embedded_perl variable ignored"); ++config_warnings; } @@ -3908,8 +4340,9 @@ void state::_set_enable_embedded_perl(std::string const& value) { */ void state::_set_enable_failure_prediction(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: enable_failure_prediction variable ignored"; + log_v2::config()->warn("Warning: enable_failure_prediction variable ignored"); ++config_warnings; return; } @@ -3935,8 +4368,9 @@ void state::_set_event_broker_options(std::string const& value) { */ void state::_set_free_child_process_memory(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: free_child_process_memory variable ignored"; + log_v2::config()->warn("Warning: free_child_process_memory variable ignored"); ++config_warnings; } @@ -3956,10 +4390,10 @@ void state::_set_host_inter_check_delay_method(std::string const& value) { _host_inter_check_delay_method = icd_user; if (!string::to(value.c_str(), scheduling_info.host_inter_check_delay) || scheduling_info.host_inter_check_delay <= 0.0) - throw(engine_error() - << "Invalid value for host_inter_check_delay_method, must " - << "be one of 'n' (none), 'd' (dumb), 's' (smart) or a " - << "stricly positive value (" << value << " provided)"); + throw engine_error() + << "Invalid value for host_inter_check_delay_method, must " + << "be one of 'n' (none), 'd' (dumb), 's' (smart) or a " + << "stricly positive value (" << value << " provided)"; } } @@ -3984,7 +4418,9 @@ void state::_set_host_perfdata_file_mode(std::string const& value) { */ void state::_set_lock_file(std::string const& value) { (void)value; - logger(log_config_warning, basic) << "Warning: lock_file variable ignored"; + engine_logger(log_config_warning, basic) + << "Warning: lock_file variable ignored"; + log_v2::config()->warn("Warning: lock_file variable ignored"); ++config_warnings; } @@ -3995,8 +4431,9 @@ void state::_set_lock_file(std::string const& value) { */ void state::_set_log_archive_path(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: log_archive_path variable ignored"; + log_v2::config()->warn("Warning: log_archive_path variable ignored"); ++config_warnings; } @@ -4007,8 +4444,9 @@ void state::_set_log_archive_path(std::string const& value) { */ void state::_set_log_initial_states(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: log_initial_states variable ignored"; + log_v2::config()->warn("Warning: log_initial_states variable ignored"); ++config_warnings; return; } @@ -4020,8 +4458,9 @@ void state::_set_log_initial_states(std::string const& value) { */ void state::_set_log_rotation_method(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: log_rotation_method variable ignored"; + log_v2::config()->warn("Warning: log_rotation_method variable ignored"); ++config_warnings; } @@ -4032,7 +4471,9 @@ void state::_set_log_rotation_method(std::string const& value) { */ void state::_set_nagios_group(std::string const& value) { (void)value; - logger(log_config_warning, basic) << "Warning: nagios_group variable ignored"; + engine_logger(log_config_warning, basic) + << "Warning: nagios_group variable ignored"; + log_v2::config()->warn("Warning: nagios_group variable ignored"); ++config_warnings; } @@ -4043,7 +4484,9 @@ void state::_set_nagios_group(std::string const& value) { */ void state::_set_nagios_user(std::string const& value) { (void)value; - logger(log_config_warning, basic) << "Warning: nagios_user variable ignored"; + engine_logger(log_config_warning, basic) + << "Warning: nagios_user variable ignored"; + log_v2::config()->warn("Warning: nagios_user variable ignored"); ++config_warnings; } @@ -4054,8 +4497,9 @@ void state::_set_nagios_user(std::string const& value) { */ void state::_set_object_cache_file(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: object_cache_file variable ignored"; + log_v2::config()->warn("Warning: object_cache_file variable ignored"); ++config_warnings; } @@ -4066,7 +4510,10 @@ void state::_set_object_cache_file(std::string const& value) { */ void state::_set_p1_file(std::string const& value) { (void)value; - logger(log_config_warning, basic) << "Warning: p1_file variable ignored"; + engine_logger(log_config_warning, basic) + << "Warning: p1_file variable ignored"; + log_v2::config()->warn("Warning: p1_file variable ignored"); + ++config_warnings; } @@ -4077,8 +4524,9 @@ void state::_set_p1_file(std::string const& value) { */ void state::_set_precached_object_file(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: precached_object_file variable ignored"; + log_v2::config()->warn("Warning: precached_object_file variable ignored"); ++config_warnings; } @@ -4105,8 +4553,10 @@ void state::_set_resource_file(std::string const& value) { void state::_set_retained_process_service_attribute_mask( std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: retained_process_service_attribute_mask variable ignored"; + log_v2::config()->warn( + "Warning: retained_process_service_attribute_mask variable ignored"); ++config_warnings; } @@ -4117,8 +4567,10 @@ void state::_set_retained_process_service_attribute_mask( */ void state::_set_retained_service_attribute_mask(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: retained_service_attribute_mask variable ignored"; + log_v2::config()->warn( + "Warning: retained_service_attribute_mask variable ignored"); ++config_warnings; } @@ -4138,10 +4590,10 @@ void state::_set_service_inter_check_delay_method(std::string const& value) { _service_inter_check_delay_method = icd_user; if (!string::to(value.c_str(), scheduling_info.service_inter_check_delay) || scheduling_info.service_inter_check_delay <= 0.0) - throw(engine_error() - << "Invalid value for service_inter_check_delay_method, " - << "must be one of 'n' (none), 'd' (dumb), 's' (smart) or " - << "a strictly positive value (" << value << " provided)"); + throw engine_error() + << "Invalid value for service_inter_check_delay_method, " + << "must be one of 'n' (none), 'd' (dumb), 's' (smart) or " + << "a strictly positive value (" << value << " provided)"; } } @@ -4182,7 +4634,9 @@ void state::_set_service_perfdata_file_mode(std::string const& value) { */ void state::_set_temp_file(std::string const& value) { (void)value; - logger(log_config_warning, basic) << "Warning: temp_file variable ignored"; + engine_logger(log_config_warning, basic) + << "Warning: temp_file variable ignored"; + log_v2::config()->warn("Warning: temp_file variable ignored"); ++config_warnings; } @@ -4193,7 +4647,9 @@ void state::_set_temp_file(std::string const& value) { */ void state::_set_temp_path(std::string const& value) { (void)value; - logger(log_config_warning, basic) << "Warning: temp_path variable ignored"; + engine_logger(log_config_warning, basic) + << "Warning: temp_path variable ignored"; + log_v2::config()->warn("Warning: temp_path variable ignored"); ++config_warnings; } @@ -4204,8 +4660,10 @@ void state::_set_temp_path(std::string const& value) { */ void state::_set_use_embedded_perl_implicitly(std::string const& value) { (void)value; - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: use_embedded_perl_implicitly variable ignored"; + log_v2::config()->warn( + "Warning: use_embedded_perl_implicitly variable ignored"); ++config_warnings; } diff --git a/centreon-engine/src/contact.cc b/centreon-engine/src/contact.cc index 00acbb7cf8b..9a499880aa8 100644 --- a/centreon-engine/src/contact.cc +++ b/centreon-engine/src/contact.cc @@ -24,6 +24,7 @@ #include "com/centreon/engine/deleter/listmember.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/notification.hh" #include "com/centreon/engine/shared.hh" @@ -531,15 +532,18 @@ std::shared_ptr add_contact( int retain_nonstatus_information) { // Make sure we have the data we need. if (name.empty()) { - logger(log_config_error, basic) << "Error: Contact name is empty"; + engine_logger(log_config_error, basic) << "Error: Contact name is empty"; + log_v2::config()->error("Error: Contact name is empty"); return nullptr; } // Check if the contact already exist. std::string const& id(name); if (contact::contacts.count(id)) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Contact '" << name << "' has already been defined"; + log_v2::config()->error("Error: Contact '{}' has already been defined", + name); return nullptr; } @@ -838,36 +842,45 @@ contactgroup_map_unsafe& contact::get_parent_groups() { bool contact::should_be_notified(notifier::notification_category cat, notifier::reason_type type, notifier const& notif) const { - logger(dbg_functions, basic) << "contact::should_be_notified()"; + engine_logger(dbg_functions, basic) << "contact::should_be_notified()"; + log_v2::functions()->trace("contact::should_be_notified()"); /* Are notifications enabled? */ switch (notif.get_notifier_type()) { case notifier::service_notification: { if (!_service_notifications_enabled) { - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "This contact shouldn't be notified from services."; + log_v2::notifications()->info( + "This contact shouldn't be notified from services."); return false; } // See if the contact can be notified at this time for the host. timezone_locker lock(get_timezone()); if (!check_time_against_period_for_notif( std::time(nullptr), get_service_notification_period_ptr())) { - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "This contact shouldn't be notified at this time."; + log_v2::notifications()->info( + "This contact shouldn't be notified at this time."); return false; } } break; case notifier::host_notification: { if (!_host_notifications_enabled) { - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "This contact shouldn't be notified from hosts."; + log_v2::notifications()->info( + "This contact shouldn't be notified from hosts."); return false; } // See if the contact can be notified at this time for the service. timezone_locker lock(get_timezone()); if (!check_time_against_period_for_notif( std::time(nullptr), get_host_notification_period_ptr())) { - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "This contact shouldn't be notified at this time."; + log_v2::notifications()->info( + "This contact shouldn't be notified at this time."); return false; } } break; @@ -878,7 +891,8 @@ bool contact::should_be_notified(notifier::notification_category cat, bool contact::_to_notify_normal(notifier::reason_type type __attribute__((unused)), notifier const& notif) const { - logger(dbg_functions, basic) << "contact::_to_notify_normal()"; + engine_logger(dbg_functions, basic) << "contact::_to_notify_normal()"; + log_v2::functions()->trace("contact::_to_notify_normal()"); notifier::notifier_type nt{notif.get_notifier_type()}; int state{notif.get_current_state_int()}; @@ -894,9 +908,13 @@ bool contact::_to_notify_normal(notifier::reason_type type t = type[state]; } if (!notify_on(nt, t)) { - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "We shouldn't notify this contact about state " << state << " since it is not configured for this contact."; + log_v2::notifications()->info( + "We shouldn't notify this contact about state {} since it is not " + "configured for this contact.", + state); return false; } @@ -906,24 +924,32 @@ bool contact::_to_notify_normal(notifier::reason_type type bool contact::_to_notify_recovery(notifier::reason_type type __attribute__((unused)), notifier const& notif) const { - logger(dbg_functions, basic) << "contact::_to_notify_recovery()"; + engine_logger(dbg_functions, basic) << "contact::_to_notify_recovery()"; + log_v2::functions()->trace("contact::_to_notify_recovery()"); notifier::notifier_type nt{notif.get_notifier_type()}; if (!notify_on(nt, notifier::ok) && !notify_on(nt, notifier::up)) { - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "We shouldn't notify this contact about a " << (nt == notifier::service_notification ? "service" : "host") << " recovery."; + log_v2::notifications()->info( + "We shouldn't notify this contact about a {} recovery.", + (nt == notifier::service_notification ? "service" : "host")); return false; } notification* normal_notif = notif.get_current_notifications()[notifier::cat_normal].get(); if (!normal_notif || !normal_notif->sent_to(get_name())) { - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "We shouldn't notify this contact about a " << (nt == notifier::service_notification ? "service" : "host") << " recovery because he has not been notified about the incident."; + log_v2::notifications()->info( + "We shouldn't notify this contact about a {} recovery because he has " + "not been notified about the incident.", + (nt == notifier::service_notification ? "service" : "host")); return false; } @@ -934,19 +960,30 @@ bool contact::_to_notify_acknowledgement(notifier::reason_type type __attribute__((unused)), notifier const& notif __attribute__((unused))) const { - logger(dbg_functions, basic) << "contact::_to_notify_acknowledgement()"; - logger(dbg_notifications, most) + engine_logger(dbg_functions, basic) + << "contact::_to_notify_acknowledgement()"; + log_v2::functions()->trace("contact::_to_notify_acknowledgement()"); + engine_logger(dbg_notifications, most) << "** Checking if contact '" << get_name() << "' should be notified about a acknowledgement notification"; + log_v2::notifications()->info( + "** Checking if contact '{}' should be notified about a acknowledgement " + "notification", + get_name()); return true; } bool contact::_to_notify_flapping(notifier::reason_type type, notifier const& notif) const { - logger(dbg_functions, basic) << "contact::_to_notify_flapping()"; - logger(dbg_notifications, most) + engine_logger(dbg_functions, basic) << "contact::_to_notify_flapping()"; + log_v2::functions()->trace("contact::_to_notify_flapping()"); + engine_logger(dbg_notifications, most) << "** Checking if contact '" << get_name() << "' should be notified about a flapping notification"; + log_v2::notifications()->info( + "** Checking if contact '{}' should be notified about a flapping " + "notification", + get_name()); notifier::notifier_type nt{notif.get_notifier_type()}; notifier::notification_flag what_notif; @@ -958,9 +995,12 @@ bool contact::_to_notify_flapping(notifier::reason_type type, what_notif = notifier::flappingdisabled; if (!notify_on(nt, what_notif)) { - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "We shouldn't notify contact '" << _name << "' about " << notifier::tab_notification_str[type] << " notifier events."; + log_v2::notifications()->info( + "We shouldn't notify contact '{}' about {} notifier events.", _name, + notifier::tab_notification_str[type]); return false; } return true; @@ -969,15 +1009,22 @@ bool contact::_to_notify_flapping(notifier::reason_type type, bool contact::_to_notify_downtime(notifier::reason_type type __attribute__((unused)), notifier const& notif) const { - logger(dbg_functions, basic) << "contact::_to_notify_downtime()"; - logger(dbg_notifications, most) + engine_logger(dbg_functions, basic) << "contact::_to_notify_downtime()"; + log_v2::functions()->trace("contact::_to_notify_downtime()"); + engine_logger(dbg_notifications, most) << "** Checking if contact '" << get_name() << "' should be notified about a downtime notification"; + log_v2::notifications()->info( + "** Checking if contact '{}' should be notified about a downtime " + "notification", + get_name()); notifier::notifier_type nt{notif.get_notifier_type()}; if (!notify_on(nt, notifier::downtime)) { - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "We shouldn't notify this contact about DOWNTIME notifier events."; + log_v2::notifications()->info( + "We shouldn't notify this contact about DOWNTIME notifier events."); return false; } return true; @@ -987,161 +1034,57 @@ bool contact::_to_notify_custom(notifier::reason_type type __attribute__((unused)), notifier const& notif __attribute__((unused))) const { - logger(dbg_functions, basic) << "contact::_to_notify_custom()"; - logger(dbg_notifications, most) + engine_logger(dbg_functions, basic) << "contact::_to_notify_custom()"; + log_v2::functions()->trace("contact::_to_notify_custom()"); + engine_logger(dbg_notifications, most) << "** Checking if contact '" << _name << "' should be notified about a custom notification"; + log_v2::notifications()->info( + "** Checking if contact '{}' should be notified about a custom " + "notification", + _name); return true; } -///* checks the viability of notifying a specific contact about a host */ -// int contact::check_host_notification_viability(host* hst, -// notifier::notification_category -// type, int options) { -// logger(dbg_functions, basic) -// << "check_contact_host_notification_viability()"; -// logger(dbg_notifications, most) -// << "** Checking host notification viability for contact '" -// << get_name() << "'..."; -// -// /* forced notifications bust through everything */ -// if (options & notifier::notification_option_forced) { -// logger(dbg_notifications, most) -// << "This is a forced host notification, so we'll " -// "send it out for this contact."; -// return OK; -// } -// -// /* are notifications enabled? */ -// if (!get_host_notifications_enabled()) { -// logger(dbg_notifications, most) -// << "Host notifications are disabled for this contact."; -// return ERROR; -// } -// -// // See if the contact can be notified at this time. -// { -// timezone_locker lock(get_timezone().c_str()); -// if (!check_time_against_period( -// time(nullptr), -// this->host_notification_period_ptr)) { -// logger(dbg_notifications, most) -// << "This contact shouldn't be notified at this time."; -// return ERROR; -// } -// } -// -// /*********************************************/ -// /*** SPECIAL CASE FOR CUSTOM NOTIFICATIONS ***/ -// /*********************************************/ -// -// /* custom notifications are good to go at this point... */ -// if (type == notifier::cat_custom) -// return OK; -// -// /****************************************/ -// /*** SPECIAL CASE FOR FLAPPING ALERTS ***/ -// /****************************************/ -// -// if (type == notifier::cat_flapping) { -// -// if (!notify_on(notifier::host_notification, notifier::flapping)) { -// logger(dbg_notifications, most) -// << "We shouldn't notify this contact about FLAPPING " -// "host events."; -// return ERROR; -// } -// -// return OK; -// } -// -// /****************************************/ -// /*** SPECIAL CASE FOR DOWNTIME ALERTS ***/ -// /****************************************/ -// -// if (type == notifier::cat_downtime) { -// -// if (!notify_on(notifier::host_notification, notifier::downtime)) { -// logger(dbg_notifications, most) -// << "We shouldn't notify this contact about DOWNTIME " -// "host events."; -// return ERROR; -// } -// -// return OK; -// } -// -// /*************************************/ -// /*** ACKS AND NORMAL NOTIFICATIONS ***/ -// /*************************************/ -// -// /* see if we should notify about problems with this host */ -// if (hst->get_current_state() == host::state_down -// && !notify_on(notifier::host_notification, notifier::down)) { -// logger(dbg_notifications, most) -// << "We shouldn't notify this contact about DOWN states."; -// return ERROR; -// } -// -// if (hst->get_current_state() == host::state_unreachable -// && !notify_on(notifier::host_notification, notifier::unreachable)) { -// logger(dbg_notifications, most) -// << "We shouldn't notify this contact about UNREACHABLE states,"; -// return ERROR; -// } -// -// if (hst->get_current_state() == host::state_up) { -// -// if (!notify_on(notifier::host_notification, notifier::recovery)) { -// logger(dbg_notifications, most) -// << "We shouldn't notify this contact about RECOVERY states."; -// return ERROR; -// } -// -// if (!((hst->get_notified_on(notifier::down) -// && notify_on(notifier::host_notification, notifier::down)) -// || (hst->get_notified_on(notifier::unreachable) -// && notify_on(notifier::host_notification, -// notifier::unreachable)))) { -// logger(dbg_notifications, most) -// << "We shouldn't notify about this recovery."; -// return ERROR; -// } -// -// } -// -// logger(dbg_notifications, most) -// << "** Host notification viability for contact '" -// << get_name() << "' PASSED."; -// -// return OK; -//} - void contact::resolve(int& w, int& e) { int warnings{0}, errors{0}; /* check service notification commands */ if (get_service_notification_commands().empty()) { - logger(log_verification_error, basic) << "Error: Contact '" << _name - << "' has no service " - "notification commands defined!"; + engine_logger(log_verification_error, basic) + << "Error: Contact '" << _name + << "' has no service " + "notification commands defined!"; + log_v2::config()->error( + "Error: Contact '{}' has no service " + "notification commands defined!", + _name); errors++; } /* check host notification commands */ if (get_host_notification_commands().empty()) { - logger(log_verification_error, basic) << "Error: Contact '" << _name - << "' has no host " - "notification commands defined!"; + engine_logger(log_verification_error, basic) + << "Error: Contact '" << _name + << "' has no host " + "notification commands defined!"; + log_v2::config()->error( + "Error: Contact '{}' has no host " + "notification commands defined!", + _name); errors++; } /* check service notification timeperiod */ if (get_service_notification_period().empty()) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Contact '" << _name << "' has no service " "notification time period defined!"; + log_v2::config()->warn( + "Warning: Contact '{}' has no service " + "notification time period defined!", + _name); warnings++; _service_notification_period_ptr = nullptr; } else { @@ -1149,10 +1092,14 @@ void contact::resolve(int& w, int& e) { timeperiod::timeperiods.find(get_service_notification_period())); if (it == timeperiod::timeperiods.end() || !it->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Service notification period '" << get_service_notification_period() << "' specified for contact '" << _name << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Service notification period '{}' specified for contact '{}' " + "is not defined anywhere!", + get_service_notification_period(), _name); errors++; _service_notification_period_ptr = nullptr; } else @@ -1162,10 +1109,14 @@ void contact::resolve(int& w, int& e) { /* check host notification timeperiod */ if (get_host_notification_period().empty()) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Contact '" << _name << "' has no host " "notification time period defined!"; + log_v2::config()->warn( + "Warning: Contact '{}' has no host " + "notification time period defined!", + _name); warnings++; _host_notification_period_ptr = nullptr; } else { @@ -1173,10 +1124,14 @@ void contact::resolve(int& w, int& e) { timeperiod::timeperiods.find(get_host_notification_period())); if (it == timeperiod::timeperiods.end() || !it->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Host notification period '" << get_host_notification_period() << "' specified for contact '" << _name << "' is not defined anywhere!"; + log_v2::config()->warn( + "Error: Host notification period '{}' specified for contact '{}' is " + "not defined anywhere!", + get_host_notification_period(), _name); errors++; _host_notification_period_ptr = nullptr; } else @@ -1188,10 +1143,15 @@ void contact::resolve(int& w, int& e) { if (notify_on(notifier::host_notification, notifier::up) && !notify_on(notifier::host_notification, notifier::down) && !notify_on(notifier::host_notification, notifier::unreachable)) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Host recovery notification option for contact '" << _name << "' doesn't make any sense - specify down " "and/or unreachable options as well"; + log_v2::config()->warn( + "Warning: Host recovery notification option for contact '{}' doesn't " + "make any sense - specify down " + "and/or unreachable options as well", + _name); warnings++; } @@ -1199,19 +1159,28 @@ void contact::resolve(int& w, int& e) { if (notify_on(notifier::service_notification, notifier::ok) && !notify_on(notifier::service_notification, notifier::critical) && !notify_on(notifier::service_notification, notifier::warning)) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Service recovery notification option for contact '" << _name << "' doesn't make any sense - specify critical " "and/or warning options as well"; + log_v2::config()->warn( + "Warning: Service recovery notification option for contact '{}' " + "doesn't make any sense - specify critical " + "and/or warning options as well", + _name); warnings++; } /* check for illegal characters in contact name */ if (contains_illegal_object_chars(const_cast(_name.c_str()))) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: The name of contact '" << _name << "' contains one or more illegal characters."; + log_v2::config()->error( + "Error: The name of contact '{}' contains one or more illegal " + "characters.", + _name); errors++; } diff --git a/centreon-engine/src/contactgroup.cc b/centreon-engine/src/contactgroup.cc index 2492db81568..ebb8dd62594 100644 --- a/centreon-engine/src/contactgroup.cc +++ b/centreon-engine/src/contactgroup.cc @@ -26,6 +26,7 @@ #include "com/centreon/engine/contactgroup.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/string.hh" @@ -127,9 +128,13 @@ void contactgroup::resolve(int& w __attribute__((unused)), int& e) { it != end; ++it) { /* Check members */ if (!it->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Contact '" << it->first << "' specified in contact group '" << _name << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Contact '{}' specified in contact group '{}' is not defined " + "anywhere!", + it->first, _name); errors++; } else it->second->get_parent_groups()[_name] = this; @@ -137,9 +142,13 @@ void contactgroup::resolve(int& w __attribute__((unused)), int& e) { /* Check for illegal characters in contact group name. */ if (contains_illegal_object_chars(const_cast(_name.c_str()))) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: The name of contact group '" << _name << "' contains one or more illegal characters."; + log_v2::config()->error( + "Error: The name of contact group '{}' contains one or more illegal " + "characters.", + _name); errors++; } diff --git a/centreon-engine/src/dependency.cc b/centreon-engine/src/dependency.cc index a66ce772c11..aa99a861419 100644 --- a/centreon-engine/src/dependency.cc +++ b/centreon-engine/src/dependency.cc @@ -20,6 +20,7 @@ #include "com/centreon/engine/dependency.hh" #include #include "com/centreon/engine/exceptions/error.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" using namespace com::centreon::engine; @@ -40,8 +41,10 @@ dependency::dependency(std::string const& dependent_hostname, _circular_path_checked{false}, _contains_circular_path{false} { if (dependent_hostname.empty() || hostname.empty()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: NULL host name in host dependency definition"; + log_v2::config()->error( + "Error: NULL host name in host dependency definition"); throw engine_error() << "Could not create execution " << "dependency of '" << dependent_hostname << "' on '" << hostname << "'"; diff --git a/centreon-engine/src/diagnostic.cc b/centreon-engine/src/diagnostic.cc index 519d839cc0c..fa3be34154b 100644 --- a/centreon-engine/src/diagnostic.cc +++ b/centreon-engine/src/diagnostic.cc @@ -24,11 +24,13 @@ #include #include #include +#include #include #include #include "com/centreon/engine/configuration/parser.hh" #include "com/centreon/engine/configuration/state.hh" #include "com/centreon/engine/exceptions/error.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/version.hh" #include "com/centreon/io/file_stream.hh" @@ -90,12 +92,11 @@ void diagnostic::generate(std::string const& cfg_file, std::vector to_remove; // Base information about the software. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: Centreon Engine " << CENTREON_ENGINE_VERSION_STRING; + std::cout << "Diagnostic: Centreon Engine " << CENTREON_ENGINE_VERSION_STRING + << std::endl; // df. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: Getting disk usage"; + std::cout << "Diagnostic: Getting disk usage" << std::endl; { std::string df_log_path(tmp_dir + "/df.log"); to_remove.push_back(df_log_path); @@ -103,8 +104,7 @@ void diagnostic::generate(std::string const& cfg_file, } // lsb_release. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: Getting LSB information"; + std::cout << "Diagnostic: Getting LSB information" << std::endl; { std::string lsb_release_log_path(tmp_dir + "/lsb_release.log"); to_remove.push_back(lsb_release_log_path); @@ -112,8 +112,7 @@ void diagnostic::generate(std::string const& cfg_file, } // uname. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: Getting system name"; + std::cout << "Diagnostic: Getting system name" << std::endl; { std::string uname_log_path(tmp_dir + "/uname.log"); to_remove.push_back(uname_log_path); @@ -121,8 +120,7 @@ void diagnostic::generate(std::string const& cfg_file, } // /proc/version - logger(logging::log_info_message, logging::basic) - << "Diagnostic: Getting kernel information"; + std::cout << "Diagnostic: Getting kernel information" << std::endl; { std::string proc_version_log_path(tmp_dir + "/proc_version.log"); to_remove.push_back(proc_version_log_path); @@ -130,8 +128,8 @@ void diagnostic::generate(std::string const& cfg_file, } // netstat. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: Getting network connections information"; + std::cout << "Diagnostic: Getting network connections information" + << std::endl; { std::string netstat_log_path(tmp_dir + "/netstat.log"); to_remove.push_back(netstat_log_path); @@ -139,8 +137,7 @@ void diagnostic::generate(std::string const& cfg_file, } // ps. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: Getting processes information"; + std::cout << "Diagnostic: Getting processes information" << std::endl; { std::string ps_log_path(tmp_dir + "/ps.log"); to_remove.push_back(ps_log_path); @@ -148,8 +145,7 @@ void diagnostic::generate(std::string const& cfg_file, } // rpm. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: Getting packages information"; + std::cout << "Diagnostic: Getting packages information" << std::endl; { std::string rpm_log_path(tmp_dir + "/rpm.log"); to_remove.push_back(rpm_log_path); @@ -157,8 +153,7 @@ void diagnostic::generate(std::string const& cfg_file, } // sestatus. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: Getting SELinux status"; + std::cout << "Diagnostic: Getting SELinux status" << std::endl; { std::string sestatus_log_path(tmp_dir + "/selinux.log"); to_remove.push_back(sestatus_log_path); @@ -166,16 +161,15 @@ void diagnostic::generate(std::string const& cfg_file, } // Parse configuration file. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: Parsing configuration file '" << cfg_file << "'"; + std::cout << "Diagnostic: Parsing configuration file '" << cfg_file << "'" + << std::endl; configuration::state conf; try { configuration::parser parsr; parsr.parse(cfg_file, conf); } catch (std::exception const& e) { - logger(logging::log_runtime_error, logging::basic) - << "Diagnostic: configuration file '" << cfg_file - << "' parsing failed: " << e.what(); + std::cerr << "Diagnostic: configuration file '" << cfg_file + << "' parsing failed: " << e.what() << std::endl; } // Create temporary configuration directory. @@ -187,8 +181,7 @@ void diagnostic::generate(std::string const& cfg_file, } // Copy base configuration file. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: Copying configuration files"; + std::cout << "Diagnostic: Copying configuration files" << std::endl; { std::string target_path(_build_target_path(tmp_cfg_dir, cfg_file)); to_remove.push_back(target_path); @@ -213,8 +206,7 @@ void diagnostic::generate(std::string const& cfg_file, } // Log file. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: getting log file"; + std::cout << "Diagnostic: getting log file" << std::endl; { std::string target_path(_build_target_path(tmp_log_dir, conf.log_file())); to_remove.push_back(target_path); @@ -222,8 +214,7 @@ void diagnostic::generate(std::string const& cfg_file, } // Debug file. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: getting debug file"; + std::cout << "Diagnostic: getting debug file" << std::endl; { std::string target_path(_build_target_path(tmp_log_dir, conf.debug_file())); to_remove.push_back(target_path); @@ -231,8 +222,7 @@ void diagnostic::generate(std::string const& cfg_file, } // Retention file. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: getting retention file"; + std::cout << "Diagnostic: getting retention file" << std::endl; { std::string target_path( _build_target_path(tmp_log_dir, conf.state_retention_file())); @@ -241,8 +231,7 @@ void diagnostic::generate(std::string const& cfg_file, } // Status file. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: getting status file"; + std::cout << "Diagnostic: getting status file" << std::endl; { std::string target_path( _build_target_path(tmp_log_dir, conf.status_file())); @@ -258,8 +247,8 @@ void diagnostic::generate(std::string const& cfg_file, my_out_file = out_file; // Create tarball. - logger(logging::log_info_message, logging::basic) - << "Diagnostic: Creating tarball '" << my_out_file << "'"; + std::cout << "Diagnostic: Creating tarball '" << my_out_file << "'" + << std::endl; { std::ostringstream cmdline; cmdline << "tar czf '" << my_out_file << "' '" << tmp_dir << "'"; diff --git a/centreon-engine/src/downtimes/downtime_manager.cc b/centreon-engine/src/downtimes/downtime_manager.cc index 21abce8acac..65c0b055156 100644 --- a/centreon-engine/src/downtimes/downtime_manager.cc +++ b/centreon-engine/src/downtimes/downtime_manager.cc @@ -25,6 +25,7 @@ #include "com/centreon/engine/events/loop.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" using namespace com::centreon::engine; @@ -44,8 +45,9 @@ void downtime_manager::delete_downtime(uint64_t downtime_id) { for (auto it = _scheduled_downtimes.begin(), end = _scheduled_downtimes.end(); it != end; ++it) { if (it->second->get_downtime_id() == downtime_id) { - logger(dbg_downtime, basic) + engine_logger(dbg_downtime, basic) << "delete downtime(id: " << downtime_id << ")"; + log_v2::downtimes()->trace("delete downtime(id: {})", downtime_id); _scheduled_downtimes.erase(it); break; } @@ -60,9 +62,11 @@ int downtime_manager::unschedule_downtime(uint64_t downtime_id) { return downtime_id == d.second->get_downtime_id(); }); - logger(dbg_functions, basic) << "unschedule_downtime()"; - logger(dbg_downtime, basic) + engine_logger(dbg_functions, basic) << "unschedule_downtime()"; + log_v2::functions()->trace("unschedule_downtime()"); + engine_logger(dbg_downtime, basic) << "unschedule downtime(id: " << downtime_id << ")"; + log_v2::downtimes()->trace("unschedule downtime(id: {})", downtime_id); /* find the downtime entry in the list in memory */ if (found == _scheduled_downtimes.end()) @@ -86,8 +90,9 @@ int downtime_manager::unschedule_downtime(uint64_t downtime_id) { } for (uint64_t id : lst) { - logger(dbg_downtime, basic) + engine_logger(dbg_downtime, basic) << "Unschedule triggered downtime (id: " << id << ")"; + log_v2::downtimes()->trace("Unschedule triggered downtime (id: {})", id); unschedule_downtime(id); } return OK; @@ -113,7 +118,8 @@ std::shared_ptr downtime_manager::find_downtime( int downtime_manager::check_pending_flex_host_downtime(host* hst) { time_t current_time(0L); - logger(dbg_functions, basic) << "check_pending_flex_host_downtime()"; + engine_logger(dbg_functions, basic) << "check_pending_flex_host_downtime()"; + log_v2::functions()->trace("check_pending_flex_host_downtime()"); if (hst == nullptr) return ERROR; @@ -145,9 +151,12 @@ int downtime_manager::check_pending_flex_host_downtime(host* hst) { /* if the time boundaries are okay, start this scheduled downtime */ if (it->second->get_start_time() <= current_time && current_time <= it->second->get_end_time()) { - logger(dbg_downtime, basic) + engine_logger(dbg_downtime, basic) << "Flexible downtime (id=" << it->second->get_downtime_id() << ") for host '" << hst->get_name() << "' starting now..."; + log_v2::downtimes()->trace( + "Flexible downtime (id={}) for host '{}' starting now...", + it->second->get_downtime_id(), hst->get_name()); it->second->start_flex_downtime(); it->second->handle(); @@ -161,7 +170,9 @@ int downtime_manager::check_pending_flex_host_downtime(host* hst) { int downtime_manager::check_pending_flex_service_downtime(service* svc) { time_t current_time(0L); - logger(dbg_functions, basic) << "check_pending_flex_service_downtime()"; + engine_logger(dbg_functions, basic) + << "check_pending_flex_service_downtime()"; + log_v2::functions()->trace("check_pending_flex_service_downtime()"); if (svc == nullptr) return ERROR; @@ -193,10 +204,14 @@ int downtime_manager::check_pending_flex_service_downtime(service* svc) { /* if the time boundaries are okay, start this scheduled downtime */ if (dt.get_start_time() <= current_time && current_time <= dt.get_end_time()) { - logger(dbg_downtime, basic) + engine_logger(dbg_downtime, basic) << "Flexible downtime (id=" << dt.get_downtime_id() << ") for service '" << svc->get_description() << "' on host '" << svc->get_hostname() << "' starting now..."; + log_v2::downtimes()->trace( + "Flexible downtime (id={}) for service '{}' on host '{}' starting " + "now...", + dt.get_downtime_id(), svc->get_description(), svc->get_hostname()); dt.start_flex_downtime(); dt.handle(); @@ -223,7 +238,8 @@ void downtime_manager::add_downtime(downtime* dt) noexcept { int downtime_manager::check_for_expired_downtime() { time_t current_time(0L); - logger(dbg_functions, basic) << "check_for_expired_downtime()"; + engine_logger(dbg_functions, basic) << "check_for_expired_downtime()"; + log_v2::functions()->trace("check_for_expired_downtime()"); time(¤t_time); @@ -236,10 +252,14 @@ int downtime_manager::check_for_expired_downtime() { /* this entry should be removed */ if (!dt.is_in_effect() && dt.get_end_time() < current_time) { - logger(dbg_downtime, basic) + engine_logger(dbg_downtime, basic) << "Expiring " << (dt.get_type() == downtime::host_downtime ? "host" : "service") << " downtime (id=" << dt.get_downtime_id() << ")..."; + log_v2::downtimes()->trace( + "Expiring {} downtime (id={})...", + dt.get_type() == downtime::host_downtime ? "host" : "service", + dt.get_downtime_id()); /* delete the downtime entry */ delete_downtime(dt.get_downtime_id()); @@ -260,10 +280,14 @@ int downtime_manager:: std::string const& service_description, std::pair const& start_time, std::string const& comment) { - logger(dbg_downtime, basic) + engine_logger(dbg_downtime, basic) << "Delete downtimes (host: '" << hostname << "', service description: '" << service_description << "', start time: " << start_time.second << ", comment: '" << comment << "')"; + log_v2::downtimes()->trace( + "Delete downtimes (host: '{}', service description: '{}', start time: " + "{}, comment: '{}')", + hostname, service_description, start_time.second, comment); int deleted{0}; /* Do not allow deletion of everything - must have at least 1 filter on. */ @@ -311,7 +335,8 @@ int downtime_manager:: return deleted; } void downtime_manager::insert_downtime(std::shared_ptr dt) { - logger(dbg_functions, basic) << "downtime_manager::insert_downtime()"; + engine_logger(dbg_functions, basic) << "downtime_manager::insert_downtime()"; + log_v2::functions()->trace("downtime_manager::insert_downtime()"); time_t start{dt->get_start_time()}; _scheduled_downtimes.insert({start, dt}); } @@ -322,8 +347,9 @@ void downtime_manager::insert_downtime(std::shared_ptr dt) { * @return OK or ERROR if an error occured. */ void downtime_manager::initialize_downtime_data() { - logger(dbg_functions, basic) + engine_logger(dbg_functions, basic) << "downtime_manager::initialize_downtime_data()"; + log_v2::functions()->trace("downtime_manager::initialize_downtime_data()"); /* clean up the old downtime data */ xdddefault_validate_downtime_data(); @@ -480,29 +506,38 @@ int downtime_manager::schedule_downtime(downtime::type type, uint64_t* new_downtime_id) { uint64_t downtime_id{0L}; - logger(dbg_functions, basic) << "schedule_downtime()"; + engine_logger(dbg_functions, basic) << "schedule_downtime()"; + log_v2::functions()->trace("schedule_downtime()"); /* don't add old or invalid downtimes */ if (start_time >= end_time || end_time <= time(nullptr)) return ERROR; if (start_time > 4102441200) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "SCHEDULE DOWNTIME ALERT : start time is out of range and setted to " "1/1/2100 00:00"; + log_v2::config()->warn( + "SCHEDULE DOWNTIME ALERT : start time is out of range and setted to " + "1/1/2100 00:00"); start_time = 4102441200; } if (end_time > 4102441200) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "SCHEDULE DOWNTIME ALERT : end time is out of range and setted to " "1/1/2100 00:00"; + log_v2::config()->warn( + "SCHEDULE DOWNTIME ALERT : end time is out of range and setted to " + "1/1/2100 00:00"); end_time = 4102441200; } if (duration > 31622400) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "SCHEDULE DOWNTIME ALERT : is too long and setted to 366 days"; + log_v2::config()->warn( + "SCHEDULE DOWNTIME ALERT : is too long and setted to 366 days"); duration = 31622400; } @@ -528,9 +563,13 @@ int downtime_manager::schedule_downtime(downtime::type type, /* registers scheduled downtime (schedules it, adds comments, etc.) */ int downtime_manager::register_downtime(downtime::type type, uint64_t downtime_id) { - logger(dbg_functions, basic) << "downtime_manager::register_downtime()"; - logger(dbg_downtime, basic) + engine_logger(dbg_functions, basic) + << "downtime_manager::register_downtime()"; + log_v2::functions()->trace("downtime_manager::register_downtime()"); + engine_logger(dbg_downtime, basic) << "register downtime(type: " << type << ", id: " << downtime_id << ")"; + log_v2::downtimes()->trace("register downtime(type: {}, id: {})", type, + downtime_id); /* find the downtime entry in memory */ std::shared_ptr temp_downtime{find_downtime(type, downtime_id)}; if (!temp_downtime) diff --git a/centreon-engine/src/downtimes/host_downtime.cc b/centreon-engine/src/downtimes/host_downtime.cc index dceb881d59f..f354c75ab51 100644 --- a/centreon-engine/src/downtimes/host_downtime.cc +++ b/centreon-engine/src/downtimes/host_downtime.cc @@ -23,6 +23,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/downtimes/downtime_manager.hh" #include "com/centreon/engine/events/loop.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/statusdata.hh" #include "com/centreon/engine/string.hh" @@ -178,10 +179,15 @@ int host_downtime::unschedule() { /* log a notice - this is parsed by the history CGI */ if (it->second->get_scheduled_downtime_depth() == 0) { - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "HOST DOWNTIME ALERT: " << it->second->get_name() << ";CANCELLED; Scheduled downtime for host has been " "cancelled."; + log_v2::events()->info( + "HOST DOWNTIME ALERT: {};CANCELLED; Scheduled downtime for host has " + "been " + "cancelled.", + it->second->get_name()); /* send a notification */ it->second->notify(notifier::reason_downtimecancelled, "", "", @@ -192,7 +198,8 @@ int host_downtime::unschedule() { } int host_downtime::subscribe() { - logger(dbg_functions, basic) << "host_downtime::subscribe()"; + engine_logger(dbg_functions, basic) << "host_downtime::subscribe()"; + log_v2::functions()->trace("host_downtime::subscribe()"); host_map::const_iterator it(host::hosts.find(get_hostname())); @@ -230,11 +237,14 @@ int host_downtime::subscribe() { << " minutes. Notifications for the " << type_string << " will not be sent out during that time period."; - logger(dbg_downtime, basic) << "Scheduled Downtime Details:"; - logger(dbg_downtime, basic) << " Type: Host Downtime\n" - " Host: " - << hst->get_name(); - logger(dbg_downtime, basic) + engine_logger(dbg_downtime, basic) << "Scheduled Downtime Details:"; + log_v2::downtimes()->trace("Scheduled Downtime Details:"); + engine_logger(dbg_downtime, basic) << " Type: Host Downtime\n" + " Host: " + << hst->get_name(); + log_v2::downtimes()->trace(" Type: Host Downtime "); + log_v2::downtimes()->trace(" Host: {}", hst->get_name()); + engine_logger(dbg_downtime, basic) << " Fixed/Flex: " << (is_fixed() ? "Fixed\n" : "Flexible\n") << " Start: " << start_time_string << "\n" @@ -249,6 +259,11 @@ int host_downtime::subscribe() { << "\n" " Trigger ID: " << get_triggered_by(); + log_v2::downtimes()->trace( + " Fixed/Flex: {} Start: {} End: {} Duration: {}h " + "{}m {}s Downtime ID: {} Trigger ID: ", + is_fixed() ? "Fixed" : "Flexible", start_time_string, end_time_string, + hours, minutes, get_downtime_id(), get_triggered_by()); /* add a non-persistent comment to the host or service regarding the scheduled * outage */ @@ -289,7 +304,8 @@ int host_downtime::handle() { time_t event_time{0L}; int attr{0}; - logger(dbg_functions, basic) << "handle_downtime()"; + engine_logger(dbg_functions, basic) << "handle_downtime()"; + log_v2::functions()->trace("handle_downtime()"); host_map::const_iterator it_hst(host::hosts.find(get_hostname())); @@ -341,16 +357,24 @@ int host_downtime::handle() { it_hst->second->dec_scheduled_downtime_depth(); if (it_hst->second->get_scheduled_downtime_depth() == 0) { - logger(dbg_downtime, basic) + engine_logger(dbg_downtime, basic) << "Host '" << it_hst->second->get_name() << "' has exited from a period of scheduled downtime (id=" << get_downtime_id() << ")."; + log_v2::downtimes()->trace( + "Host '{}' has exited from a period of scheduled downtime (id={}).", + it_hst->second->get_name(), get_downtime_id()); /* log a notice - this one is parsed by the history CGI */ - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "HOST DOWNTIME ALERT: " << it_hst->second->get_name() << ";STOPPED; Host has exited from a period of scheduled " "downtime"; + log_v2::events()->info( + "HOST DOWNTIME ALERT: {};STOPPED; Host has exited from a period of " + "scheduled " + "downtime", + it_hst->second->get_name()); /* send a notification */ it_hst->second->notify(notifier::reason_downtimeend, get_author(), @@ -409,15 +433,22 @@ int host_downtime::handle() { get_triggered_by(), get_duration(), get_downtime_id(), nullptr); if (it_hst->second->get_scheduled_downtime_depth() == 0) { - logger(dbg_downtime, basic) + engine_logger(dbg_downtime, basic) << "Host '" << it_hst->second->get_name() << "' has entered a period of scheduled downtime (id=" << get_downtime_id() << ")."; + log_v2::downtimes()->trace( + "Host '{}' has entered a period of scheduled downtime (id={}).", + it_hst->second->get_name(), get_downtime_id()); /* log a notice - this one is parsed by the history CGI */ - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "HOST DOWNTIME ALERT: " << it_hst->second->get_name() << ";STARTED; Host has entered a period of scheduled downtime"; + log_v2::events()->info( + "HOST DOWNTIME ALERT: {};STARTED; Host has entered a period of " + "scheduled downtime", + it_hst->second->get_name()); /* send a notification */ it_hst->second->notify(notifier::reason_downtimestart, get_author(), diff --git a/centreon-engine/src/downtimes/service_downtime.cc b/centreon-engine/src/downtimes/service_downtime.cc index 96ad4d0d44b..4bc80760e34 100644 --- a/centreon-engine/src/downtimes/service_downtime.cc +++ b/centreon-engine/src/downtimes/service_downtime.cc @@ -26,6 +26,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/downtimes/downtime_manager.hh" #include "com/centreon/engine/events/loop.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/statusdata.hh" #include "com/centreon/engine/string.hh" @@ -178,7 +179,8 @@ void service_downtime::print(std::ostream& os) const { } int service_downtime::unschedule() { - logger(dbg_functions, basic) << "service_downtime::unschedule()"; + engine_logger(dbg_functions, basic) << "service_downtime::unschedule()"; + log_v2::functions()->trace("service_downtime::unschedule()"); service_map::const_iterator found( service::services.find({get_hostname(), get_service_description()})); @@ -206,11 +208,15 @@ int service_downtime::unschedule() { /* log a notice - this is parsed by the history CGI */ if (found->second->get_scheduled_downtime_depth() == 0) { - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "SERVICE DOWNTIME ALERT: " << found->second->get_hostname() << ";" << found->second->get_description() << ";CANCELLED; Scheduled downtime " "for service has been cancelled."; + log_v2::events()->info( + "SERVICE DOWNTIME ALERT: {};{};CANCELLED; Scheduled downtime " + "for service has been cancelled.", + found->second->get_hostname(), found->second->get_description()); /* send a notification */ found->second->notify(notifier::reason_downtimecancelled, "", "", @@ -221,7 +227,8 @@ int service_downtime::unschedule() { } int service_downtime::subscribe() { - logger(dbg_functions, basic) << "service_downtime::subscribe()"; + engine_logger(dbg_functions, basic) << "service_downtime::subscribe()"; + log_v2::functions()->trace("service_downtime::subscribe()"); service_map::const_iterator found( service::services.find({get_hostname(), get_service_description()})); @@ -259,14 +266,19 @@ int service_downtime::subscribe() { "period.", type_string, start_time_string, end_time_string, hours, minutes); - logger(dbg_downtime, basic) << "Scheduled Downtime Details:"; - logger(dbg_downtime, basic) << " Type: Service Downtime\n" - " Host: " - << found->second->get_hostname() - << "\n" - " Service: " - << found->second->get_description(); - logger(dbg_downtime, basic) + engine_logger(dbg_downtime, basic) << "Scheduled Downtime Details:"; + log_v2::downtimes()->trace("Scheduled Downtime Details:"); + engine_logger(dbg_downtime, basic) << " Type: Service Downtime\n" + " Host: " + << found->second->get_hostname() + << "\n" + " Service: " + << found->second->get_description(); + log_v2::downtimes()->trace(" Type: Service Downtime"); + log_v2::downtimes()->trace(" Host: {}", found->second->get_hostname()); + log_v2::downtimes()->trace(" Service: {}", found->second->get_description()); + + engine_logger(dbg_downtime, basic) << " Fixed/Flex: " << (is_fixed() ? "Fixed\n" : "Flexible\n") << " Start: " << start_time_string << "\n" @@ -281,6 +293,11 @@ int service_downtime::subscribe() { << "\n" " Trigger ID: " << get_triggered_by(); + log_v2::downtimes()->trace( + " Fixed/Flex: {} Start: {} End: {} Duration: {}h " + "{}m {}s Downtime ID: {} Trigger ID: {}", + is_fixed() ? "Fixed" : "Flexible", start_time_string, end_time_string, + hours, minutes, seconds, get_downtime_id(), get_triggered_by()); /* add a non-persistent comment to the host or service regarding the scheduled * outage */ @@ -321,7 +338,8 @@ int service_downtime::handle() { time_t event_time(0L); int attr(0); - logger(dbg_functions, basic) << "handle_downtime()"; + engine_logger(dbg_functions, basic) << "handle_downtime()"; + log_v2::functions()->trace("handle_downtime()"); service_map::const_iterator found( service::services.find({get_hostname(), get_service_description()})); @@ -376,19 +394,29 @@ int service_downtime::handle() { found->second->dec_scheduled_downtime_depth(); if (found->second->get_scheduled_downtime_depth() == 0) { - logger(dbg_downtime, basic) + engine_logger(dbg_downtime, basic) << "Service '" << found->second->get_description() << "' on host '" << found->second->get_hostname() << "' has exited from a period of " "scheduled downtime (id=" << get_downtime_id() << ")."; + log_v2::downtimes()->trace( + "Service '{}' on host '{}' has exited from a period of " + "scheduled downtime (id={}).", + found->second->get_description(), found->second->get_hostname(), + get_downtime_id()); /* log a notice - this one is parsed by the history CGI */ - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "SERVICE DOWNTIME ALERT: " << found->second->get_hostname() << ";" << found->second->get_description() << ";STOPPED; Service has exited from a period of scheduled " "downtime"; + log_v2::events()->info( + "SERVICE DOWNTIME ALERT: {};{};STOPPED; Service has exited from a " + "period of scheduled " + "downtime", + found->second->get_hostname(), found->second->get_description()); /* send a notification */ found->second->notify(notifier::reason_downtimeend, get_author(), @@ -445,19 +473,29 @@ int service_downtime::handle() { get_downtime_id(), nullptr); if (found->second->get_scheduled_downtime_depth() == 0) { - logger(dbg_downtime, basic) + engine_logger(dbg_downtime, basic) << "Service '" << found->second->get_description() << "' on host '" << found->second->get_hostname() << "' has entered a period of scheduled " "downtime (id=" << get_downtime_id() << ")."; + log_v2::downtimes()->trace( + "Service '{}' on host '{}' has entered a period of scheduled " + "downtime (id={}).", + found->second->get_description(), found->second->get_hostname(), + get_downtime_id()); /* log a notice - this one is parsed by the history CGI */ - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "SERVICE DOWNTIME ALERT: " << found->second->get_hostname() << ";" << found->second->get_description() << ";STARTED; Service has entered a period of scheduled " "downtime"; + log_v2::events()->info( + "SERVICE DOWNTIME ALERT: {};{};STARTED; Service has entered a period " + "of scheduled " + "downtime", + found->second->get_hostname(), found->second->get_description()); /* send a notification */ found->second->notify(notifier::reason_downtimestart, get_author(), @@ -509,7 +547,8 @@ std::string const& service_downtime::get_service_description() const { } void service_downtime::schedule() { - logger(dbg_functions, basic) << "service_downtime::schedule()"; + engine_logger(dbg_functions, basic) << "service_downtime::schedule()"; + log_v2::functions()->trace("service_downtime::schedule()"); downtime_manager::instance().add_downtime(this); /* send data to event broker */ diff --git a/centreon-engine/src/escalation.cc b/centreon-engine/src/escalation.cc index 7ddf51312eb..6413b5aa012 100644 --- a/centreon-engine/src/escalation.cc +++ b/centreon-engine/src/escalation.cc @@ -19,6 +19,7 @@ #include "com/centreon/engine/escalation.hh" #include "com/centreon/engine/exceptions/error.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/timeperiod.hh" @@ -122,9 +123,13 @@ void escalation::resolve(int& w __attribute__((unused)), int& e) { timeperiod::timeperiods.find(get_escalation_period())}; if (it == timeperiod::timeperiods.end() || !it->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Escalation period '" << get_escalation_period() << "' specified in escalation is not defined anywhere!"; + log_v2::config()->error( + "Error: Escalation period '{}' specified in escalation is not " + "defined anywhere!", + get_escalation_period()); errors++; } else // Save the timeperiod pointer for later. @@ -140,10 +145,15 @@ void escalation::resolve(int& w __attribute__((unused)), int& e) { contactgroup::contactgroups.find(it->first)}; if (it_cg == contactgroup::contactgroups.end() || !it_cg->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Contact group '" << it->first << "' specified in escalation for this notifier is not defined " "anywhere!"; + log_v2::config()->error( + "Error: Contact group '{}' specified in escalation for this notifier " + "is not defined " + "anywhere!", + it->first); errors++; } else { // Save the contactgroup pointer for later. diff --git a/centreon-engine/src/events/loop.cc b/centreon-engine/src/events/loop.cc index 570741c89cf..d059ae26d00 100644 --- a/centreon-engine/src/events/loop.cc +++ b/centreon-engine/src/events/loop.cc @@ -33,6 +33,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/configuration/parser.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/statusdata.hh" #include "com/centreon/logging/engine.hh" @@ -72,11 +73,12 @@ void loop::clear() { */ void loop::run() { // Debug message. - logger(dbg_functions, basic) << "events::loop::run()"; + engine_logger(dbg_functions, basic) << "events::loop::run()"; + log_v2::functions()->trace("events::loop::run()"); - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "Configuration loaded, main loop starting."; - + log_v2::process()->info("Configuration loaded, main loop starting."); // Initialize some time members. time(&_last_time); _last_status_update = 0L; @@ -102,7 +104,8 @@ void loop::run() { loop::loop() : _need_reload(0), _reload_running(false) {} static void apply_conf(std::atomic* reloading) { - logger(log_info_message, more) << "Starting to reload configuration."; + engine_logger(log_info_message, more) << "Starting to reload configuration."; + log_v2::process()->info("Starting to reload configuration."); try { configuration::state config; { @@ -111,13 +114,16 @@ static void apply_conf(std::atomic* reloading) { p.parse(path, config); } configuration::applier::state::instance().apply(config); - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "Configuration reloaded, main loop continuing."; + log_v2::process()->info("Configuration reloaded, main loop continuing."); } catch (std::exception const& e) { - logger(log_config_error, most) << "Error: " << e.what(); + engine_logger(log_config_error, most) << "Error: " << e.what(); + log_v2::config()->error("Error: {}", e.what()); } *reloading = false; - logger(log_info_message, more) << "Reload configuration finished."; + engine_logger(log_info_message, more) << "Reload configuration finished."; + log_v2::process()->info("Reload configuration finished."); } /** @@ -132,9 +138,11 @@ void loop::_dispatching() { // If we don't have any events to handle, exit. if (_event_list_high.empty() && _event_list_low.empty()) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "There aren't any events that need to be handled! " << "Exiting..."; + log_v2::runtime()->error( + "There aren't any events that need to be handled! Exiting..."); break; } @@ -146,14 +154,17 @@ void loop::_dispatching() { // Start reload configuration. if (_need_reload) { - logger(log_info_message, most) << "Need reload."; + engine_logger(log_info_message, most) << "Need reload."; + log_v2::process()->info("Need reload."); if (!reloading) { - logger(log_info_message, most) << "Reloading..."; + engine_logger(log_info_message, most) << "Reloading..."; + log_v2::process()->info("Reloading..."); reloading = true; std::async(std::launch::async, apply_conf, &reloading); - } else - logger(log_info_message, most) << "Already reloading..."; - + } else { + engine_logger(log_info_message, most) << "Already reloading..."; + log_v2::process()->info("Already reloading..."); + } _need_reload = 0; } @@ -180,22 +191,36 @@ void loop::_dispatching() { _last_time = current_time; // Log messages about event lists. - logger(dbg_events, more) << "** Event Check Loop"; - if (!_event_list_high.empty()) - logger(dbg_events, more) + engine_logger(dbg_events, more) << "** Event Check Loop"; + log_v2::events()->debug("** Event Check Loop"); + if (!_event_list_high.empty()) { + engine_logger(dbg_events, more) << "Next High Priority Event Time: " << my_ctime(&(*_event_list_high.begin())->run_time); - else - logger(dbg_events, more) << "No high priority events are scheduled..."; - if (!_event_list_low.empty()) - logger(dbg_events, more) + log_v2::events()->debug("Next High Priority Event Time: {}", + my_ctime(&(*_event_list_high.begin())->run_time)); + } else { + engine_logger(dbg_events, more) + << "No high priority events are scheduled..."; + log_v2::events()->debug("No high priority events are scheduled..."); + } + if (!_event_list_low.empty()) { + engine_logger(dbg_events, more) << "Next Low Priority Event Time: " << my_ctime(&(*_event_list_low.begin())->run_time); - else - logger(dbg_events, more) << "No low priority events are scheduled..."; - logger(dbg_events, more) + log_v2::events()->debug("Next Low Priority Event Time: {}", + my_ctime(&(*_event_list_low.begin())->run_time)); + } else { + engine_logger(dbg_events, more) + << "No low priority events are scheduled..."; + log_v2::events()->debug("No low priority events are scheduled..."); + } + engine_logger(dbg_events, more) << "Current/Max Service Checks: " << currently_running_service_checks << '/' << config->max_parallel_service_checks(); + log_v2::events()->debug("Current/Max Service Checks: {}/{}", + currently_running_service_checks, + config->max_parallel_service_checks()); // Update status information occassionally - NagVis watches the // NDOUtils DB to see if Engine is alive. @@ -245,28 +270,46 @@ void loop::_dispatching() { // Move it at least 5 seconds (to overcome the current peak), // with a random 10 seconds (to spread the load). nudge_seconds = 5 + (rand() % 10); - logger(dbg_events | dbg_checks, basic) + engine_logger(dbg_events | dbg_checks, basic) << "**WARNING** Max concurrent service checks (" << currently_running_service_checks << "/" << config->max_parallel_service_checks() << ") has been reached! Nudging " << temp_service->get_hostname() << ":" << temp_service->get_description() << " by " << nudge_seconds << " seconds..."; - logger(log_runtime_warning, basic) + log_v2::events()->trace( + "**WARNING** Max concurrent service checks ({}/{}) has been " + "reached! Nudging {}:{} by {} seconds...", + currently_running_service_checks, + config->max_parallel_service_checks(), + temp_service->get_hostname(), temp_service->get_description(), + nudge_seconds); + + engine_logger(log_runtime_warning, basic) << "\tMax concurrent service checks (" << currently_running_service_checks << "/" << config->max_parallel_service_checks() << ") has been reached. Nudging " << temp_service->get_hostname() << ":" << temp_service->get_description() << " by " << nudge_seconds << " seconds..."; + log_v2::runtime()->warn( + "\tMax concurrent service checks ({}/{}) has been reached. " + "Nudging {}:{} by {} seconds...", + currently_running_service_checks, + config->max_parallel_service_checks(), + temp_service->get_hostname(), temp_service->get_description(), + nudge_seconds); run_event = false; } // Don't run a service check if active checks are disabled. if (!config->execute_service_checks()) { - logger(dbg_events | dbg_checks, more) + engine_logger(dbg_events | dbg_checks, more) << "We're not executing service checks right now, " << "so we'll skip this event."; + log_v2::events()->debug( + "We're not executing service checks right now, so we'll skip " + "this event."); run_event = false; } @@ -319,9 +362,12 @@ void loop::_dispatching() { // Don't run a host check if active checks are disabled. if (!config->execute_host_checks()) { - logger(dbg_events | dbg_checks, more) + engine_logger(dbg_events | dbg_checks, more) << "We're not executing host checks right now, " << "so we'll skip this event."; + log_v2::events()->debug( + "We're not executing host checks right now, so we'll skip this " + "event."); run_event = false; } @@ -363,7 +409,8 @@ void loop::_dispatching() { // We may have just removed the only item from the list. // Handle the event. - logger(dbg_events, more) << "Running event..."; + engine_logger(dbg_events, more) << "Running event..."; + log_v2::events()->debug("Running event..."); temp_event->handle_timed_event(); // Reschedule the event if necessary. @@ -375,8 +422,10 @@ void loop::_dispatching() { } // Wait a while so we don't hog the CPU... else { - logger(dbg_events, most) + engine_logger(dbg_events, most) << "Did not execute scheduled event. Idling for a bit..."; + log_v2::events()->debug( + "Did not execute scheduled event. Idling for a bit..."); uint64_t d = static_cast(config->sleep_time() * 1000000000); std::this_thread::sleep_for(std::chrono::nanoseconds(d)); } @@ -386,8 +435,10 @@ void loop::_dispatching() { current_time < (*_event_list_high.begin())->run_time) && (_event_list_low.empty() || current_time < (*_event_list_low.begin())->run_time)) { - logger(dbg_events, most) + engine_logger(dbg_events, most) << "No events to execute at the moment. Idling for a bit..."; + log_v2::events()->debug( + "No events to execute at the moment. Idling for a bit..."); // Check for external commands if we're supposed to check as // often as possible. @@ -447,7 +498,8 @@ void loop::adjust_check_scheduling() { host* hst(nullptr); com::centreon::engine::service* svc(nullptr); - logger(dbg_functions, basic) << "adjust_check_scheduling()"; + engine_logger(dbg_functions, basic) << "adjust_check_scheduling()"; + log_v2::functions()->trace("adjust_check_scheduling()"); /* TODO: - Track host check overhead on a per-host basis @@ -606,29 +658,41 @@ void loop::compensate_for_system_time_change(unsigned long last_time, int seconds{0}; long time_difference = current_time - last_time; - logger(dbg_functions, basic) << "compensate_for_system_time_change()"; + engine_logger(dbg_functions, basic) << "compensate_for_system_time_change()"; + log_v2::functions()->trace("compensate_for_system_time_change()"); // we moved back in time... if (time_difference < 0) { get_time_breakdown(-time_difference, &days, &hours, &minutes, &seconds); - logger(dbg_events, basic) + engine_logger(dbg_events, basic) << "Detected a backwards time change of " << days << "d " << hours << "h " << minutes << "m " << seconds << "s."; + log_v2::events()->trace( + "Detected a backwards time change of {}d {}h {}m {}s.", days, hours, + minutes, seconds); } // we moved into the future... else { get_time_breakdown(time_difference, &days, &hours, &minutes, &seconds); - logger(dbg_events, basic) + engine_logger(dbg_events, basic) << "Detected a forwards time change of " << days << "d " << hours << "h " << minutes << "m " << seconds << "s."; + log_v2::events()->trace( + "Detected a forwards time change of {}d {}h {}m {}s.", days, hours, + minutes, seconds); } // log the time change. - logger(log_process_info | log_runtime_warning, basic) + engine_logger(log_process_info | log_runtime_warning, basic) << "Warning: A system time change of " << days << "d " << hours << "h " << minutes << "m " << seconds << "s (" << (time_difference < 0 ? "backwards" : "forwards") << " in time) has been detected. Compensating..."; + log_v2::runtime()->warn( + "Warning: A system time change of {}d {}h {}m {}s ({} in time) has been " + "detected. Compensating...", + days, hours, minutes, seconds, + time_difference < 0 ? "backwards" : "forwards"); // adjust the next run time for all high priority timed events. for (auto it = _event_list_high.begin(), end = _event_list_high.end(); @@ -760,7 +824,8 @@ void loop::compensate_for_system_time_change(unsigned long last_time, * @param[in] event_list_tail The tail of the event list. */ void loop::add_event(timed_event* event, loop::priority priority) { - logger(dbg_functions, basic) << "add_event()"; + engine_logger(dbg_functions, basic) << "add_event()"; + log_v2::functions()->trace("add_event()"); timed_event_list* list; @@ -799,7 +864,8 @@ void loop::add_event(timed_event* event, loop::priority priority) { } void loop::remove_downtime(uint64_t downtime_id) { - logger(dbg_functions, basic) << "loop::remove_downtime()"; + engine_logger(dbg_functions, basic) << "loop::remove_downtime()"; + log_v2::functions()->trace("loop::remove_downtime()"); for (auto it = _event_list_high.begin(), end = _event_list_high.end(); it != end; ++it) { @@ -823,7 +889,8 @@ void loop::remove_downtime(uint64_t downtime_id) { * @param[in,out] event_list_tail The tail of the event list. */ void loop::remove_event(timed_event* event, loop::priority priority) { - logger(dbg_functions, basic) << "loop::remove_event()"; + engine_logger(dbg_functions, basic) << "loop::remove_event()"; + log_v2::functions()->trace("loop::remove_event()"); // send event data to broker. broker_timed_event(NEBTYPE_TIMEDEVENT_REMOVE, NEBFLAG_NONE, NEBATTR_NONE, @@ -867,7 +934,8 @@ timed_event* loop::find_event(loop::priority priority, void* data) { timed_event_list* list; - logger(dbg_functions, basic) << "resort_event_list()"; + engine_logger(dbg_functions, basic) << "resort_event_list()"; + log_v2::functions()->trace("resort_event_list()"); // move current event list to temp list. if (priority == loop::low) @@ -890,7 +958,8 @@ timed_event* loop::find_event(loop::priority priority, * @param[in,out] event_list_tail The tail of the event list. */ void loop::reschedule_event(timed_event* event, loop::priority priority) { - logger(dbg_functions, basic) << "reschedule_event()"; + engine_logger(dbg_functions, basic) << "reschedule_event()"; + log_v2::functions()->trace("reschedule_event()"); // reschedule recurring events... if (event->recurring) { @@ -928,7 +997,8 @@ void loop::reschedule_event(timed_event* event, loop::priority priority) { void loop::resort_event_list(loop::priority priority) { timed_event_list* list; - logger(dbg_functions, basic) << "resort_event_list()"; + engine_logger(dbg_functions, basic) << "resort_event_list()"; + log_v2::functions()->trace("resort_event_list()"); // move current event list to temp list. if (priority == loop::low) diff --git a/centreon-engine/src/events/sched_info.cc b/centreon-engine/src/events/sched_info.cc index 3dbc0035659..b89a6142ac3 100644 --- a/centreon-engine/src/events/sched_info.cc +++ b/centreon-engine/src/events/sched_info.cc @@ -22,7 +22,9 @@ #include "com/centreon/engine/events/sched_info.hh" #include +#include #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/statusdata.hh" #include "com/centreon/engine/string.hh" @@ -35,117 +37,105 @@ using namespace com::centreon::engine::logging; */ void display_scheduling_info() { // Notice. - logger(log_info_message, basic) - << "\nProjected scheduling information for host and service checks\n" - << "is listed below. This information assumes that you are going\n" - << "to start running Centreon Engine with your current config files.\n\n"; + std::cout << "\nProjected scheduling information for host and service " + "checks\n is listed below. This information assumes that you " + "are going\n to start running Centreon Engine with your current " + "config files.\n\n"; // Host scheduling information. - logger(log_info_message, basic) - << "HOST SCHEDULING INFORMATION\n" - << "---------------------------\n" - << "Total hosts: " << scheduling_info.total_hosts - << "\n" - << "Total scheduled hosts: " - << scheduling_info.total_scheduled_hosts << "\n"; - if (config->host_inter_check_delay_method() == configuration::state::icd_none) - logger(log_info_message, basic) - << "Host inter-check delay method: NONE\n"; - else if (config->host_inter_check_delay_method() == - configuration::state::icd_dumb) - logger(log_info_message, basic) - << "Host inter-check delay method: DUMB\n"; - else if (config->host_inter_check_delay_method() == - configuration::state::icd_smart) - logger(log_info_message, basic) - << "Host inter-check delay method: SMART\n" - << "Average host check interval: " - << scheduling_info.average_host_check_interval << " sec\n"; - else - logger(log_info_message, basic) - << "Host inter-check delay method: USER-SUPPLIED VALUE\n"; - logger(log_info_message, basic) - << "Host inter-check delay: " - << scheduling_info.host_inter_check_delay << " sec\n" - << "Max host check spread: " - << scheduling_info.max_host_check_spread << " min\n" - << "First scheduled check: " - << ((scheduling_info.total_scheduled_hosts == 0) - ? "N/A\n" - : ctime(&scheduling_info.first_host_check)) - << "Last scheduled check: " - << ((scheduling_info.total_scheduled_hosts == 0) - ? "N/A\n" - : ctime(&scheduling_info.last_host_check)) - << "\n"; - + std::cout << "HOST SCHEDULING INFORMATION\n" + "---------------------------\n" + "Total hosts: " + << scheduling_info.total_hosts + << "\n" + "Total scheduled hosts: " + << scheduling_info.total_scheduled_hosts << "\n"; + if (config->host_inter_check_delay_method() == + configuration::state::icd_none) { + std::cout << "Host inter-check delay method: NONE\n"; + } else if (config->host_inter_check_delay_method() == + configuration::state::icd_dumb) { + std::cout << "Host inter-check delay method: DUMB\n"; + } else if (config->host_inter_check_delay_method() == + configuration::state::icd_smart) { + std::cout << "Host inter-check delay method: SMART\n" + "Average host check interval: " + << scheduling_info.average_host_check_interval << " sec\n"; + } else { + std::cout << "Host inter-check delay method: USER-SUPPLIED VALUE\n"; + } + std::cout << "Host inter-check delay: " + << scheduling_info.host_inter_check_delay + << " sec\n Max host check spread: " + << scheduling_info.max_host_check_spread + << " min\n First scheduled check: " + << (scheduling_info.total_scheduled_hosts == 0 + ? "N/A\n" + : ctime(&scheduling_info.first_host_check)) + << "Last scheduled check: " + << (scheduling_info.total_scheduled_hosts == 0 + ? "N/A\n" + : ctime(&scheduling_info.last_host_check)) + << "\n"; // Service scheduling information. - logger(log_info_message, basic) - << "SERVICE SCHEDULING INFORMATION\n" - << "-------------------------------\n" - << "Total services: " - << scheduling_info.total_services << "\n" - << "Total scheduled services: " - << scheduling_info.total_scheduled_services << "\n"; + std::cout << "SERVICE SCHEDULING INFORMATION\n" + "-------------------------------\n" + "Total services: " + << scheduling_info.total_services + << "\n" + "Total scheduled services: " + << scheduling_info.total_scheduled_services << "\n"; if (config->service_inter_check_delay_method() == - configuration::state::icd_none) - logger(log_info_message, basic) - << "Service inter-check delay method: NONE\n"; - else if (config->service_inter_check_delay_method() == - configuration::state::icd_dumb) - logger(log_info_message, basic) - << "Service inter-check delay method: DUMB\n"; - else if (config->service_inter_check_delay_method() == - configuration::state::icd_smart) { - logger(log_info_message, basic) - << "Service inter-check delay method: SMART\n" - << "Average service check interval: " - << scheduling_info.average_service_check_interval << " sec\n"; - } else - logger(log_info_message, basic) - << "Service inter-check delay method: USER-SUPPLIED VALUE\n"; - logger(log_info_message, basic) - << "Inter-check delay: " - << scheduling_info.service_inter_check_delay << " sec\n" - << "Interleave factor method: " - << ((config->service_interleave_factor_method() == - configuration::state::ilf_user) - ? "USER-SUPPLIED VALUE" - : "SMART") - << "\n"; + configuration::state::icd_none) { + std::cout << "Service inter-check delay method: NONE\n"; + } else if (config->service_inter_check_delay_method() == + configuration::state::icd_dumb) { + std::cout << "Service inter-check delay method: DUMB\n"; + } else if (config->service_inter_check_delay_method() == + configuration::state::icd_smart) { + std::cout << "Service inter-check delay method: SMART\n" + "Average service check interval: " + << scheduling_info.average_service_check_interval << " sec\n"; + } else { + std::cout << "Service inter-check delay method: USER-SUPPLIED VALUE\n"; + } + std::cout << "Inter-check delay: " + << scheduling_info.service_inter_check_delay + << " sec\n Interleave factor method: " + << (config->service_interleave_factor_method() == + configuration::state::ilf_user + ? "USER-SUPPLIED VALUE\n" + : "SMART\n"); if (config->service_interleave_factor_method() == - configuration::state::ilf_smart) - logger(log_info_message, basic) - << "Average services per host: " - << scheduling_info.average_services_per_host << "\n"; - logger(log_info_message, basic) - << "Service interleave factor: " - << scheduling_info.service_interleave_factor << "\n" - << "Max service check spread: " - << scheduling_info.max_service_check_spread << " min\n" - << "First scheduled check: " - << ctime(&scheduling_info.first_service_check) - << "Last scheduled check: " - << ctime(&scheduling_info.last_service_check) << "\n"; - + configuration::state::ilf_smart) { + std::cout << "Average services per host: " + << scheduling_info.average_services_per_host << "\n"; + } + std::cout << "Service interleave factor: " + << scheduling_info.service_interleave_factor + << "\n" + "Max service check spread: " + << scheduling_info.max_service_check_spread + << " min\n" + "First scheduled check: " + << ctime(&scheduling_info.first_service_check) + << "Last scheduled check: " + << ctime(&scheduling_info.last_service_check) << "\n"; // Check processing information. - logger(log_info_message, basic) - << "CHECK PROCESSING INFORMATION\n" - << "----------------------------\n" - << "Check result reaper interval: " - << config->check_reaper_interval() << " sec\n"; - if (config->max_parallel_service_checks() == 0) - logger(log_info_message, basic) - << "Max concurrent service checks: Unlimited\n"; - else - logger(log_info_message, basic) - << "Max concurrent service checks: " - << config->max_parallel_service_checks() << "\n"; - logger(log_info_message, basic) << "\n"; - + std::cout << "CHECK PROCESSING INFORMATION\n" + "----------------------------\n" + "Check result reaper interval: " + << config->check_reaper_interval() << " sec\n"; + if (config->max_parallel_service_checks() == 0) { + std::cout << "Max concurrent service checks: Unlimited\n"; + } else { + std::cout << "Max concurrent service checks: " + << config->max_parallel_service_checks() << "\n"; + } + std::cout << "\n"; // Performance suggestions. - logger(log_info_message, basic) << "PERFORMANCE SUGGESTIONS\n" - << "-----------------------\n"; + std::cout << "PERFORMANCE SUGGESTIONS\n" + "-----------------------\n"; int suggestions(0); // MAX REAPER INTERVAL RECOMMENDATION. @@ -159,15 +149,13 @@ void display_scheduling_info() { if (max_reaper_interval > 30.0) max_reaper_interval = 30.0; if (max_reaper_interval < config->check_reaper_interval()) { - logger(log_info_message, basic) - << "* Value for 'check_result_reaper_frequency' should be <= " - << static_cast(max_reaper_interval) << " seconds\n"; + std::cout << "* Value for 'check_result_reaper_frequency' should be <= " + << static_cast(max_reaper_interval) << " seconds\n"; ++suggestions; } if (config->check_reaper_interval() < 2) { - logger(log_info_message, basic) - << "* Value for 'check_result_reaper_frequency' should be >= 2 " - "seconds\n"; + std::cout << "* Value for 'check_result_reaper_frequency' should be >= 2 " + "seconds\n"; ++suggestions; } @@ -198,14 +186,13 @@ void display_scheduling_info() { // Compare with configured value. if ((minimum_concurrent_checks > config->max_parallel_service_checks()) && config->max_parallel_service_checks() != 0) { - logger(log_info_message, basic) - << "* Value for 'max_concurrent_checks' option should be >= " - << static_cast(minimum_concurrent_checks) << "\n"; + std::cout << "* Value for 'max_concurrent_checks' option should be >= " + << static_cast(minimum_concurrent_checks) << "\n"; ++suggestions; } - if (suggestions == 0) - logger(log_info_message, basic) - << "I have no suggestions - things look okay.\n"; + if (suggestions == 0) { + std::cout << "I have no suggestions - things look okay.\n"; + } return; } diff --git a/centreon-engine/src/events/timed_event.cc b/centreon-engine/src/events/timed_event.cc index 553cedf9a3a..b810d522a5d 100644 --- a/centreon-engine/src/events/timed_event.cc +++ b/centreon-engine/src/events/timed_event.cc @@ -30,6 +30,7 @@ #include "com/centreon/engine/events/loop.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/objects.hh" #include "com/centreon/engine/retention/dump.hh" @@ -104,10 +105,14 @@ void timed_event::_exec_event_service_check() { double latency = (double)((double)(tv.tv_sec - run_time) + (double)(tv.tv_usec / 1000) / 1000.0); - logger(dbg_events, basic) + engine_logger(dbg_events, basic) << "** Service Check Event ==> Host: '" << svc->get_hostname() << "', Service: '" << svc->get_description() << "', Options: " << event_options << ", Latency: " << latency << " sec"; + log_v2::events()->trace( + "** Service Check Event ==> Host: '{}', Service: '{}', Options: {}, " + "Latency: {} sec", + svc->get_hostname(), svc->get_description(), event_options, latency); // run the service check. svc->run_scheduled_check(event_options, latency); @@ -118,7 +123,8 @@ void timed_event::_exec_event_service_check() { * */ void timed_event::_exec_event_command_check() { - logger(dbg_events, basic) << "** External Command Check Event"; + engine_logger(dbg_events, basic) << "** External Command Check Event"; + log_v2::events()->trace("** External Command Check Event"); // send data to event broker. broker_external_command(NEBTYPE_EXTERNALCOMMAND_CHECK, NEBFLAG_NONE, @@ -130,7 +136,8 @@ void timed_event::_exec_event_command_check() { * */ void timed_event::_exec_event_enginerpc_check() { - logger(dbg_events, basic) << "** EngineRPC Command Check Event"; + engine_logger(dbg_events, basic) << "** EngineRPC Command Check Event"; + log_v2::events()->trace("** EngineRPC Command Check Event"); // send data to event broker. command_manager::instance().execute(); @@ -147,14 +154,17 @@ void timed_event::_exec_event_log_rotation() {} * */ void timed_event::_exec_event_program_shutdown() { - logger(dbg_events, basic) << "** Program Shutdown Event"; + engine_logger(dbg_events, basic) << "** Program Shutdown Event"; + log_v2::events()->trace("** Program Shutdown Event"); // set the shutdown flag. sigshutdown = true; // log the shutdown. - logger(log_process_info, basic) + engine_logger(log_process_info, basic) << "PROGRAM_SHUTDOWN event encountered, shutting down..."; + log_v2::process()->info( + "PROGRAM_SHUTDOWN event encountered, shutting down..."); } /** @@ -162,14 +172,16 @@ void timed_event::_exec_event_program_shutdown() { * */ void timed_event::_exec_event_program_restart() { - logger(dbg_events, basic) << "** Program Restart Event"; + engine_logger(dbg_events, basic) << "** Program Restart Event"; + log_v2::events()->trace("** Program Restart Event"); // reload configuration. sighup = true; // log the restart. - logger(log_process_info, basic) + engine_logger(log_process_info, basic) << "PROGRAM_RESTART event encountered, restarting..."; + log_v2::process()->info("PROGRAM_RESTART event encountered, restarting..."); } /** @@ -177,13 +189,15 @@ void timed_event::_exec_event_program_restart() { * */ void timed_event::_exec_event_check_reaper() { - logger(dbg_events, basic) << "** Check Result Reaper"; + engine_logger(dbg_events, basic) << "** Check Result Reaper"; + log_v2::events()->trace("** Check Result Reaper"); // reap host and service check results. try { checks::checker::instance().reap(); } catch (std::exception const& e) { - logger(log_runtime_error, basic) << "Error: " << e.what(); + engine_logger(log_runtime_error, basic) << "Error: " << e.what(); + log_v2::runtime()->error("Error: {}", e.what()); } } @@ -192,7 +206,9 @@ void timed_event::_exec_event_check_reaper() { * */ void timed_event::_exec_event_orphan_check() { - logger(dbg_events, basic) << "** Orphaned Host and Service Check Event"; + engine_logger(dbg_events, basic) + << "** Orphaned Host and Service Check Event"; + log_v2::events()->trace("** Orphaned Host and Service Check Event"); // check for orphaned hosts and services. if (config->check_orphaned_hosts()) @@ -206,7 +222,8 @@ void timed_event::_exec_event_orphan_check() { * */ void timed_event::_exec_event_retention_save() { - logger(dbg_events, basic) << "** Retention Data Save Event"; + engine_logger(dbg_events, basic) << "** Retention Data Save Event"; + log_v2::events()->trace("** Retention Data Save Event"); // save state retention data. retention::dump::save(config->state_retention_file()); @@ -217,7 +234,8 @@ void timed_event::_exec_event_retention_save() { * */ void timed_event::_exec_event_status_save() { - logger(dbg_events, basic) << "** Status Data Save Event"; + engine_logger(dbg_events, basic) << "** Status Data Save Event"; + log_v2::events()->trace("** Status Data Save Event"); // save all status data (program, host, and service). update_all_status_data(); @@ -228,7 +246,8 @@ void timed_event::_exec_event_status_save() { * */ void timed_event::_exec_event_scheduled_downtime() { - logger(dbg_events, basic) << "** Scheduled Downtime Event"; + engine_logger(dbg_events, basic) << "** Scheduled Downtime Event"; + log_v2::events()->trace("** Scheduled Downtime Event"); // process scheduled downtime info. if (event_data) { @@ -243,7 +262,8 @@ void timed_event::_exec_event_scheduled_downtime() { * */ void timed_event::_exec_event_sfreshness_check() { - logger(dbg_events, basic) << "** Service Result Freshness Check Event"; + engine_logger(dbg_events, basic) << "** Service Result Freshness Check Event"; + log_v2::events()->trace("** Service Result Freshness Check Event"); // check service result freshness. service::check_result_freshness(); @@ -254,7 +274,8 @@ void timed_event::_exec_event_sfreshness_check() { * */ void timed_event::_exec_event_expire_downtime() { - logger(dbg_events, basic) << "** Expire Downtime Event"; + engine_logger(dbg_events, basic) << "** Expire Downtime Event"; + log_v2::events()->trace("** Expire Downtime Event"); // check for expired scheduled downtime entries. downtime_manager::instance().check_for_expired_downtime(); @@ -273,9 +294,12 @@ void timed_event::_exec_event_host_check() { double latency = (double)((double)(tv.tv_sec - run_time) + (double)(tv.tv_usec / 1000) / 1000.0); - logger(dbg_events, basic) + engine_logger(dbg_events, basic) << "** Host Check Event ==> Host: '" << hst->get_name() << "', Options: " << event_options << ", Latency: " << latency << " sec"; + log_v2::events()->trace( + "** Host Check Event ==> Host: '{}', Options: {}, Latency: {} sec", + hst->get_name(), event_options, latency); // run the host check. hst->run_scheduled_check(event_options, latency); @@ -286,7 +310,8 @@ void timed_event::_exec_event_host_check() { * */ void timed_event::_exec_event_hfreshness_check() { - logger(dbg_events, basic) << "** Host Result Freshness Check Event"; + engine_logger(dbg_events, basic) << "** Host Result Freshness Check Event"; + log_v2::events()->trace("** Host Result Freshness Check Event"); // check host result freshness. host::check_result_freshness(); @@ -297,7 +322,8 @@ void timed_event::_exec_event_hfreshness_check() { * */ void timed_event::_exec_event_reschedule_checks() { - logger(dbg_events, basic) << "** Reschedule Checks Event"; + engine_logger(dbg_events, basic) << "** Reschedule Checks Event"; + log_v2::events()->trace("** Reschedule Checks Event"); // adjust scheduling of host and service checks. events::loop::instance().adjust_check_scheduling(); @@ -308,7 +334,8 @@ void timed_event::_exec_event_reschedule_checks() { * */ void timed_event::_exec_event_expire_comment() { - logger(dbg_events, basic) << "** Expire Comment Event"; + engine_logger(dbg_events, basic) << "** Expire Comment Event"; + log_v2::events()->trace("** Expire Comment Event"); // check for expired comment. comment::remove_if_expired_comment((unsigned long)event_data); @@ -319,7 +346,8 @@ void timed_event::_exec_event_expire_comment() { * */ void timed_event::_exec_event_expire_host_ack() { - logger(dbg_events, basic) << "** Expire Host Acknowledgement Event"; + engine_logger(dbg_events, basic) << "** Expire Host Acknowledgement Event"; + log_v2::events()->trace("** Expire Host Acknowledgement Event"); static_cast(event_data)->check_for_expired_acknowledgement(); } @@ -328,7 +356,8 @@ void timed_event::_exec_event_expire_host_ack() { * */ void timed_event::_exec_event_expire_service_ack() { - logger(dbg_events, basic) << "** Expire Service Acknowledgement Event"; + engine_logger(dbg_events, basic) << "** Expire Service Acknowledgement Event"; + log_v2::events()->trace("** Expire Service Acknowledgement Event"); static_cast(event_data)->check_for_expired_acknowledgement(); } @@ -338,7 +367,8 @@ void timed_event::_exec_event_expire_service_ack() { * @param[in] event The event to execute. */ void timed_event::_exec_event_user_function() { - logger(dbg_events, basic) << "** User Function Event"; + engine_logger(dbg_events, basic) << "** User Function Event"; + log_v2::events()->trace("** User Function Event"); // run a user-defined function. if (event_data) { @@ -363,7 +393,8 @@ void timed_event::_exec_event_user_function() { * @return the adjusted time. */ time_t adjust_timestamp_for_time_change(int64_t time_difference, time_t ts) { - logger(dbg_functions, basic) << "adjust_timestamp_for_time_change()"; + engine_logger(dbg_functions, basic) << "adjust_timestamp_for_time_change()"; + log_v2::functions()->trace("adjust_timestamp_for_time_change()"); // we shouldn't do anything with epoch or invalid values. if (ts == (time_t)0 || ts == (time_t)-1) @@ -405,14 +436,17 @@ int timed_event::handle_timed_event() { &timed_event::_exec_event_expire_service_ack, &timed_event::_exec_event_enginerpc_check}; - logger(dbg_functions, basic) << "handle_timed_event()"; + engine_logger(dbg_functions, basic) << "handle_timed_event()"; + log_v2::functions()->trace("handle_timed_event()"); // send event data to broker. broker_timed_event(NEBTYPE_TIMEDEVENT_EXECUTE, NEBFLAG_NONE, NEBATTR_NONE, this, nullptr); - logger(dbg_events, basic) << "** Timed Event ** Type: " << event_type - << ", Run Time: " << my_ctime(&run_time); + engine_logger(dbg_events, basic) << "** Timed Event ** Type: " << event_type + << ", Run Time: " << my_ctime(&run_time); + log_v2::events()->trace("** Timed Event ** Type: {}, Run Time: {}", + event_type, my_ctime(&run_time)); // how should we handle the event? if (event_type < tab_exec_event.size()) diff --git a/centreon-engine/src/flapping.cc b/centreon-engine/src/flapping.cc index 64282787746..73962aedc18 100644 --- a/centreon-engine/src/flapping.cc +++ b/centreon-engine/src/flapping.cc @@ -24,6 +24,7 @@ #include "com/centreon/engine/broker.hh" #include "com/centreon/engine/comment.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/statusdata.hh" @@ -38,7 +39,8 @@ using namespace com::centreon::engine::logging; void enable_flap_detection_routines() { unsigned long attr = MODATTR_FLAP_DETECTION_ENABLED; - logger(dbg_functions, basic) << "enable_flap_detection_routines()"; + engine_logger(dbg_functions, basic) << "enable_flap_detection_routines()"; + log_v2::functions()->trace("enable_flap_detection_routines()"); /* bail out if we're already set */ if (config->enable_flap_detection()) @@ -75,7 +77,8 @@ void enable_flap_detection_routines() { void disable_flap_detection_routines() { unsigned long attr = MODATTR_FLAP_DETECTION_ENABLED; - logger(dbg_functions, basic) << "disable_flap_detection_routines()"; + engine_logger(dbg_functions, basic) << "disable_flap_detection_routines()"; + log_v2::functions()->trace("disable_flap_detection_routines()"); /* bail out if we're already set */ if (!config->enable_flap_detection()) diff --git a/centreon-engine/src/host.cc b/centreon-engine/src/host.cc index e5e00c26aa0..0595aa68ed6 100644 --- a/centreon-engine/src/host.cc +++ b/centreon-engine/src/host.cc @@ -30,6 +30,7 @@ #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/flapping.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" @@ -260,20 +261,27 @@ host::host(uint64_t host_id, _initial_state{initial_state} { // Make sure we have the data we need. if (name.empty() || address.empty()) { - logger(log_config_error, basic) << "Error: Host name or address is nullptr"; + engine_logger(log_config_error, basic) + << "Error: Host name or address is nullptr"; + log_v2::config()->error("Error: Host name or address is nullptr"); throw engine_error() << "Could not register host '" << name << "'"; } if (host_id == 0) { - logger(log_config_error, basic) << "Error: Host must contain a host id " - "because it comes from a database"; + engine_logger(log_config_error, basic) + << "Error: Host must contain a host id " + "because it comes from a database"; + log_v2::config()->error( + "Error: Host must contain a host id " + "because it comes from a database"); throw engine_error() << "Could not register host '" << name << "'"; } // Check if the host already exists. uint64_t id{host_id}; if (is_host_exist(id)) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Host '" << name << "' has already been defined"; + log_v2::config()->error("Error: Host '{}' has already been defined", name); throw engine_error() << "Could not register host '" << name << "'"; } @@ -313,15 +321,18 @@ void host::add_child_host(host* child) { void host::add_parent_host(std::string const& host_name) { // Make sure we have the data we need. if (host_name.empty()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "add child link called with bad host_name"; + log_v2::config()->error("add child link called with bad host_name"); throw engine_error() << "add child link called with bad host_name"; } // A host cannot be a parent/child of itself. if (_name == host_name) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Host '" << _name << "' cannot be a child/parent of itself"; + log_v2::config()->error( + "Error: Host '{}' cannot be a child/parent of itself", _name); throw engine_error() << "host is child/parent itself"; } @@ -1176,9 +1187,12 @@ int host::log_event() { } std::string const& state_type(tab_state_type[get_state_type()]); - logger(log_options, basic) + engine_logger(log_options, basic) << "HOST ALERT: " << get_name() << ";" << state << ";" << state_type << ";" << get_current_attempt() << ";" << get_plugin_output(); + log_v2::events()->info("HOST ALERT: {};{};{};{};{}", get_name(), state, + state_type, get_current_attempt(), + get_plugin_output()); return OK; } @@ -1192,7 +1206,8 @@ int host::handle_async_check_result_3x(check_result* queued_check_result) { struct timeval start_time_hires; struct timeval end_time_hires; - logger(dbg_functions, basic) << "handle_async_host_check_result_3x()"; + engine_logger(dbg_functions, basic) << "handle_async_host_check_result_3x()"; + log_v2::functions()->trace("handle_async_host_check_result_3x()"); /* make sure we have what we need */ if (!queued_check_result) @@ -1210,9 +1225,12 @@ int host::handle_async_check_result_3x(check_result* queued_check_result) { if (execution_time < 0.0) execution_time = 0.0; - logger(dbg_checks, more) << "** Handling async check result for host '" - << get_name() << "'..."; - logger(dbg_checks, most) + engine_logger(dbg_checks, more) + << "** Handling async check result for host '" << get_name() << "'..."; + log_v2::checks()->debug("** Handling async check result for host '{}'...", + get_name()); + + engine_logger(dbg_checks, most) << "\tCheck Type: " << (queued_check_result->get_check_type() == check_active ? "Active" : "Passive") @@ -1231,6 +1249,27 @@ int host::handle_async_check_result_3x(check_result* queued_check_result) { << "\n" << "\tOutput: " << queued_check_result->get_output(); + log_v2::checks()->debug("Check Type: {}", + queued_check_result->get_check_type() == check_active + ? "Active" + : "Passive"); + log_v2::checks()->debug("Check Options: {}", + queued_check_result->get_check_options()); + log_v2::checks()->debug( + "Reschedule Check?: {}", + queued_check_result->get_reschedule_check() ? "Yes" : "No"); + log_v2::checks()->debug( + "Should Reschedule Current Host Check?: {}", + queued_check_result->get_reschedule_check() ? "Yes" : "No"); + log_v2::checks()->debug("Exited OK?: {}", + queued_check_result->get_exited_ok() ? "Yes" : "No"); + log_v2::checks()->debug("Exec Time: {:.3f}\n", execution_time); + log_v2::checks()->debug("Latency: {}", + queued_check_result->get_latency()); + log_v2::checks()->debug("return Status: {}", + queued_check_result->get_return_code()); + log_v2::checks()->debug("Output: {}", + queued_check_result->get_output()); /* decrement the number of host checks still out there... */ if (queued_check_result->get_check_type() == check_active && currently_running_host_checks > 0) @@ -1241,15 +1280,22 @@ int host::handle_async_check_result_3x(check_result* queued_check_result) { * check results */ if (queued_check_result->get_check_type() == check_passive) { if (!config->accept_passive_host_checks()) { - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Discarding passive host check result because passive host " "checks are disabled globally."; + log_v2::checks()->trace( + "Discarding passive host check result because passive host " + "checks are disabled globally."); + return ERROR; } if (!get_accept_passive_checks()) { - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Discarding passive host check result because passive checks " "are disabled for this host."; + log_v2::checks()->trace( + "Discarding passive host check result because passive checks " + "are disabled for this host."); return ERROR; } } @@ -1271,9 +1317,12 @@ int host::handle_async_check_result_3x(check_result* queued_check_result) { if ((queued_check_result->get_check_options() & CHECK_OPTION_FRESHNESS_CHECK) && is_result_fresh(current_time, false)) { - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Discarding host freshness check result because the host is " "currently fresh (race condition avoided)."; + log_v2::checks()->trace( + "Discarding host freshness check result because the host is " + "currently fresh (race condition avoided)."); return OK; } @@ -1363,7 +1412,7 @@ int host::handle_async_check_result_3x(check_result* queued_check_result) { std::replace(temp_str.begin(), temp_str.end(), ';', ':'); set_plugin_output(temp_str); - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "Parsing check output...\n" << "Short Output:\n" << (get_plugin_output().empty() ? "NULL" : get_plugin_output()) << "\n" @@ -1372,7 +1421,12 @@ int host::handle_async_check_result_3x(check_result* queued_check_result) { << "\n" << "Perf Data:\n" << (get_perf_data().empty() ? "NULL" : get_perf_data()); - + log_v2::checks()->debug( + "Parsing check output... Short Output: {} Long Output: {} " + "Perf Data: {}", + get_plugin_output().empty() ? "NULL" : get_plugin_output(), + get_long_plugin_output().empty() ? "NULL" : get_long_plugin_output(), + get_perf_data().empty() ? "NULL" : get_perf_data()); /* get the unprocessed return code */ /* NOTE: for passive checks, this is the final/processed state */ svc_res = static_cast( @@ -1385,9 +1439,11 @@ int host::handle_async_check_result_3x(check_result* queued_check_result) { /* if there was some error running the command, just skip it (this shouldn't * be happening) */ if (!queued_check_result->get_exited_ok()) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Check of host '" << get_name() << "' did not exit properly!"; + log_v2::runtime()->warn( + "Warning: Check of host '{}' did not exit properly!", get_name()); set_plugin_output("(Host check did not exit properly)"); set_long_plugin_output(""); @@ -1399,7 +1455,7 @@ int host::handle_async_check_result_3x(check_result* queued_check_result) { /* make sure the return code is within bounds */ else if (queued_check_result->get_return_code() < 0 || queued_check_result->get_return_code() > 3) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: return (code of " << queued_check_result->get_return_code() << " for check of host '" << get_name() << "' was out of bounds." @@ -1408,6 +1464,14 @@ int host::handle_async_check_result_3x(check_result* queued_check_result) { ? " Make sure the plugin you're trying to run actually " "exists." : ""); + log_v2::runtime()->warn( + "Warning: return (code of {} for check of host '{}' was out of " + "bounds.", + queued_check_result->get_return_code(), get_name(), + (queued_check_result->get_return_code() == 126 || + queued_check_result->get_return_code() == 127) + ? " Make sure the plugin you're trying to run actually exists." + : ""); std::ostringstream oss; oss << "(Return code of " << queued_check_result->get_return_code() @@ -1458,8 +1522,12 @@ int host::handle_async_check_result_3x(check_result* queued_check_result) { reschedule_check, true, config->cached_host_check_horizon()); - logger(dbg_checks, more) << "** Async check result for host '" << get_name() - << "' handled: new state=" << get_current_state(); + engine_logger(dbg_checks, more) + << "** Async check result for host '" << get_name() + << "' handled: new state=" << get_current_state(); + log_v2::checks()->debug( + "** Async check result for host '{}' handled: new state={}", get_name(), + get_current_state()); /* high resolution start time for event broker */ start_time_hires = queued_check_result->get_start_time(); @@ -1489,11 +1557,16 @@ int host::run_scheduled_check(int check_options, double latency) { time_t next_valid_time = 0L; bool time_is_valid = true; - logger(dbg_functions, basic) << "run_scheduled_host_check_3x()"; + engine_logger(dbg_functions, basic) << "run_scheduled_host_check_3x()"; + log_v2::functions()->trace("run_scheduled_host_check_3x()"); - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Attempting to run scheduled check of host '" << get_name() << "': check options=" << check_options << ", latency=" << latency; + log_v2::checks()->trace( + "Attempting to run scheduled check of host '{}': check options={}, " + "latency={}", + get_name(), check_options, latency); /* attempt to run the check */ result = run_async_check(check_options, latency, true, true, &time_is_valid, @@ -1501,8 +1574,9 @@ int host::run_scheduled_check(int check_options, double latency) { /* an error occurred, so reschedule the check */ if (result == ERROR) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Unable to run scheduled host check at this time"; + log_v2::checks()->debug("Unable to run scheduled host check at this time"); /* only attempt to (re)schedule checks that should get checked... */ if (get_should_be_scheduled()) { @@ -1536,23 +1610,33 @@ int host::run_scheduled_check(int check_options, double latency) { set_next_check((time_t)(next_valid_time + (60 * 60 * 24 * 7))); - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Check of host '" << get_name() << "' could not be " "rescheduled properly. Scheduling check for next week... " << " next_check " << get_next_check(); + log_v2::runtime()->warn( + "Warning: Check of host '{}' could not be " + "rescheduled properly. Scheduling check for next week... {} " + "next_check {}", + get_name(), get_name(), get_next_check()); - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Unable to find any valid times to reschedule the next" " host check!"; + log_v2::checks()->debug( + "Unable to find any valid times to reschedule the next" + " host check!"); } /* this service could be rescheduled... */ else { set_next_check(next_valid_time); set_should_be_scheduled(true); - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Rescheduled next host check for " << my_ctime(&next_valid_time); + log_v2::checks()->debug("Rescheduled next host check for {}", + my_ctime(&next_valid_time)); } } @@ -1579,21 +1663,29 @@ int host::run_async_check(int check_options, bool reschedule_check, bool* time_is_valid, time_t* preferred_time) noexcept { - logger(dbg_functions, basic) + engine_logger(dbg_functions, basic) << "host::run_async_check, check_options=" << check_options << ", latency=" << latency << ", scheduled_check=" << scheduled_check << ", reschedule_check=" << reschedule_check; + log_v2::functions()->trace( + "host::run_async_check, check_options={}, latency={}, " + "scheduled_check={}, reschedule_check={}", + check_options, latency, scheduled_check, reschedule_check); // Preamble. if (!get_check_command_ptr()) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Attempt to run active check on host '" << get_name() << "' with no check command"; + log_v2::runtime()->error( + "Error: Attempt to run active check on host '{}' with no check command", + get_name()); return ERROR; } - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "** Running async check of host '" << get_name() << "'..."; + log_v2::checks()->trace("** Running async check of host '{}'...", get_name()); // Check if the host is viable now. if (!verify_check_viability(check_options, time_is_valid, preferred_time)) @@ -1608,9 +1700,13 @@ int host::run_async_check(int check_options, // Don't execute a new host check if one is already running. if (get_is_executing() && !(check_options & CHECK_OPTION_FORCE_EXECUTION)) { - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "A check of this host (" << get_name() << ") is already being executed, so we'll pass for the moment..."; + log_v2::checks()->trace( + "A check of this host ({}) is already being executed, so we'll pass " + "for the moment...", + get_name()); return OK; } @@ -1628,21 +1724,28 @@ int host::run_async_check(int check_options, // Host check was cancel by NEB module. Reschedule check later. if (NEBERROR_CALLBACKCANCEL == res) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Some broker module cancelled check of host '" << get_name() << "'"; + log_v2::runtime()->error( + "Error: Some broker module cancelled check of host '{}'", get_name()); return ERROR; } // Host check was overriden by NEB module. else if (NEBERROR_CALLBACKOVERRIDE == res) { - logger(dbg_functions, basic) + engine_logger(dbg_functions, basic) << "Some broker module overrode check of host '" << get_name() << "' so we'll bail out"; + log_v2::functions()->trace( + "Some broker module overrode check of host '{}' so we'll bail out", + get_name()); return OK; } // Checking starts. - logger(dbg_functions, basic) << "Checking host '" << get_name() << "'..."; + engine_logger(dbg_functions, basic) + << "Checking host '" << get_name() << "'..."; + log_v2::functions()->trace("Checking host '{}'...", get_name()); // Clear check options. if (scheduled_check) @@ -1731,8 +1834,10 @@ int host::run_async_check(int check_options, checks::checker::instance().add_check_result_to_reap( check_result_info.release()); - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Error: Host check command execution failed: " << e.what(); + log_v2::runtime()->warn("Error: Host check command execution failed: {}", + e.what()); } } while (retry); @@ -1753,17 +1858,24 @@ bool host::schedule_check(time_t check_time, int options) { timed_event* temp_event = nullptr; int use_original_event = true; - logger(dbg_functions, basic) << "schedule_host_check()"; + engine_logger(dbg_functions, basic) << "schedule_host_check()"; + log_v2::functions()->trace("schedule_host_check()"); - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Scheduling a " << (options & CHECK_OPTION_FORCE_EXECUTION ? "forced" : "non-forced") << ", active check of host '" << get_name() << "' @ " << my_ctime(&check_time); + log_v2::checks()->trace( + "Scheduling a {}, active check of host '{}' @ {}", + options & CHECK_OPTION_FORCE_EXECUTION ? "forced" : "non-forced", + get_name(), my_ctime(&check_time)); /* don't schedule a check if active checks of this host are disabled */ if (!get_checks_enabled() && !(options & CHECK_OPTION_FORCE_EXECUTION)) { - logger(dbg_checks, basic) << "Active checks are disabled for this host."; + engine_logger(dbg_checks, basic) + << "Active checks are disabled for this host."; + log_v2::checks()->trace("Active checks are disabled for this host."); return false; } @@ -1784,10 +1896,11 @@ bool host::schedule_check(time_t check_time, int options) { /* we found another host check event for this host in the queue - what should * we do? */ if (temp_event) { - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "Found another host check event for this host @ " << my_ctime(&temp_event->run_time); - + log_v2::checks()->debug("Found another host check event for this host @ {}", + my_ctime(&temp_event->run_time)); /* use the originally scheduled check unless we decide otherwise */ use_original_event = true; @@ -1797,9 +1910,12 @@ bool host::schedule_check(time_t check_time, int options) { * original, so use it instead */ if ((options & CHECK_OPTION_FORCE_EXECUTION) && (check_time < temp_event->run_time)) { - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "New host check event is forced and occurs before the " "existing event, so the new event be used instead."; + log_v2::checks()->debug( + "New host check event is forced and occurs before the " + "existing event, so the new event be used instead."); use_original_event = false; } } @@ -1809,25 +1925,34 @@ bool host::schedule_check(time_t check_time, int options) { /* the new event is a forced check, so use it instead */ if ((options & CHECK_OPTION_FORCE_EXECUTION)) { use_original_event = false; - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "New host check event is forced, so it will be used " "instead of the existing event."; + log_v2::checks()->debug( + "New host check event is forced, so it will be used " + "instead of the existing event."); } /* the new event is not forced either and its execution time is earlier than the original, so use it instead */ else if (check_time < temp_event->run_time) { use_original_event = false; - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "New host check event occurs before the existing (older) " "event, so it will be used instead."; + log_v2::checks()->debug( + "New host check event occurs before the existing (older) " + "event, so it will be used instead."); } /* the new event is older, so override the existing one */ else { - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "New host check event occurs after the existing event, " "so we'll ignore it."; + log_v2::checks()->debug( + "New host check event occurs after the existing event, " + "so we'll ignore it."); } } @@ -1840,7 +1965,8 @@ bool host::schedule_check(time_t check_time, int options) { /* use the new event */ if (!use_original_event) { - logger(dbg_checks, most) << "Scheduling new host check event."; + engine_logger(dbg_checks, most) << "Scheduling new host check event."; + log_v2::checks()->debug("Scheduling new host check event."); /* set the next host check time */ set_next_check(check_time); @@ -1856,8 +1982,10 @@ bool host::schedule_check(time_t check_time, int options) { if (temp_event != nullptr) set_next_check(temp_event->run_time); - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "Keeping original host check event (ignoring the new one)."; + log_v2::checks()->debug( + "Keeping original host check event (ignoring the new one)."); } /* update the status log */ @@ -1883,10 +2011,12 @@ void host::check_for_flapping(bool update, double low_curve_value = 0.75; double high_curve_value = 1.25; - logger(dbg_functions, basic) << "host::check_for_flapping()"; + engine_logger(dbg_functions, basic) << "host::check_for_flapping()"; + log_v2::functions()->trace("host::check_for_flapping()"); - logger(dbg_flapping, more) + engine_logger(dbg_flapping, more) << "Checking host '" << get_name() << "' for flapping..."; + log_v2::checks()->debug("Checking host '{}' for flapping...", get_name()); time(¤t_time); @@ -1971,10 +2101,13 @@ void host::check_for_flapping(bool update, set_percent_state_change(curved_percent_change); - logger(dbg_flapping, most) + engine_logger(dbg_flapping, most) << com::centreon::logging::setprecision(2) << "LFT=" << low_threshold << ", HFT=" << high_threshold << ", CPC=" << curved_percent_change << ", PSC=" << curved_percent_change << "%"; + log_v2::checks()->debug("LFT={:.2f}, HFT={}, CPC={}, PSC={}%", low_threshold, + high_threshold, curved_percent_change, + curved_percent_change); /* don't do anything if we don't have flap detection enabled on a program-wide * basis */ @@ -2000,9 +2133,11 @@ void host::check_for_flapping(bool update, if ((get_current_state() != host::state_up) || get_is_flapping()) is_flapping = true; } - logger(dbg_flapping, more) + engine_logger(dbg_flapping, more) << "Host " << (is_flapping ? "is" : "is not") << " flapping (" << curved_percent_change << "% state change)."; + log_v2::checks()->debug("Host {} flapping ({}% state change).", + is_flapping ? "is" : "is not", curved_percent_change); /* did the host just start flapping? */ if (is_flapping && !get_is_flapping()) @@ -2018,16 +2153,23 @@ void host::set_flap(double percent_change, double high_threshold, double low_threshold, bool allow_flapstart_notification) { - logger(dbg_functions, basic) << "set_host_flap()"; + engine_logger(dbg_functions, basic) << "set_host_flap()"; + log_v2::functions()->trace("set_host_flap()"); - logger(dbg_flapping, more) << "Host '" << get_name() << "' started flapping!"; + engine_logger(dbg_flapping, more) + << "Host '" << get_name() << "' started flapping!"; + log_v2::checks()->debug("Host '{}' started flapping!", get_name()); /* log a notice - this one is parsed by the history CGI */ - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << com::centreon::logging::setprecision(1) << "HOST FLAPPING ALERT: " << get_name() << ";STARTED; Host appears to have started flapping (" << percent_change << "% change > " << high_threshold << "% threshold)"; + log_v2::runtime()->warn( + "HOST FLAPPING ALERT: {};STARTED; Host appears to have started flapping " + "({:.1f}% change > {:.1f}% threshold)", + get_name(), percent_change, high_threshold); /* add a non-persistent comment to the host */ std::ostringstream oss; @@ -2067,17 +2209,23 @@ void host::set_flap(double percent_change, void host::clear_flap(double percent_change, double high_threshold, double low_threshold) { - logger(dbg_functions, basic) << "host::clear_flap()"; + engine_logger(dbg_functions, basic) << "host::clear_flap()"; + log_v2::functions()->trace("host::clear_flap()"); - logger(dbg_flapping, basic) + engine_logger(dbg_flapping, basic) << "Host '" << get_name() << "' stopped flapping."; + log_v2::checks()->debug("Host '{}' stopped flapping.", get_name()); /* log a notice - this one is parsed by the history CGI */ - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << com::centreon::logging::setprecision(1) << "HOST FLAPPING ALERT: " << get_name() << ";STOPPED; Host appears to have stopped flapping (" << percent_change << "% change < " << low_threshold << "% threshold)"; + log_v2::events()->info( + "HOST FLAPPING ALERT: {};STOPPED; Host appears to have stopped flapping " + "({:.1f}% change < {:.1f}% threshold)", + get_name(), percent_change, low_threshold); /* delete the comment we added earlier */ if (get_flapping_comment_id() != 0) @@ -2116,8 +2264,10 @@ void host::check_for_expired_acknowledgement() { if (get_acknowledgement_timeout() > 0) { time_t now(time(nullptr)); if (get_last_acknowledgement() + get_acknowledgement_timeout() >= now) { - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "Acknowledgement of host '" << get_name() << "' just expired"; + log_v2::events()->info("Acknowledgement of host '{}' just expired", + get_name()); set_problem_has_been_acknowledged(false); set_acknowledgement_type(ACKNOWLEDGEMENT_NONE); update_status(); @@ -2132,7 +2282,8 @@ int host::handle_state() { bool state_change = false; time_t current_time; - logger(dbg_functions, basic) << "handle_host_state()"; + engine_logger(dbg_functions, basic) << "handle_host_state()"; + log_v2::functions()->trace("handle_host_state()"); /* get current time */ time(¤t_time); @@ -2282,7 +2433,8 @@ bool host::verify_check_viability(int check_options, time_t preferred_time = 0L; int check_interval = 0; - logger(dbg_functions, basic) << "check_host_check_viability_3x()"; + engine_logger(dbg_functions, basic) << "check_host_check_viability_3x()"; + log_v2::functions()->trace("check_host_check_viability_3x()"); /* get the check interval to use if we need to reschedule the check */ if (this->get_state_type() == soft && @@ -2360,9 +2512,11 @@ int host::notify_contact(nagios_macros* mac, int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; int neb_result; - logger(dbg_functions, basic) << "notify_contact_of_host()"; - logger(dbg_notifications, most) + engine_logger(dbg_functions, basic) << "notify_contact_of_host()"; + log_v2::functions()->trace("notify_contact_of_host()"); + engine_logger(dbg_notifications, most) << "** Notifying contact '" << cntct->get_name() << "'"; + log_v2::notifications()->info("** Notifying contact '{}'", cntct->get_name()); /* get start time */ gettimeofday(&start_time, nullptr); @@ -2404,8 +2558,9 @@ int host::notify_contact(nagios_macros* mac, if (raw_command.empty()) continue; - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "Raw notification command: " << raw_command; + log_v2::notifications()->info("Raw notification command: {}", raw_command); /* process any macros contained in the argument */ process_macros_r(mac, raw_command, processed_command, macro_options); @@ -2414,8 +2569,10 @@ int host::notify_contact(nagios_macros* mac, /* run the notification command... */ - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "Processed notification command: " << processed_command; + log_v2::notifications()->info("Processed notification command: {}", + processed_command); /* log the notification to program log file */ if (config->log_notifications()) { @@ -2443,10 +2600,14 @@ int host::notify_contact(nagios_macros* mac, .append(host_state_str) .append(")"); - logger(log_host_notification, basic) + engine_logger(log_host_notification, basic) << "HOST NOTIFICATION: " << cntct->get_name() << ';' << this->get_name() << ';' << host_notification_state << ";" << cmd->get_name() << ';' << this->get_plugin_output() << info; + log_v2::notifications()->info("HOST NOTIFICATION: {};{};{};{};{};{}", + cntct->get_name(), this->get_name(), + host_notification_state, cmd->get_name(), + this->get_plugin_output(), info); } /* run the notification command */ @@ -2455,18 +2616,25 @@ int host::notify_contact(nagios_macros* mac, my_system_r(mac, processed_command, config->notification_timeout(), &early_timeout, &exectime, out, 0); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: can't execute host notification '" << cntct->get_name() << "' : " << e.what(); + log_v2::runtime()->error( + "Error: can't execute host notification '{}' : {}", cntct->get_name(), + e.what()); } /* check to see if the notification timed out */ if (early_timeout) { - logger(log_host_notification | log_runtime_warning, basic) + engine_logger(log_host_notification | log_runtime_warning, basic) << "Warning: Contact '" << cntct->get_name() << "' host notification command '" << processed_command << "' timed out after " << config->notification_timeout() << " seconds"; + log_v2::notifications()->info( + "Warning: Contact '{}' host notification command '{}' timed out " + "after {} seconds", + cntct->get_name(), processed_command, config->notification_timeout()); } /* get end time */ @@ -2507,10 +2675,13 @@ void host::update_notification_flags() { void host::disable_flap_detection() { unsigned long attr = MODATTR_FLAP_DETECTION_ENABLED; - logger(dbg_functions, basic) << "disable_host_flap_detection()"; + engine_logger(dbg_functions, basic) << "disable_host_flap_detection()"; + log_v2::functions()->trace("disable_host_flap_detection()"); - logger(dbg_functions, more) + engine_logger(dbg_functions, more) << "Disabling flap detection for host '" << get_name() << "'."; + log_v2::functions()->debug("Disabling flap detection for host '{}'.", + get_name()); /* nothing to do... */ if (!get_flap_detection_enabled()) @@ -2535,10 +2706,12 @@ void host::disable_flap_detection() { void host::enable_flap_detection() { unsigned long attr = MODATTR_FLAP_DETECTION_ENABLED; - logger(dbg_functions, basic) << "host::enable_flap_detection()"; + engine_logger(dbg_functions, basic) << "host::enable_flap_detection()"; + log_v2::functions()->trace("host::enable_flap_detection()"); - logger(dbg_flapping, more) + engine_logger(dbg_flapping, more) << "Enabling flap detection for host '" << get_name() << "'."; + log_v2::checks()->debug("Enabling flap detection for host '{}'.", get_name()); /* nothing to do... */ if (get_flap_detection_enabled()) @@ -2571,8 +2744,9 @@ bool host::is_valid_escalation_for_notification(escalation const* e, uint32_t notification_number; time_t current_time; - logger(dbg_functions, basic) + engine_logger(dbg_functions, basic) << "host::is_valid_escalation_for_notification()"; + log_v2::functions()->trace("host::is_valid_escalation_for_notification()"); /* get the current time */ time(¤t_time); @@ -2637,7 +2811,9 @@ bool host::is_result_fresh(time_t current_time, int log_this) { int tminutes = 0; int tseconds = 0; - logger(dbg_checks, most) << "Checking freshness of host '" << _name << "'..."; + engine_logger(dbg_checks, most) + << "Checking freshness of host '" << _name << "'..."; + log_v2::checks()->debug("Checking freshness of host '{}'...", _name); /* use user-supplied freshness threshold or auto-calculate a freshness * threshold to use? */ @@ -2653,9 +2829,11 @@ bool host::is_result_fresh(time_t current_time, int log_this) { } else freshness_threshold = get_freshness_threshold(); - logger(dbg_checks, most) << "Freshness thresholds: host=" - << get_freshness_threshold() - << ", use=" << freshness_threshold; + engine_logger(dbg_checks, most) + << "Freshness thresholds: host=" << get_freshness_threshold() + << ", use=" << freshness_threshold; + log_v2::checks()->debug("Freshness thresholds: host={}, use={}", + get_freshness_threshold(), freshness_threshold); /* calculate expiration time */ /* CHANGED 11/10/05 EG - program start is only used in expiration time @@ -2677,12 +2855,13 @@ bool host::is_result_fresh(time_t current_time, int log_this) { else expiration_time = (time_t)(get_last_check() + freshness_threshold); - logger(dbg_checks, most) << "HBC: " << has_been_checked() - << ", PS: " << program_start - << ", ES: " << event_start - << ", LC: " << get_last_check() - << ", CT: " << current_time - << ", ET: " << expiration_time; + engine_logger(dbg_checks, most) + << "HBC: " << has_been_checked() << ", PS: " << program_start + << ", ES: " << event_start << ", LC: " << get_last_check() + << ", CT: " << current_time << ", ET: " << expiration_time; + log_v2::checks()->debug("HBC: {}, PS: {}, ES: {}, LC: {}, CT: {}, ET: {}", + has_been_checked(), program_start, event_start, + get_last_check(), current_time, expiration_time); /* the results for the last check of this host are stale */ if (expiration_time < current_time) { @@ -2693,26 +2872,40 @@ bool host::is_result_fresh(time_t current_time, int log_this) { /* log a warning */ if (log_this) - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: The results of host '" << _name << "' are stale by " << days << "d " << hours << "h " << minutes << "m " << seconds << "s (threshold=" << tdays << "d " << thours << "h " << tminutes << "m " << tseconds << "s). I'm forcing an immediate check of" " the host."; - - logger(dbg_checks, more) + log_v2::runtime()->warn( + "Warning: The results of host '{}' are stale by {}d {}h {}m {}s " + "(threshold={}d {}h {}m {}s). I'm forcing an immediate check of the " + "host.", + _name, days, hours, minutes, seconds, tdays, thours, tminutes, + tseconds); + + engine_logger(dbg_checks, more) << "Check results for host '" << _name << "' are stale by " << days << "d " << hours << "h " << minutes << "m " << seconds << "s (threshold=" << tdays << "d " << thours << "h " << tminutes << "m " << tseconds << "s). " "Forcing an immediate check of the host..."; + log_v2::checks()->debug( + "Check results for host '{}' are stale by {}d {}h {}m {}s " + "(threshold={}d {}h {}m {}s). Forcing an immediate check of the " + "host...", + _name, days, hours, minutes, seconds, tdays, thours, tminutes, + tseconds); return false; } else - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Check results for host '" << this->get_name() << "' are fresh."; + log_v2::checks()->debug("Check results for host '{}' are fresh.", + this->get_name()); return true; } @@ -2720,8 +2913,9 @@ bool host::is_result_fresh(time_t current_time, int log_this) { /* handles the details for a host when flap detection is disabled (globally or * per-host) */ void host::handle_flap_detection_disabled() { - logger(dbg_functions, basic) << "handle_host_flap_detection_disabled()"; - + engine_logger(dbg_functions, basic) + << "handle_host_flap_detection_disabled()"; + log_v2::functions()->trace("handle_host_flap_detection_disabled()"); /* if the host was flapping, remove the flapping indicator */ if (get_is_flapping()) { this->set_is_flapping(false); @@ -2732,9 +2926,12 @@ void host::handle_flap_detection_disabled() { this->set_flapping_comment_id(0); /* log a notice - this one is parsed by the history CGI */ - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "HOST FLAPPING ALERT: " << this->get_name() << ";DISABLED; Flap detection has been disabled"; + log_v2::events()->info( + "HOST FLAPPING ALERT: {};DISABLED; Flap detection has been disabled", + this->get_name()); /* send data to event broker */ broker_flapping_data(NEBTYPE_FLAPPING_STOP, NEBFLAG_NONE, @@ -2756,7 +2953,8 @@ int host::perform_on_demand_check(enum host::host_state* check_return_code, int check_options, int use_cached_result, unsigned long check_timestamp_horizon) { - logger(dbg_functions, basic) << "perform_on_demand_host_check()"; + engine_logger(dbg_functions, basic) << "perform_on_demand_host_check()"; + log_v2::functions()->trace("perform_on_demand_host_check()"); perform_on_demand_check_3x(check_return_code, check_options, use_cached_result, check_timestamp_horizon); @@ -2770,10 +2968,12 @@ int host::perform_on_demand_check_3x(host::host_state* check_result_code, unsigned long check_timestamp_horizon) { int result = OK; - logger(dbg_functions, basic) << "perform_on_demand_host_check_3x()"; + engine_logger(dbg_functions, basic) << "perform_on_demand_host_check_3x()"; + log_v2::functions()->trace("perform_on_demand_host_check_3x()"); - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "** On-demand check for host '" << _name << "'..."; + log_v2::checks()->trace("** On-demand check for host '{}'...", _name); /* check the status of the host */ result = this->run_sync_check_3x(check_result_code, check_options, @@ -2787,18 +2987,23 @@ int host::run_sync_check_3x(enum host::host_state* check_result_code, int check_options, int use_cached_result, unsigned long check_timestamp_horizon) { - logger(dbg_functions, basic) + engine_logger(dbg_functions, basic) << "run_sync_host_check_3x: hst=" << this << ", check_options=" << check_options << ", use_cached_result=" << use_cached_result << ", check_timestamp_horizon=" << check_timestamp_horizon; + log_v2::functions()->trace( + "run_sync_host_check_3x: hst={}, check_options={}, use_cached_result={}, " + "check_timestamp_horizon={}", + (void*)this, check_options, use_cached_result, check_timestamp_horizon); try { checks::checker::instance().run_sync(this, check_result_code, check_options, use_cached_result, check_timestamp_horizon); } catch (std::exception const& e) { - logger(log_runtime_error, basic) << "Error: " << e.what(); + engine_logger(log_runtime_error, basic) << "Error: " << e.what(); + log_v2::runtime()->error("Error: {}", e.what()); return ERROR; } return OK; @@ -2822,14 +3027,22 @@ int host::process_check_result_3x(enum host::host_state new_state, int run_async_check = true; bool has_parent; - logger(dbg_functions, basic) << "process_host_check_result_3x()"; + engine_logger(dbg_functions, basic) << "process_host_check_result_3x()"; + log_v2::functions()->trace("process_host_check_result_3x()"); - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "HOST: " << _name << ", ATTEMPT=" << get_current_attempt() << "/" << get_max_attempts() << ", CHECK TYPE=" << (get_check_type() == check_active ? "ACTIVE" : "PASSIVE") << ", STATE TYPE=" << (get_state_type() == hard ? "HARD" : "SOFT") << ", OLD STATE=" << get_current_state() << ", NEW STATE=" << new_state; + log_v2::checks()->debug( + "HOST: {}, ATTEMPT={}/{}, CHECK TYPE={}, STATE TYPE={}, OLD STATE={}, " + "NEW STATE={}", + _name, get_current_attempt(), get_max_attempts(), + get_check_type() == check_active ? "ACTIVE" : "PASSIVE", + get_state_type() == hard ? "HARD" : "SOFT", get_current_state(), + new_state); /* get the current time */ time(¤t_time); @@ -2848,14 +3061,17 @@ int host::process_check_result_3x(enum host::host_state new_state, * commands by getting dropped in checkresults dir */ if (get_check_type() == check_passive) { if (config->log_passive_checks()) - logger(log_passive_check, basic) + engine_logger(log_passive_check, basic) << "PASSIVE HOST CHECK: " << _name << ";" << new_state << ";" << get_plugin_output(); + log_v2::checks()->debug("PASSIVE HOST CHECK: {};{};{}", _name, new_state, + get_plugin_output()); } /******* HOST WAS DOWN/UNREACHABLE INITIALLY *******/ if (_current_state != host::state_up) { - logger(dbg_checks, more) << "Host was DOWN/UNREACHABLE."; + engine_logger(dbg_checks, more) << "Host was DOWN/UNREACHABLE."; + log_v2::checks()->debug("Host was DOWN/UNREACHABLE."); /***** HOST IS NOW UP *****/ /* the host just recovered! */ @@ -2872,9 +3088,12 @@ int host::process_check_result_3x(enum host::host_state new_state, else set_state_type(soft); - logger(dbg_checks, more) << "Host experienced a " - << (get_state_type() == hard ? "HARD" : "SOFT") - << " recovery (it's now UP)."; + engine_logger(dbg_checks, more) + << "Host experienced a " + << (get_state_type() == hard ? "HARD" : "SOFT") + << " recovery (it's now UP)."; + log_v2::checks()->debug("Host experienced a {} recovery (it's now UP).", + get_state_type() == hard ? "HARD" : "SOFT"); /* reschedule the next check of the host at the normal interval */ reschedule_check = true; @@ -2884,7 +3103,9 @@ int host::process_check_result_3x(enum host::host_state new_state, /* propagate checks to immediate parents if they are not already UP */ /* we do this because a parent host (or grandparent) may have recovered * somewhere and we should catch the recovery as soon as possible */ - logger(dbg_checks, more) << "Propagating checks to parent host(s)..."; + engine_logger(dbg_checks, more) + << "Propagating checks to parent host(s)..."; + log_v2::checks()->debug("Propagating checks to parent host(s)..."); for (host_map_unsafe::iterator it{parent_hosts.begin()}, end{parent_hosts.end()}; @@ -2892,8 +3113,10 @@ int host::process_check_result_3x(enum host::host_state new_state, if (!it->second) continue; if (it->second->get_current_state() != host::state_up) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Check of parent host '" << it->first << "' queued."; + log_v2::checks()->debug("Check of parent host '{}' queued.", + it->first); check_hostlist.push_back(it->second); } } @@ -2901,7 +3124,9 @@ int host::process_check_result_3x(enum host::host_state new_state, /* propagate checks to immediate children if they are not already UP */ /* we do this because children may currently be UNREACHABLE, but may (as a * result of this recovery) switch to UP or DOWN states */ - logger(dbg_checks, more) << "Propagating checks to child host(s)..."; + engine_logger(dbg_checks, more) + << "Propagating checks to child host(s)..."; + log_v2::checks()->debug("Propagating checks to child host(s)..."); for (host_map_unsafe::iterator it{child_hosts.begin()}, end{child_hosts.end()}; @@ -2909,8 +3134,10 @@ int host::process_check_result_3x(enum host::host_state new_state, if (!it->second) continue; if (it->second->get_current_state() != host::state_up) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Check of child host '" << it->first << "' queued."; + log_v2::checks()->debug("Check of child host '{}' queued.", + it->first); check_hostlist.push_back(it->second); } } @@ -2919,7 +3146,8 @@ int host::process_check_result_3x(enum host::host_state new_state, /***** HOST IS STILL DOWN/UNREACHABLE *****/ /* we're still in a problem state... */ else { - logger(dbg_checks, more) << "Host is still DOWN/UNREACHABLE."; + engine_logger(dbg_checks, more) << "Host is still DOWN/UNREACHABLE."; + log_v2::checks()->debug("Host is still DOWN/UNREACHABLE."); /* passive checks are treated as HARD states by default... */ if (get_check_type() == check_passive && @@ -2976,12 +3204,14 @@ int host::process_check_result_3x(enum host::host_state new_state, /******* HOST WAS UP INITIALLY *******/ else { - logger(dbg_checks, more) << "Host was UP."; + engine_logger(dbg_checks, more) << "Host was UP."; + log_v2::checks()->debug("Host was UP."); /***** HOST IS STILL UP *****/ /* either the host never went down since last check */ if (new_state == host::state_up) { - logger(dbg_checks, more) << "Host is still UP."; + engine_logger(dbg_checks, more) << "Host is still UP."; + log_v2::checks()->debug("Host is still UP."); /* set the current state */ _current_state = host::state_up; @@ -2997,11 +3227,13 @@ int host::process_check_result_3x(enum host::host_state new_state, } /***** HOST IS NOW DOWN/UNREACHABLE *****/ else { - logger(dbg_checks, more) << "Host is now DOWN/UNREACHABLE."; + engine_logger(dbg_checks, more) << "Host is now DOWN/UNREACHABLE."; + log_v2::checks()->debug("Host is now DOWN/UNREACHABLE."); /***** SPECIAL CASE FOR HOSTS WITH MAX_ATTEMPTS==1 *****/ if (get_max_attempts() == 1) { - logger(dbg_checks, more) << "Max attempts = 1!."; + engine_logger(dbg_checks, more) << "Max attempts = 1!."; + log_v2::checks()->debug("Max attempts = 1!."); /* set the state type */ set_state_type(hard); @@ -3023,9 +3255,12 @@ int host::process_check_result_3x(enum host::host_state new_state, if (get_check_type() == check_active) { has_parent = false; - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "** WARNING: Max attempts = 1, so we have to run serial " "checks of all parent hosts!"; + log_v2::checks()->debug( + "** WARNING: Max attempts = 1, so we have to run serial " + "checks of all parent hosts!"); for (host_map_unsafe::iterator it{parent_hosts.begin()}, end{parent_hosts.end()}; @@ -3035,8 +3270,10 @@ int host::process_check_result_3x(enum host::host_state new_state, has_parent = true; - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Running serial check parent host '" << it->first << "'..."; + log_v2::checks()->debug("Running serial check parent host '{}'...", + it->first); /* run an immediate check of the parent host */ it->second->run_sync_check_3x(&parent_state, check_options, @@ -3045,8 +3282,10 @@ int host::process_check_result_3x(enum host::host_state new_state, /* bail out as soon as we find one parent host that is UP */ if (parent_state == host::state_up) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Parent host is UP, so this one is DOWN."; + log_v2::checks()->debug( + "Parent host is UP, so this one is DOWN."); /* set the current state */ _current_state = host::state_down; @@ -3057,12 +3296,16 @@ int host::process_check_result_3x(enum host::host_state new_state, if (!has_parent) { /* host has no parents, so its up */ if (parent_hosts.empty()) { - logger(dbg_checks, more) << "Host has no parents, so it's DOWN."; + engine_logger(dbg_checks, more) + << "Host has no parents, so it's DOWN."; + log_v2::checks()->debug("Host has no parents, so it's DOWN."); _current_state = host::state_down; } else { /* no parents were up, so this host is UNREACHABLE */ - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "No parents were UP, so this host is UNREACHABLE."; + log_v2::checks()->debug( + "No parents were UP, so this host is UNREACHABLE."); _current_state = host::state_unreachable; } } @@ -3081,8 +3324,10 @@ int host::process_check_result_3x(enum host::host_state new_state, /* propagate checks to immediate children if they are not UNREACHABLE */ /* we do this because we may now be blocking the route to child hosts */ - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Propagating check to immediate non-UNREACHABLE child hosts..."; + log_v2::checks()->debug( + "Propagating check to immediate non-UNREACHABLE child hosts..."); for (host_map_unsafe::iterator it{child_hosts.begin()}, end{child_hosts.end()}; @@ -3090,8 +3335,10 @@ int host::process_check_result_3x(enum host::host_state new_state, if (!it->second) continue; if (it->second->get_current_state() != host::state_unreachable) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Check of child host '" << it->first << "' queued."; + log_v2::checks()->debug("Check of child host '{}' queued.", + it->first); check_hostlist.push_back(it->second); } } @@ -3145,9 +3392,12 @@ int host::process_check_result_3x(enum host::host_state new_state, * and blocked our route */ /* checking the parents ASAP will allow us to better determine the final * state (DOWN/UNREACHABLE) of this host later */ - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Propagating checks to immediate parent hosts that " "are UP..."; + log_v2::checks()->debug( + "Propagating checks to immediate parent hosts that " + "are UP..."); for (host_map_unsafe::iterator it{parent_hosts.begin()}, end{parent_hosts.end()}; @@ -3156,16 +3406,20 @@ int host::process_check_result_3x(enum host::host_state new_state, continue; if (it->second->get_current_state() == host::state_up) { check_hostlist.push_back(it->second); - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Check of host '" << it->first << "' queued."; + log_v2::checks()->debug("Check of host '{}' queued.", it->first); } } /* propagate checks to immediate children if they are not UNREACHABLE */ /* we do this because we may now be blocking the route to child hosts */ - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Propagating checks to immediate non-UNREACHABLE " "child hosts..."; + log_v2::checks()->debug( + "Propagating checks to immediate non-UNREACHABLE " + "child hosts..."); for (host_map_unsafe::iterator it{child_hosts.begin()}, end{child_hosts.end()}; @@ -3173,8 +3427,10 @@ int host::process_check_result_3x(enum host::host_state new_state, if (!it->second) continue; if (it->second->get_current_state() != host::state_unreachable) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Check of child host '" << it->first << "' queued."; + log_v2::checks()->debug("Check of child host '{}' queued.", + it->first); check_hostlist.push_back(it->second); } } @@ -3186,9 +3442,12 @@ int host::process_check_result_3x(enum host::host_state new_state, * notifications AND execution */ /* we do to help ensure that the dependency checks are accurate before * it comes time to notify */ - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Propagating predictive dependency checks to hosts this " "one depends on..."; + log_v2::checks()->debug( + "Propagating predictive dependency checks to hosts this " + "one depends on..."); for (hostdependency_mmap::const_iterator it{hostdependency::hostdependencies.find(_name)}, @@ -3198,9 +3457,11 @@ int host::process_check_result_3x(enum host::host_state new_state, if (temp_dependency->dependent_host_ptr == this && temp_dependency->master_host_ptr != nullptr) { master_host = (host*)temp_dependency->master_host_ptr; - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Check of host '" << master_host->get_name() << "' queued."; + log_v2::checks()->debug("Check of host '{}' queued.", + master_host->get_name()); check_hostlist.push_back(master_host); } } @@ -3209,20 +3470,30 @@ int host::process_check_result_3x(enum host::host_state new_state, } } - logger(dbg_checks, more) << "Pre-handle_host_state() Host: " << _name - << ", Attempt=" << get_current_attempt() << "/" - << get_max_attempts() << ", Type=" - << (get_state_type() == hard ? "HARD" : "SOFT") - << ", Final State=" << _current_state; + engine_logger(dbg_checks, more) + << "Pre-handle_host_state() Host: " << _name + << ", Attempt=" << get_current_attempt() << "/" << get_max_attempts() + << ", Type=" << (get_state_type() == hard ? "HARD" : "SOFT") + << ", Final State=" << _current_state; + log_v2::checks()->debug( + "Pre-handle_host_state() Host: {}, Attempt={}/{}, Type={}, Final " + "State={}", + _name, get_current_attempt(), get_max_attempts(), + get_state_type() == hard ? "HARD" : "SOFT", _current_state); /* handle the host state */ handle_state(); - logger(dbg_checks, more) << "Post-handle_host_state() Host: " << _name - << ", Attempt=" << get_current_attempt() << "/" - << get_max_attempts() << ", Type=" - << (get_state_type() == hard ? "HARD" : "SOFT") - << ", Final State=" << _current_state; + engine_logger(dbg_checks, more) + << "Post-handle_host_state() Host: " << _name + << ", Attempt=" << get_current_attempt() << "/" << get_max_attempts() + << ", Type=" << (get_state_type() == hard ? "HARD" : "SOFT") + << ", Final State=" << _current_state; + log_v2::checks()->debug( + "Post-handle_host_state() Host: {}, Attempt={}/{}, Type={}, Final " + "State={}", + _name, get_current_attempt(), get_max_attempts(), + get_state_type() == hard ? "HARD" : "SOFT", _current_state); /******************** POST-PROCESSING STUFF *********************/ @@ -3248,8 +3519,10 @@ int host::process_check_result_3x(enum host::host_state new_state, * checks, unless overridden above) */ bool sent = false; if (reschedule_check) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Rescheduling next check of host at " << my_ctime(&next_check); + log_v2::checks()->debug("Rescheduling next check of host at {}", + my_ctime(&next_check)); /* default is to reschedule host check unless a test below fails... */ set_should_be_scheduled(true); @@ -3302,13 +3575,19 @@ int host::process_check_result_3x(enum host::host_state new_state, run_async_check = true; temp_host = *it; - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "ASYNC CHECK OF HOST: " << temp_host->get_name() << ", CURRENTTIME: " << current_time << ", LASTHOSTCHECK: " << temp_host->get_last_check() << ", CACHEDTIMEHORIZON: " << check_timestamp_horizon << ", USECACHEDRESULT: " << use_cached_result << ", ISEXECUTING: " << temp_host->get_is_executing(); + log_v2::checks()->debug( + "ASYNC CHECK OF HOST: {}, CURRENTTIME: {}, LASTHOSTCHECK: {}, " + "CACHEDTIMEHORIZON: {}, USECACHEDRESULT: {}, ISEXECUTING: {}", + temp_host->get_name(), current_time, temp_host->get_last_check(), + check_timestamp_horizon, use_cached_result, + temp_host->get_is_executing()); if (use_cached_result && (static_cast( current_time - temp_host->get_last_check()) <= @@ -3335,21 +3614,27 @@ enum host::host_state host::determine_host_reachability() { enum host::host_state state = host::state_down; bool is_host_present = false; - logger(dbg_functions, basic) << "determine_host_reachability()"; + engine_logger(dbg_functions, basic) << "determine_host_reachability()"; + log_v2::functions()->trace("determine_host_reachability()"); - logger(dbg_checks, most) << "Determining state of host '" << _name - << "': current state=" << _current_state; + engine_logger(dbg_checks, most) << "Determining state of host '" << _name + << "': current state=" << _current_state; + log_v2::checks()->debug("Determining state of host '{}': current state= {}", + _name, _current_state); /* host is UP - no translation needed */ if (_current_state == host::state_up) { state = host::state_up; - logger(dbg_checks, most) << "Host is UP, no state translation needed."; + engine_logger(dbg_checks, most) + << "Host is UP, no state translation needed."; + log_v2::checks()->debug("Host is UP, no state translation needed."); } /* host has no parents, so it is DOWN */ else if (parent_hosts.size() == 0) { state = host::state_down; - logger(dbg_checks, most) << "Host has no parents, so it is DOWN."; + engine_logger(dbg_checks, most) << "Host has no parents, so it is DOWN."; + log_v2::checks()->debug("Host has no parents, so it is DOWN."); } /* check all parent hosts to see if we're DOWN or UNREACHABLE */ @@ -3365,15 +3650,19 @@ enum host::host_state host::determine_host_reachability() { is_host_present = true; /* set the current state */ state = host::state_down; - logger(dbg_checks, most) << "At least one parent (" << it->first - << ") is up, so host is DOWN."; + engine_logger(dbg_checks, most) << "At least one parent (" << it->first + << ") is up, so host is DOWN."; + log_v2::checks()->debug( + "At least one parent ({}) is up, so host is DOWN.", it->first); break; } } /* no parents were up, so this host is UNREACHABLE */ if (!is_host_present) { state = host::state_unreachable; - logger(dbg_checks, most) << "No parents were up, so host is UNREACHABLE."; + engine_logger(dbg_checks, most) + << "No parents were up, so host is UNREACHABLE."; + log_v2::checks()->debug("No parents were up, so host is UNREACHABLE."); } } @@ -3397,7 +3686,8 @@ std::list& host::get_parent_groups() { * @return true if it is authorized. */ bool host::authorized_by_dependencies(dependency::types dependency_type) const { - logger(dbg_functions, basic) << "host::authorized_by_dependencies()"; + engine_logger(dbg_functions, basic) << "host::authorized_by_dependencies()"; + log_v2::functions()->trace("host::authorized_by_dependencies()"); auto p(hostdependency::hostdependencies.equal_range(_name)); for (hostdependency_mmap::const_iterator it{p.first}, end{p.second}; @@ -3449,13 +3739,17 @@ bool host::authorized_by_dependencies(dependency::types dependency_type) const { void host::check_result_freshness() { time_t current_time = 0L; - logger(dbg_functions, basic) << "check_host_result_freshness()"; - logger(dbg_checks, most) + engine_logger(dbg_functions, basic) << "check_host_result_freshness()"; + log_v2::functions()->trace("check_host_result_freshness()"); + engine_logger(dbg_checks, most) << "Attempting to check the freshness of host check results..."; + log_v2::checks()->debug( + "Attempting to check the freshness of host check results..."); /* bail out if we're not supposed to be checking freshness */ if (!config->check_host_freshness()) { - logger(dbg_checks, most) << "Host freshness checking is disabled."; + engine_logger(dbg_checks, most) << "Host freshness checking is disabled."; + log_v2::checks()->debug("Host freshness checking is disabled."); return; } @@ -3511,15 +3805,19 @@ void host::check_result_freshness() { * */ void host::adjust_check_attempt(bool is_active) { - logger(dbg_functions, basic) << "adjust_host_check_attempt_3x()"; - - logger(dbg_checks, most) << "Adjusting check attempt number for host '" - << _name - << "': current attempt=" << get_current_attempt() - << "/" << get_max_attempts() - << ", state=" << _current_state - << ", state type=" << get_state_type(); - + engine_logger(dbg_functions, basic) << "adjust_host_check_attempt_3x()"; + log_v2::functions()->trace("adjust_host_check_attempt_3x()"); + + engine_logger(dbg_checks, most) + << "Adjusting check attempt number for host '" << _name + << "': current attempt=" << get_current_attempt() << "/" + << get_max_attempts() << ", state=" << _current_state + << ", state type=" << get_state_type(); + log_v2::checks()->debug( + "Adjusting check attempt number for host '{}': current attempt= {}/{}, " + "state= {}, state type= {}", + _name, get_current_attempt(), get_max_attempts(), _current_state, + get_state_type()); /* if host is in a hard state, reset current attempt number */ if (get_state_type() == notifier::hard) set_current_attempt(1); @@ -3534,8 +3832,10 @@ void host::adjust_check_attempt(bool is_active) { else if (get_current_attempt() < get_max_attempts()) set_current_attempt(get_current_attempt() + 1); - logger(dbg_checks, most) << "New check attempt number = " - << get_current_attempt(); + engine_logger(dbg_checks, most) + << "New check attempt number = " << get_current_attempt(); + log_v2::checks()->debug("New check attempt number = {}", + get_current_attempt()); } /* check for hosts that never returned from a check... */ @@ -3543,7 +3843,8 @@ void host::check_for_orphaned() { time_t current_time = 0L; time_t expected_time = 0L; - logger(dbg_functions, basic) << "check_for_orphaned_hosts()"; + engine_logger(dbg_functions, basic) << "check_for_orphaned_hosts()"; + log_v2::functions()->trace("check_for_orphaned_hosts()"); /* get the current time */ time(¤t_time); @@ -3570,14 +3871,22 @@ void host::check_for_orphaned() { * the results haven't come back in... */ if (expected_time < current_time) { /* log a warning */ - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: The check of host '" << it->second->get_name() << "' looks like it was orphaned (results never came back). " "I'm scheduling an immediate check of the host..."; + log_v2::runtime()->warn( + "Warning: The check of host '{}' looks like it was orphaned (results " + "never came back). " + "I'm scheduling an immediate check of the host...", + it->second->get_name()); - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Host '" << it->second->get_name() << "' was orphaned, so we're scheduling an immediate check..."; + log_v2::checks()->debug( + "Host '{}' was orphaned, so we're scheduling an immediate check...", + it->second->get_name()); /* decrement the number of running host checks */ if (currently_running_host_checks > 0) @@ -3620,9 +3929,12 @@ void host::resolve(int& w, int& e) { try { notifier::resolve(warnings, errors); } catch (std::exception const& e) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Host '" << _name << "' has problem in its notifier part: " << e.what(); + log_v2::config()->error( + "Error: Host '{}' has problem in its notifier part: {}", _name, + e.what()); } for (service_map::iterator it_svc{service::services.begin()}, @@ -3633,18 +3945,23 @@ void host::resolve(int& w, int& e) { } if (services.empty()) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Host '" << _name << "' has no services associated with it!"; + log_v2::config()->warn( + "Warning: Host '{}' has no services associated with it!", _name); ++w; } else { for (service_map_unsafe::iterator it{services.begin()}, end{services.end()}; it != end; ++it) { service_map::const_iterator found{service::services.find(it->first)}; if (found == service::services.end() || !found->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Host '" << _name << "' has a service '" << it->first.second << "' that does not exist!"; + log_v2::config()->error( + "Error: Host '{}' has a service '{}' that does not exist!", _name, + it->first.second); ++errors; } else { it->second = found->second.get(); @@ -3658,10 +3975,12 @@ void host::resolve(int& w, int& e) { it != end; it++) { host_map::const_iterator it_host{host::hosts.find(it->first)}; if (it_host == host::hosts.end() || !it_host->second) { - logger(log_verification_error, basic) << "Error: '" << it->first - << "' is not a " - "valid parent for host '" - << _name << "'!"; + engine_logger(log_verification_error, basic) << "Error: '" << it->first + << "' is not a " + "valid parent for host '" + << _name << "'!"; + log_v2::config()->error( + "Error: '{}' is not a valid parent for host '{}'!", it->first, _name); errors++; } else { it->second = it_host->second.get(); @@ -3672,20 +3991,28 @@ void host::resolve(int& w, int& e) { /* check for illegal characters in host name */ if (contains_illegal_object_chars(_name.c_str())) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: The name of host '" << _name << "' contains one or more illegal characters."; + log_v2::config()->error( + "Error: The name of host '{}' contains one or more illegal characters.", + _name); errors++; } // Check for sane recovery options. if (get_notifications_enabled() && get_notify_on(notifier::up) && !get_notify_on(notifier::down) && !get_notify_on(notifier::unreachable)) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Recovery notification option in host '" << get_display_name() << "' definition doesn't make any sense - specify down and/or " "unreachable options as well"; + log_v2::config()->warn( + "Warning: Recovery notification option in host '{}' definition doesn't " + "make any sense - specify down and/or " + "unreachable options as well", + get_display_name()); warnings++; } diff --git a/centreon-engine/src/hostdependency.cc b/centreon-engine/src/hostdependency.cc index 5bb1e22f45d..18ae390254d 100644 --- a/centreon-engine/src/hostdependency.cc +++ b/centreon-engine/src/hostdependency.cc @@ -23,6 +23,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/shared.hh" #include "com/centreon/engine/string.hh" @@ -234,10 +235,14 @@ void hostdependency::resolve(int& w, int& e) { // Find the dependent host. host_map::const_iterator it{host::hosts.find(_dependent_hostname)}; if (it == host::hosts.end() || !it->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Dependent host specified in host dependency for " "host '" << _dependent_hostname << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Dependent host specified in host dependency for " + "host '{}' is not defined anywhere!", + _dependent_hostname); errors++; dependent_host_ptr = nullptr; } else @@ -246,9 +251,13 @@ void hostdependency::resolve(int& w, int& e) { // Find the host we're depending on. it = host::hosts.find(_hostname); if (it == host::hosts.end() || !it->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Host specified in host dependency for host '" << _dependent_hostname << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Host specified in host dependency for host '{}' is not defined " + "anywhere!", + _dependent_hostname); errors++; master_host_ptr = nullptr; } else @@ -256,9 +265,13 @@ void hostdependency::resolve(int& w, int& e) { // Make sure they're not the same host. if (dependent_host_ptr == master_host_ptr && dependent_host_ptr != nullptr) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Host dependency definition for host '" << _dependent_hostname << "' is circular (it depends on itself)!"; + log_v2::config()->error( + "Error: Host dependency definition for host '{}' is circular (it " + "depends on itself)!", + _dependent_hostname); errors++; } @@ -268,10 +281,14 @@ void hostdependency::resolve(int& w, int& e) { timeperiod::timeperiods.find(_dependency_period)}; if (it == timeperiod::timeperiods.end() || !it->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Dependency period '" << this->get_dependency_period() << "' specified in host dependency for host '" << _dependent_hostname << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Dependency period '{}' specified in host dependency for host " + "'{}' is not defined anywhere!", + this->get_dependency_period(), _dependent_hostname); errors++; dependency_period_ptr = nullptr; } else diff --git a/centreon-engine/src/hostescalation.cc b/centreon-engine/src/hostescalation.cc index e9e7f766d1f..44913c3aa0f 100644 --- a/centreon-engine/src/hostescalation.cc +++ b/centreon-engine/src/hostescalation.cc @@ -22,6 +22,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/shared.hh" #include "com/centreon/engine/string.hh" @@ -77,7 +78,8 @@ std::string const& hostescalation::get_hostname() const { * @return A boolean. */ bool hostescalation::is_viable(int state, uint32_t notification_number) const { - logger(dbg_functions, basic) << "serviceescalation::is_viable()"; + engine_logger(dbg_functions, basic) << "serviceescalation::is_viable()"; + log_v2::functions()->trace("serviceescalation::is_viable()"); bool retval{escalation::is_viable(state, notification_number)}; if (retval) { @@ -101,9 +103,13 @@ void hostescalation::resolve(int& w, int& e) { // Find the host. host_map::const_iterator found(host::hosts.find(this->get_hostname())); if (found == host::hosts.end() || !found->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Host '" << this->get_hostname() << "' specified in host escalation is not defined anywhere!"; + log_v2::config()->error( + "Error: Host '{}' specified in host escalation is not defined " + "anywhere!", + this->get_hostname()); errors++; notifier_ptr = nullptr; } else { @@ -114,8 +120,9 @@ void hostescalation::resolve(int& w, int& e) { try { escalation::resolve(w, errors); } catch (std::exception const& ee) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Notifier escalation error: " << ee.what(); + log_v2::config()->error("Error: Notifier escalation error: {}", ee.what()); } // Add errors. diff --git a/centreon-engine/src/hostgroup.cc b/centreon-engine/src/hostgroup.cc index 6fc2b7240fb..af424cb7fe8 100644 --- a/centreon-engine/src/hostgroup.cc +++ b/centreon-engine/src/hostgroup.cc @@ -22,6 +22,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/shared.hh" #include "com/centreon/engine/string.hh" @@ -58,15 +59,18 @@ hostgroup::hostgroup(uint64_t id, _action_url{action_url} { // Make sure we have the data we need. if (name.empty()) { - logger(log_config_error, basic) << "Error: Hostgroup name is NULL"; + engine_logger(log_config_error, basic) << "Error: Hostgroup name is NULL"; + log_v2::config()->error("Error: Hostgroup name is NULL"); throw(engine_error() << "Could not register host group '" << name << "'"); } // Check if the host group already exist. hostgroup_map::const_iterator found(hostgroup::hostgroups.find(name)); if (found != hostgroup::hostgroups.end()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Hostgroup '" << name << "' has already been defined"; + log_v2::config()->error("Error: Hostgroup '{}' has already been defined", + name); throw(engine_error() << "Could not register host group '" << name << "'"); } } @@ -161,9 +165,13 @@ void hostgroup::resolve(int& w, int& e) { it != end; ++it) { host_map::const_iterator it_host{host::hosts.find(it->first)}; if (it_host == host::hosts.end() || !it_host->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Host '" << it->first << "' specified in host group '" << get_group_name() << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Host '{}' specified in host group '{}' is not defined " + "anywhere!", + it->first, get_group_name()); it->second = nullptr; errors++; } @@ -185,9 +193,13 @@ void hostgroup::resolve(int& w, int& e) { // Check for illegal characters in hostgroup name. if (contains_illegal_object_chars(get_group_name().c_str())) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: The name of hostgroup '" << get_group_name() << "' contains one or more illegal characters."; + log_v2::config()->error( + "Error: The name of hostgroup '{}' contains one or more illegal " + "characters.", + get_group_name()); errors++; } diff --git a/centreon-engine/src/log_v2.cc b/centreon-engine/src/log_v2.cc new file mode 100644 index 00000000000..09e67c9a00f --- /dev/null +++ b/centreon-engine/src/log_v2.cc @@ -0,0 +1,319 @@ +/* +** Copyright 2021 Centreon +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +** +** For more information : contact@centreon.com +*/ + +#include "com/centreon/engine/log_v2.hh" +#include +#include +#include +#include +#include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/logging/broker_sink.hh" + +using namespace com::centreon::engine; +using namespace spdlog; + +log_v2& log_v2::instance() { + static log_v2 instance; + return instance; +} + +log_v2::log_v2() { + auto stdout_sink = std::make_shared(); + auto null_sink = std::make_shared(); + + _functions_log = std::make_shared("functions", stdout_sink); + _functions_log->set_level(level::from_str("error")); + _functions_log->flush_on(level::from_str("error")); + _functions_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _config_log = std::make_shared("config", stdout_sink); + _config_log->set_level(level::from_str("info")); + _config_log->flush_on(level::from_str("info")); + _config_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _events_log = std::make_shared("events", stdout_sink); + _events_log->set_level(level::from_str("info")); + _events_log->flush_on(level::from_str("info")); + _events_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _checks_log = std::make_shared("checks", stdout_sink); + _checks_log->set_level(level::from_str("info")); + _checks_log->flush_on(level::from_str("info")); + _checks_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _notifications_log = + std::make_shared("notifications", stdout_sink); + _notifications_log->set_level(level::from_str("error")); + _notifications_log->flush_on(level::from_str("error")); + _notifications_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _eventbroker_log = + std::make_shared("eventbroker", stdout_sink); + _eventbroker_log->set_level(level::from_str("error")); + _eventbroker_log->flush_on(level::from_str("error")); + _eventbroker_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _external_command_log = + std::make_shared("external_command", stdout_sink); + _external_command_log->set_level(level::from_str("error")); + _external_command_log->flush_on(level::from_str("error")); + _external_command_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _commands_log = std::make_shared("commands", stdout_sink); + _commands_log->set_level(level::from_str("error")); + _commands_log->flush_on(level::from_str("error")); + _commands_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _downtimes_log = std::make_shared("downtimes", stdout_sink); + _downtimes_log->set_level(level::from_str("error")); + _downtimes_log->flush_on(level::from_str("error")); + _downtimes_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _comments_log = std::make_shared("comments", stdout_sink); + _comments_log->set_level(level::from_str("error")); + _comments_log->flush_on(level::from_str("error")); + _comments_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _macros_log = std::make_shared("macros", stdout_sink); + _macros_log->set_level(level::from_str("error")); + _macros_log->flush_on(level::from_str("error")); + _macros_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _process_log = std::make_shared("process", stdout_sink); + _process_log->set_level(level::from_str("info")); + _process_log->flush_on(level::from_str("info")); + _process_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _runtime_log = std::make_shared("runtime", stdout_sink); + _runtime_log->set_level(level::from_str("error")); + _runtime_log->flush_on(level::from_str("error")); + _runtime_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); +} + +void log_v2::apply(const configuration::state& config) { + if (verify_config || test_scheduling) + return; + + std::vector sinks; + if (config.log_v2_enabled()) { + if (config.log_v2_logger() == "file") { + if (config.log_file() != "") + sinks.push_back( + std::make_shared(config.log_file())); + else { + log_v2::config()->error("log_file name is empty"); + sinks.push_back(std::make_shared()); + } + } else if (config.log_v2_logger() == "syslog") + sinks.push_back(std::make_shared("centreon-engine", + 0, 0, true)); + auto broker_sink = std::make_shared(); + broker_sink->set_level(spdlog::level::info); + sinks.push_back(broker_sink); + } else + sinks.push_back(std::make_shared()); + + _functions_log = + std::make_shared("functions", begin(sinks), end(sinks)); + _functions_log->set_level(level::from_str(config.log_level_functions())); + _functions_log->flush_on(level::from_str(config.log_level_functions())); + if (config.log_pid()) + _functions_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] [%P] %v"); + else + _functions_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _config_log = + std::make_shared("config", begin(sinks), end(sinks)); + _config_log->set_level(level::from_str(config.log_level_config())); + _config_log->flush_on(level::from_str(config.log_level_config())); + if (config.log_pid()) + _config_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] [%P] %v"); + else + _config_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _events_log = + std::make_shared("events", begin(sinks), end(sinks)); + _events_log->set_level(level::from_str(config.log_level_events())); + _events_log->flush_on(level::from_str(config.log_level_events())); + if (config.log_pid()) + _events_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] [%P] %v"); + else + _events_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _checks_log = + std::make_shared("checks", begin(sinks), end(sinks)); + _checks_log->set_level(level::from_str(config.log_level_checks())); + _checks_log->flush_on(level::from_str(config.log_level_checks())); + if (config.log_pid()) + _checks_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] [%P] %v"); + else + _checks_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _notifications_log = std::make_shared( + "notifications", begin(sinks), end(sinks)); + _notifications_log->set_level( + level::from_str(config.log_level_notifications())); + _notifications_log->flush_on( + level::from_str(config.log_level_notifications())); + if (config.log_pid()) + _notifications_log->set_pattern( + "[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] [%P] %v"); + else + _notifications_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _eventbroker_log = + std::make_shared("eventbroker", begin(sinks), end(sinks)); + _eventbroker_log->set_level(level::from_str(config.log_level_eventbroker())); + _eventbroker_log->flush_on(level::from_str(config.log_level_eventbroker())); + if (config.log_pid()) + _eventbroker_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] [%P] %v"); + else + _eventbroker_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _external_command_log = std::make_shared( + "external_command", begin(sinks), end(sinks)); + _external_command_log->set_level( + level::from_str(config.log_level_external_command())); + _external_command_log->flush_on( + level::from_str(config.log_level_external_command())); + if (config.log_pid()) + _external_command_log->set_pattern( + "[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] [%P] %v"); + else + _external_command_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _commands_log = + std::make_shared("commands", begin(sinks), end(sinks)); + _commands_log->set_level(level::from_str(config.log_level_commands())); + _commands_log->flush_on(level::from_str(config.log_level_commands())); + if (config.log_pid()) + _commands_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] [%P] %v"); + else + _commands_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _downtimes_log = + std::make_shared("downtimes", begin(sinks), end(sinks)); + _downtimes_log->set_level(level::from_str(config.log_level_downtimes())); + _downtimes_log->flush_on(level::from_str(config.log_level_downtimes())); + if (config.log_pid()) + _downtimes_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] [%P] %v"); + else + _downtimes_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _comments_log = + std::make_shared("comments", begin(sinks), end(sinks)); + _comments_log->set_level(level::from_str(config.log_level_comments())); + _comments_log->flush_on(level::from_str(config.log_level_comments())); + if (config.log_pid()) + _comments_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] [%P] %v"); + else + _comments_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _macros_log = + std::make_shared("macros", begin(sinks), end(sinks)); + _macros_log->set_level(level::from_str(config.log_level_macros())); + _macros_log->flush_on(level::from_str(config.log_level_macros())); + if (config.log_pid()) + _macros_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] [%P] %v"); + else + _macros_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _process_log = + std::make_shared("process", begin(sinks), end(sinks)); + _process_log->set_level(level::from_str(config.log_level_process())); + _process_log->flush_on(level::from_str(config.log_level_process())); + if (config.log_pid()) + _process_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] [%P] %v"); + else + _process_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); + + _runtime_log = + std::make_shared("runtime", begin(sinks), end(sinks)); + _runtime_log->set_level(level::from_str(config.log_level_process())); + _runtime_log->flush_on(level::from_str(config.log_level_process())); + if (config.log_pid()) + _runtime_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] [%P] %v"); + else + _runtime_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); +} + +std::shared_ptr log_v2::functions() { + return instance()._functions_log; +} + +std::shared_ptr log_v2::config() { + return instance()._config_log; +} + +std::shared_ptr log_v2::events() { + return instance()._events_log; +} + +std::shared_ptr log_v2::checks() { + return instance()._checks_log; +} + +std::shared_ptr log_v2::notifications() { + return instance()._notifications_log; +} + +std::shared_ptr log_v2::eventbroker() { + return instance()._eventbroker_log; +} + +std::shared_ptr log_v2::external_command() { + return instance()._external_command_log; +} + +std::shared_ptr log_v2::commands() { + return instance()._commands_log; +} + +std::shared_ptr log_v2::downtimes() { + return instance()._downtimes_log; +} + +std::shared_ptr log_v2::comments() { + return instance()._comments_log; +} + +std::shared_ptr log_v2::macros() { + return instance()._macros_log; +} + +std::shared_ptr log_v2::process() { + return instance()._process_log; +} + +std::shared_ptr log_v2::runtime() { + return instance()._runtime_log; +} + +/** + * @brief Check if the given level makes part of the available levels. + * + * @param level A level as a string + * + * @return A boolean. + */ + +bool log_v2::contains_level(const std::string& level_name) { + auto level = level::from_str(level_name); + // ignore unrecognized level names + return !(level == level::off && level_name != "off"); +} diff --git a/centreon-engine/src/logging/CMakeLists.txt b/centreon-engine/src/logging/CMakeLists.txt index 87901edae4c..e58b514d4dd 100644 --- a/centreon-engine/src/logging/CMakeLists.txt +++ b/centreon-engine/src/logging/CMakeLists.txt @@ -35,6 +35,7 @@ set( "${INC_DIR}/logger.hh" "${INC_DIR}/broker.hh" "${INC_DIR}/debug_file.hh" + "${INC_DIR}/broker_sink.hh" # "${INC_DIR}/dumpers.hh" PARENT_SCOPE diff --git a/centreon-engine/src/macros.cc b/centreon-engine/src/macros.cc old mode 100755 new mode 100644 index 1938a0a31b6..71b3e8cf3e9 --- a/centreon-engine/src/macros.cc +++ b/centreon-engine/src/macros.cc @@ -25,6 +25,7 @@ #include #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/shared.hh" #include "com/centreon/engine/string.hh" @@ -391,8 +392,10 @@ int grab_standard_hostgroup_macro_r(nagios_macros* mac, break; default: - logger(dbg_macros, basic) + engine_logger(dbg_macros, basic) << "UNHANDLED HOSTGROUP MACRO #" << macro_type << "! THIS IS A BUG!"; + log_v2::macros()->trace("UNHANDLED HOSTGROUP MACRO #{}! THIS IS A BUG!", + macro_type); return ERROR; } @@ -470,8 +473,10 @@ int grab_standard_servicegroup_macro_r(nagios_macros* mac, break; default: - logger(dbg_macros, basic) << "UNHANDLED SERVICEGROUP MACRO #" - << macro_type << "! THIS IS A BUG!"; + engine_logger(dbg_macros, basic) << "UNHANDLED SERVICEGROUP MACRO #" + << macro_type << "! THIS IS A BUG!"; + log_v2::macros()->trace( + "UNHANDLED SERVICEGROUP MACRO #{}! THIS IS A BUG!", macro_type); return ERROR; } @@ -558,8 +563,10 @@ int grab_standard_contact_macro_r(nagios_macros* mac, } break; default: - logger(dbg_macros, basic) + engine_logger(dbg_macros, basic) << "UNHANDLED CONTACT MACRO #" << macro_type << "! THIS IS A BUG!"; + log_v2::macros()->trace("UNHANDLED CONTACT MACRO #{}! THIS IS A BUG!", + macro_type); return ERROR; } return OK; @@ -618,8 +625,10 @@ int grab_standard_contactgroup_macro( break; default: - logger(dbg_macros, basic) << "UNHANDLED CONTACTGROUP MACRO #" - << macro_type << "! THIS IS A BUG!"; + engine_logger(dbg_macros, basic) << "UNHANDLED CONTACTGROUP MACRO #" + << macro_type << "! THIS IS A BUG!"; + log_v2::macros()->trace( + "UNHANDLED CONTACTGROUP MACRO #{}! THIS IS A BUG!", macro_type); return ERROR; } return OK; diff --git a/centreon-engine/src/macros/grab_host.cc b/centreon-engine/src/macros/grab_host.cc index 5e11d39aaa5..e2a39966d4a 100755 --- a/centreon-engine/src/macros/grab_host.cc +++ b/centreon-engine/src/macros/grab_host.cc @@ -21,6 +21,7 @@ #include "com/centreon/engine/macros/grab_host.hh" #include #include +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros/clear_host.hh" #include "com/centreon/engine/macros/clear_hostgroup.hh" @@ -454,8 +455,10 @@ int grab_standard_host_macro_r(nagios_macros* mac, } // Non-existent macro. else { - logger(dbg_macros, basic) + engine_logger(dbg_macros, basic) << "UNHANDLED HOST MACRO #" << macro_type << "! THIS IS A BUG!"; + log_v2::macros()->trace("UNHANDLED HOST MACRO #{}! THIS IS A BUG!", + macro_type); retval = ERROR; } } else diff --git a/centreon-engine/src/macros/grab_service.cc b/centreon-engine/src/macros/grab_service.cc index 1c215abc8a9..5bb6271b749 100644 --- a/centreon-engine/src/macros/grab_service.cc +++ b/centreon-engine/src/macros/grab_service.cc @@ -21,6 +21,7 @@ #include "com/centreon/engine/macros/grab_service.hh" #include #include +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros/clear_service.hh" #include "com/centreon/engine/macros/clear_servicegroup.hh" @@ -416,8 +417,10 @@ int grab_standard_service_macro_r(nagios_macros* mac, } // Non-existent macro. else { - logger(dbg_macros, basic) + engine_logger(dbg_macros, basic) << "UNHANDLED SERVICE MACRO #" << macro_type << "! THIS IS A BUG!"; + log_v2::macros()->trace("UNHANDLED SERVICE MACRO #{}! THIS IS A BUG!", + macro_type); retval = ERROR; } } else diff --git a/centreon-engine/src/macros/grab_value.cc b/centreon-engine/src/macros/grab_value.cc old mode 100755 new mode 100644 index 1075c3b08ac..90ff6e78c96 --- a/centreon-engine/src/macros/grab_value.cc +++ b/centreon-engine/src/macros/grab_value.cc @@ -22,6 +22,7 @@ #include #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" #include "com/centreon/engine/string.hh" @@ -950,8 +951,9 @@ int grab_macro_value_r(nagios_macros* mac, continue; if (strcmp(macro_x_names[x].c_str(), buf) == 0) { - logger(dbg_macros, most) + engine_logger(dbg_macros, most) << " macros[" << x << "] (" << macro_x_names[x] << ") match."; + log_v2::macros()->trace(" macros[{}] ({}) match.", x, macro_x_names[x]); /* get the macro value */ result = grab_macrox_value_r(mac, x, arg[0] ? arg[0] : "", @@ -963,7 +965,9 @@ int grab_macro_value_r(nagios_macros* mac, if ((x >= 16 && x <= 19) || (x >= 49 && x <= 52) || (x >= 99 && x <= 100) || (x >= 124 && x <= 127)) { *clean_options |= (STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS); - logger(dbg_macros, most) << " New clean options: " << *clean_options; + engine_logger(dbg_macros, most) + << " New clean options: " << *clean_options; + log_v2::macros()->trace(" New clean options: {}", *clean_options); } break; } @@ -1085,8 +1089,10 @@ int grab_macro_value_r(nagios_macros* mac, } /* no macro matched... */ else { - logger(dbg_macros, basic) + engine_logger(dbg_macros, basic) << " WARNING: Could not find a macro matching '" << macro_name << "'!"; + log_v2::macros()->trace(" WARNING: Could not find a macro matching '{}'!", + macro_name); result = ERROR; } @@ -1122,8 +1128,10 @@ int grab_macrox_value_r(nagios_macros* mac, redirector.routines.find(macro_type)); if (redirector.routines.end() == it) { retval = ERROR; - logger(dbg_macros, basic) + engine_logger(dbg_macros, basic) << "UNHANDLED MACRO #" << macro_type << "! THIS IS A BUG!"; + log_v2::macros()->trace("UNHANDLED MACRO #{}! THIS IS A BUG!", + macro_type); } else { retval = (*it->second)(mac, macro_type, arg1, arg2, output, free_macro); } diff --git a/centreon-engine/src/macros/process.cc b/centreon-engine/src/macros/process.cc old mode 100755 new mode 100644 index 83599da97dc..8d976f03974 --- a/centreon-engine/src/macros/process.cc +++ b/centreon-engine/src/macros/process.cc @@ -19,6 +19,7 @@ */ #include "com/centreon/engine/macros/process.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" #include "com/centreon/engine/string.hh" @@ -42,16 +43,19 @@ int process_macros_r(nagios_macros* mac, int free_macro = false; int macro_options = 0; - logger(dbg_functions, basic) << "process_macros_r()"; + engine_logger(dbg_functions, basic) << "process_macros_r()"; + log_v2::functions()->trace("process_macros_r()"); output_buffer = ""; if (input_buffer.empty()) return ERROR; - logger(dbg_macros, more) << "**** BEGIN MACRO PROCESSING ***********\n" - "Processing: '" - << input_buffer << "'"; + engine_logger(dbg_macros, more) << "**** BEGIN MACRO PROCESSING ***********\n" + "Processing: '" + << input_buffer << "'"; + log_v2::macros()->trace("**** BEGIN MACRO PROCESSING **** Processing: '{}'", + input_buffer); for (std::string::const_iterator it{input_buffer.begin()}, end{input_buffer.end()}; @@ -77,30 +81,43 @@ int process_macros_r(nagios_macros* mac, result = grab_macro_value_r(mac, token, token_resolved, &clean_options, &free_macro); - logger(dbg_macros, most) + engine_logger(dbg_macros, most) << " Processed '" << token.c_str() << "', To '" << token_resolved << "', Clean Options: " << clean_options << ", Free: " << free_macro; + log_v2::macros()->trace( + " Processed '{}', To '{}', Clean Options: {}, Free: {}", token, + token_resolved, clean_options, free_macro); /* an error occurred - we couldn't parse the macro, so continue on */ if (result == ERROR) { - logger(dbg_macros, basic) + engine_logger(dbg_macros, basic) << " WARNING: An error occurred processing macro '" << token << "'!"; + log_v2::macros()->trace( + " WARNING: An error occurred processing macro '{}'!", token); } /* insert macro */ if (!token_resolved.empty()) { - logger(dbg_macros, most) << " Processed '" << token - << "', Clean Options: " << clean_options - << ", Free: " << free_macro; + engine_logger(dbg_macros, most) + << " Processed '" << token + << "', Clean Options: " << clean_options + << ", Free: " << free_macro; + log_v2::macros()->trace( + " Processed '{}', Clean Options: {}, Free: {}", token, + clean_options, free_macro); /* include any cleaning options passed back to us */ macro_options = (options | clean_options); - logger(dbg_macros, most) << " Cleaning options: global=" << options - << ", local=" << clean_options - << ", effective=" << macro_options; + engine_logger(dbg_macros, most) + << " Cleaning options: global=" << options + << ", local=" << clean_options + << ", effective=" << macro_options; + log_v2::macros()->trace( + " Cleaning options: global={}, local={}, effective={}", + options, clean_options, macro_options); /* some macros are cleaned... */ if (clean_macro || (macro_options & STRIP_ILLEGAL_MACRO_CHARS) || @@ -113,10 +130,13 @@ int process_macros_r(nagios_macros* mac, if (!cleaned_macro.empty()) { output_buffer.append(cleaned_macro); - logger(dbg_macros, basic) + engine_logger(dbg_macros, basic) << " Cleaned macro. Running output (" << output_buffer.length() << "): '" << output_buffer << "'"; + log_v2::macros()->trace( + " Cleaned macro. Running output ({}): '{}'", + output_buffer.length(), output_buffer); } } } else { @@ -124,16 +144,22 @@ int process_macros_r(nagios_macros* mac, * buffer */ output_buffer.append(token_resolved); - logger(dbg_macros, basic) + engine_logger(dbg_macros, basic) << " Uncleaned macro. Running output (" << output_buffer.length() << "): '" << output_buffer << "'"; + log_v2::macros()->trace( + " Uncleaned macro. Running output ({}): '{}'", + output_buffer.length(), output_buffer); } /* free memory if necessary (if we URL encoded the macro or we were * told to do so by grab_macro_value()) */ - logger(dbg_macros, basic) + engine_logger(dbg_macros, basic) << " Just finished macro. Running output (" << output_buffer.length() << "): '" << output_buffer << "'"; + log_v2::macros()->trace( + " Just finished macro. Running output ({}): '{}'", + output_buffer.length(), output_buffer); } it += pos - where; @@ -144,8 +170,11 @@ int process_macros_r(nagios_macros* mac, } } - logger(dbg_macros, more) << " Done. Final output: '" << output_buffer - << "'\n" - "**** END MACRO PROCESSING *************"; + engine_logger(dbg_macros, more) << " Done. Final output: '" << output_buffer + << "'\n" + "**** END MACRO PROCESSING *************"; + log_v2::macros()->trace( + " Done. Final output: '{}' **** END MACRO PROCESSING ****", + output_buffer); return OK; } diff --git a/centreon-engine/src/main.cc b/centreon-engine/src/main.cc index 5a4880362dc..76240b99e78 100644 --- a/centreon-engine/src/main.cc +++ b/centreon-engine/src/main.cc @@ -1,7 +1,7 @@ /* ** Copyright 1999-2009 Ethan Galstad ** Copyright 2009-2010 Nagios Core Development Team and Community Contributors -** Copyright 2011-2017 Centreon +** Copyright 2011-2021 Centreon ** ** This file is part of Centreon Engine. ** @@ -26,7 +26,6 @@ #include #endif // HAVE_GETOPT_H #include - #include #include @@ -43,6 +42,7 @@ #include "com/centreon/engine/enginerpc.hh" #include "com/centreon/engine/events/loop.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging.hh" #include "com/centreon/engine/logging/broker.hh" #include "com/centreon/engine/logging/logger.hh" @@ -173,62 +173,68 @@ int main(int argc, char* argv[]) { // Just display the license. if (display_license) { - logger(logging::log_info_message, logging::basic) - << "Centreon Engine " << CENTREON_ENGINE_VERSION_STRING << "\n" + std::cout + << "Centreon Engine " << CENTREON_ENGINE_VERSION_STRING << "\n" - << "Copyright 1999-2009 Ethan Galstad\n" - << "Copyright 2009-2010 Nagios Core Development Team and Community " + "\n" + "Copyright 1999-2009 Ethan Galstad\n" + "Copyright 2009-2010 Nagios Core Development Team and Community " "Contributors\n" - << "Copyright 2011-2021 Centreon\n" - << "\n" - << "This program is free software: you can redistribute it and/or\n" - << "modify it under the terms of the GNU General Public License " + "Copyright 2011-2021 Centreon\n" + "\n" + "This program is free software: you can redistribute it and/or\n" + "modify it under the terms of the GNU General Public License " "version 2\n" - << "as published by the Free Software Foundation.\n" - << "\n" - << "Centreon Engine is distributed in the hope that it will be " + "as published by the Free Software Foundation.\n" + "\n" + "Centreon Engine is distributed in the hope that it will be " "useful,\n" - << "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " + "but WITHOUT ANY WARRANTY; without even the implied warranty " + "of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " "GNU\n" - << "General Public License for more details.\n" - << "\n" - << "You should have received a copy of the GNU General Public " + "General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU General Public " "License\n" - << "along with this program. If not, see\n" - << "."; + "along with this program. If not, see\n" + ".\n"; + retval = EXIT_SUCCESS; } // If requested or if an error occured, print usage. else if (error || display_help) { - logger(logging::log_info_message, logging::basic) - << "Usage: " << argv[0] << " [options] \n" - << "\n" - << "Basics:\n" - << " -h, --help Print help.\n" - << " -V, --license, --version Print software version and " + std::cout + << "Usage: " << argv[0] + << " [options] \n" + "\n" + "Basics:\n" + " -h, --help Print help.\n" + " -V, --license, --version Print software version and " "license.\n" - << "\n" - << "Configuration:\n" - << " -v, --verify-config Verify all configuration data.\n" - << " -s, --test-scheduling Shows projected/recommended check\n" - << " scheduling and other diagnostic " + "\n" + "Configuration:\n" + " -v, --verify-config Verify all configuration data.\n" + " -s, --test-scheduling Shows projected/recommended " + "check\n" + " scheduling and other diagnostic " "info\n" - << " based on the current " + " based on the current " "configuration\n" - << " files.\n" - << " -x, --dont-verify-paths Don't check for circular object " + " files.\n" + " -x, --dont-verify-paths Don't check for circular object " "paths -\n" - << " USE WITH CAUTION !\n" - << " -D, --diagnose Generate a diagnostic file.\n" - << "\n" - << "Online:\n" - << " Website https://www.centreon.com\n" - << " Reference documentation " + " USE WITH CAUTION !\n" + " -D, --diagnose Generate a diagnostic file.\n" + "\n" + "Online:\n" + " Website https://www.centreon.com\n" + " Reference documentation " "https://documentation.centreon.com/docs/centreon-engine/en/" "latest/\n" - << " Sources " - "https://github.com/centreon/centreon-engine"; + " Sources " + "https://github.com/centreon/centreon-engine\n"; + retval = (display_help ? EXIT_SUCCESS : EXIT_FAILURE); } // We're just verifying the configuration. @@ -244,39 +250,46 @@ int main(int argc, char* argv[]) { configuration::applier::state::instance().apply(config); - logger(logging::log_info_message, logging::basic) - << "\n" - << "Checked " << commands::command::commands.size() - << " commands.\n" - << "Checked " << commands::connector::connectors.size() - << " connectors.\n" - << "Checked " << contact::contacts.size() << " contacts.\n" - << "Checked " << hostdependency::hostdependencies.size() - << " host dependencies.\n" - << "Checked " << hostescalation::hostescalations.size() - << " host escalations.\n" - << "Checked " << hostgroup::hostgroups.size() << " host groups.\n" - << "Checked " << host::hosts.size() << " hosts.\n" - << "Checked " << servicedependency::servicedependencies.size() - << " service dependencies.\n" - << "Checked " << serviceescalation::serviceescalations.size() - << " service escalations.\n" - << "Checked " << servicegroup::servicegroups.size() - << " service groups.\n" - << "Checked " << service::services.size() << " services.\n" - << "Checked " << timeperiod::timeperiods.size() - << " time periods.\n" - << "\n" - << "Total Warnings: " << config_warnings << "\n" - << "Total Errors: " << config_errors; - + std::cout << "\n Checked " << commands::command::commands.size() + << " commands.\n Checked " + << commands::connector::connectors.size() + << " connectors.\n Checked " << contact::contacts.size() + << " contacts.\n Checked " + << hostdependency::hostdependencies.size() + << " host dependencies.\n Checked " + << hostescalation::hostescalations.size() + << " host escalations.\n Checked " + << hostgroup::hostgroups.size() << " host groups.\n Checked " + << host::hosts.size() << " hosts.\n Checked " + << servicedependency::servicedependencies.size() + << " service dependencies.\n Checked " + << serviceescalation::serviceescalations.size() + << " service escalations.\n Checked " + << servicegroup::servicegroups.size() + << " service groups.\n Checked " << service::services.size() + << " services.\n Checked " << timeperiod::timeperiods.size() + << " time periods.\n\n Total Warnings: " << config_warnings + << "\n Total Errors: " << config_errors << std::endl; retval = (config_errors ? EXIT_FAILURE : EXIT_SUCCESS); } catch (std::exception const& e) { - logger(logging::log_config_error, logging::basic) - << "Error while processing a config file: " << e.what(); - logger(logging::log_config_error, logging::basic) - << "One or more problems occurred while processing " - "the config files.\n\n" ERROR_CONFIGURATION; + std::cout << "Error while processing a config file: " << e.what() + << std::endl; + + std::cout + << "One or more problems occurred while processing the config " + "files.\n " + "Check your configuration file(s) to ensure that they contain " + "valid directives and data definitions.\nIf you are upgrading " + "from " + "a previous version of Centreon Engine, you should be aware " + "that " + "some variables/definitions may have been removed or modified " + "in " + "this version.\n Make sure to read the documentation regarding " + "the " + "config files, as well as the version changelog to find out " + "what " + "has changed.\n"; } } // We're just testing scheduling. @@ -296,7 +309,8 @@ int main(int argc, char* argv[]) { try { p.parse(config.state_retention_file(), state); } catch (std::exception const& e) { - logger(logging::log_config_error, logging::basic) << e.what(); + std::cout << "Error while parsing the retention: {}" << e.what() + << std::endl; } } @@ -306,7 +320,7 @@ int main(int argc, char* argv[]) { display_scheduling_info(); retval = EXIT_SUCCESS; } catch (std::exception const& e) { - logger(logging::log_config_error, logging::basic) << e.what(); + std::cout << e.what() << std::endl; } } // Diagnostic. @@ -349,7 +363,9 @@ int main(int argc, char* argv[]) { try { p.parse(config.state_retention_file(), state); } catch (std::exception const& e) { - logger(logging::log_config_error, logging::basic) << e.what(); + log_v2::config()->error("{}", e.what()); + engine_logger(logging::log_config_error, logging::basic) + << e.what(); } } @@ -402,17 +418,20 @@ int main(int argc, char* argv[]) { event_start = time(NULL); mac->x[MACRO_EVENTSTARTTIME] = std::to_string(event_start); - logger(logging::log_info_message, logging::basic) + engine_logger(logging::log_info_message, logging::basic) << "Event loop start at " << string::ctime(event_start); - + log_v2::config()->info("Event loop start at {}", + string::ctime(event_start)); // Start monitoring all services (doesn't return until a // restart or shutdown signal is encountered). com::centreon::engine::events::loop::instance().run(); - if (sigshutdown) - logger(logging::log_process_info, logging::basic) + if (sigshutdown) { + engine_logger(logging::log_process_info, logging::basic) << "Caught SIG" << sigs[sig_id] << ", shutting down ..."; - + log_v2::process()->info("Caught SIG {}, shutting down ...", + sigs[sig_id]); + } // Send program data to broker. broker_program_state(NEBTYPE_PROCESS_EVENTLOOPEND, NEBFLAG_NONE, NEBATTR_NONE, NULL); @@ -427,16 +446,19 @@ int main(int argc, char* argv[]) { cleanup_status_data(true); // Shutdown stuff. - if (sigshutdown) - logger(logging::log_process_info, logging::basic) + if (sigshutdown) { + engine_logger(logging::log_process_info, logging::basic) << "Successfully shutdown ... (PID=" << getpid() << ")"; + log_v2::process()->info("Successfully shutdown ... (PID={})", + getpid()); + } retval = EXIT_SUCCESS; } catch (std::exception const& e) { // Log. - logger(logging::log_runtime_error, logging::basic) + engine_logger(logging::log_runtime_error, logging::basic) << "Error: " << e.what(); - + log_v2::process()->error("Error: {}", e.what()); // Send program data to broker. broker_program_state(NEBTYPE_PROCESS_SHUTDOWN, NEBFLAG_PROCESS_INITIATED, @@ -449,7 +471,9 @@ int main(int argc, char* argv[]) { delete[] config_file; config_file = NULL; } catch (std::exception const& e) { - logger(logging::log_runtime_error, logging::basic) << "Error: " << e.what(); + engine_logger(logging::log_runtime_error, logging::basic) + << "Error: " << e.what(); + log_v2::process()->error("Error: {}", e.what()); } // Unload singletons and global objects. diff --git a/centreon-engine/src/nebmods.cc b/centreon-engine/src/nebmods.cc index eefa1209486..3ca761c6767 100644 --- a/centreon-engine/src/nebmods.cc +++ b/centreon-engine/src/nebmods.cc @@ -24,6 +24,7 @@ #include #include "com/centreon/engine/broker/loader.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/neberrors.hh" #include "com/centreon/engine/utils.hh" @@ -59,11 +60,16 @@ int neb_add_module(char const* filename, try { broker::loader::instance().add_module(filename, args); - logger(dbg_eventbroker, basic) + engine_logger(dbg_eventbroker, basic) << "Added module: name='" << filename << "', args='" << args << "'"; + log_v2::eventbroker()->trace("Added module: name='{}', args='{}'", filename, + args); } catch (...) { - logger(dbg_eventbroker, basic) << "Counld not add module: name='" - << filename << "', args='" << args << "'"; + engine_logger(dbg_eventbroker, basic) + << "Counld not add module: name='" << filename << "', args='" << args + << "'"; + log_v2::eventbroker()->trace("Counld not add module: name='{}', args='{}'", + filename, args); return ERROR; } return OK; @@ -72,9 +78,11 @@ int neb_add_module(char const* filename, /* free memory allocated to module list */ int neb_free_module_list() { try { - logger(dbg_eventbroker, basic) << "unload all modules success."; + engine_logger(dbg_eventbroker, basic) << "unload all modules success."; + log_v2::eventbroker()->trace("unload all modules success."); } catch (...) { - logger(dbg_eventbroker, basic) << "unload all modules failed."; + engine_logger(dbg_eventbroker, basic) << "unload all modules failed."; + log_v2::eventbroker()->trace("unload all modules failed."); return ERROR; } return OK; @@ -104,7 +112,8 @@ int neb_load_all_modules() { if (neb_load_module(&(*(*it)))) ++unloaded; } catch (...) { - logger(dbg_eventbroker, basic) << "Could not load all modules"; + engine_logger(dbg_eventbroker, basic) << "Could not load all modules"; + log_v2::eventbroker()->trace("Could not load all modules"); return -1; } return unloaded; @@ -123,17 +132,23 @@ int neb_load_module(void* mod) { try { module->open(); - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "Event broker module '" << module->get_filename() << "' initialized successfully"; + log_v2::events()->info("Event broker module '{}' initialized successfully", + module->get_filename()); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Could not load module '" << module->get_filename() << "': " << e.what(); + log_v2::runtime()->error("Error: Could not load module '{}': {}", + module->get_filename(), e.what()); return ERROR; } catch (...) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Could not load module '" << module->get_filename() << "'"; + log_v2::runtime()->error("Error: Could not load module '{}'", + module->get_filename()); return ERROR; } return OK; @@ -155,16 +170,20 @@ int neb_reload_all_modules() { it != end; ++it) { neb_reload_module(&**it); } - logger(dbg_eventbroker, basic) << "All modules got successfully reloaded"; + engine_logger(dbg_eventbroker, basic) + << "All modules got successfully reloaded"; + log_v2::eventbroker()->trace("All modules got successfully reloaded"); } retval = OK; } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Warning: Module reloading failed: " << e.what(); + log_v2::runtime()->error("Warning: Module reloading failed: {}", e.what()); retval = ERROR; } catch (...) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Warning: Module reloading failed: unknown error"; + log_v2::runtime()->error("Warning: Module reloading failed: unknown error"); retval = ERROR; } return retval; @@ -179,11 +198,15 @@ int neb_reload_module(void* mod) { if (module->is_loaded() == false) return OK; - logger(dbg_eventbroker, basic) + engine_logger(dbg_eventbroker, basic) << "Attempting to reload module '" << module->get_filename() << "'"; + log_v2::eventbroker()->trace("Attempting to reload module '{}'", + module->get_filename()); module->reload(); - logger(dbg_eventbroker, basic) + engine_logger(dbg_eventbroker, basic) << "Module '" << module->get_filename() << "' reloaded successfully"; + log_v2::eventbroker()->trace("Module '{}' reloaded successfully", + module->get_filename()); return OK; } @@ -207,15 +230,19 @@ int neb_unload_all_modules(int flags, int reason) { it != end; ++it) neb_unload_module((*it).get(), flags, reason); loader.unload_modules(); - logger(dbg_eventbroker, basic) << "All modules got successfully unloaded"; + engine_logger(dbg_eventbroker, basic) + << "All modules got successfully unloaded"; + log_v2::eventbroker()->trace("All modules got successfully unloaded"); retval = OK; } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Module unloading failed: " << e.what(); + log_v2::runtime()->error("Error: Module unloading failed: {}", e.what()); retval = ERROR; } catch (...) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: unloading of all modules failed"; + log_v2::runtime()->error("Error: unloading of all modules failed"); retval = ERROR; } return retval; @@ -232,20 +259,26 @@ int neb_unload_module(broker::handle* module, int flags, int reason) { if (!module->is_loaded()) return OK; - logger(dbg_eventbroker, basic) + engine_logger(dbg_eventbroker, basic) << "Attempting to unload module '" << module->get_filename() << "'"; + log_v2::eventbroker()->trace("Attempting to unload module '{}'", + module->get_filename()); module->close(); /* deregister all of the module's callbacks */ neb_deregister_module_callbacks(module); - logger(dbg_eventbroker, basic) + engine_logger(dbg_eventbroker, basic) << "Module '" << module->get_filename() << "' unloaded successfully"; + log_v2::eventbroker()->trace("Module '{}' unloaded successfully", + module->get_filename()); - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "Event broker module '" << module->get_filename() << "' deinitialized successfully"; + log_v2::events()->info("Event broker module '{}' deinitialized successfully", + module->get_filename()); return OK; } @@ -294,11 +327,15 @@ int neb_set_module_info(void* handle, int type, char const* data) { break; } - logger(dbg_eventbroker, basic) + engine_logger(dbg_eventbroker, basic) << "set module info success: filename='" << module->get_filename() << "', type='" << type << "'"; + log_v2::eventbroker()->trace( + "set module info success: filename='{}', type='{}'", + module->get_filename(), type); } catch (...) { - logger(dbg_eventbroker, basic) << "Counld not set module info."; + engine_logger(dbg_eventbroker, basic) << "Counld not set module info."; + log_v2::eventbroker()->trace("Counld not set module info."); return ERROR; } @@ -447,7 +484,7 @@ int neb_make_callbacks(int callback_type, void* data) { if (callback_type < 0 || callback_type >= NEBCALLBACK_NUMITEMS) return ERROR; - logger(dbg_eventbroker, more) + engine_logger(dbg_eventbroker, more) << "Making callbacks (type " << callback_type << ")..."; /* make the callbacks... */ @@ -463,7 +500,7 @@ int neb_make_callbacks(int callback_type, void* data) { cbresult = (*neb.func)(callback_type, data); total_callbacks++; - logger(dbg_eventbroker, most) + engine_logger(dbg_eventbroker, most) << "Callback #" << total_callbacks << " (type " << callback_type << ") return (code = " << cbresult << ")"; diff --git a/centreon-engine/src/notification.cc b/centreon-engine/src/notification.cc index 23a0709fbd9..0e2d36b63db 100755 --- a/centreon-engine/src/notification.cc +++ b/centreon-engine/src/notification.cc @@ -21,6 +21,7 @@ #include #include "com/centreon/engine/broker.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" #include "com/centreon/engine/macros/defines.hh" @@ -205,8 +206,9 @@ int notification::execute(std::unordered_set const& to_notify) { _message.c_str(), _escalated, contacts_notified, nullptr); - logger(dbg_notifications, basic) + engine_logger(dbg_notifications, basic) << contacts_notified << " contacts were notified."; + log_v2::notifications()->trace(" contacts were notified."); return OK; } diff --git a/centreon-engine/src/notifier.cc b/centreon-engine/src/notifier.cc index c649e5739ff..31f4f565f47 100644 --- a/centreon-engine/src/notifier.cc +++ b/centreon-engine/src/notifier.cc @@ -27,6 +27,7 @@ #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" #include "com/centreon/engine/hostescalation.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" #include "com/centreon/engine/neberrors.hh" @@ -156,9 +157,12 @@ notifier::notifier(notifier::notifier_type notifier_type, _state_history{{}}, _pending_flex_downtime{0} { if (retry_interval <= 0) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid notification_interval value for notifier '" << display_name << "'"; + log_v2::config()->error( + "Error: Invalid notification_interval value for notifier '{}'", + display_name); throw engine_error() << "Could not register notifier '" << display_name << "'"; } @@ -217,7 +221,9 @@ void notifier::set_notification_number(int num) { bool notifier::_is_notification_viable_normal(reason_type type __attribute__((unused)), notification_option options) { - logger(dbg_functions, basic) << "notifier::is_notification_viable_normal()"; + engine_logger(dbg_functions, basic) + << "notifier::is_notification_viable_normal()"; + log_v2::functions()->trace("notifier::is_notification_viable_normal()"); /* forced notifications bust through everything */ uint32_t notification_interval = @@ -226,33 +232,44 @@ bool notifier::_is_notification_viable_normal(reason_type type : _notification[cat_normal]->get_notification_interval(); if (options & notification_option_forced) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This is a forced notification, so we'll send it out."; + log_v2::notifications()->debug( + "This is a forced notification, so we'll send it out."); return true; } /* are notifications enabled? */ if (!config->enable_notifications()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "Notifications are disabled, so notifications will " "not be sent out."; + log_v2::notifications()->debug( + "Notifications are disabled, so notifications will " + "not be sent out."); return false; } /* are notifications temporarily disabled for this notifier? */ if (!get_notifications_enabled()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "Notifications are temporarily disabled for " "this notifier, so we won't send one out."; + log_v2::notifications()->debug( + "Notifications are temporarily disabled for " + "this notifier, so we won't send one out."); return false; } /* if this notifier is currently in a scheduled downtime period, don't send * the notification */ if (is_in_downtime()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier is currently in a scheduled downtime, so " "we won't send notifications."; + log_v2::notifications()->debug( + "This notifier is currently in a scheduled downtime, so " + "we won't send notifications."); return false; } @@ -262,50 +279,68 @@ bool notifier::_is_notification_viable_normal(reason_type type time(&now); if (!check_time_against_period_for_notif(now, tp)) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier shouldn't have notifications sent out " "at this time."; + log_v2::notifications()->debug( + "This notifier shouldn't have notifications sent out " + "at this time."); return false; } /* if this notifier is flapping, don't send the notification */ if (get_is_flapping()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier is flapping, so we won't send notifications."; + log_v2::notifications()->debug( + "This notifier is flapping, so we won't send notifications."); return false; } /* On volatile services notifications are always sent */ if (get_is_volatile()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This is a volatile service notification, so it is sent."; + log_v2::notifications()->debug( + "This is a volatile service notification, so it is sent."); return true; } if (get_state_type() != hard) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier is in soft state, so we won't send notifications."; + log_v2::notifications()->debug( + "This notifier is in soft state, so we won't send notifications."); return false; } if (get_problem_has_been_acknowledged()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier problem has been acknowledged, so we won't send " "notifications."; + log_v2::notifications()->debug( + "This notifier problem has been acknowledged, so we won't send " + "notifications."); return false; } if (get_current_state_int() == 0) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "We don't send a normal notification when the state is ok/up"; + log_v2::notifications()->debug( + "We don't send a normal notification when the state is ok/up"); return false; } if (!get_notify_on_current_state()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier is unable to notify the state " << get_current_state_as_string() << ": not configured for that or, for a service, its host may be down"; + log_v2::notifications()->debug( + "This notifier is unable to notify the state {}: not configured for " + "that or, for a service, its host may be down", + get_current_state_as_string()); return false; } @@ -313,17 +348,24 @@ bool notifier::_is_notification_viable_normal(reason_type type get_last_hard_state_change() + _first_notification_delay * config->interval_length() > now) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier is configured with a first notification delay, we " "won't send notification until timestamp " << (_first_notification_delay * config->interval_length()); + log_v2::notifications()->debug( + "This notifier is configured with a first notification delay, we " + "won't send notification until timestamp {}", + _first_notification_delay * config->interval_length()); return false; } if (!authorized_by_dependencies(dependency::notification)) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier won't send any notification since it depends on" " another notifier that has already sent one"; + log_v2::notifications()->debug( + "This notifier won't send any notification since it depends on" + " another notifier that has already sent one"); return false; } @@ -332,20 +374,29 @@ bool notifier::_is_notification_viable_normal(reason_type type * and we notify as soon as we can */ if (get_last_hard_state_change() <= _last_notification) { if (notification_interval == 0) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier problem has already been sent at " << _last_notification << " so, since the notification interval is 0, it won't be sent" << " anymore"; + log_v2::notifications()->debug( + "This notifier problem has already been sent at {} so, since the " + "notification interval is 0, it won't be sent anymore", + _last_notification); return false; } else if (notification_interval > 0) { if (_last_notification + notification_interval * config->interval_length() > now) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier problem has been sent at " << _last_notification << " so it won't be sent until " << (notification_interval * config->interval_length()); + log_v2::notifications()->debug( + "This notifier problem has been sent at {} so it won't be sent " + "until {}", + _last_notification, + notification_interval * config->interval_length()); return false; } } @@ -358,22 +409,30 @@ bool notifier::_is_notification_viable_recovery(reason_type type __attribute__((unused)), notification_option options __attribute__((unused))) { - logger(dbg_functions, basic) << "notifier::is_notification_viable_recovery()"; + engine_logger(dbg_functions, basic) + << "notifier::is_notification_viable_recovery()"; + log_v2::functions()->trace("notifier::is_notification_viable_recovery()"); bool retval{true}; bool send_later{false}; /* are notifications enabled? */ if (!config->enable_notifications()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "Notifications are disabled, so notifications will " "not be sent out."; + log_v2::notifications()->debug( + "Notifications are disabled, so notifications will " + "not be sent out."); retval = false; } /* are notifications temporarily disabled for this notifier? */ else if (!get_notifications_enabled()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "Notifications are temporarily disabled for " "this notifier, so we won't send one out."; + log_v2::notifications()->debug( + "Notifications are temporarily disabled for " + "this notifier, so we won't send one out."); retval = false; } else { timeperiod* tp{get_notification_timeperiod()}; @@ -382,63 +441,91 @@ bool notifier::_is_notification_viable_recovery(reason_type type std::time(&now); if (!check_time_against_period_for_notif(now, tp)) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier shouldn't have notifications sent out " "at this time."; + log_v2::notifications()->debug( + "This notifier shouldn't have notifications sent out " + "at this time."); retval = false; send_later = true; } /* if this notifier is currently in a scheduled downtime period, don't send * the notification */ else if (is_in_downtime()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier is currently in a scheduled downtime, so " "we won't send notifications."; + log_v2::notifications()->debug( + "This notifier is currently in a scheduled downtime, so " + "we won't send notifications."); retval = false; send_later = true; } /* if this notifier is flapping, don't send the notification */ else if (get_is_flapping()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier is flapping, so we won't send notifications."; + log_v2::notifications()->debug( + "This notifier is flapping, so we won't send notifications."); retval = false; send_later = true; } else if (get_state_type() != hard) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier is in soft state, so we won't send notifications."; + log_v2::notifications()->debug( + "This notifier is in soft state, so we won't send notifications."); retval = false; send_later = true; } /* Recovery is sent on state OK or UP */ else if (get_current_state_int() != 0) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier state is not UP/OK to send a recovery notification"; + log_v2::notifications()->debug( + "This notifier state is not UP/OK to send a recovery notification"); retval = false; send_later = true; } else if (!(get_notify_on(up) || get_notify_on(ok))) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier is not configured to send a recovery notification"; + log_v2::notifications()->debug( + "This notifier is not configured to send a recovery notification"); retval = false; send_later = false; } else if (get_last_hard_state_change() + _recovery_notification_delay * config->interval_length() > now) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This notifier is configured with a recovery notification delay. " << "It won't send any recovery notification until timestamp " << " so it won't be sent until " << (get_last_hard_state_change() + _recovery_notification_delay); + log_v2::notifications()->debug( + "This notifier is configured with a recovery notification delay. " + "It won't send any recovery notification until timestamp " + "so it won't be sent until {}", + get_last_hard_state_change() + _recovery_notification_delay); retval = false; send_later = true; } else if (_notification_number == 0) { - logger(dbg_notifications, more) << "No notification has been sent to " - "announce a problem. So no recovery" - << " notification will be sent"; + engine_logger(dbg_notifications, more) + << "No notification has been sent to " + "announce a problem. So no recovery" + << " notification will be sent"; + log_v2::notifications()->debug( + "No notification has been sent to " + "announce a problem. So no recovery notification will be sent"); retval = false; } else if (!_notification[cat_normal]) { - logger(dbg_notifications, more) << "We should not send a notification " - "since no normal notification has" - " been sent before"; + engine_logger(dbg_notifications, more) + << "We should not send a notification " + "since no normal notification has" + " been sent before"; + log_v2::notifications()->debug( + "We should not send a notification " + "since no normal notification has" + " been sent before"); retval = false; } } @@ -456,34 +543,48 @@ bool notifier::_is_notification_viable_recovery(reason_type type bool notifier::_is_notification_viable_acknowledgement( reason_type type __attribute__((unused)), notification_option options) { - logger(dbg_functions, basic) + engine_logger(dbg_functions, basic) << "notifier::is_notification_viable_acknowledgement()"; + log_v2::functions()->trace( + "notifier::is_notification_viable_acknowledgement()"); /* forced notifications bust through everything */ if (options & notification_option_forced) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This is a forced notification, so we'll send it out."; + log_v2::notifications()->debug( + "This is a forced notification, so we'll send it out."); return true; } /* are notifications enabled? */ if (!config->enable_notifications()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "Notifications are disabled, so notifications will " "not be sent out."; + log_v2::notifications()->debug( + "Notifications are disabled, so notifications will " + "not be sent out."); return false; } /* are notifications temporarily disabled for this notifier? */ if (!get_notifications_enabled()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "Notifications are temporarily disabled for " "this notifier, so we won't send one out."; + log_v2::notifications()->debug( + "Notifications are temporarily disabled for " + "this notifier, so we won't send one out."); return false; } if (get_current_state_int() == 0) { - logger(dbg_notifications, more) << "The notifier is currently OK/UP, so we " - "won't send an acknowledgement."; + engine_logger(dbg_notifications, more) + << "The notifier is currently OK/UP, so we " + "won't send an acknowledgement."; + log_v2::notifications()->debug( + "The notifier is currently OK/UP, so we " + "won't send an acknowledgement."); return false; } return true; @@ -491,27 +592,37 @@ bool notifier::_is_notification_viable_acknowledgement( bool notifier::_is_notification_viable_flapping(reason_type type, notification_option options) { - logger(dbg_functions, basic) << "notifier::is_notification_viable_flapping()"; + engine_logger(dbg_functions, basic) + << "notifier::is_notification_viable_flapping()"; + log_v2::functions()->trace("notifier::is_notification_viable_flapping()"); /* forced notifications bust through everything */ if (options & notification_option_forced) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This is a forced notification, so we'll send it out."; + log_v2::notifications()->debug( + "This is a forced notification, so we'll send it out."); return true; } /* are notifications enabled? */ if (!config->enable_notifications()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "Notifications are disabled, so notifications will " "not be sent out."; + log_v2::notifications()->debug( + "Notifications are disabled, so notifications will " + "not be sent out."); return false; } /* are notifications temporarily disabled for this notifier? */ if (!get_notifications_enabled()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "Notifications are temporarily disabled for " "this notifier, so we won't send one out."; + log_v2::notifications()->debug( + "Notifications are temporarily disabled for " + "this notifier, so we won't send one out."); return false; } @@ -525,27 +636,36 @@ bool notifier::_is_notification_viable_flapping(reason_type type, f = flappingdisabled; if (!get_notify_on(f)) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "We shouldn't notify about " << tab_notification_str[type] << " events for this notifier."; + log_v2::notifications()->debug( + "We shouldn't notify about {} events for this notifier.", + tab_notification_str[type]); return false; } /* Don't send a start notification if a flapping notification is already there */ if (type == reason_flappingstart && _notification[cat_flapping]) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "A flapping notification is already running, we can not send " "a start notification now."; + log_v2::notifications()->debug( + "A flapping notification is already running, we can not send " + "a start notification now."); return false; /* Don't send a stop/cancel notification if the previous flapping * notification is not a start flapping */ } else if (type == reason_flappingstop || type == reason_flappingdisabled) { if (!_notification[cat_flapping] || _notification[cat_flapping]->get_reason() != reason_flappingstart) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "A stop or cancellation flapping notification can only be sent " "after a start flapping notification."; + log_v2::notifications()->debug( + "A stop or cancellation flapping notification can only be sent " + "after a start flapping notification."); return false; } } @@ -553,16 +673,23 @@ bool notifier::_is_notification_viable_flapping(reason_type type, /* Don't send a notification if the same has already been sent previously. */ if (_notification[cat_flapping] && _notification[cat_flapping]->get_reason() == type) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "We shouldn't notify about a " << tab_notification_str[type] << " event: already sent."; + log_v2::notifications()->debug( + "We shouldn't notify about a {} event: already sent.", + tab_notification_str[type]); return false; } /* Don't send notifications during scheduled downtime */ if (is_in_downtime()) { - logger(dbg_notifications, more) << "We shouldn't notify about FLAPPING " - "events during scheduled downtime."; + engine_logger(dbg_notifications, more) + << "We shouldn't notify about FLAPPING " + "events during scheduled downtime."; + log_v2::notifications()->debug( + "We shouldn't notify about FLAPPING " + "events during scheduled downtime."); return false; } return true; @@ -571,41 +698,55 @@ bool notifier::_is_notification_viable_flapping(reason_type type, bool notifier::_is_notification_viable_downtime(reason_type type __attribute__((unused)), notification_option options) { - logger(dbg_functions, basic) << "notifier::is_notification_viable_downtime()"; + engine_logger(dbg_functions, basic) + << "notifier::is_notification_viable_downtime()"; + log_v2::functions()->trace("notifier::is_notification_viable_downtime()"); /* forced notifications bust through everything */ if (options & notification_option_forced) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This is a forced notification, so we'll send it out."; + log_v2::notifications()->debug( + "This is a forced notification, so we'll send it out."); return true; } /* are notifications enabled? */ if (!config->enable_notifications()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "Notifications are disabled, so notifications will " "not be sent out."; + log_v2::notifications()->debug( + "Notifications are disabled, so notifications will " + "not be sent out."); return false; } /* are notifications temporarily disabled for this notifier? */ if (!get_notifications_enabled()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "Notifications are temporarily disabled for " "this notifier, so we won't send one out."; + log_v2::notifications()->debug( + "Notifications are temporarily disabled for " + "this notifier, so we won't send one out."); return false; } if (!config->enable_notifications()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "Notifications are disabled, so notifications won't be sent out."; + log_v2::notifications()->debug( + "Notifications are disabled, so notifications won't be sent out."); return false; } /* Don't send a notification if we are not supposed to */ if (!get_notify_on(downtime)) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "We shouldn't notify about DOWNTIME events for this notifier."; + log_v2::notifications()->debug( + "We shouldn't notify about DOWNTIME events for this notifier."); return false; } @@ -613,8 +754,12 @@ bool notifier::_is_notification_viable_downtime(reason_type type * service, we don't care of the host, so the use of * get_scheduled_downtime_depth()) */ if (get_scheduled_downtime_depth() > 0) { - logger(dbg_notifications, more) << "We shouldn't notify about DOWNTIME " - "events during scheduled downtime."; + engine_logger(dbg_notifications, more) + << "We shouldn't notify about DOWNTIME " + "events during scheduled downtime."; + log_v2::notifications()->debug( + "We shouldn't notify about DOWNTIME " + "events during scheduled downtime."); return false; } return true; @@ -623,34 +768,46 @@ bool notifier::_is_notification_viable_downtime(reason_type type bool notifier::_is_notification_viable_custom(reason_type type __attribute__((unused)), notification_option options) { - logger(dbg_functions, basic) << "notifier::is_notification_viable_custom()"; + engine_logger(dbg_functions, basic) + << "notifier::is_notification_viable_custom()"; + log_v2::functions()->trace("notifier::is_notification_viable_custom()"); /* forced notifications bust through everything */ if (options & notification_option_forced) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "This is a forced notification, so we'll send it out."; + log_v2::notifications()->debug( + "This is a forced notification, so we'll send it out."); return true; } /* are notifications enabled? */ if (!config->enable_notifications()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "Notifications are disabled, so notifications will " "not be sent out."; + log_v2::notifications()->debug( + "Notifications are disabled, so notifications will " + "not be sent out."); return false; } /* are notifications temporarily disabled for this notifier? */ if (!get_notifications_enabled()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "Notifications are temporarily disabled for " "this notifier, so we won't send one out."; + log_v2::notifications()->debug( + "Notifications are temporarily disabled for " + "this notifier, so we won't send one out."); return false; } /* Don't send notifications during scheduled downtime */ if (is_in_downtime()) { - logger(dbg_notifications, more) + engine_logger(dbg_notifications, more) << "We shouldn't send a CUSTOM notification during scheduled downtime."; + log_v2::notifications()->debug( + "We shouldn't send a CUSTOM notification during scheduled downtime."); return false; } return true; @@ -757,7 +914,8 @@ int notifier::notify(notifier::reason_type type, std::string const& not_author, std::string const& not_data, notification_option options) { - logger(dbg_functions, basic) << "notifier::notify()"; + engine_logger(dbg_functions, basic) << "notifier::notify()"; + log_v2::functions()->trace("notifier::notify()"); notification_category cat{get_category(type)}; /* Has this notification got sense? */ @@ -1161,10 +1319,14 @@ void notifier::resolve(int& w, int& e) { command_map::iterator cmd_found{commands::command::commands.find(cmd_name)}; if (cmd_found == commands::command::commands.end() || !cmd_found->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Event handler command '" << cmd_name << "' specified for host '" << get_display_name() << "' not defined anywhere"; + log_v2::config()->error( + "Error: Event handler command '{}' specified for host '{}' not " + "defined anywhere", + cmd_name, get_display_name()); errors++; } else /* save the pointer to the event handler command for later */ @@ -1180,20 +1342,27 @@ void notifier::resolve(int& w, int& e) { command_map::iterator cmd_found{commands::command::commands.find(cmd_name)}; if (cmd_found == commands::command::commands.end() || !cmd_found->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Notifier check command '" << cmd_name << "' specified for host '" << get_display_name() - << "' is not defined anywhere!", - errors++; + << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Notifier check command '{}' specified for host '{}' is not " + "defined anywhere!", + cmd_name, get_display_name()); + errors++; } else /* save the pointer to the check command for later */ set_check_command_ptr(cmd_found->second.get()); } if (get_check_period().empty()) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Notifier '" << get_display_name() << "' has no check time period defined!"; + log_v2::config()->warn( + "Warning: Notifier '{}' has no check time period defined!", + get_display_name()); warnings++; check_period_ptr = nullptr; } else { @@ -1201,10 +1370,14 @@ void notifier::resolve(int& w, int& e) { timeperiod::timeperiods.find(get_check_period())}; if (found_it == timeperiod::timeperiods.end() || !found_it->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Check period '" << get_check_period() << "' specified for host '" << get_display_name() << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Check period '{}' specified for host '{}' is not defined " + "anywhere!", + get_check_period(), get_display_name()); errors++; check_period_ptr = nullptr; } else @@ -1218,9 +1391,13 @@ void notifier::resolve(int& w, int& e) { it != end; ++it) { contact_map::const_iterator found_it{contact::contacts.find(it->first)}; if (found_it == contact::contacts.end() || !found_it->second.get()) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Contact '" << it->first << "' specified in notifier '" << get_display_name() << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Contact '{}' specified in notifier '{}' is not defined " + "anywhere!", + it->first, get_display_name()); errors++; } else /* save the pointer to the contact */ @@ -1236,9 +1413,13 @@ void notifier::resolve(int& w, int& e) { contactgroup::contactgroups.find(it->first)}; if (found_it == contactgroup::contactgroups.end()) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Contact group '" << it->first << "' specified in host '" << get_display_name() << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Contact group '{}' specified in host '{}' is not defined " + "anywhere!", + it->first, get_display_name()); errors++; } else it->second = found_it->second.get(); @@ -1250,19 +1431,26 @@ void notifier::resolve(int& w, int& e) { timeperiod::timeperiods.find(get_notification_period())}; if (found_it == timeperiod::timeperiods.end() || !found_it->second.get()) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Notification period '" << get_notification_period() << "' specified for notifier '" << get_display_name() << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Notification period '{}' specified for notifier '{}' is not " + "defined anywhere!", + get_notification_period(), get_display_name()); errors++; _notification_period_ptr = nullptr; } else // Save the pointer to the notification timeperiod for later. _notification_period_ptr = found_it->second.get(); } else if (get_notifications_enabled()) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Notifier '" << get_display_name() << "' has no notification time period defined!"; + log_v2::config()->warn( + "Warning: Notifier '{}' has no notification time period defined!", + get_display_name()); warnings++; _notification_period_ptr = nullptr; } @@ -1311,14 +1499,19 @@ void notifier::dec_pending_flex_downtime() noexcept { time_t notifier::get_next_notification_time(time_t offset) { bool have_escalated_interval{false}; - logger(dbg_functions, basic) << "notifier::get_next_notification_time()"; - logger(dbg_notifications, most) + engine_logger(dbg_functions, basic) + << "notifier::get_next_notification_time()"; + log_v2::functions()->trace("notifier::get_next_notification_time()"); + engine_logger(dbg_notifications, most) << "Calculating next valid notification time..."; + log_v2::notifications()->info("Calculating next valid notification time..."); /* default notification interval */ uint32_t interval_to_use{_notification_interval}; - logger(dbg_notifications, most) << "Default interval: " << interval_to_use; + engine_logger(dbg_notifications, most) + << "Default interval: " << interval_to_use; + log_v2::notifications()->info("Default interval: {}", interval_to_use); /* * search all the escalation entries for valid matches for this service (at @@ -1333,9 +1526,11 @@ time_t notifier::get_next_notification_time(time_t offset) { if (!is_valid_escalation_for_notification(e, notification_option_none)) continue; - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "Found a valid escalation w/ interval of " << e->get_notification_interval(); + log_v2::notifications()->info("Found a valid escalation w/ interval of {}", + e->get_notification_interval()); /* * if we haven't used a notification interval from an escalation yet, @@ -1349,7 +1544,9 @@ time_t notifier::get_next_notification_time(time_t offset) { else if (e->get_notification_interval() < interval_to_use) interval_to_use = e->get_notification_interval(); - logger(dbg_notifications, most) << "New interval: " << interval_to_use; + engine_logger(dbg_notifications, most) + << "New interval: " << interval_to_use; + log_v2::notifications()->info("New interval: {}", interval_to_use); } /* @@ -1361,9 +1558,14 @@ time_t notifier::get_next_notification_time(time_t offset) { else set_no_more_notifications(false); - logger(dbg_notifications, most) << "Interval used for calculating next valid " - "notification time: " - << interval_to_use; + engine_logger(dbg_notifications, most) + << "Interval used for calculating next valid " + "notification time: " + << interval_to_use; + log_v2::notifications()->info( + "Interval used for calculating next valid " + "notification time: {}", + interval_to_use); /* calculate next notification time */ time_t next_notification{ @@ -1401,9 +1603,12 @@ void notifier::set_notification(int32_t idx, std::string const& value) { char const* v = value.c_str(); if (strncmp(v, "type: ", 6)) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Bad format in the notification part, the line should start " "with 'type: '"; + log_v2::config()->error( + "Error: Bad format in the notification part, the line should start " + "with 'type: '"); return; } @@ -1411,17 +1616,23 @@ void notifier::set_notification(int32_t idx, std::string const& value) { char* next; reason_type type = static_cast(strtol(v, &next, 10)); if (next == v || *next != ',' || next[1] != ' ') { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Bad format in the notification part, the separator between " << "two fields is ', '"; + log_v2::config()->error( + "Error: Bad format in the notification part, the separator between two " + "fields is ', '"); return; } v = next + 2; if (strncmp(v, "author: ", 8)) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Bad format in the notification part, the expected field " " after 'type' is 'author'"; + log_v2::config()->error( + "Error: Bad format in the notification part, the expected field after " + "'type' is 'author'"); return; } @@ -1432,86 +1643,116 @@ void notifier::set_notification(int32_t idx, std::string const& value) { v = next + 2; if (strncmp(v, "options: ", 9)) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Bad format in the notification part, the expected field " " after 'author' is 'options'"; + log_v2::config()->error( + "Error: Bad format in the notification part, the expected field after " + "'author' is 'options'"); return; } v += 9; int options = strtol(v, &next, 10); if (next == v || *next != ',' || next[1] != ' ') { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Bad format in the notification part, the separator between " << "two fields is ', '"; + log_v2::config()->error( + "Error: Bad format in the notification part, the separator between two " + "fields is ', '"); return; } v = next + 2; if (strncmp(v, "escalated: ", 11)) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Bad format in the notification part, the expected field " " after 'options' is 'escalated'"; + log_v2::config()->error( + "Error: Bad format in the notification part, the expected field " + " after 'options' is 'escalated'"); return; } v += 11; bool escalated = static_cast(strtol(v, &next, 10)); if (next == v || *next != ',' || next[1] != ' ') { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Bad format in the notification part, the separator between " << "two fields is ', '"; + log_v2::config()->error( + "Error: Bad format in the notification part, the separator between two " + "fields is ', '"); return; } v = next + 2; if (strncmp(v, "id: ", 4)) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Bad format in the notification part, the expected field " " after 'escalated' is 'id'"; + log_v2::config()->error( + "Error: Bad format in the notification part, the expected field " + " after 'escalated' is 'id'"); return; } v += 4; int id = strtol(v, &next, 10); if (next == v || *next != ',' || next[1] != ' ') { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Bad format in the notification part, the separator between " << "two fields is ', '"; + log_v2::config()->error( + "Error: Bad format in the notification part, the separator between two " + "fields is ', '"); return; } v = next + 2; if (strncmp(v, "number: ", 8)) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Bad format in the notification part, the expected field " " after 'id' is 'number'"; + log_v2::config()->error( + "Error: Bad format in the notification part, the expected field " + " after 'id' is 'number'"); return; } v += 8; int number = strtol(v, &next, 10); if (next == v || *next != ',' || next[1] != ' ') { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Bad format in the notification part, the separator between " << "two fields is ', '"; + log_v2::config()->error( + "Error: Bad format in the notification part, the separator between two " + "fields is ', '"); return; } v = next + 2; if (strncmp(v, "interval: ", 10)) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Bad format in the notification part, the expected field " " after 'number' is 'interval'"; + log_v2::config()->error( + "Error: Bad format in the notification part, the expected field " + " after 'number' is 'interval'"); return; } v += 10; int interval = strtol(v, &next, 10); if (next == v) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Bad format in the notification part, the 'interval' value " "should be an integer"; + log_v2::config()->error( + "Error: Bad format in the notification part, the 'interval' value " + "should be an integer"); return; } diff --git a/centreon-engine/src/retention/dump.cc b/centreon-engine/src/retention/dump.cc index 07e37cdd3fa..1b0d954e40d 100644 --- a/centreon-engine/src/retention/dump.cc +++ b/centreon-engine/src/retention/dump.cc @@ -29,6 +29,7 @@ #include "com/centreon/engine/downtimes/service_downtime.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" using namespace com::centreon::engine; @@ -47,7 +48,8 @@ using namespace com::centreon::engine::retention; */ std::ostream& dump::comment(std::ostream& os, com::centreon::engine::comment const& obj) { - logger(dbg_functions, basic) << "dump::comment()"; + engine_logger(dbg_functions, basic) << "dump::comment()"; + log_v2::functions()->trace("dump::comment()"); char const* host_name; char const* service_description; if (obj.get_comment_type() == com::centreon::engine::comment::host) { @@ -107,7 +109,8 @@ std::ostream& dump::comment(std::ostream& os, * @return The output stream. */ std::ostream& dump::comments(std::ostream& os) { - logger(dbg_functions, basic) << "dump::comments()"; + engine_logger(dbg_functions, basic) << "dump::comments()"; + log_v2::functions()->trace("dump::comments()"); for (comment_map::iterator it(comment::comments.begin()), end(comment::comments.end()); it != end; ++it) @@ -212,7 +215,8 @@ std::ostream& dump::notifications( * @return The output stream. */ std::ostream& dump::scheduled_downtime(std::ostream& os, downtime const& obj) { - logger(dbg_functions, basic) << "dump::scheduled_downtime()"; + engine_logger(dbg_functions, basic) << "dump::scheduled_downtime()"; + log_v2::functions()->trace("dump::scheduled_downtime()"); obj.retention(os); return os; } @@ -225,7 +229,8 @@ std::ostream& dump::scheduled_downtime(std::ostream& os, downtime const& obj) { * @return The output stream. */ std::ostream& dump::downtimes(std::ostream& os) { - logger(dbg_functions, basic) << "dump::downtimes()"; + engine_logger(dbg_functions, basic) << "dump::downtimes()"; + log_v2::functions()->trace("dump::downtimes()"); for (std::pair> const& obj : downtimes::downtime_manager::instance().get_scheduled_downtimes()) dump::scheduled_downtime(os, *obj.second); @@ -565,7 +570,8 @@ bool dump::save(std::string const& path) { ret = true; } catch (std::exception const& e) { - logger(log_runtime_error, basic) << e.what(); + engine_logger(log_runtime_error, basic) << e.what(); + log_v2::runtime()->error(e.what()); } // send data to event broker. diff --git a/centreon-engine/src/retention/host.cc b/centreon-engine/src/retention/host.cc index 7ea749e868d..ca27dabde48 100644 --- a/centreon-engine/src/retention/host.cc +++ b/centreon-engine/src/retention/host.cc @@ -20,6 +20,7 @@ #include "com/centreon/engine/retention/host.hh" #include #include "com/centreon/engine/common.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/string.hh" @@ -1098,9 +1099,12 @@ bool host::_set_last_state_change(time_t value) { bool host::_set_last_time_down(time_t value) { time_t now = time(nullptr); if (value > now) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Host last time down cannot be in the future (bad value: " << value << ")"; + log_v2::config()->warn( + "Warning: Host last time down cannot be in the future (bad value: {})", + value); value = now; } _last_time_down = value; @@ -1115,10 +1119,14 @@ bool host::_set_last_time_down(time_t value) { bool host::_set_last_time_unreachable(time_t value) { time_t now = time(nullptr); if (value > now) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Host last time unreachable cannot be in the future (bad " "value: " << value << ")"; + log_v2::config()->warn( + "Warning: Host last time unreachable cannot be in the future (bad " + "value: {})", + value); value = now; } _last_time_unreachable = value; @@ -1133,9 +1141,12 @@ bool host::_set_last_time_unreachable(time_t value) { bool host::_set_last_time_up(time_t value) { time_t now = time(nullptr); if (value > now) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Host last time up cannot be in the future (bad value: " << value << ")"; + log_v2::config()->warn( + "Warning: Host last time up cannot be in the future (bad value: {})", + value); value = now; } _last_time_up = value; diff --git a/centreon-engine/src/retention/service.cc b/centreon-engine/src/retention/service.cc index 8e9b1f5674d..ac3717023aa 100644 --- a/centreon-engine/src/retention/service.cc +++ b/centreon-engine/src/retention/service.cc @@ -20,6 +20,7 @@ #include "com/centreon/engine/retention/service.hh" #include #include "com/centreon/engine/common.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/string.hh" @@ -1175,10 +1176,16 @@ bool service::_set_last_state_change(time_t value) { bool service::_set_last_time_critical(time_t value) { time_t now = time(nullptr); if (value > now) { - logger(log_verification_error, basic) << "Warning: Service last time " - "critical cannot be in the future " - "(bad value: " - << value << ")"; + engine_logger(log_verification_error, basic) + << "Warning: Service last time " + "critical cannot be in the future " + "(bad value: " + << value << ")"; + log_v2::config()->warn( + "Warning: Service last time " + "critical cannot be in the future " + "(bad value: {})", + value); value = now; } _last_time_critical = value; @@ -1193,9 +1200,12 @@ bool service::_set_last_time_critical(time_t value) { bool service::_set_last_time_ok(time_t value) { time_t now = time(nullptr); if (value > now) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Service last time ok cannot be in the future (bad value: " << value << ")"; + log_v2::config()->warn( + "Warning: Service last time ok cannot be in the future (bad value: {})", + value); value = now; } _last_time_ok = value; @@ -1210,10 +1220,16 @@ bool service::_set_last_time_ok(time_t value) { bool service::_set_last_time_unknown(time_t value) { time_t now = time(nullptr); if (value > now) { - logger(log_verification_error, basic) << "Warning: Service last time " - "unknown cannot be in the future " - "(bad value: " - << value << ")"; + engine_logger(log_verification_error, basic) + << "Warning: Service last time " + "unknown cannot be in the future " + "(bad value: " + << value << ")"; + log_v2::config()->warn( + "Warning: Service last time " + "unknown cannot be in the future " + "(bad value: {})", + value); value = now; } _last_time_unknown = value; @@ -1228,10 +1244,16 @@ bool service::_set_last_time_unknown(time_t value) { bool service::_set_last_time_warning(time_t value) { time_t now = time(nullptr); if (value > now) { - logger(log_verification_error, basic) << "Warning: Service last time " - "warning cannot be in the future " - "(bad value: " - << value << ")"; + engine_logger(log_verification_error, basic) + << "Warning: Service last time " + "warning cannot be in the future " + "(bad value: " + << value << ")"; + log_v2::config()->warn( + "Warning: Service last time " + "warning cannot be in the future " + "(bad value: {})", + value); value = now; } _last_time_warning = value; diff --git a/centreon-engine/src/sehandlers.cc b/centreon-engine/src/sehandlers.cc old mode 100755 new mode 100644 index 2887f7bae14..41deb6406dd --- a/centreon-engine/src/sehandlers.cc +++ b/centreon-engine/src/sehandlers.cc @@ -25,6 +25,7 @@ #include "com/centreon/engine/downtimes/downtime.hh" #include "com/centreon/engine/downtimes/downtime_manager.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" @@ -49,7 +50,9 @@ int obsessive_compulsive_host_check_processor( int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; nagios_macros* mac(get_global_macros()); - logger(dbg_functions, basic) << "obsessive_compulsive_host_check_processor()"; + engine_logger(dbg_functions, basic) + << "obsessive_compulsive_host_check_processor()"; + log_v2::functions()->trace("obsessive_compulsive_host_check_processor()"); if (hst == nullptr) return ERROR; @@ -75,9 +78,11 @@ int obsessive_compulsive_host_check_processor( return ERROR; } - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "Raw obsessive compulsive host processor command line: " << raw_command; + log_v2::checks()->debug( + "Raw obsessive compulsive host processor command line: {}", raw_command); /* process any macros in the raw command line */ process_macros_r(mac, raw_command, processed_command, macro_options); @@ -86,9 +91,14 @@ int obsessive_compulsive_host_check_processor( return ERROR; } - logger(dbg_checks, most) << "Processed obsessive compulsive host processor " - "command line: " - << processed_command; + engine_logger(dbg_checks, most) + << "Processed obsessive compulsive host processor " + "command line: " + << processed_command; + log_v2::checks()->debug( + "Processed obsessive compulsive host processor " + "command line: {}", + processed_command); /* run the command */ try { @@ -96,18 +106,24 @@ int obsessive_compulsive_host_check_processor( my_system_r(mac, processed_command, config->ochp_timeout(), &early_timeout, &exectime, tmp, 0); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: can't execute compulsive host processor command line '" << processed_command << "' : " << e.what(); + log_v2::runtime()->error( + "Error: can't execute compulsive host processor command line '{}' : {}", + processed_command, e.what()); } clear_volatile_macros_r(mac); /* check to see if the command timed out */ if (early_timeout == true) - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: OCHP command '" << processed_command << "' for host '" << hst->get_name() << "' timed out after " << config->ochp_timeout() << " seconds"; + log_v2::runtime()->warn( + "Warning: OCHP command '{}' for host '{}' timed out after {} seconds", + processed_command, hst->get_name(), config->ochp_timeout()); return OK; } @@ -131,7 +147,8 @@ int run_global_service_event_handler(nagios_macros* mac, int neb_result = OK; int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; - logger(dbg_functions, basic) << "run_global_service_event_handler()"; + engine_logger(dbg_functions, basic) << "run_global_service_event_handler()"; + log_v2::functions()->trace("run_global_service_event_handler()"); if (svc == nullptr) return ERROR; @@ -144,9 +161,12 @@ int run_global_service_event_handler(nagios_macros* mac, if (config->global_service_event_handler().empty()) return ERROR; - logger(dbg_eventhandlers, more) + engine_logger(dbg_eventhandlers, more) << "Running global event handler for service '" << svc->get_description() << "' on host '" << svc->get_hostname() << "'..."; + log_v2::events()->debug( + "Running global event handler for service '{}' on host '{}'...", + svc->get_description(), svc->get_hostname()); /* get start time */ gettimeofday(&start_time, nullptr); @@ -159,26 +179,33 @@ int run_global_service_event_handler(nagios_macros* mac, return ERROR; } - logger(dbg_eventhandlers, most) + engine_logger(dbg_eventhandlers, most) << "Raw global service event handler command line: " << raw_command; + log_v2::events()->debug("Raw global service event handler command line: {}", + raw_command); /* process any macros in the raw command line */ process_macros_r(mac, raw_command, processed_command, macro_options); if (processed_command.empty()) return ERROR; - logger(dbg_eventhandlers, most) << "Processed global service event handler " - "command line: " - << processed_command; + engine_logger(dbg_eventhandlers, most) + << "Processed global service event handler " + "command line: " + << processed_command; + log_v2::events()->debug( + "Processed global service event handler command line: {}", + processed_command); - if (config->log_event_handlers() == true) { + if (config->log_event_handlers()) { std::ostringstream oss; oss << "GLOBAL SERVICE EVENT HANDLER: " << svc->get_hostname() << ';' << svc->get_description() << ";$SERVICESTATE$;$SERVICESTATETYPE$;$SERVICEATTEMPT$;" << config->global_service_event_handler(); process_macros_r(mac, oss.str(), processed_logentry, macro_options); - logger(log_event_handler, basic) << processed_logentry; + engine_logger(log_event_handler, basic) << processed_logentry; + log_v2::events()->debug(processed_logentry); } /* send event data to broker */ @@ -205,19 +232,27 @@ int run_global_service_event_handler(nagios_macros* mac, my_system_r(mac, processed_command, config->event_handler_timeout(), &early_timeout, &exectime, command_output, 0); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: can't execute global service event handler " "command line '" << processed_command << "' : " << e.what(); + log_v2::runtime()->error( + "Error: can't execute global service event handler " + "command line '{}' : {}", + processed_command, e.what()); } /* check to see if the event handler timed out */ - if (early_timeout == true) - logger(log_event_handler | log_runtime_warning, basic) + if (early_timeout == true) { + engine_logger(log_event_handler | log_runtime_warning, basic) << "Warning: Global service event handler command '" << processed_command << "' timed out after " << config->event_handler_timeout() << " seconds"; - + log_v2::events()->info( + "Warning: Global service event handler command '{}' timed out after {} " + "seconds", + processed_command, config->event_handler_timeout()); + } /* get end time */ gettimeofday(&end_time, nullptr); @@ -249,7 +284,8 @@ int run_service_event_handler(nagios_macros* mac, int neb_result = OK; int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; - logger(dbg_functions, basic) << "run_service_event_handler()"; + engine_logger(dbg_functions, basic) << "run_service_event_handler()"; + log_v2::functions()->trace("run_service_event_handler()"); if (svc == nullptr) return ERROR; @@ -258,9 +294,12 @@ int run_service_event_handler(nagios_macros* mac, if (svc->get_event_handler().empty()) return ERROR; - logger(dbg_eventhandlers, more) + engine_logger(dbg_eventhandlers, more) << "Running event handler for service '" << svc->get_description() << "' on host '" << svc->get_hostname() << "'..."; + log_v2::events()->debug( + "Running event handler for service '{}' on host '{}'...", + svc->get_description(), svc->get_hostname()); /* get start time */ gettimeofday(&start_time, nullptr); @@ -272,16 +311,20 @@ int run_service_event_handler(nagios_macros* mac, if (raw_command.empty()) return ERROR; - logger(dbg_eventhandlers, most) + engine_logger(dbg_eventhandlers, most) << "Raw service event handler command line: " << raw_command; + log_v2::events()->debug("Raw service event handler command line: {}", + raw_command); /* process any macros in the raw command line */ process_macros_r(mac, raw_command, processed_command, macro_options); if (processed_command.empty()) return ERROR; - logger(dbg_eventhandlers, most) + engine_logger(dbg_eventhandlers, most) << "Processed service event handler command line: " << processed_command; + log_v2::events()->debug("Processed service event handler command line: {}", + processed_command); if (config->log_event_handlers() == true) { std::ostringstream oss; @@ -290,7 +333,8 @@ int run_service_event_handler(nagios_macros* mac, << ";$SERVICESTATE$;$SERVICESTATETYPE$;$SERVICEATTEMPT$;" << svc->get_event_handler(); process_macros_r(mac, oss.str(), processed_logentry, macro_options); - logger(log_event_handler, basic) << processed_logentry; + engine_logger(log_event_handler, basic) << processed_logentry; + log_v2::events()->info(processed_logentry); } /* send event data to broker */ @@ -317,18 +361,25 @@ int run_service_event_handler(nagios_macros* mac, my_system_r(mac, processed_command, config->event_handler_timeout(), &early_timeout, &exectime, command_output, 0); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: can't execute service event handler command line '" << processed_command << "' : " << e.what(); + log_v2::runtime()->error( + "Error: can't execute service event handler command line '{}' : {}", + processed_command, e.what()); } /* check to see if the event handler timed out */ - if (early_timeout == true) - logger(log_event_handler | log_runtime_warning, basic) + if (early_timeout == true) { + engine_logger(log_event_handler | log_runtime_warning, basic) << "Warning: Service event handler command '" << processed_command << "' timed out after " << config->event_handler_timeout() << " seconds"; - + log_v2::events()->info( + "Warning: Service event handler command '{}' timed out after {} " + "seconds", + processed_command, config->event_handler_timeout()); + } /* get end time */ gettimeofday(&end_time, nullptr); @@ -353,7 +404,8 @@ int run_service_event_handler(nagios_macros* mac, int handle_host_event(com::centreon::engine::host* hst) { nagios_macros* mac(get_global_macros()); - logger(dbg_functions, basic) << "handle_host_event()"; + engine_logger(dbg_functions, basic) << "handle_host_event()"; + log_v2::functions()->trace("handle_host_event()"); if (hst == nullptr) return ERROR; @@ -403,7 +455,8 @@ int run_global_host_event_handler(nagios_macros* mac, int neb_result = OK; int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; - logger(dbg_functions, basic) << "run_global_host_event_handler()"; + engine_logger(dbg_functions, basic) << "run_global_host_event_handler()"; + log_v2::functions()->trace("run_global_host_event_handler()"); if (hst == nullptr) return ERROR; @@ -416,8 +469,10 @@ int run_global_host_event_handler(nagios_macros* mac, if (config->global_host_event_handler() == "") return ERROR; - logger(dbg_eventhandlers, more) + engine_logger(dbg_eventhandlers, more) << "Running global event handler for host '" << hst->get_name() << "'..."; + log_v2::events()->debug("Running global event handler for host '{}'...", + hst->get_name()); /* get start time */ gettimeofday(&start_time, nullptr); @@ -429,17 +484,23 @@ int run_global_host_event_handler(nagios_macros* mac, if (raw_command.empty()) return ERROR; - logger(dbg_eventhandlers, most) + engine_logger(dbg_eventhandlers, most) << "Raw global host event handler command line: " << raw_command; + log_v2::events()->debug("Raw global host event handler command line: {}", + raw_command); /* process any macros in the raw command line */ process_macros_r(mac, raw_command, processed_command, macro_options); if (processed_command.empty()) return ERROR; - logger(dbg_eventhandlers, most) << "Processed global host event handler " - "command line: " - << processed_command; + engine_logger(dbg_eventhandlers, most) + << "Processed global host event handler " + "command line: " + << processed_command; + log_v2::events()->debug( + "Processed global host event handler command line: {}", + processed_command); if (config->log_event_handlers() == true) { std::ostringstream oss; @@ -447,7 +508,8 @@ int run_global_host_event_handler(nagios_macros* mac, << "$HOSTSTATE$;$HOSTSTATETYPE$;$HOSTATTEMPT$;" << config->global_host_event_handler(); process_macros_r(mac, oss.str(), processed_logentry, macro_options); - logger(log_event_handler, basic) << processed_logentry; + engine_logger(log_event_handler, basic) << processed_logentry; + log_v2::events()->info(processed_logentry); } /* send event data to broker */ @@ -474,18 +536,25 @@ int run_global_host_event_handler(nagios_macros* mac, my_system_r(mac, processed_command, config->event_handler_timeout(), &early_timeout, &exectime, command_output, 0); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: can't execute global host event handler command line '" << processed_command << "' : " << e.what(); + log_v2::runtime()->error( + "Error: can't execute global host event handler command line '{}' : {}", + processed_command, e.what()); } /* check for a timeout in the execution of the event handler command */ - if (early_timeout == true) - logger(log_event_handler | log_runtime_warning, basic) + if (early_timeout == true) { + engine_logger(log_event_handler | log_runtime_warning, basic) << "Warning: Global host event handler command '" << processed_command << "' timed out after " << config->event_handler_timeout() << " seconds"; - + log_v2::events()->info( + "Warning: Global host event handler command '{}' timed out after {} " + "seconds", + processed_command, config->event_handler_timeout()); + } /* get end time */ gettimeofday(&end_time, nullptr); @@ -517,7 +586,8 @@ int run_host_event_handler(nagios_macros* mac, int neb_result = OK; int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; - logger(dbg_functions, basic) << "run_host_event_handler()"; + engine_logger(dbg_functions, basic) << "run_host_event_handler()"; + log_v2::functions()->trace("run_host_event_handler()"); if (hst == nullptr) return ERROR; @@ -526,8 +596,10 @@ int run_host_event_handler(nagios_macros* mac, if (hst->get_event_handler().empty()) return ERROR; - logger(dbg_eventhandlers, more) + engine_logger(dbg_eventhandlers, more) << "Running event handler for host '" << hst->get_name() << "'..."; + log_v2::events()->debug("Running event handler for host '{}'...", + hst->get_name()); /* get start time */ gettimeofday(&start_time, nullptr); @@ -539,16 +611,20 @@ int run_host_event_handler(nagios_macros* mac, if (raw_command.empty()) return ERROR; - logger(dbg_eventhandlers, most) + engine_logger(dbg_eventhandlers, most) << "Raw host event handler command line: " << raw_command; + log_v2::events()->debug("Raw host event handler command line: {}", + raw_command); /* process any macros in the raw command line */ process_macros_r(mac, raw_command, processed_command, macro_options); if (processed_command.empty()) return ERROR; - logger(dbg_eventhandlers, most) + engine_logger(dbg_eventhandlers, most) << "Processed host event handler command line: " << processed_command; + log_v2::events()->debug("Processed host event handler command line: {}", + processed_command); if (config->log_event_handlers() == true) { std::ostringstream oss; @@ -556,7 +632,8 @@ int run_host_event_handler(nagios_macros* mac, << ";$HOSTSTATE$;$HOSTSTATETYPE$;$HOSTATTEMPT$;" << hst->get_event_handler(); process_macros_r(mac, oss.str(), processed_logentry, macro_options); - logger(log_event_handler, basic) << processed_logentry; + engine_logger(log_event_handler, basic) << processed_logentry; + log_v2::events()->info(processed_logentry); } /* send event data to broker */ @@ -582,18 +659,24 @@ int run_host_event_handler(nagios_macros* mac, my_system_r(mac, processed_command, config->event_handler_timeout(), &early_timeout, &exectime, command_output, 0); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: can't execute host event handler command line '" << processed_command << "' : " << e.what(); + log_v2::runtime()->error( + "Error: can't execute host event handler command line '{}' : {}", + processed_command, e.what()); } /* check to see if the event handler timed out */ - if (early_timeout == true) - logger(log_event_handler | log_runtime_warning, basic) + if (early_timeout == true) { + engine_logger(log_event_handler | log_runtime_warning, basic) << "Warning: Host event handler command '" << processed_command << "' timed out after " << config->event_handler_timeout() << " seconds"; - + log_v2::events()->info( + "Warning: Host event handler command '{}' timed out after {} seconds", + processed_command, config->event_handler_timeout()); + } /* get end time */ gettimeofday(&end_time, nullptr); diff --git a/centreon-engine/src/service.cc b/centreon-engine/src/service.cc index 3c1131443a2..3c815d203b7 100644 --- a/centreon-engine/src/service.cc +++ b/centreon-engine/src/service.cc @@ -30,6 +30,7 @@ #include "com/centreon/engine/flapping.hh" #include "com/centreon/engine/globals.hh" #include "com/centreon/engine/hostdependency.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" @@ -666,54 +667,80 @@ com::centreon::engine::service* add_service( std::string const& timezone) { // Make sure we have everything we need. if (!service_id) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Service comes from a database, therefore its service id " << "must not be null"; + log_v2::config()->error( + "Error: Service comes from a database, therefore its service id must " + "not be null"); return nullptr; } else if (description.empty()) { - logger(log_config_error, basic) << "Error: Service description is not set"; + engine_logger(log_config_error, basic) + << "Error: Service description is not set"; + log_v2::config()->error("Error: Service description is not set"); return nullptr; } else if (host_name.empty()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Host name of service '" << description << "' is not set"; + log_v2::config()->error("Error: Host name of service '{}' is not set", + description); return nullptr; } else if (check_command.empty()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Check command of service '" << description << "' on host '" << host_name << "' is not set"; + log_v2::config()->error( + "Error: Check command of service '{}' on host '{}' is not set", + description, host_name); return nullptr; } uint64_t hid = get_host_id(host_name); if (!host_id) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: The service '" << description << "' cannot be created because" << " host '" << host_name << "' does not exist (host_id is null)"; + log_v2::config()->error( + "Error: The service '{}' cannot be created because host '{}' does not " + "exist (host_id is null)", + description, host_name); return nullptr; } else if (host_id != hid) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: The service '" << description << "' cannot be created because the host id corresponding to the host" << " '" << host_name << "' is not the same as the one in configuration"; + log_v2::config()->error( + "Error: The service '{}' cannot be created because the host id " + "corresponding to the host '{}' is not the same as the one in " + "configuration", + description, host_name); return nullptr; } // Check values. if (max_attempts <= 0 || check_interval < 0 || retry_interval <= 0 || notification_interval < 0) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid max_attempts, check_interval, retry_interval" ", or notification_interval value for service '" << description << "' on host '" << host_name << "'"; + log_v2::config()->error( + "Error: Invalid max_attempts, check_interval, retry_interval" + ", or notification_interval value for service '{}' on host '{}'", + description, host_name); return nullptr; } // Check if the service is already exist. std::pair id(std::make_pair(host_id, service_id)); if (is_service_exist(id)) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Service '" << description << "' on host '" << host_name << "' has already been defined"; + log_v2::config()->error( + "Error: Service '{}' on host '{}' has already been defined", + description, host_name); return nullptr; } @@ -789,10 +816,13 @@ void service::check_for_expired_acknowledgement() { if (get_acknowledgement_timeout() > 0) { time_t now(time(nullptr)); if (get_last_acknowledgement() + get_acknowledgement_timeout() >= now) { - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << "Acknowledgement of service '" << get_description() << "' on host '" << this->get_host_ptr()->get_name() << "' just expired"; + log_v2::events()->info( + "Acknowledgement of service '{}' on host '{}' just expired", + get_description(), this->get_host_ptr()->get_name()); set_problem_has_been_acknowledged(false); set_acknowledgement_type(ACKNOWLEDGEMENT_NONE); update_status(); @@ -974,7 +1004,8 @@ int service::handle_async_check_result(check_result* queued_check_result) { int state_changes_use_cached_state = true; int flapping_check_done = false; - logger(dbg_functions, basic) << "handle_async_service_check_result()"; + engine_logger(dbg_functions, basic) << "handle_async_service_check_result()"; + log_v2::functions()->trace("handle_async_service_check_result()"); /* make sure we have what we need */ if (!queued_check_result) @@ -993,10 +1024,13 @@ int service::handle_async_check_result(check_result* queued_check_result) { if (execution_time < 0.0) execution_time = 0.0; - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "** Handling check result for service '" << _description << "' on host '" << _hostname << "'..."; - logger(dbg_checks, more) + log_v2::checks()->trace( + "** Handling check result for service '{}' on host '{}'...", _description, + _hostname); + engine_logger(dbg_checks, more) << "HOST: " << _hostname << ", SERVICE: " << _description << ", CHECK TYPE: " << (queued_check_result->get_check_type() == check_active ? "Active" @@ -1009,6 +1043,17 @@ int service::handle_async_check_result(check_result* queued_check_result) { << ", EXEC TIME: " << execution_time << ", return CODE: " << queued_check_result->get_return_code() << ", OUTPUT: " << queued_check_result->get_output(); + log_v2::checks()->debug( + "HOST: {}, SERVICE: {}, CHECK TYPE: {}, OPTIONS: {}, RESCHEDULE: {}, " + "EXITED OK: {}, EXEC TIME: {}, return CODE: {}, OUTPUT: {}", + _hostname, _description, + queued_check_result->get_check_type() == check_active ? "Active" + : "Passive", + queued_check_result->get_check_options(), + queued_check_result->get_reschedule_check() ? "Yes" : "No", + queued_check_result->get_exited_ok() ? "Yes" : "No", execution_time, + queued_check_result->get_return_code(), + queued_check_result->get_output()); /* decrement the number of service checks still out there... */ if (queued_check_result->get_check_type() == check_active && @@ -1020,15 +1065,21 @@ int service::handle_async_check_result(check_result* queued_check_result) { * passive check results */ if (queued_check_result->get_check_type() == check_passive) { if (!config->accept_passive_service_checks()) { - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Discarding passive service check result because passive " "service checks are disabled globally."; + log_v2::checks()->trace( + "Discarding passive service check result because passive " + "service checks are disabled globally."); return ERROR; } if (!get_accept_passive_checks()) { - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Discarding passive service check result because passive " "checks are disabled for this service."; + log_v2::checks()->trace( + "Discarding passive service check result because passive " + "checks are disabled for this service."); return ERROR; } } @@ -1056,9 +1107,12 @@ int service::handle_async_check_result(check_result* queued_check_result) { if ((queued_check_result->get_check_options() & CHECK_OPTION_FRESHNESS_CHECK) && is_result_fresh(current_time, false)) { - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Discarding service freshness check result because the service " "is currently fresh (race condition avoided)."; + log_v2::checks()->trace( + "Discarding service freshness check result because the service " + "is currently fresh (race condition avoided)."); return OK; } @@ -1095,9 +1149,12 @@ int service::handle_async_check_result(check_result* queued_check_result) { * shouldn't be happening) */ if (!queued_check_result->get_exited_ok()) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Check of service '" << _description << "' on host '" << _hostname << "' did not exit properly!"; + log_v2::runtime()->warn( + "Warning: Check of service '{}' on host '{}' did not exit properly!", + _description, _hostname); set_plugin_output("(Service check did not exit properly)"); _current_state = service::state_unknown; @@ -1105,7 +1162,7 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* make sure the return code is within bounds */ else if (queued_check_result->get_return_code() < 0 || queued_check_result->get_return_code() > 3) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: return (code of " << queued_check_result->get_return_code() << " for check of service '" << _description << "' on host '" << _hostname << "' was out of bounds." @@ -1115,6 +1172,16 @@ int service::handle_async_check_result(check_result* queued_check_result) { ? " Make sure the plugin you're trying to run actually " "exists." : "")); + log_v2::runtime()->warn( + "Warning: return (code of {} for check of service '{}' on host '{}' " + "was out of bounds.{}", + queued_check_result->get_return_code(), _description, _hostname, + (queued_check_result->get_return_code() == 126 + ? "Make sure the plugin you're trying to run is executable." + : (queued_check_result->get_return_code() == 127 + ? " Make sure the plugin you're trying to run actually " + "exists." + : ""))); std::ostringstream oss; oss << "(Return code of " << queued_check_result->get_return_code() @@ -1157,7 +1224,7 @@ int service::handle_async_check_result(check_result* queued_check_result) { set_plugin_output(plugin_output); } - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "Parsing check output...\n" << "Short Output:\n" << (get_plugin_output().empty() ? "NULL" : get_plugin_output()) << "\n" @@ -1167,6 +1234,11 @@ int service::handle_async_check_result(check_result* queued_check_result) { << "\n" << "Perf Data:\n" << (get_perf_data().empty() ? "NULL" : get_perf_data()); + log_v2::checks()->debug( + "Parsing check output Short Output: {} Long Output: {} Perf Data: {}", + get_plugin_output().empty() ? "NULL" : get_plugin_output(), + get_long_plugin_output().empty() ? "NULL" : get_long_plugin_output(), + get_perf_data().empty() ? "NULL" : get_perf_data()); /* grab the return code */ _current_state = static_cast( @@ -1201,9 +1273,11 @@ int service::handle_async_check_result(check_result* queued_check_result) { */ if (get_check_type() == check_passive) { if (config->log_passive_checks()) - logger(log_passive_check, basic) + engine_logger(log_passive_check, basic) << "PASSIVE SERVICE CHECK: " << _hostname << ";" << _description << ";" << _current_state << ";" << get_plugin_output(); + log_v2::checks()->info("PASSIVE SERVICE CHECK: {};{};{};{}", _hostname, + _description, _current_state, get_plugin_output()); } host* hst{get_host_ptr()}; @@ -1231,17 +1305,21 @@ int service::handle_async_check_result(check_result* queued_check_result) { get_current_attempt() < get_max_attempts()) add_current_attempt(1); - logger(dbg_checks, most) << "ST: " - << (get_state_type() == soft ? "SOFT" : "HARD") - << " CA: " << get_current_attempt() - << " MA: " << get_max_attempts() - << " CS: " << _current_state - << " LS: " << _last_state - << " LHS: " << _last_hard_state; + engine_logger(dbg_checks, most) + << "ST: " << (get_state_type() == soft ? "SOFT" : "HARD") + << " CA: " << get_current_attempt() << " MA: " << get_max_attempts() + << " CS: " << _current_state << " LS: " << _last_state + << " LHS: " << _last_hard_state; + log_v2::checks()->debug("ST: {} CA: {} MA: {} CS: {} LS: {} LHS: {}", + (get_state_type() == soft ? "SOFT" : "HARD"), + get_current_attempt(), get_max_attempts(), + _current_state, _last_state, _last_hard_state); /* check for a state change (either soft or hard) */ if (_current_state != _last_state) { - logger(dbg_checks, most) << "Service has changed state since last check!"; + engine_logger(dbg_checks, most) + << "Service has changed state since last check!"; + log_v2::checks()->debug("Service has changed state since last check!"); state_change = true; } @@ -1252,7 +1330,8 @@ int service::handle_async_check_result(check_result* queued_check_result) { * looks like a soft recovery instead of a hard one */ if (_host_problem_at_last_check && _current_state == service::state_ok) { - logger(dbg_checks, most) << "Service had a HARD STATE CHANGE!!"; + engine_logger(dbg_checks, most) << "Service had a HARD STATE CHANGE!!"; + log_v2::checks()->debug("Service had a HARD STATE CHANGE!!"); hard_state_change = true; } @@ -1263,7 +1342,8 @@ int service::handle_async_check_result(check_result* queued_check_result) { if (get_current_attempt() >= get_max_attempts() && (_current_state != _last_hard_state || get_last_state_change() > get_last_hard_state_change())) { - logger(dbg_checks, most) << "Service had a HARD STATE CHANGE!!"; + engine_logger(dbg_checks, most) << "Service had a HARD STATE CHANGE!!"; + log_v2::checks()->debug("Service had a HARD STATE CHANGE!!"); hard_state_change = true; } @@ -1352,7 +1432,8 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* if the service is up and running OK... */ if (_current_state == service::state_ok) { - logger(dbg_checks, more) << "Service is OK."; + engine_logger(dbg_checks, more) << "Service is OK."; + log_v2::checks()->debug("Service is OK."); /* reset the acknowledgement flag (this should already have been done, but * just in case...) */ @@ -1361,16 +1442,21 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* verify the route to the host and send out host recovery notifications */ if (hst->get_current_state() != host::state_up) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Host is NOT UP, so we'll check it to see if it recovered..."; + log_v2::checks()->debug( + "Host is NOT UP, so we'll check it to see if it recovered..."); /* 09/23/07 EG don't launch a new host check if we already did so earlier */ - if (first_host_check_initiated) - logger(dbg_checks, more) + if (first_host_check_initiated) { + engine_logger(dbg_checks, more) << "First host check was already initiated, so we'll skip a " "new host check."; - else { + log_v2::checks()->debug( + "First host check was already initiated, so we'll skip a " + "new host check."); + } else { /* can we use the last cached host state? */ /* usually only use cached host state if no service state change has * occurred */ @@ -1378,8 +1464,10 @@ int service::handle_async_check_result(check_result* queued_check_result) { hst->has_been_checked() && (static_cast(current_time - hst->get_last_check()) <= config->cached_host_check_horizon())) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "* Using cached host state: " << hst->get_current_state(); + log_v2::checks()->debug("* Using cached host state: {}", + hst->get_current_state()); update_check_stats(ACTIVE_ONDEMAND_HOST_CHECK_STATS, current_time); update_check_stats(ACTIVE_CACHED_HOST_CHECK_STATS, current_time); } @@ -1393,7 +1481,8 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* if a hard service recovery has occurred... */ if (hard_state_change) { - logger(dbg_checks, more) << "Service experienced a HARD RECOVERY."; + engine_logger(dbg_checks, more) << "Service experienced a HARD RECOVERY."; + log_v2::checks()->debug("Service experienced a HARD RECOVERY."); /* set the state type macro */ set_state_type(hard); @@ -1421,7 +1510,8 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* else if a soft service recovery has occurred... */ else if (state_change) { - logger(dbg_checks, more) << "Service experienced a SOFT RECOVERY."; + engine_logger(dbg_checks, more) << "Service experienced a SOFT RECOVERY."; + log_v2::checks()->debug("Service experienced a SOFT RECOVERY."); /* this is a soft recovery */ set_state_type(soft); @@ -1437,9 +1527,10 @@ int service::handle_async_check_result(check_result* queued_check_result) { } /* else no service state change has occurred... */ - else - logger(dbg_checks, more) << "Service did not change state."; - + else { + engine_logger(dbg_checks, more) << "Service did not change state."; + log_v2::checks()->debug("Service did not change state."); + } /* Check if we need to send a recovery notification */ notify(reason_recovery, "", "", notification_option_none); @@ -1468,13 +1559,17 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* hey, something's not working quite like it should... */ else { - logger(dbg_checks, more) << "Service is in a non-OK state!"; + engine_logger(dbg_checks, more) << "Service is in a non-OK state!"; + log_v2::checks()->debug("Service is in a non-OK state!"); /* check the route to the host if its up right now... */ if (hst->get_current_state() == host::state_up) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Host is currently UP, so we'll recheck its state to " "make sure..."; + log_v2::checks()->debug( + "Host is currently UP, so we'll recheck its state to " + "make sure..."); /* previous logic was to simply run a sync (serial) host check */ /* can we use the last cached host state? */ @@ -1485,8 +1580,10 @@ int service::handle_async_check_result(check_result* queued_check_result) { config->cached_host_check_horizon())) { /* use current host state as route result */ route_result = hst->get_current_state(); - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "* Using cached host state: " << hst->get_current_state(); + log_v2::checks()->debug("* Using cached host state: {}", + hst->get_current_state()); update_check_stats(ACTIVE_ONDEMAND_HOST_CHECK_STATS, current_time); update_check_stats(ACTIVE_CACHED_HOST_CHECK_STATS, current_time); } @@ -1505,8 +1602,10 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* else assume same host state */ else { route_result = hst->get_current_state(); - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "* Using last known host state: " << hst->get_current_state(); + log_v2::checks()->debug("* Using last known host state: {}", + hst->get_current_state()); update_check_stats(ACTIVE_ONDEMAND_HOST_CHECK_STATS, current_time); update_check_stats(ACTIVE_CACHED_HOST_CHECK_STATS, current_time); } @@ -1515,14 +1614,18 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* else the host is either down or unreachable, so recheck it if necessary */ else { - logger(dbg_checks, more) << "Host is currently DOWN/UNREACHABLE."; + engine_logger(dbg_checks, more) << "Host is currently DOWN/UNREACHABLE."; + log_v2::checks()->debug("Host is currently DOWN/UNREACHABLE."); /* the service wobbled between non-OK states, so check the host... */ if ((state_change && !state_changes_use_cached_state) && _last_hard_state != service::state_ok) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Service wobbled between non-OK states, so we'll recheck" " the host state..."; + log_v2::checks()->debug( + "Service wobbled between non-OK states, so we'll recheck" + " the host state..."); /* previous logic was to simply run a sync (serial) host check */ /* use current host state as route result */ route_result = hst->get_current_state(); @@ -1535,8 +1638,9 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* else fake the host check, but (possibly) resend host notifications to contacts... */ else { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Assuming host is in same state as before..."; + log_v2::checks()->debug("Assuming host is in same state as before..."); /* if the host has never been checked before, set the checked flag and * last check time */ @@ -1560,8 +1664,10 @@ int service::handle_async_check_result(check_result* queued_check_result) { * check retries/caching. Not sure if we should take that into account and * do something different or not... */ if (route_result != host::state_up) { - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "Host is not UP, so we mark state changes if appropriate"; + log_v2::checks()->debug( + "Host is not UP, so we mark state changes if appropriate"); /* "fake" a hard state change for the service - well, its not really fake, * but it didn't get caught earlier... */ @@ -1603,9 +1709,11 @@ int service::handle_async_check_result(check_result* queued_check_result) { set_current_attempt(1); } - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Current/Max Attempt(s): " << get_current_attempt() << '/' << get_max_attempts(); + log_v2::checks()->debug("Current/Max Attempt(s): {}/{}", + get_current_attempt(), get_max_attempts()); /* if we should retry the service check, do so (except it the host is down * or unreachable!) */ @@ -1613,8 +1721,10 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* the host is down or unreachable, so don't attempt to retry the service * check */ if (route_result != host::state_up) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Host isn't UP, so we won't retry the service check..."; + log_v2::checks()->debug( + "Host isn't UP, so we won't retry the service check..."); /* the host is not up, so reschedule the next service check at regular * interval */ @@ -1635,8 +1745,10 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* the host is up, so continue to retry the service check */ else { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Host is UP, so we'll retry the service check..."; + log_v2::checks()->debug( + "Host is UP, so we'll retry the service check..."); /* this is a soft state */ set_state_type(soft); @@ -1657,9 +1769,12 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* perform dependency checks on the second to last check of the service */ if (config->enable_predictive_service_dependency_checks() && get_current_attempt() == (get_max_attempts() - 1)) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Looking for services to check for predictive " "dependency checks..."; + log_v2::checks()->debug( + "Looking for services to check for predictive " + "dependency checks..."); /* check services that THIS ONE depends on for notification AND * execution */ @@ -1674,10 +1789,14 @@ int service::handle_async_check_result(check_result* queued_check_result) { if (temp_dependency->dependent_service_ptr == this && temp_dependency->master_service_ptr) { master_service = temp_dependency->master_service_ptr; - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "Predictive check of service '" << master_service->get_description() << "' on host '" << master_service->get_hostname() << "' queued."; + log_v2::checks()->debug( + "Predictive check of service '{}' on host '{}' queued.", + master_service->get_description(), + master_service->get_hostname()); check_servicelist.push_back(master_service); } } @@ -1687,9 +1806,12 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* we've reached the maximum number of service rechecks, so handle the error */ else { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Service has reached max number of rechecks, so we'll " "handle the error..."; + log_v2::checks()->debug( + "Service has reached max number of rechecks, so we'll " + "handle the error..."); /* this is a hard state */ set_state_type(hard); @@ -1751,8 +1873,10 @@ int service::handle_async_check_result(check_result* queued_check_result) { /* reschedule the next service check ONLY for active, scheduled checks */ if (reschedule_check) { - logger(dbg_checks, more) << "Rescheduling next check of service at " - << my_ctime(&next_service_check); + engine_logger(dbg_checks, more) << "Rescheduling next check of service at " + << my_ctime(&next_service_check); + log_v2::checks()->debug("Rescheduling next check of service at {}", + my_ctime(&next_service_check)); /* default is to reschedule service check unless a test below fails... */ set_should_be_scheduled(true); @@ -1878,10 +2002,13 @@ int service::log_event() { } std::string const& state_type{tab_state_type[get_state_type()]}; - logger(log_options, basic) + engine_logger(log_options, basic) << "SERVICE ALERT: " << _hostname << ";" << _description << ";" << state << ";" << state_type << ";" << get_current_attempt() << ";" << get_plugin_output(); + log_v2::events()->info("SERVICE ALERT: {};{};{};{};{};{}", _hostname, + _description, state, state_type, get_current_attempt(), + get_plugin_output()); return OK; } @@ -1904,11 +2031,14 @@ void service::check_for_flapping(bool update, /* large install tweaks skips all flap detection logic - including state * change calculation */ - logger(dbg_functions, basic) << "check_for_flapping()"; + engine_logger(dbg_functions, basic) << "check_for_flapping()"; + log_v2::functions()->trace("check_for_flapping()"); - logger(dbg_flapping, more) + engine_logger(dbg_flapping, more) << "Checking service '" << _description << "' on host '" << _hostname << "' for flapping..."; + log_v2::checks()->debug("Checking service '{}' on host '{}' for flapping...", + _description, _hostname); /* if this is a soft service state and not a soft recovery, don't record this * in the history */ @@ -1980,10 +2110,13 @@ void service::check_for_flapping(bool update, set_percent_state_change(curved_percent_change); - logger(dbg_flapping, most) + engine_logger(dbg_flapping, most) << com::centreon::logging::setprecision(2) << "LFT=" << low_threshold << ", HFT=" << high_threshold << ", CPC=" << curved_percent_change << ", PSC=" << curved_percent_change << "%"; + log_v2::checks()->debug("LFT={:.2f}, HFT={:.2f}, CPC={:.2f}, PSC={:.2f}%", + low_threshold, high_threshold, curved_percent_change, + curved_percent_change); /* don't do anything if we don't have flap detection enabled on a program-wide * basis */ @@ -2010,10 +2143,12 @@ void service::check_for_flapping(bool update, if ((_current_state != service::state_ok) || get_is_flapping()) is_flapping = true; } - logger(dbg_flapping, more) + engine_logger(dbg_flapping, more) << com::centreon::logging::setprecision(2) << "Service " << (is_flapping ? "is" : "is not") << " flapping (" << curved_percent_change << "% state change)."; + log_v2::checks()->debug("Service {} flapping ({:.2f}% state change).", + is_flapping ? "is" : "is not", curved_percent_change); /* did the service just start flapping? */ if (is_flapping && !get_is_flapping()) @@ -2029,7 +2164,8 @@ void service::check_for_flapping(bool update, int service::handle_service_event() { nagios_macros* mac(get_global_macros()); - logger(dbg_functions, basic) << "handle_service_event()"; + engine_logger(dbg_functions, basic) << "handle_service_event()"; + log_v2::functions()->trace("handle_service_event()"); /* send event data to broker */ broker_statechange_data(NEBTYPE_STATECHANGE_END, NEBFLAG_NONE, NEBATTR_NONE, @@ -2077,8 +2213,9 @@ int service::obsessive_compulsive_service_check_processor() { int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; nagios_macros* mac(get_global_macros()); - logger(dbg_functions, basic) + engine_logger(dbg_functions, basic) << "obsessive_compulsive_service_check_processor()"; + log_v2::functions()->trace("obsessive_compulsive_service_check_processor()"); /* bail out if we shouldn't be obsessing */ if (config->obsess_over_services() == false) @@ -2106,9 +2243,14 @@ int service::obsessive_compulsive_service_check_processor() { return ERROR; } - logger(dbg_checks, most) << "Raw obsessive compulsive service processor " - "command line: " - << raw_command; + engine_logger(dbg_checks, most) + << "Raw obsessive compulsive service processor " + "command line: " + << raw_command; + log_v2::checks()->debug( + "Raw obsessive compulsive service processor " + "command line: {}", + raw_command); /* process any macros in the raw command line */ process_macros_r(mac, raw_command, processed_command, macro_options); @@ -2117,9 +2259,13 @@ int service::obsessive_compulsive_service_check_processor() { return ERROR; } - logger(dbg_checks, most) << "Processed obsessive compulsive service " - "processor command line: " - << processed_command; + engine_logger(dbg_checks, most) << "Processed obsessive compulsive service " + "processor command line: " + << processed_command; + log_v2::checks()->debug( + "Processed obsessive compulsive service " + "processor command line: {}", + processed_command); /* run the command */ try { @@ -2127,19 +2273,27 @@ int service::obsessive_compulsive_service_check_processor() { my_system_r(mac, processed_command, config->ocsp_timeout(), &early_timeout, &exectime, tmp, 0); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: can't execute compulsive service processor command line '" << processed_command << "' : " << e.what(); + log_v2::runtime()->error( + "Error: can't execute compulsive service processor command line '{}' : " + "{}", + processed_command, e.what()); } clear_volatile_macros_r(mac); /* check to see if the command timed out */ if (early_timeout == true) - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: OCSP command '" << processed_command << "' for service '" << _description << "' on host '" << _hostname << "' timed out after " << config->ocsp_timeout() << " seconds"; + log_v2::runtime()->warn( + "Warning: OCSP command '{}' for service '{}' on host '{}' timed out " + "after {} seconds", + processed_command, _description, _hostname, config->ocsp_timeout()); return OK; } @@ -2167,11 +2321,16 @@ int service::run_scheduled_check(int check_options, double latency) { time_t next_valid_time = 0L; bool time_is_valid = true; - logger(dbg_functions, basic) << "run_scheduled_service_check()"; - logger(dbg_checks, basic) + engine_logger(dbg_functions, basic) << "run_scheduled_service_check()"; + log_v2::functions()->trace("run_scheduled_service_check()"); + engine_logger(dbg_checks, basic) << "Attempting to run scheduled check of service '" << _description << "' on host '" << _hostname << "': check options=" << check_options << ", latency=" << latency; + log_v2::checks()->trace( + "Attempting to run scheduled check of service '{}' on host '{}': check " + "options={}, latency={}", + _description, _hostname, check_options, latency); /* attempt to run the check */ result = run_async_check(check_options, latency, true, true, &time_is_valid, @@ -2179,8 +2338,10 @@ int service::run_scheduled_check(int check_options, double latency) { /* an error occurred, so reschedule the check */ if (result == ERROR) { - logger(dbg_checks, more) + engine_logger(dbg_checks, more) << "Unable to run scheduled service check at this time"; + log_v2::checks()->debug( + "Unable to run scheduled service check at this time"); /* only attempt to (re)schedule checks that should get checked... */ if (get_should_be_scheduled()) { @@ -2211,21 +2372,31 @@ int service::run_scheduled_check(int check_options, double latency) { if (!time_is_valid && !check_time_against_period( next_valid_time, this->check_period_ptr)) { set_next_check((time_t)(next_valid_time + 60 * 60 * 24 * 7)); - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Check of service '" << _description << "' on host '" << _hostname << "' could not be " "rescheduled properly. Scheduling check for next week..."; - logger(dbg_checks, more) + log_v2::runtime()->warn( + "Warning: Check of service '{}' on host '{}' could not be " + "rescheduled properly. Scheduling check for next week...", + _description, _hostname); + engine_logger(dbg_checks, more) << "Unable to find any valid times to reschedule the next " "service check!"; + log_v2::checks()->debug( + "Unable to find any valid times to reschedule the next " + "service check!"); } // This service could be rescheduled... else { set_next_check(next_valid_time); set_should_be_scheduled(true); - logger(dbg_checks, more) << "Rescheduled next service check for " - << my_ctime(&next_valid_time); + engine_logger(dbg_checks, more) + << "Rescheduled next service check for " + << my_ctime(&next_valid_time); + log_v2::checks()->debug("Rescheduled next service check for {}", + my_ctime(&next_valid_time)); } } } @@ -2257,23 +2428,34 @@ int service::run_async_check(int check_options, bool reschedule_check, bool* time_is_valid, time_t* preferred_time) noexcept { - logger(dbg_functions, basic) + engine_logger(dbg_functions, basic) << "service::run_async_check, check_options=" << check_options << ", latency=" << latency << ", scheduled_check=" << scheduled_check << ", reschedule_check=" << reschedule_check; + log_v2::functions()->trace( + "service::run_async_check, check_options={}, latency={}, " + "scheduled_check={}, reschedule_check={}", + check_options, latency, scheduled_check, reschedule_check); // Preamble. if (!get_check_command_ptr()) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Attempt to run active check on service '" << get_description() << "' on host '" << get_host_ptr()->get_name() << "' with no check command"; + log_v2::runtime()->error( + "Error: Attempt to run active check on service '{}' on host '{}' with " + "no check command", + get_description(), get_host_ptr()->get_name()); return ERROR; } - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "** Running async check of service '" << get_description() << "' on host '" << get_hostname() << "'..."; + log_v2::checks()->trace( + "** Running async check of service '{} on host '{}'...", + get_description(), get_hostname()); // Check if the service is viable now. if (!verify_check_viability(check_options, time_is_valid, preferred_time)) @@ -2293,22 +2475,32 @@ int service::run_async_check(int check_options, if (preferred_time != nullptr) *preferred_time += static_cast(get_check_interval() * config->interval_length()); - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Some broker module cancelled check of service '" << get_description() << "' on host '" << get_hostname(); + log_v2::runtime()->error( + "Error: Some broker module cancelled check of service '{}' on host " + "'{}'", + get_description(), get_hostname()); return ERROR; } // Service check was override by NEB module. else if (NEBERROR_CALLBACKOVERRIDE == res) { - logger(dbg_functions, basic) + engine_logger(dbg_functions, basic) << "Some broker module overrode check of service '" << get_description() << "' on host '" << get_hostname() << "' so we'll bail out"; + log_v2::functions()->trace( + "Some broker module overrode check of service '{}' on host '{}' so " + "we'll bail out", + get_description(), get_hostname()); return OK; } // Checking starts. - logger(dbg_checks, basic) << "Checking service '" << get_description() - << "' on host '" << get_hostname() << "'..."; + engine_logger(dbg_checks, basic) << "Checking service '" << get_description() + << "' on host '" << get_hostname() << "'..."; + log_v2::checks()->trace("Checking service '{}' on host '{}'...", + get_description(), get_hostname()); // Clear check options. if (scheduled_check) @@ -2331,8 +2523,10 @@ int service::run_async_check(int check_options, // Update the number of running service checks. ++currently_running_service_checks; - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Current running service checks: " << currently_running_service_checks; + log_v2::checks()->trace("Current running service checks: {}", + currently_running_service_checks); // Set the execution flag. set_is_executing(true); @@ -2396,8 +2590,10 @@ int service::run_async_check(int check_options, checks::checker::instance().add_check_result_to_reap( check_result_info.release()); - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Error: Service check command execution failed: " << e.what(); + log_v2::runtime()->warn( + "Error: Service check command execution failed: {}", e.what()); } } while (retry); @@ -2416,18 +2612,25 @@ int service::run_async_check(int check_options, * @return A boolean telling if service_status has been sent or not to broker. */ bool service::schedule_check(time_t check_time, int options) { - logger(dbg_functions, basic) << "schedule_service_check()"; + engine_logger(dbg_functions, basic) << "schedule_service_check()"; + log_v2::functions()->trace("schedule_service_check()"); - logger(dbg_checks, basic) + engine_logger(dbg_checks, basic) << "Scheduling a " << (options & CHECK_OPTION_FORCE_EXECUTION ? "forced" : "non-forced") << ", active check of service '" << _description << "' on host '" << _hostname << "' @ " << my_ctime(&check_time); + log_v2::checks()->trace( + "Scheduling a {}, active check of service '{}' on host '{}' @ {}", + options & CHECK_OPTION_FORCE_EXECUTION ? "forced" : "non-forced", + _description, _hostname, my_ctime(&check_time)); // Don't schedule a check if active checks // of this service are disabled. if (!get_checks_enabled() && !(options & CHECK_OPTION_FORCE_EXECUTION)) { - logger(dbg_checks, basic) << "Active checks of this service are disabled."; + engine_logger(dbg_checks, basic) + << "Active checks of this service are disabled."; + log_v2::checks()->trace("Active checks of this service are disabled."); return false; } @@ -2439,9 +2642,12 @@ bool service::schedule_check(time_t check_time, int options) { // We found another service check event for this service in // the queue - what should we do? if (temp_event) { - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "Found another service check event for this service @ " << my_ctime(&temp_event->run_time); + log_v2::checks()->debug( + "Found another service check event for this service @ {}", + my_ctime(&temp_event->run_time)); // Use the originally scheduled check unless we decide otherwise. use_original_event = true; @@ -2453,9 +2659,12 @@ bool service::schedule_check(time_t check_time, int options) { if ((options & CHECK_OPTION_FORCE_EXECUTION) && (check_time < temp_event->run_time)) { use_original_event = false; - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "New service check event is forced and occurs before the " "existing event, so the new event will be used instead."; + log_v2::checks()->debug( + "New service check event is forced and occurs before the " + "existing event, so the new event will be used instead."); } } // The original event is not a forced check... @@ -2463,23 +2672,32 @@ bool service::schedule_check(time_t check_time, int options) { // The new event is a forced check, so use it instead. if ((options & CHECK_OPTION_FORCE_EXECUTION)) { use_original_event = false; - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "New service check event is forced, so it will be used " "instead of the existing event."; + log_v2::checks()->debug( + "New service check event is forced, so it will be used " + "instead of the existing event."); } // The new event is not forced either and its execution time is // earlier than the original, so use it instead. else if (check_time < temp_event->run_time) { use_original_event = false; - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "New service check event occurs before the existing " "(older) event, so it will be used instead."; + log_v2::checks()->debug( + "New service check event occurs before the existing " + "(older) event, so it will be used instead."); } // The new event is older, so override the existing one. else { - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "New service check event occurs after the existing event, " "so we'll ignore it."; + log_v2::checks()->debug( + "New service check event occurs after the existing event, " + "so we'll ignore it."); } } } @@ -2497,7 +2715,8 @@ bool service::schedule_check(time_t check_time, int options) { no_update_status_now = true; } - logger(dbg_checks, most) << "Scheduling new service check event."; + engine_logger(dbg_checks, most) << "Scheduling new service check event."; + log_v2::checks()->debug("Scheduling new service check event."); // Allocate memory for a new event item. try { @@ -2523,8 +2742,10 @@ bool service::schedule_check(time_t check_time, int options) { if (temp_event) set_next_check(temp_event->run_time); - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "Keeping original service check event (ignoring the new one)."; + log_v2::checks()->debug( + "Keeping original service check event (ignoring the new one)."); } // Update the status log. @@ -2537,17 +2758,25 @@ void service::set_flap(double percent_change, double high_threshold, double low_threshold, int allow_flapstart_notification) { - logger(dbg_functions, basic) << "set_service_flap()"; + engine_logger(dbg_functions, basic) << "set_service_flap()"; + log_v2::functions()->trace("set_service_flap()"); - logger(dbg_flapping, more) << "Service '" << _description << "' on host '" - << _hostname << "' started flapping!"; + engine_logger(dbg_flapping, more) + << "Service '" << _description << "' on host '" << _hostname + << "' started flapping!"; + log_v2::checks()->debug("Service '{}' on host '{}' started flapping!", + _description, _hostname); /* log a notice - this one is parsed by the history CGI */ - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << com::centreon::logging::setprecision(1) << "SERVICE FLAPPING ALERT: " << _hostname << ";" << _description << ";STARTED; Service appears to have started flapping (" << percent_change << "% change >= " << high_threshold << "% threshold)"; + log_v2::runtime()->warn( + "SERVICE FLAPPING ALERT: {};{};STARTED; Service appears to have started " + "flapping ({:.1f}% change >= {:.1f}% threshold)", + _hostname, _description, percent_change, high_threshold); /* add a non-persistent comment to the service */ std::ostringstream oss; @@ -2587,17 +2816,25 @@ void service::set_flap(double percent_change, void service::clear_flap(double percent_change, double high_threshold, double low_threshold) { - logger(dbg_functions, basic) << "clear_service_flap()"; + engine_logger(dbg_functions, basic) << "clear_service_flap()"; + log_v2::functions()->trace("clear_service_flap()"); - logger(dbg_flapping, more) << "Service '" << _description << "' on host '" - << _hostname << "' stopped flapping."; + engine_logger(dbg_flapping, more) + << "Service '" << _description << "' on host '" << _hostname + << "' stopped flapping."; + log_v2::checks()->debug("Service '{}' on host '{}' stopped flapping.", + _description, _hostname); /* log a notice - this one is parsed by the history CGI */ - logger(log_info_message, basic) + engine_logger(log_info_message, basic) << com::centreon::logging::setprecision(1) << "SERVICE FLAPPING ALERT: " << _hostname << ";" << _description << ";STOPPED; Service appears to have stopped flapping (" << percent_change << "% change < " << low_threshold << "% threshold)"; + log_v2::events()->info( + "SERVICE FLAPPING ALERT: {};{};STOPPED; Service appears to have stopped " + "flapping ({:.1f}% change < {:.1f}% threshold)", + _hostname, _description, percent_change, low_threshold); /* delete the comment we added earlier */ if (this->get_flapping_comment_id() != 0) @@ -2623,11 +2860,15 @@ void service::clear_flap(double percent_change, void service::enable_flap_detection() { unsigned long attr = MODATTR_FLAP_DETECTION_ENABLED; - logger(dbg_functions, basic) << "service::enable_flap_detection()"; + engine_logger(dbg_functions, basic) << "service::enable_flap_detection()"; + log_v2::functions()->trace("service::enable_flap_detection()"); - logger(dbg_flapping, more) + engine_logger(dbg_flapping, more) << "Enabling flap detection for service '" << _description << "' on host '" << _hostname << "'."; + log_v2::checks()->debug( + "Enabling flap detection for service '{}' on host '{}'.", _description, + _hostname); /* nothing to do... */ if (get_flap_detection_enabled()) @@ -2655,11 +2896,15 @@ void service::enable_flap_detection() { void service::disable_flap_detection() { unsigned long attr = MODATTR_FLAP_DETECTION_ENABLED; - logger(dbg_functions, basic) << "disable_service_flap_detection()"; + engine_logger(dbg_functions, basic) << "disable_service_flap_detection()"; + log_v2::functions()->trace("disable_service_flap_detection()"); - logger(dbg_flapping, more) + engine_logger(dbg_flapping, more) << "Disabling flap detection for service '" << _description << "' on host '" << _hostname << "'."; + log_v2::checks()->debug( + "Disabling flap detection for service '{}' on host '{}'.", _description, + _hostname); /* nothing to do... */ if (!get_flap_detection_enabled()) @@ -2697,7 +2942,8 @@ bool service::verify_check_viability(int check_options, time_t preferred_time = 0L; int check_interval = 0; - logger(dbg_functions, basic) << "check_service_check_viability()"; + engine_logger(dbg_functions, basic) << "check_service_check_viability()"; + log_v2::functions()->trace("check_service_check_viability()"); /* get the check interval to use if we need to reschedule the check */ if (get_state_type() == soft && _current_state != service::state_ok) @@ -2720,8 +2966,10 @@ bool service::verify_check_viability(int check_options, preferred_time = current_time + check_interval; perform_check = false; - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "Active checks of the service are currently disabled."; + log_v2::checks()->debug( + "Active checks of the service are currently disabled."); } // Make sure this is a valid time to check the service. @@ -2733,9 +2981,12 @@ bool service::verify_check_viability(int check_options, if (time_is_valid) *time_is_valid = false; perform_check = false; - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "This is not a valid time for this service to be actively " "checked."; + log_v2::checks()->debug( + "This is not a valid time for this service to be actively " + "checked."); } } @@ -2744,9 +2995,12 @@ bool service::verify_check_viability(int check_options, preferred_time = current_time + check_interval; perform_check = false; - logger(dbg_checks, most) + engine_logger(dbg_checks, most) << "Execution dependencies for this service failed, so it will " "not be actively checked."; + log_v2::checks()->debug( + "Execution dependencies for this service failed, so it will " + "not be actively checked."); } } @@ -2779,9 +3033,11 @@ int service::notify_contact(nagios_macros* mac, int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; int neb_result; - logger(dbg_functions, basic) << "notify_contact_of_service()"; - logger(dbg_notifications, most) + engine_logger(dbg_functions, basic) << "notify_contact_of_service()"; + log_v2::functions()->trace("notify_contact_of_service()"); + engine_logger(dbg_notifications, most) << "** Notifying contact '" << cntct->get_name() << "'"; + log_v2::notifications()->info("** Notifying contact '{}'", cntct->get_name()); /* get start time */ gettimeofday(&start_time, nullptr); @@ -2823,8 +3079,9 @@ int service::notify_contact(nagios_macros* mac, if (raw_command.empty()) continue; - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "Raw notification command: " << raw_command; + log_v2::notifications()->info("Raw notification command: {}", raw_command); /* process any macros contained in the argument */ process_macros_r(mac, raw_command, processed_command, macro_options); @@ -2833,8 +3090,10 @@ int service::notify_contact(nagios_macros* mac, /* run the notification command... */ - logger(dbg_notifications, most) + engine_logger(dbg_notifications, most) << "Processed notification command: " << processed_command; + log_v2::notifications()->info("Processed notification command: {}", + processed_command); /* log the notification to program log file */ if (config->log_notifications()) { @@ -2861,11 +3120,15 @@ int service::notify_contact(nagios_macros* mac, .append(service_state_str) .append(")"); - logger(log_service_notification, basic) + engine_logger(log_service_notification, basic) << "SERVICE NOTIFICATION: " << cntct->get_name() << ';' << get_hostname() << ';' << get_description() << ';' << service_notification_state << ";" << cmd->get_name() << ';' << get_plugin_output() << info; + log_v2::notifications()->info( + "SERVICE NOTIFICATION: {};{};{};{};{};{};{}", cntct->get_name(), + get_hostname(), get_description(), service_notification_state, + cmd->get_name(), get_plugin_output(), info); } /* run the notification command */ @@ -2874,18 +3137,25 @@ int service::notify_contact(nagios_macros* mac, my_system_r(mac, processed_command, config->notification_timeout(), &early_timeout, &exectime, tmp, 0); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: can't execute service notification '" << cntct->get_name() << "' : " << e.what(); + log_v2::runtime()->error( + "Error: can't execute service notification '{}' : {}", + cntct->get_name(), e.what()); } /* check to see if the notification command timed out */ if (early_timeout) { - logger(log_service_notification | log_runtime_warning, basic) + engine_logger(log_service_notification | log_runtime_warning, basic) << "Warning: Contact '" << cntct->get_name() << "' service notification command '" << processed_command << "' timed out after " << config->notification_timeout() << " seconds"; + log_v2::notifications()->info( + "Warning: Contact '{}' service notification command '{}' timed out " + "after {} seconds", + cntct->get_name(), processed_command, config->notification_timeout()); } /* get end time */ @@ -2932,8 +3202,9 @@ bool service::is_valid_escalation_for_notification(escalation const* e, uint32_t notification_number; time_t current_time; - logger(dbg_functions, basic) + engine_logger(dbg_functions, basic) << "service::is_valid_escalation_for_notification()"; + log_v2::functions()->trace("service::is_valid_escalation_for_notification()"); /* get the current time */ time(¤t_time); @@ -3002,9 +3273,11 @@ bool service::is_result_fresh(time_t current_time, int log_this) { int tminutes = 0; int tseconds = 0; - logger(dbg_checks, most) << "Checking freshness of service '" - << this->get_description() << "' on host '" - << this->get_hostname() << "'..."; + engine_logger(dbg_checks, most) + << "Checking freshness of service '" << this->get_description() + << "' on host '" << this->get_hostname() << "'..."; + log_v2::checks()->debug("Checking freshness of service '{}' on host '{}'...", + this->get_description(), this->get_hostname()); /* use user-supplied freshness threshold or auto-calculate a freshness * threshold to use? */ @@ -3020,9 +3293,11 @@ bool service::is_result_fresh(time_t current_time, int log_this) { } else freshness_threshold = this->get_freshness_threshold(); - logger(dbg_checks, most) << "Freshness thresholds: service=" - << this->get_freshness_threshold() - << ", use=" << freshness_threshold; + engine_logger(dbg_checks, most) + << "Freshness thresholds: service=" << this->get_freshness_threshold() + << ", use=" << freshness_threshold; + log_v2::checks()->debug("Freshness thresholds: service={}, use={}", + this->get_freshness_threshold(), freshness_threshold); /* calculate expiration time */ /* CHANGED 11/10/05 EG - program start is only used in expiration time @@ -3048,12 +3323,13 @@ bool service::is_result_fresh(time_t current_time, int log_this) { else expiration_time = (time_t)(get_last_check() + freshness_threshold); - logger(dbg_checks, most) << "HBC: " << this->has_been_checked() - << ", PS: " << program_start - << ", ES: " << event_start - << ", LC: " << get_last_check() - << ", CT: " << current_time - << ", ET: " << expiration_time; + engine_logger(dbg_checks, most) + << "HBC: " << this->has_been_checked() << ", PS: " << program_start + << ", ES: " << event_start << ", LC: " << get_last_check() + << ", CT: " << current_time << ", ET: " << expiration_time; + log_v2::checks()->debug("HBC: {}, PS: {}, ES: {}, LC: {}, CT: {}, ET: {}", + this->has_been_checked(), program_start, event_start, + get_last_check(), current_time, expiration_time); /* the results for the last check of this service are stale */ if (expiration_time < current_time) { @@ -3064,7 +3340,7 @@ bool service::is_result_fresh(time_t current_time, int log_this) { /* log a warning */ if (log_this) - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: The results of service '" << this->get_description() << "' on host '" << this->get_hostname() << "' are stale by " << days << "d " << hours << "h " << minutes << "m " << seconds @@ -3072,8 +3348,15 @@ bool service::is_result_fresh(time_t current_time, int log_this) { << "m " << tseconds << "s). I'm forcing an immediate check " "of the service."; - - logger(dbg_checks, more) + log_v2::runtime()->warn( + "Warning: The results of service '{}' on host '{}' are stale by {}d " + "{}h {}m {}s (threshold={}d {}h {}m {}s). I'm forcing an immediate " + "check " + "of the service.", + this->get_description(), this->get_hostname(), days, hours, minutes, + seconds, tdays, thours, tminutes, tseconds); + + engine_logger(dbg_checks, more) << "Check results for service '" << this->get_description() << "' on host '" << this->get_hostname() << "' are stale by " << days << "d " << hours << "h " << minutes << "m " << seconds @@ -3081,13 +3364,22 @@ bool service::is_result_fresh(time_t current_time, int log_this) { << "m " << tseconds << "s). Forcing an immediate check of " "the service..."; + log_v2::checks()->debug( + "Check results for service '{}' on host '{}' are stale by {}d {}h {}m " + "{}s (threshold={}d {}h {}m {}s). Forcing an immediate check of the " + "service...", + this->get_description(), this->get_hostname(), days, hours, minutes, + seconds, tdays, thours, tminutes, tseconds); return false; } - logger(dbg_checks, more) << "Check results for service '" - << this->get_description() << "' on host '" - << this->get_hostname() << "' are fresh."; + engine_logger(dbg_checks, more) + << "Check results for service '" << this->get_description() + << "' on host '" << this->get_hostname() << "' are fresh."; + log_v2::checks()->debug( + "Check results for service '{}' on host '{}' are fresh.", + this->get_description(), this->get_hostname()); return true; } @@ -3097,7 +3389,9 @@ bool service::is_result_fresh(time_t current_time, int log_this) { * (globally or per-service). */ void service::handle_flap_detection_disabled() { - logger(dbg_functions, basic) << "handle_service_flap_detection_disabled()"; + engine_logger(dbg_functions, basic) + << "handle_service_flap_detection_disabled()"; + log_v2::functions()->trace("handle_service_flap_detection_disabled()"); /* if the service was flapping, remove the flapping indicator */ if (get_is_flapping()) { @@ -3109,9 +3403,14 @@ void service::handle_flap_detection_disabled() { set_flapping_comment_id(0); /* log a notice - this one is parsed by the history CGI */ - logger(log_info_message, basic) - << "SERVICE FLAPPING ALERT: " << get_hostname() << ";" - << get_description() << ";DISABLED; Flap detection has been disabled"; + engine_logger(log_info_message, basic) + << "SERVICE FLAPPING ALERT: " << this->get_hostname() << ";" + << this->get_description() + << ";DISABLED; Flap detection has been disabled"; + log_v2::events()->debug( + "SERVICE FLAPPING ALERT: {};{};DISABLED; Flap detection has been " + "disabled", + this->get_hostname(), this->get_description()); /* send data to event broker */ broker_flapping_data(NEBTYPE_FLAPPING_STOP, NEBFLAG_NONE, @@ -3154,7 +3453,9 @@ timeperiod* service::get_notification_timeperiod() const { */ bool service::authorized_by_dependencies( dependency::types dependency_type) const { - logger(dbg_functions, basic) << "service::authorized_by_dependencies()"; + engine_logger(dbg_functions, basic) + << "service::authorized_by_dependencies()"; + log_v2::functions()->trace("service::authorized_by_dependencies()"); auto p(servicedependency::servicedependencies.equal_range( {_hostname, _description})); @@ -3209,7 +3510,8 @@ void service::check_for_orphaned() { time_t current_time{0L}; time_t expected_time{0L}; - logger(dbg_functions, basic) << "check_for_orphaned_services()"; + engine_logger(dbg_functions, basic) << "check_for_orphaned_services()"; + log_v2::functions()->trace("check_for_orphaned_services()"); /* get the current time */ time(¤t_time); @@ -3233,16 +3535,26 @@ void service::check_for_orphaned() { * reason the results haven't come back in... */ if (expected_time < current_time) { /* log a warning */ - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: The check of service '" << it->first.second << "' on host '" << it->first.first << "' looks like it was orphaned " "(results never came back). I'm scheduling an immediate check " "of the service..."; - - logger(dbg_checks, more) + log_v2::runtime()->warn( + "Warning: The check of service '{}' on host '{}' looks like it was " + "orphaned " + "(results never came back). I'm scheduling an immediate check " + "of the service...", + it->first.second, it->first.first); + + engine_logger(dbg_checks, more) << "Service '" << it->first.second << "' on host '" << it->first.first << "' was orphaned, so we're scheduling an immediate check..."; + log_v2::checks()->debug( + "Service '{}' on host '{}' was orphaned, so we're scheduling an " + "immediate check...", + it->first.second, it->first.first); /* decrement the number of running service checks */ if (currently_running_service_checks > 0) @@ -3261,13 +3573,17 @@ void service::check_for_orphaned() { void service::check_result_freshness() { time_t current_time{0L}; - logger(dbg_functions, basic) << "check_service_result_freshness()"; - logger(dbg_checks, more) + engine_logger(dbg_functions, basic) << "check_service_result_freshness()"; + log_v2::functions()->trace("check_service_result_freshness()"); + engine_logger(dbg_checks, more) << "Checking the freshness of service check results..."; + log_v2::checks()->debug("Checking the freshness of service check results..."); /* bail out if we're not supposed to be checking freshness */ if (!config->check_service_freshness()) { - logger(dbg_checks, more) << "Service freshness checking is disabled."; + engine_logger(dbg_checks, more) + << "Service freshness checking is disabled."; + log_v2::checks()->debug("Service freshness checking is disabled."); return; } /* get the current time */ @@ -3358,9 +3674,13 @@ void service::resolve(int& w, int& e) { try { notifier::resolve(warnings, errors); } catch (std::exception const& e) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Service description '" << _description << "' of host '" << _hostname << "' has problem in its notifier part: " << e.what(); + log_v2::config()->error( + "Error: Service description '{}' of host '{}' has problem in its " + "notifier part: {}", + _description, _hostname, e.what()); } { @@ -3370,11 +3690,14 @@ void service::resolve(int& w, int& e) { /* we couldn't find an associated host! */ if (it == host::hosts.end() || !it->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Host '" << _hostname << "' specified in service " "'" << _description << "' not defined anywhere!"; + log_v2::config()->error( + "Error: Host '{}' specified in service '{}' not defined anywhere!", + _hostname, _description); errors++; set_host_ptr(nullptr); } else { @@ -3396,32 +3719,48 @@ void service::resolve(int& w, int& e) { // Check for sane recovery options. if (get_notifications_enabled() && get_notify_on(notifier::ok) && !get_notify_on(notifier::warning) && !get_notify_on(notifier::critical)) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Recovery notification option in service '" << _description << "' for host '" << _hostname << "' doesn't make any sense - specify warning and /or critical " "options as well"; + log_v2::config()->warn( + "Warning: Recovery notification option in service '{}' for host '{}' " + "doesn't make any sense - specify warning and /or critical " + "options as well", + _description, _hostname); warnings++; } // See if the notification interval is less than the check interval. if (get_notifications_enabled() && get_notification_interval() && get_notification_interval() < get_check_interval()) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Warning: Service '" << _description << "' on host '" << _hostname << "' has a notification interval less than " "its check interval! Notifications are only re-sent after " "checks are made, so the effective notification interval will " "be that of the check interval."; + log_v2::config()->warn( + "Warning: Service '{}' on host '{}' has a notification interval less " + "than " + "its check interval! Notifications are only re-sent after " + "checks are made, so the effective notification interval will " + "be that of the check interval.", + _description, _hostname); warnings++; } /* check for illegal characters in service description */ if (contains_illegal_object_chars(_description.c_str())) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: The description string for service '" << _description << "' on host '" << _hostname << "' contains one or more illegal characters."; + log_v2::config()->error( + "Error: The description string for service '{}' on host '{}' contains " + "one or more illegal characters.", + _description, _hostname); errors++; } diff --git a/centreon-engine/src/servicedependency.cc b/centreon-engine/src/servicedependency.cc index 67feae035d0..34e9cbc462a 100644 --- a/centreon-engine/src/servicedependency.cc +++ b/centreon-engine/src/servicedependency.cc @@ -21,6 +21,7 @@ #include "com/centreon/engine/broker.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/shared.hh" #include "com/centreon/engine/string.hh" @@ -292,12 +293,17 @@ void servicedependency::resolve(int& w, int& e) { {get_dependent_hostname(), get_dependent_service_description()})}; if (found == service::services.end() || !found->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Dependent service '" << get_dependent_service_description() << "' on host '" << get_dependent_hostname() << "' specified in service dependency for service '" << get_service_description() << "' on host '" << get_hostname() << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Dependent service '{}' on host '{}' specified in service " + "dependency for service '{}' on host '{}' is not defined anywhere!", + get_dependent_service_description(), get_dependent_hostname(), + get_service_description(), get_service_description()); errors++; dependent_service_ptr = nullptr; } else @@ -308,11 +314,16 @@ void servicedependency::resolve(int& w, int& e) { // Find the service we're depending on. if (found == service::services.end() || !found->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Service '" << get_service_description() << "' on host '" << get_hostname() << "' specified in service dependency for service '" << get_dependent_service_description() << "' on host '" << get_dependent_hostname() << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Service '{}' on host '{}' specified in service dependency for " + "service '{}' on host '{}' is not defined anywhere!", + get_service_description(), get_hostname(), + get_dependent_service_description(), get_dependent_hostname()); errors++; master_service_ptr = nullptr; } else @@ -322,10 +333,14 @@ void servicedependency::resolve(int& w, int& e) { // Make sure they're not the same service. if (dependent_service_ptr == master_service_ptr && dependent_service_ptr != nullptr) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Service dependency definition for service '" << get_dependent_service_description() << "' on host '" << get_dependent_hostname() << "' is circular (it depends on itself)!"; + log_v2::config()->error( + "Error: Service dependency definition for service '{}' on host '{}' is " + "circular (it depends on itself)!", + get_dependent_service_description(), get_dependent_hostname()); errors++; } @@ -335,11 +350,16 @@ void servicedependency::resolve(int& w, int& e) { timeperiod::timeperiods.find(get_dependency_period())}; if (it == timeperiod::timeperiods.end() || !it->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Dependency period '" << get_dependency_period() << "' specified in service dependency for service '" << get_dependent_service_description() << "' on host '" << get_dependent_hostname() << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Dependency period '{}' specified in service dependency for " + "service '{}' on host '{}' is not defined anywhere!", + get_dependency_period(), get_dependent_service_description(), + get_dependent_hostname()); errors++; dependency_period_ptr = nullptr; } else diff --git a/centreon-engine/src/serviceescalation.cc b/centreon-engine/src/serviceescalation.cc index 25e16503dae..ee4bc35634f 100644 --- a/centreon-engine/src/serviceescalation.cc +++ b/centreon-engine/src/serviceescalation.cc @@ -22,6 +22,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" using namespace com::centreon::engine::configuration::applier; @@ -71,7 +72,8 @@ std::string const& serviceescalation::get_description() const { */ bool serviceescalation::is_viable(int state, uint32_t notification_number) const { - logger(dbg_functions, basic) << "serviceescalation::is_viable()"; + engine_logger(dbg_functions, basic) << "serviceescalation::is_viable()"; + log_v2::functions()->trace("serviceescalation::is_viable()"); bool retval{escalation::is_viable(state, notification_number)}; if (retval) { @@ -97,10 +99,14 @@ void serviceescalation::resolve(int& w, int& e) { service_map::const_iterator found{ service::services.find({get_hostname(), get_description()})}; if (found == service::services.end() || !found->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Service '" << get_description() << "' on host '" << get_hostname() << "' specified in service escalation is not defined anywhere!"; + log_v2::config()->error( + "Error: Service '{}' on host '{}' specified in service escalation is " + "not defined anywhere!", + get_description(), get_hostname()); errors++; notifier_ptr = nullptr; } else { @@ -111,8 +117,9 @@ void serviceescalation::resolve(int& w, int& e) { try { escalation::resolve(w, errors); } catch (std::exception const& ee) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Notifier escalation error: " << ee.what(); + log_v2::config()->error("Error: Notifier escalation error: {}", ee.what()); } // Add errors. diff --git a/centreon-engine/src/servicegroup.cc b/centreon-engine/src/servicegroup.cc index 09e2372be2d..0db1f668534 100644 --- a/centreon-engine/src/servicegroup.cc +++ b/centreon-engine/src/servicegroup.cc @@ -22,6 +22,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/shared.hh" #include "com/centreon/engine/string.hh" @@ -59,8 +60,11 @@ servicegroup::servicegroup(uint64_t id, _action_url{action_url} { // Check if the service group already exist. if (is_servicegroup_exist(group_name)) { - logger(log_config_error, basic) << "Error: Servicegroup '" << group_name - << "' has already been defined"; + engine_logger(log_config_error, basic) + << "Error: Servicegroup '" << group_name + << "' has already been defined"; + log_v2::config()->error("Error: Servicegroup '{}' has already been defined", + group_name); throw engine_error() << "Could not register service group '" << group_name << "'"; } @@ -168,10 +172,14 @@ void servicegroup::resolve(int& w, int& e) { service_map::const_iterator found(service::services.find(it->first)); if (found == service::services.end() || !found->second) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Service '" << it->first.second << "' on host '" << it->first.first << "' specified in service group '" << _group_name << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Service '{}' on host '{}' specified in service group '{}' is " + "not defined anywhere!", + it->first.second, it->first.first, _group_name); errors++; } // Save a pointer to this servicegroup for faster service/group @@ -192,9 +200,13 @@ void servicegroup::resolve(int& w, int& e) { // Check for illegal characters in servicegroup name. if (contains_illegal_object_chars(_group_name.c_str())) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: The name of servicegroup '" << _group_name << "' contains one or more illegal characters."; + log_v2::config()->error( + "Error: The name of servicegroup '{}' contains one or more illegal " + "characters.", + _group_name); errors++; } diff --git a/centreon-engine/src/timeperiod.cc b/centreon-engine/src/timeperiod.cc index 6587ee7a91a..f11ce34bee8 100644 --- a/centreon-engine/src/timeperiod.cc +++ b/centreon-engine/src/timeperiod.cc @@ -23,6 +23,7 @@ #include "com/centreon/engine/daterange.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/shared.hh" #include "com/centreon/engine/string.hh" @@ -47,16 +48,19 @@ timeperiod_map timeperiod::timeperiods; timeperiod::timeperiod(std::string const& name, std::string const& alias) : _name{name}, _alias{alias} { if (name.empty() || alias.empty()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Name or alias for timeperiod is NULL"; + log_v2::config()->error("Error: Name or alias for timeperiod is NULL"); throw engine_error() << "Could not register time period '" << name << "'"; } // Check if the timeperiod already exist. timeperiod_map::const_iterator it{timeperiod::timeperiods.find(name)}; if (it != timeperiod::timeperiods.end()) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Timeperiod '" << name << "' has already been defined"; + log_v2::config()->error("Error: Timeperiod '{}' has already been defined", + name); throw engine_error() << "Could not register time period '" << name << "'"; } } @@ -758,7 +762,8 @@ static bool _timerange_to_time_t(timerange* trange, * @return true on success, false on failure. */ bool check_time_against_period(time_t test_time, timeperiod* tperiod) { - logger(dbg_functions, basic) << "check_time_against_period()"; + engine_logger(dbg_functions, basic) << "check_time_against_period()"; + log_v2::functions()->trace("check_time_against_period()"); // If no period was specified, assume the time is good. if (!tperiod) @@ -782,7 +787,9 @@ bool check_time_against_period(time_t test_time, timeperiod* tperiod) { */ bool check_time_against_period_for_notif(time_t test_time, timeperiod* tperiod) { - logger(dbg_functions, basic) << "check_time_against_period_for_notif()"; + engine_logger(dbg_functions, basic) + << "check_time_against_period_for_notif()"; + log_v2::functions()->trace("check_time_against_period_for_notif()"); // If no period was specified, assume the time is good. if (!tperiod) @@ -806,7 +813,9 @@ bool check_time_against_period_for_notif(time_t test_time, void timeperiod::get_next_invalid_time_per_timeperiod(time_t preferred_time, time_t* invalid_time, bool notif_timeperiod) { - logger(dbg_functions, basic) << "get_next_invalid_time_per_timeperiod()"; + engine_logger(dbg_functions, basic) + << "get_next_invalid_time_per_timeperiod()"; + log_v2::functions()->trace("get_next_invalid_time_per_timeperiod()"); // If no time can be found, the original preferred time will be set // in invalid_time at the end of the loop. @@ -991,7 +1000,8 @@ static time_t _get_next_valid_time_in_timeranges(time_t preferred_time, void timeperiod::get_next_valid_time_per_timeperiod(time_t preferred_time, time_t* valid_time, bool notif_timeperiod) { - logger(dbg_functions, basic) << "get_next_valid_time_per_timeperiod()"; + engine_logger(dbg_functions, basic) << "get_next_valid_time_per_timeperiod()"; + log_v2::functions()->trace("get_next_valid_time_per_timeperiod()"); // If no time can be found, the original preferred time will be set // in valid_time at the end of the loop. @@ -1115,7 +1125,8 @@ void timeperiod::get_next_valid_time_per_timeperiod(time_t preferred_time, void get_next_valid_time(time_t pref_time, time_t* valid_time, timeperiod* tperiod) { - logger(dbg_functions, basic) << "get_next_valid_time()"; + engine_logger(dbg_functions, basic) << "get_next_valid_time()"; + log_v2::functions()->trace("get_next_valid_time()"); // Preferred time must be now or in the future. time_t preferred_time(std::max(pref_time, time(NULL))); @@ -1147,9 +1158,13 @@ void timeperiod::resolve(int& w __attribute__((unused)), int& e) { // Check for illegal characters in timeperiod name. if (contains_illegal_object_chars(_name.c_str())) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: The name of time period '" << _name << "' contains one or more illegal characters."; + log_v2::config()->error( + "Error: The name of time period '{}' contains one or more illegal " + "characters.", + _name); errors++; } @@ -1161,10 +1176,14 @@ void timeperiod::resolve(int& w __attribute__((unused)), int& e) { timeperiod::timeperiods.find(it->first)}; if (found == timeperiod::timeperiods.end()) { - logger(log_verification_error, basic) + engine_logger(log_verification_error, basic) << "Error: Excluded time period '" << it->first << "' specified in timeperiod '" << _name << "' is not defined anywhere!"; + log_v2::config()->error( + "Error: Excluded time period '{}' specified in timeperiod '{}' is " + "not defined anywhere!", + it->first, _name); errors++; } else { // Save the timeperiod pointer for later. diff --git a/centreon-engine/src/timerange.cc b/centreon-engine/src/timerange.cc index e788cd24c97..4108d710521 100644 --- a/centreon-engine/src/timerange.cc +++ b/centreon-engine/src/timerange.cc @@ -22,6 +22,7 @@ #include #include "com/centreon/engine/daterange.hh" #include "com/centreon/engine/exceptions/error.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/string.hh" #include "com/centreon/engine/timeperiod.hh" @@ -32,14 +33,18 @@ using namespace com::centreon::engine::logging; timerange::timerange(uint64_t start, uint64_t end) { // Make sure we have the data we need. if (start > 86400) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Start time " << start << " is not valid for timeperiod"; + log_v2::config()->error("Error: Start time {} is not valid for timeperiod", + start); throw engine_error() << "Could not create timerange " << "start'" << start << "' end '" << end << "'"; } if (end > 86400) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: End time " << end << " is not value for timeperiod"; + log_v2::config()->error("Error: End time {} is not value for timeperiod", + end); throw engine_error() << "Could not create timerange " << "start'" << start << "' end '" << end << "'"; } diff --git a/centreon-engine/src/utils.cc b/centreon-engine/src/utils.cc index b51e660bc62..865c6d645b2 100644 --- a/centreon-engine/src/utils.cc +++ b/centreon-engine/src/utils.cc @@ -47,6 +47,7 @@ #include "com/centreon/engine/downtimes/downtime_manager.hh" #include "com/centreon/engine/events/loop.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" #include "com/centreon/engine/nebmods.hh" @@ -70,7 +71,8 @@ int my_system_r(nagios_macros* mac, double* exectime, std::string& output, unsigned int max_output_length) { - logger(dbg_functions, basic) << "my_system_r()"; + engine_logger(dbg_functions, basic) << "my_system_r()"; + log_v2::functions()->trace("my_system_r()"); // initialize return variables. *early_timeout = false; @@ -81,7 +83,8 @@ int my_system_r(nagios_macros* mac, return service::state_ok; } - logger(dbg_commands, more) << "Running command '" << cmd << "'..."; + engine_logger(dbg_commands, more) << "Running command '" << cmd << "'..."; + log_v2::commands()->debug("Running command '{}'...", cmd); timeval start_time = timeval(); timeval end_time = timeval(); @@ -109,10 +112,14 @@ int my_system_r(nagios_macros* mac, output = res.output; int result(res.exit_code); - logger(dbg_commands, more) << com::centreon::logging::setprecision(3) - << "Execution time=" << *exectime - << " sec, early timeout=" << *early_timeout - << ", result=" << result << ", output=" << output; + engine_logger(dbg_commands, more) + << com::centreon::logging::setprecision(3) + << "Execution time=" << *exectime + << " sec, early timeout=" << *early_timeout << ", result=" << result + << ", output=" << output; + log_v2::commands()->debug( + "Execution time={:.3f} sec, early timeout={}, result={}, output={}", + *exectime, *early_timeout, result, output); // send event broker. broker_system_command(NEBTYPE_SYSTEM_COMMAND_END, NEBFLAG_NONE, NEBATTR_NONE, @@ -144,7 +151,8 @@ int get_raw_command_line_r(nagios_macros* mac, int arg_index = 0; int escaped = false; - logger(dbg_functions, basic) << "get_raw_command_line_r()"; + engine_logger(dbg_functions, basic) << "get_raw_command_line_r()"; + log_v2::functions()->trace("get_raw_command_line_r()"); /* clear the argv macros */ clear_argv_macros_r(mac); @@ -154,8 +162,10 @@ int get_raw_command_line_r(nagios_macros* mac, return ERROR; } - logger(dbg_commands | dbg_checks | dbg_macros, most) + engine_logger(dbg_commands | dbg_checks | dbg_macros, most) << "Raw Command Input: " << cmd_ptr->get_command_line(); + log_v2::commands()->debug("Raw Command Input: {}", + cmd_ptr->get_command_line()); /* get the full command line */ full_command = cmd_ptr->get_command_line(); @@ -205,8 +215,9 @@ int get_raw_command_line_r(nagios_macros* mac, } } - logger(dbg_commands | dbg_checks | dbg_macros, most) + engine_logger(dbg_commands | dbg_checks | dbg_macros, most) << "Expanded Command Output: " << full_command; + log_v2::commands()->debug("Expanded Command Output: {}", full_command); return OK; } diff --git a/centreon-engine/src/xpddefault.cc b/centreon-engine/src/xpddefault.cc old mode 100755 new mode 100644 index 52ac9fee70e..3c9b82b916c --- a/centreon-engine/src/xpddefault.cc +++ b/centreon-engine/src/xpddefault.cc @@ -29,6 +29,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/globals.hh" #include "com/centreon/engine/host.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" #include "com/centreon/engine/service.hh" @@ -97,10 +98,15 @@ int xpddefault_initialize_performance_data() { commands::command::commands.find(temp_command_name); if (cmd_found == commands::command::commands.end() || !cmd_found->second) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Host performance command '" << temp_command_name << "' was not found - host performance data will not " "be processed!"; + log_v2::runtime()->warn( + "Warning: Host performance command '{}' was not found - host " + "performance data will not " + "be processed!", + temp_command_name); } else xpddefault_host_perfdata_command_ptr = cmd_found->second.get(); // save the command pointer for later. @@ -118,10 +124,15 @@ int xpddefault_initialize_performance_data() { commands::command::commands.find(temp_command_name); if (cmd_found == commands::command::commands.end() || !cmd_found->second) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Service performance command '" << temp_command_name << "' was not found - service performance data will not " "be processed!"; + log_v2::runtime()->warn( + "Warning: Service performance command '{}' was not found - service " + "performance data will not " + "be processed!", + temp_command_name); } else xpddefault_service_perfdata_command_ptr = cmd_found->second.get(); @@ -139,11 +150,16 @@ int xpddefault_initialize_performance_data() { commands::command::commands.find(temp_command_name); if (cmd_found == commands::command::commands.end() || !cmd_found->second) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Host performance file processing command '" << temp_command_name << "' was not found - host performance " "data file will not be processed!"; + log_v2::runtime()->warn( + "Warning: Host performance file processing command '{}' was not " + "found - host performance " + "data file will not be processed!", + temp_command_name); } else xpddefault_host_perfdata_file_processing_command_ptr = cmd_found->second.get(); @@ -162,11 +178,16 @@ int xpddefault_initialize_performance_data() { commands::command::commands.find(temp_command_name); if (cmd_found == commands::command::commands.end() || !cmd_found->second) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Service performance file processing command '" << temp_command_name << "' was not found - service performance " "data file will not be processed!"; + log_v2::runtime()->warn( + "Warning: Service performance file processing command '{}' was not " + "found - service performance " + "data file will not be processed!", + temp_command_name); } else xpddefault_service_perfdata_file_processing_command_ptr = cmd_found->second.get(); @@ -279,7 +300,9 @@ int xpddefault_run_service_performance_data_command( int result(OK); int macro_options(STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS); - logger(dbg_functions, basic) << "run_service_performance_data_command()"; + engine_logger(dbg_functions, basic) + << "run_service_performance_data_command()"; + log_v2::functions()->trace("run_service_performance_data_command()"); if (svc == nullptr) return ERROR; @@ -295,8 +318,10 @@ int xpddefault_run_service_performance_data_command( if (raw_command_line.c_str()) return ERROR; - logger(dbg_perfdata, most) + engine_logger(dbg_perfdata, most) << "Raw service performance data command line: " << raw_command_line; + log_v2::commands()->debug("Raw service performance data command line: {}", + raw_command_line); // process any macros in the raw command line. process_macros_r(mac, raw_command_line, processed_command_line, @@ -304,9 +329,12 @@ int xpddefault_run_service_performance_data_command( if (processed_command_line.empty()) return ERROR; - logger(dbg_perfdata, most) << "Processed service performance data " - "command line: " - << processed_command_line; + engine_logger(dbg_perfdata, most) << "Processed service performance data " + "command line: " + << processed_command_line; + log_v2::commands()->debug( + "Processed service performance data command line: {}", + processed_command_line); // run the command. try { @@ -314,18 +342,26 @@ int xpddefault_run_service_performance_data_command( my_system_r(mac, processed_command_line, config->perfdata_timeout(), &early_timeout, &exectime, tmp, 0); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: can't execute service performance data command line '" << processed_command_line << "' : " << e.what(); + log_v2::runtime()->error( + "Error: can't execute service performance data command line '{}' : {}", + processed_command_line, e.what()); } // check to see if the command timed out. if (early_timeout == true) - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Service performance data command '" << processed_command_line << "' for service '" << svc->get_description() << "' on host '" << svc->get_hostname() << "' timed out after " << config->perfdata_timeout() << " seconds"; + log_v2::runtime()->warn( + "Warning: Service performance data command '{}' for service '{}' on host " + "'{}' timed out after {} seconds", + processed_command_line, svc->get_description(), svc->get_hostname(), + config->perfdata_timeout()); return result; } @@ -340,7 +376,8 @@ int xpddefault_run_host_performance_data_command(nagios_macros* mac, int result(OK); int macro_options(STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS); - logger(dbg_functions, basic) << "run_host_performance_data_command()"; + engine_logger(dbg_functions, basic) << "run_host_performance_data_command()"; + log_v2::functions()->trace("run_host_performance_data_command()"); if (hst == nullptr) return ERROR; @@ -356,15 +393,20 @@ int xpddefault_run_host_performance_data_command(nagios_macros* mac, if (raw_command_line.empty()) return ERROR; - logger(dbg_perfdata, most) + engine_logger(dbg_perfdata, most) << "Raw host performance data command line: " << raw_command_line; + log_v2::commands()->info("Raw host performance data command line: {}", + raw_command_line); // process any macros in the raw command line. process_macros_r(mac, raw_command_line, processed_command_line, macro_options); - logger(dbg_perfdata, most) << "Processed host performance data command line: " - << processed_command_line; + engine_logger(dbg_perfdata, most) + << "Processed host performance data command line: " + << processed_command_line; + log_v2::commands()->info("Processed host performance data command line: {}", + processed_command_line); // run the command. try { @@ -372,9 +414,12 @@ int xpddefault_run_host_performance_data_command(nagios_macros* mac, my_system_r(mac, processed_command_line, config->perfdata_timeout(), &early_timeout, &exectime, tmp, 0); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: can't execute host performance data command line '" << processed_command_line << "' : " << e.what(); + log_v2::runtime()->error( + "Error: can't execute host performance data command line '{}' : {}", + processed_command_line, e.what()); } if (processed_command_line.empty()) @@ -382,10 +427,14 @@ int xpddefault_run_host_performance_data_command(nagios_macros* mac, // check to see if the command timed out. if (early_timeout == true) - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Host performance data command '" << processed_command_line << "' for host '" << hst->get_name() << "' timed out after " << config->perfdata_timeout() << " seconds"; + log_v2::runtime()->warn( + "Warning: Host performance data command '{}' for host '{}' timed out " + "after {} seconds", + processed_command_line, hst->get_name(), config->perfdata_timeout()); return result; } @@ -410,10 +459,15 @@ int xpddefault_open_host_perfdata_file() { : "a"); if (xpddefault_host_perfdata_fp == nullptr) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: File '" << xpddefault_host_perfdata_fp << "' could not be opened - host performance data will not " "be written to file!"; + log_v2::runtime()->warn( + "Warning: File '{}' could not be opened - host performance data will " + "not " + "be written to file!", + (void*)xpddefault_host_perfdata_fp); return ERROR; } @@ -441,10 +495,15 @@ int xpddefault_open_service_perfdata_file() { : "a"); if (xpddefault_service_perfdata_fp == nullptr) { - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: File '" << config->service_perfdata_file() << "' could not be opened - service performance data will not " "be written to file!"; + log_v2::runtime()->warn( + "Warning: File '{}' could not be opened - service performance data " + "will not " + "be written to file!", + config->service_perfdata_file()); return ERROR; } @@ -516,7 +575,9 @@ int xpddefault_update_service_performance_data_file( std::string processed_output; int result(OK); - logger(dbg_functions, basic) << "update_service_performance_data_file()"; + engine_logger(dbg_functions, basic) + << "update_service_performance_data_file()"; + log_v2::functions()->trace("update_service_performance_data_file()"); if (svc == nullptr) return ERROR; @@ -529,16 +590,20 @@ int xpddefault_update_service_performance_data_file( // get the raw line to write. raw_output = xpddefault_service_perfdata_file_template; - logger(dbg_perfdata, most) + engine_logger(dbg_perfdata, most) << "Raw service performance data file output: " << raw_output; + log_v2::commands()->info("Raw service performance data file output: {}", + raw_output); // process any macros in the raw output line. process_macros_r(mac, raw_output, processed_output, 0); if (processed_output.empty()) return ERROR; - logger(dbg_perfdata, most) + engine_logger(dbg_perfdata, most) << "Processed service performance data file output: " << processed_output; + log_v2::commands()->info("Processed service performance data file output: {}", + processed_output); // lock, write to and unlock host performance data file. pthread_mutex_lock(&xpddefault_service_perfdata_fp_lock); @@ -557,7 +622,8 @@ int xpddefault_update_host_performance_data_file(nagios_macros* mac, std::string processed_output; int result(OK); - logger(dbg_functions, basic) << "update_host_performance_data_file()"; + engine_logger(dbg_functions, basic) << "update_host_performance_data_file()"; + log_v2::functions()->trace("update_host_performance_data_file()"); if (hst == nullptr) return ERROR; @@ -570,16 +636,19 @@ int xpddefault_update_host_performance_data_file(nagios_macros* mac, // get the raw output. raw_output = string::dup(xpddefault_host_perfdata_file_template); - logger(dbg_perfdata, most) + engine_logger(dbg_perfdata, most) << "Raw host performance file output: " << raw_output; + log_v2::commands()->info("Raw host performance file output: {}", raw_output); // process any macros in the raw output. process_macros_r(mac, raw_output, processed_output, 0); if (processed_output.empty()) return ERROR; - logger(dbg_perfdata, most) + engine_logger(dbg_perfdata, most) << "Processed host performance data file output: " << processed_output; + log_v2::commands()->info("Processed host performance data file output: {}", + processed_output); // lock, write to and unlock host performance data file. pthread_mutex_lock(&xpddefault_host_perfdata_fp_lock); @@ -601,7 +670,8 @@ int xpddefault_process_host_perfdata_file() { int macro_options(STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS); nagios_macros* mac(get_global_macros()); - logger(dbg_functions, basic) << "process_host_perfdata_file()"; + engine_logger(dbg_functions, basic) << "process_host_perfdata_file()"; + log_v2::functions()->trace("process_host_perfdata_file()"); // we don't have a command. if (config->host_perfdata_file_processing_command().empty()) @@ -617,9 +687,12 @@ int xpddefault_process_host_perfdata_file() { return ERROR; } - logger(dbg_perfdata, most) + engine_logger(dbg_perfdata, most) << "Raw host performance data file processing command line: " << raw_command_line; + log_v2::commands()->info( + "Raw host performance data file processing command line: {}", + raw_command_line); // process any macros in the raw command line. process_macros_r(mac, raw_command_line, processed_command_line, @@ -629,10 +702,13 @@ int xpddefault_process_host_perfdata_file() { return ERROR; } - logger(dbg_perfdata, most) + engine_logger(dbg_perfdata, most) << "Processed host performance data file processing command " "line: " << processed_command_line; + log_v2::commands()->info( + "Processed host performance data file processing command line: {}", + processed_command_line); // lock and close the performance data file. pthread_mutex_lock(&xpddefault_host_perfdata_fp_lock); @@ -644,10 +720,14 @@ int xpddefault_process_host_perfdata_file() { my_system_r(mac, processed_command_line, config->perfdata_timeout(), &early_timeout, &exectime, tmp, 0); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: can't execute host performance data file processing command " "line '" << processed_command_line << "' : " << e.what(); + log_v2::runtime()->error( + "Error: can't execute host performance data file processing command " + "line '{}' : {}", + processed_command_line, e.what()); } clear_volatile_macros_r(mac); @@ -657,10 +737,14 @@ int xpddefault_process_host_perfdata_file() { // check to see if the command timed out. if (early_timeout == true) - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Host performance data file processing command '" << processed_command_line << "' timed out after " << config->perfdata_timeout() << " seconds"; + log_v2::runtime()->warn( + "Warning: Host performance data file processing command '{}' timed out " + "after {} seconds", + processed_command_line, config->perfdata_timeout()); return result; } @@ -674,7 +758,8 @@ int xpddefault_process_service_perfdata_file() { int macro_options(STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS); nagios_macros* mac(get_global_macros()); - logger(dbg_functions, basic) << "process_service_perfdata_file()"; + engine_logger(dbg_functions, basic) << "process_service_perfdata_file()"; + log_v2::functions()->trace("process_service_perfdata_file()"); // we don't have a command. if (config->service_perfdata_file_processing_command().empty()) @@ -690,9 +775,13 @@ int xpddefault_process_service_perfdata_file() { return ERROR; } - logger(dbg_perfdata, most) << "Raw service performance data file processing " - "command line: " - << raw_command_line; + engine_logger(dbg_perfdata, most) + << "Raw service performance data file processing " + "command line: " + << raw_command_line; + log_v2::commands()->info( + "Raw service performance data file processing command line: {}", + raw_command_line); // process any macros in the raw command line. process_macros_r(mac, raw_command_line, processed_command_line, @@ -702,10 +791,13 @@ int xpddefault_process_service_perfdata_file() { return ERROR; } - logger(dbg_perfdata, most) + engine_logger(dbg_perfdata, most) << "Processed service performance data file processing " "command line: " << processed_command_line; + log_v2::commands()->info( + "Processed service performance data file processing command line: {}", + processed_command_line); // lock and close the performance data file. pthread_mutex_lock(&xpddefault_service_perfdata_fp_lock); @@ -717,10 +809,14 @@ int xpddefault_process_service_perfdata_file() { my_system_r(mac, processed_command_line, config->perfdata_timeout(), &early_timeout, &exectime, tmp, 0); } catch (std::exception const& e) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: can't execute service performance data file processing " "command line '" << processed_command_line << "' : " << e.what(); + log_v2::runtime()->error( + "Error: can't execute service performance data file processing " + "command line '{}' : {}", + processed_command_line, e.what()); } // re-open and unlock the performance data file. @@ -731,10 +827,14 @@ int xpddefault_process_service_perfdata_file() { // check to see if the command timed out. if (early_timeout == true) - logger(log_runtime_warning, basic) + engine_logger(log_runtime_warning, basic) << "Warning: Service performance data file processing command '" << processed_command_line << "' timed out after " << config->perfdata_timeout() << " seconds"; + log_v2::runtime()->warn( + "Warning: Service performance data file processing command '{}' timed " + "out after {} seconds", + processed_command_line, config->perfdata_timeout()); // free memory. return result; diff --git a/centreon-engine/src/xsddefault.cc b/centreon-engine/src/xsddefault.cc index 87d21f39a4b..cdfc3975063 100644 --- a/centreon-engine/src/xsddefault.cc +++ b/centreon-engine/src/xsddefault.cc @@ -37,6 +37,7 @@ #include "com/centreon/engine/downtimes/downtime.hh" #include "com/centreon/engine/downtimes/downtime_manager.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" #include "com/centreon/engine/statusdata.hh" @@ -64,9 +65,12 @@ int xsddefault_initialize_status_data() { if ((xsddefault_status_log_fd = open(config->status_file().c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP)) == -1) { - logger(engine::logging::log_runtime_error, engine::logging::basic) + engine_logger(engine::logging::log_runtime_error, engine::logging::basic) << "Error: Unable to open status data file '" << config->status_file() << "': " << strerror(errno); + log_v2::runtime()->error( + "Error: Unable to open status data file '{}': {}", + config->status_file(), strerror(errno)); return ERROR; } set_cloexec(xsddefault_status_log_fd); @@ -104,8 +108,9 @@ int xsddefault_save_status_data() { int used_external_command_buffer_slots(0); int high_external_command_buffer_slots(0); - logger(engine::logging::dbg_functions, engine::logging::basic) + engine_logger(engine::logging::dbg_functions, engine::logging::basic) << "save_status_data()"; + log_v2::functions()->trace("save_status_data()"); // get number of items in the command buffer if (config->check_external_commands()) { @@ -733,9 +738,12 @@ int xsddefault_save_status_data() { (fsync(xsddefault_status_log_fd) == -1) || (lseek(xsddefault_status_log_fd, 0, SEEK_SET) == (off_t)-1)) { char const* msg(strerror(errno)); - logger(engine::logging::log_runtime_error, engine::logging::basic) + engine_logger(engine::logging::log_runtime_error, engine::logging::basic) << "Error: Unable to update status data file '" << config->status_file() << "': " << msg; + log_v2::runtime()->error( + "Error: Unable to update status data file '{}': {}", + config->status_file(), msg); return ERROR; } @@ -747,9 +755,12 @@ int xsddefault_save_status_data() { ssize_t wb(write(xsddefault_status_log_fd, data_ptr, size)); if (wb <= 0) { char const* msg(strerror(errno)); - logger(engine::logging::log_runtime_error, engine::logging::basic) + engine_logger(engine::logging::log_runtime_error, engine::logging::basic) << "Error: Unable to update status data file '" << config->status_file() << "': " << msg; + log_v2::runtime()->error( + "Error: Unable to update status data file '{}': {}", + config->status_file(), msg); return ERROR; } data_ptr += wb; diff --git a/centreon-engine/test/configuration/applier/events.cc b/centreon-engine/test/configuration/applier/events.cc index fc66981bb89..15546d42df9 100644 --- a/centreon-engine/test/configuration/applier/events.cc +++ b/centreon-engine/test/configuration/applier/events.cc @@ -22,6 +22,7 @@ #include #include "com/centreon/engine/events/defines.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/statusdata.hh" using namespace com::centreon::engine; @@ -44,7 +45,8 @@ void init_timing_loop() { struct timeval tv[9]; double runtime[9]; - logger(dbg_functions, basic) << "init_timing_loop()"; + engine_logger(dbg_functions, basic) << "init_timing_loop()"; + log_v2::functions()->trace("init_timing_loop()"); /* get the time right now */ time(¤t_time); @@ -106,9 +108,12 @@ void init_timing_loop() { } else { temp_service->should_be_scheduled = false; - logger(dbg_events, more) + engine_logger(dbg_events, more) << "Service '" << temp_service->description << "' on host '" << temp_service->host_name << "' should not be scheduled."; + log_v2::events()->debug( + "Service '{}' on host '{}' should not be scheduled.", + temp_service->description, temp_service->host_name); } scheduling_info.total_services++; @@ -149,8 +154,10 @@ void init_timing_loop() { } else { temp_host->should_be_scheduled = false; - logger(dbg_events, more) + engine_logger(dbg_events, more) << "Host '" << temp_host->name << "' should not be scheduled."; + log_v2::events()->debug("Host '{}' should not be scheduled.", + temp_host->name); } scheduling_info.total_hosts++; @@ -186,7 +193,9 @@ void init_timing_loop() { /******** DETERMINE SERVICE SCHEDULING PARAMS ********/ - logger(dbg_events, most) << "Determining service scheduling parameters..."; + engine_logger(dbg_events, most) + << "Determining service scheduling parameters..."; + log_v2::events()->debug("Determining service scheduling parameters..."); /* default max service check spread (in minutes) */ scheduling_info.max_service_check_spread = ::max_service_check_spread; @@ -233,16 +242,23 @@ void init_timing_loop() { } else scheduling_info.service_inter_check_delay = 0.0; - logger(dbg_events, more) << "Total scheduled service checks: " - << scheduling_info.total_scheduled_services; - logger(dbg_events, more) + engine_logger(dbg_events, more) + << "Total scheduled service checks: " + << scheduling_info.total_scheduled_services; + log_v2::events()->debug("Total scheduled service checks: {}", + scheduling_info.total_scheduled_services); + engine_logger(dbg_events, more) << com::centreon::logging::setprecision(2) << "Average service check interval: " << scheduling_info.average_service_check_interval << " sec"; - logger(dbg_events, more) + log_v2::events()->debug("Average service check interval: {:.2f} sec", + scheduling_info.average_service_check_interval); + engine_logger(dbg_events, more) << com::centreon::logging::setprecision(2) << "Service inter-check delay: " << scheduling_info.service_inter_check_delay << " sec"; + log_v2::events()->debug("Service inter-check delay: {:.2f} sec", + scheduling_info.service_inter_check_delay); } /* how should we determine the service interleave factor? */ @@ -256,12 +272,20 @@ void init_timing_loop() { scheduling_info.service_interleave_factor = (int)(ceil(scheduling_info.average_scheduled_services_per_host)); - logger(dbg_events, more) << "Total scheduled service checks: " - << scheduling_info.total_scheduled_services; - logger(dbg_events, more) + engine_logger(dbg_events, more) + << "Total scheduled service checks: " + << scheduling_info.total_scheduled_services; + log_v2::events()->debug("Total scheduled service checks: {}", + scheduling_info.total_scheduled_services); + engine_logger(dbg_events, more) << "Total hosts: " << scheduling_info.total_hosts; - logger(dbg_events, more) << "Service Interleave factor: " - << scheduling_info.service_interleave_factor; + log_v2::events()->debug("Total hosts: {}", + scheduling_info.total_hosts); + engine_logger(dbg_events, more) + << "Service Interleave factor: " + << scheduling_info.service_interleave_factor; + log_v2::events()->debug("Service Interleave factor: {}", + scheduling_info.service_interleave_factor); } /* calculate number of service interleave blocks */ @@ -275,22 +299,31 @@ void init_timing_loop() { scheduling_info.first_service_check = (time_t)0L; scheduling_info.last_service_check = (time_t)0L; - logger(dbg_events, more) << "Total scheduled services: " - << scheduling_info.total_scheduled_services; - logger(dbg_events, more) << "Service Interleave factor: " - << scheduling_info.service_interleave_factor; - logger(dbg_events, more) << "Total service interleave blocks: " - << total_interleave_blocks; - logger(dbg_events, more) << com::centreon::logging::setprecision(1) - << "Service inter-check delay: " - << scheduling_info.service_inter_check_delay; + engine_logger(dbg_events, more) << "Total scheduled services: " + << scheduling_info.total_scheduled_services; + log_v2::events()->debug("Total scheduled services: {}", + scheduling_info.total_scheduled_services); + engine_logger(dbg_events, more) << "Service Interleave factor: " + << scheduling_info.service_interleave_factor; + log_v2::events()->debug("Service Interleave factor: {}", + scheduling_info.service_interleave_factor); + engine_logger(dbg_events, more) + << "Total service interleave blocks: " << total_interleave_blocks; + log_v2::events()->debug("Total service interleave blocks: {}", + total_interleave_blocks); + engine_logger(dbg_events, more) << com::centreon::logging::setprecision(1) + << "Service inter-check delay: " + << scheduling_info.service_inter_check_delay; + log_v2::events()->debug("Service inter-check delay: {:.1f}", + scheduling_info.service_inter_check_delay); if (test_scheduling == true) gettimeofday(&tv[3], nullptr); /******** SCHEDULE SERVICE CHECKS ********/ - logger(dbg_events, most) << "Scheduling service checks..."; + engine_logger(dbg_events, most) << "Scheduling service checks..."; + log_v2::events()->debug("Scheduling service checks..."); /* determine check times for service checks (with interleaving to minimize * remote load) */ @@ -298,20 +331,27 @@ void init_timing_loop() { for (temp_service = service_list; temp_service != nullptr && scheduling_info.service_interleave_factor > 0;) { - logger(dbg_events, most) + engine_logger(dbg_events, most) << "Current Interleave Block: " << current_interleave_block; + log_v2::events()->debug("Current Interleave Block: {}", + current_interleave_block); for (interleave_block_index = 0; interleave_block_index < scheduling_info.service_interleave_factor && temp_service != nullptr; temp_service = temp_service->next) { - logger(dbg_events, most) + engine_logger(dbg_events, most) << "Service '" << temp_service->description << "' on host '" << temp_service->host_name << "'"; + log_v2::events()->debug("Service '{}' on host '{}'", + temp_service->description, + temp_service->host_name); /* skip this service if it shouldn't be scheduled */ if (temp_service->should_be_scheduled == false) { - logger(dbg_events, most) << "Service check should not be scheduled."; + engine_logger(dbg_events, most) + << "Service check should not be scheduled."; + log_v2::events()->debug("Service check should not be scheduled."); continue; } @@ -319,10 +359,14 @@ void init_timing_loop() { * data), but reschedule ones that were supposed to happen while we * weren't running... */ if (temp_service->next_check > current_time) { - logger(dbg_events, most) + engine_logger(dbg_events, most) << "Service is already scheduled to be checked in " "the future: " << my_ctime(&temp_service->next_check); + log_v2::events()->debug( + "Service is already scheduled to be checked in " + "the future: {}", + my_ctime(&temp_service->next_check)); continue; } @@ -334,40 +378,55 @@ void init_timing_loop() { mult_factor = current_interleave_block + (interleave_block_index * total_interleave_blocks); - logger(dbg_events, most) + engine_logger(dbg_events, most) << "CIB: " << current_interleave_block << ", IBI: " << interleave_block_index << ", TIB: " << total_interleave_blocks << ", SIF: " << scheduling_info.service_interleave_factor; + log_v2::events()->debug("CIB: {}, IBI: {}, TIB: {}, SIF: {}", + current_interleave_block, interleave_block_index, + total_interleave_blocks, + scheduling_info.service_interleave_factor); - logger(dbg_events, most) << "Mult factor: " << mult_factor; + engine_logger(dbg_events, most) << "Mult factor: " << mult_factor; + log_v2::events()->debug("Mult factor: {}", mult_factor); /* set the preferred next check time for the service */ temp_service->next_check = (time_t)(current_time + (mult_factor * scheduling_info.service_inter_check_delay)); - logger(dbg_events, most) + engine_logger(dbg_events, most) << "Preferred Check Time: " << temp_service->next_check << " --> " << my_ctime(&temp_service->next_check); + log_v2::events()->debug("Preferred Check Time: {} --> {}", + temp_service->next_check, + my_ctime(&temp_service->next_check)); /* make sure the service can actually be scheduled when we want */ is_valid_time = check_time_against_period(temp_service->next_check, temp_service->check_period_ptr); if (is_valid_time == ERROR) { - logger(dbg_events, most) << "Preferred Time is Invalid In Timeperiod '" - << temp_service->check_period_ptr->name - << "': " << temp_service->next_check << " --> " - << my_ctime(&temp_service->next_check); - + engine_logger(dbg_events, most) + << "Preferred Time is Invalid In Timeperiod '" + << temp_service->check_period_ptr->name + << "': " << temp_service->next_check << " --> " + << my_ctime(&temp_service->next_check); + log_v2::events()->debug( + "Preferred Time is Invalid In Timeperiod '{}': {} --> {}", + temp_service->check_period_ptr->name, temp_service->next_check, + my_ctime(&temp_service->next_check)); get_next_valid_time(temp_service->next_check, &next_valid_time, temp_service->check_period_ptr); temp_service->next_check = next_valid_time; } - logger(dbg_events, most) + engine_logger(dbg_events, most) << "Actual Check Time: " << temp_service->next_check << " --> " << my_ctime(&temp_service->next_check); + log_v2::events()->debug("Actual Check Time: {} --> {}", + temp_service->next_check, + my_ctime(&temp_service->next_check)); if (scheduling_info.first_service_check == (time_t)0 || (temp_service->next_check < scheduling_info.first_service_check)) @@ -411,7 +470,9 @@ void init_timing_loop() { /******** DETERMINE HOST SCHEDULING PARAMS ********/ - logger(dbg_events, most) << "Determining host scheduling parameters..."; + engine_logger(dbg_events, most) + << "Determining host scheduling parameters..."; + log_v2::events()->debug("Determining host scheduling parameters..."); scheduling_info.first_host_check = (time_t)0L; scheduling_info.last_host_check = (time_t)0L; @@ -471,18 +532,27 @@ void init_timing_loop() { } else scheduling_info.host_inter_check_delay = 0.0; - logger(dbg_events, most) << "Total scheduled host checks: " - << scheduling_info.total_scheduled_hosts; - logger(dbg_events, most) << "Host check interval total: " - << scheduling_info.host_check_interval_total; - logger(dbg_events, most) + engine_logger(dbg_events, most) << "Total scheduled host checks: " + << scheduling_info.total_scheduled_hosts; + log_v2::events()->debug("Total scheduled host checks: {}", + scheduling_info.total_scheduled_hosts); + engine_logger(dbg_events, most) + << "Host check interval total: " + << scheduling_info.host_check_interval_total; + log_v2::events()->debug("Host check interval total: {}", + scheduling_info.host_check_interval_total); + engine_logger(dbg_events, most) << com::centreon::logging::setprecision(2) << "Average host check interval: " << scheduling_info.average_host_check_interval << " sec"; - logger(dbg_events, most) + log_v2::events()->debug("Average host check interval: {:.2f} sec", + scheduling_info.average_host_check_interval); + engine_logger(dbg_events, most) << com::centreon::logging::setprecision(2) << "Host inter-check delay: " << scheduling_info.host_inter_check_delay << " sec"; + log_v2::events()->debug("Host inter-check delay: {:.2f} sec", + scheduling_info.host_inter_check_delay); } if (test_scheduling == true) @@ -490,17 +560,20 @@ void init_timing_loop() { /******** SCHEDULE HOST CHECKS ********/ - logger(dbg_events, most) << "Scheduling host checks..."; + engine_logger(dbg_events, most) << "Scheduling host checks..."; + log_v2::events()->debug("Scheduling host checks..."); /* determine check times for host checks */ mult_factor = 0; for (temp_host = host_list; temp_host != nullptr; temp_host = temp_host->next) { - logger(dbg_events, most) << "Host '" << temp_host->name << "'"; + engine_logger(dbg_events, most) << "Host '" << temp_host->name << "'"; + log_v2::events()->debug("Host '{}'", temp_host->name); /* skip hosts that shouldn't be scheduled */ if (temp_host->should_be_scheduled == false) { - logger(dbg_events, most) << "Host check should not be scheduled."; + engine_logger(dbg_events, most) << "Host check should not be scheduled."; + log_v2::events()->debug("Host check should not be scheduled."); continue; } @@ -508,9 +581,12 @@ void init_timing_loop() { * data), but reschedule ones that were supposed to be checked before we * started */ if (temp_host->next_check > current_time) { - logger(dbg_events, most) + engine_logger(dbg_events, most) << "Host is already scheduled to be checked in the future: " << my_ctime(&temp_host->next_check); + log_v2::events()->debug( + "Host is already scheduled to be checked in the future: {}", + my_ctime(&temp_host->next_check)); continue; } @@ -518,9 +594,12 @@ void init_timing_loop() { temp_host->next_check = (time_t)( current_time + (mult_factor * scheduling_info.host_inter_check_delay)); - logger(dbg_events, most) + engine_logger(dbg_events, most) << "Preferred Check Time: " << temp_host->next_check << " --> " << my_ctime(&temp_host->next_check); + log_v2::events()->debug("Preferred Check Time: {} --> {}", + temp_host->next_check, + my_ctime(&temp_host->next_check)); /* make sure the host can actually be scheduled at this time */ is_valid_time = check_time_against_period(temp_host->next_check, @@ -531,8 +610,12 @@ void init_timing_loop() { temp_host->next_check = next_valid_time; } - logger(dbg_events, most) << "Actual Check Time: " << temp_host->next_check - << " --> " << my_ctime(&temp_host->next_check); + engine_logger(dbg_events, most) + << "Actual Check Time: " << temp_host->next_check << " --> " + << my_ctime(&temp_host->next_check); + log_v2::events()->debug("Actual Check Time: {} --> {}", + temp_host->next_check, + my_ctime(&temp_host->next_check)); if (scheduling_info.first_host_check == (time_t)0 || (temp_host->next_check < scheduling_info.first_host_check)) @@ -686,6 +769,7 @@ void init_timing_loop() { printf("\n\n"); } - logger(dbg_functions, basic) << "init_timing_loop()"; + engine_logger(dbg_functions, basic) << "init_timing_loop()"; + log_v2::functions()->trace("init_timing_loop()"); return; } diff --git a/centreon-engine/test/configuration/applier/xodtemplate.cc b/centreon-engine/test/configuration/applier/xodtemplate.cc index 6cd4a533afa..3848153b17b 100644 --- a/centreon-engine/test/configuration/applier/xodtemplate.cc +++ b/centreon-engine/test/configuration/applier/xodtemplate.cc @@ -38,6 +38,7 @@ #include "com/centreon/engine/commands/set.hh" #include "com/centreon/engine/common.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" @@ -552,7 +553,7 @@ int xodtemplate_process_config_dir(char* dirname, int options) { /* open the directory for reading */ dirp = opendir(dirname); if (dirp == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not open config directory '" << dirname << "' for reading."; return ERROR; @@ -570,7 +571,7 @@ int xodtemplate_process_config_dir(char* dirname, int options) { /* process this if it's a non-hidden config file... */ if (stat(file, &stat_buf) == -1) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Could not open config directory member '" << file << "' for reading."; closedir(dirp); @@ -641,7 +642,7 @@ int xodtemplate_process_config_file(char* filename, int options) { /* open the config file for reading */ if ((thefile = mmap_fopen(filename)) == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Cannot open config file '" << filename << "' for reading: " << strerror(errno); return ERROR; @@ -694,7 +695,7 @@ int xodtemplate_process_config_file(char* filename, int options) { /* make sure an object type is specified... */ if (input[0] == '\x0') { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: No object type specified in file '" << filename << "' on line " << current_line << "."; result = ERROR; @@ -712,7 +713,7 @@ int xodtemplate_process_config_file(char* filename, int options) { strcmp(input, "hostdependency") && strcmp(input, "hostescalation") && strcmp(input, "hostextinfo") && strcmp(input, "serviceextinfo") && strcmp(input, "connector")) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid object definition type '" << input << "' in file '" << filename << "' on line " << current_line << "."; result = ERROR; @@ -721,7 +722,7 @@ int xodtemplate_process_config_file(char* filename, int options) { /* we're already in an object definition... */ if (in_definition == true) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Unexpected start of object definition in file '" << filename << "' on line " << current_line << ". Make sure you close preceding objects before " @@ -734,7 +735,7 @@ int xodtemplate_process_config_file(char* filename, int options) { if (xodtemplate_begin_object_definition(input, options, xodtemplate_current_config_file, current_line) == ERROR) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add object definition in file '" << filename << "' on line " << current_line << "."; result = ERROR; @@ -751,7 +752,7 @@ int xodtemplate_process_config_file(char* filename, int options) { /* close out current definition */ if (xodtemplate_end_object_definition(options) == ERROR) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not complete object definition in file '" << filename << "' on line " << current_line << "."; result = ERROR; @@ -762,7 +763,7 @@ int xodtemplate_process_config_file(char* filename, int options) { else { /* add directive to object definition */ if (xodtemplate_add_object_property(input, options) == ERROR) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add object property in file '" << filename << "' on line " << current_line << "."; result = ERROR; @@ -794,7 +795,7 @@ int xodtemplate_process_config_file(char* filename, int options) { } /* unexpected token or statement */ else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Unexpected token or statement in file '" << filename << "' on line " << current_line << "."; result = ERROR; @@ -809,7 +810,7 @@ int xodtemplate_process_config_file(char* filename, int options) { /* whoops - EOF while we were in the middle of an object definition... */ if (in_definition == true && result == OK) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Unexpected EOF in file '" << filename << "' on line " << current_line << " - check for a missing closing bracket.", result = ERROR; @@ -1061,7 +1062,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for service '" << value << "' (config file '" << xodtemplate_config_file_name(temp_service->_config_file) @@ -1094,7 +1095,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for service '" << value << "' (config file '" << xodtemplate_config_file_name(temp_service->_config_file) @@ -1128,7 +1129,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for service '" << value << "' (config file '" << xodtemplate_config_file_name(temp_service->_config_file) @@ -1216,7 +1217,7 @@ int xodtemplate_add_object_property(char* input, int options) { else if (!strcmp(value, "c") || !strcmp(value, "critical")) temp_service->initial_state = STATE_CRITICAL; else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid initial state '" << value << "' in service definition."; result = ERROR; @@ -1294,7 +1295,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_service->flap_detection_on_unknown = true; temp_service->flap_detection_on_critical = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid flap detection option '" << temp_ptr << "' in service definition."; return ERROR; @@ -1331,7 +1332,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_service->notify_on_flapping = true; temp_service->notify_on_downtime = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid notification option '" << temp_ptr << "' in service definition."; return ERROR; @@ -1369,7 +1370,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_service->stalk_on_unknown = true; temp_service->stalk_on_critical = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid stalking option '" << temp_ptr << "' in service definition."; return ERROR; @@ -1395,7 +1396,7 @@ int xodtemplate_add_object_property(char* input, int options) { /* make sure we have a variable name */ if (!strcmp(customvarname, "")) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Null custom variable name."; delete[] customvarname; return ERROR; @@ -1419,7 +1420,7 @@ int xodtemplate_add_object_property(char* input, int options) { delete[] customvarname; delete[] customvarvalue; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid service object directive '" << variable << "'."; return ERROR; } @@ -1442,7 +1443,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for host '" << value << "' (config file '" << xodtemplate_config_file_name(temp_host->_config_file) @@ -1466,7 +1467,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for host '" << value << "' (config file '" << xodtemplate_config_file_name(temp_host->_config_file) @@ -1556,8 +1557,9 @@ int xodtemplate_add_object_property(char* input, int options) { else if (!strcmp(value, "u") || !strcmp(value, "unreachable")) temp_host->initial_state = 2; /* HOST_UNREACHABLE */ else { - logger(log_config_error, basic) << "Error: Invalid initial state '" - << value << "' in host definition."; + engine_logger(log_config_error, basic) + << "Error: Invalid initial state '" << value + << "' in host definition."; result = ERROR; } temp_host->have_initial_state = true; @@ -1620,7 +1622,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_host->flap_detection_on_down = true; temp_host->flap_detection_on_unreachable = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid flap detection option '" << temp_ptr << "' in host definition."; result = ERROR; @@ -1653,7 +1655,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_host->notify_on_flapping = true; temp_host->notify_on_downtime = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid notification option '" << temp_ptr << "' in host definition."; result = ERROR; @@ -1687,7 +1689,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_host->stalk_on_down = true; temp_host->stalk_on_unreachable = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid stalking option '" << temp_ptr << "' in host definition."; result = ERROR; @@ -1699,14 +1701,14 @@ int xodtemplate_add_object_property(char* input, int options) { temp_host->have_process_perf_data = true; } else if (!strcmp(variable, "2d_coords")) { if ((temp_ptr = strtok(value, ", ")) == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid 2d_coords value '" << temp_ptr << "' in host definition."; return ERROR; } temp_host->x_2d = atoi(temp_ptr); if ((temp_ptr = strtok(NULL, ", ")) == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid 2d_coords value '" << temp_ptr << "' in host definition."; return ERROR; @@ -1715,21 +1717,21 @@ int xodtemplate_add_object_property(char* input, int options) { temp_host->have_2d_coords = true; } else if (!strcmp(variable, "3d_coords")) { if ((temp_ptr = strtok(value, ", ")) == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid 3d_coords value '" << temp_ptr << "' in host definition."; return ERROR; } temp_host->x_3d = strtod(temp_ptr, NULL); if ((temp_ptr = strtok(NULL, ", ")) == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid 3d_coords value '" << temp_ptr << "' in host definition."; return ERROR; } temp_host->y_3d = strtod(temp_ptr, NULL); if ((temp_ptr = strtok(NULL, ", ")) == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid 3d_coords value '" << temp_ptr << "' in host definition."; return ERROR; @@ -1754,7 +1756,7 @@ int xodtemplate_add_object_property(char* input, int options) { /* make sure we have a variable name */ if (!strcmp(customvarname, "")) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Null custom variable name."; delete[] customvarname; return ERROR; @@ -1777,7 +1779,7 @@ int xodtemplate_add_object_property(char* input, int options) { delete[] customvarname; delete[] customvarvalue; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid host object directive '" << variable << "'."; return ERROR; } @@ -1801,7 +1803,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for timeperiod '" << value << "' (config file '" << xodtemplate_config_file_name(temp_timeperiod->_config_file) @@ -1825,7 +1827,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for timeperiod '" << value << "' (config file '" << xodtemplate_config_file_name(temp_timeperiod->_config_file) @@ -1848,7 +1850,7 @@ int xodtemplate_add_object_property(char* input, int options) { value) == OK) result = OK; else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid timeperiod object directive '" << variable << "'."; return ERROR; @@ -1872,7 +1874,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for contact '" << value << "' (config file '" << xodtemplate_config_file_name(temp_contact->_config_file) @@ -1896,7 +1898,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for contact '" << value << "' (config file '" << xodtemplate_config_file_name(temp_contact->_config_file) @@ -1973,7 +1975,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_contact->notify_on_host_flapping = true; temp_contact->notify_on_host_downtime = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid host notification option '" << temp_ptr << "' in contact definition."; return ERROR; @@ -2010,7 +2012,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_contact->notify_on_service_flapping = true; temp_contact->notify_on_service_downtime = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid service notification option '" << temp_ptr << "' in contact definition."; return ERROR; @@ -2044,7 +2046,7 @@ int xodtemplate_add_object_property(char* input, int options) { /* make sure we have a variable name */ if (customvarname == NULL || !strcmp(customvarname, "")) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Null custom variable name."; delete[] customvarname; return ERROR; @@ -2068,7 +2070,7 @@ int xodtemplate_add_object_property(char* input, int options) { delete[] customvarname; delete[] customvarvalue; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid contact object directive '" << variable << "'."; return ERROR; } @@ -2092,7 +2094,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for command '" << value << "' (config file '" << xodtemplate_config_file_name(temp_command->_config_file) @@ -2116,7 +2118,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for command '" << value << "' (config file '" << xodtemplate_config_file_name(temp_command->_config_file) @@ -2135,7 +2137,7 @@ int xodtemplate_add_object_property(char* input, int options) { else if (!strcmp(variable, "connector")) temp_command->connector_name = string::dup(value); else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid command object directive '" << variable << "'."; return ERROR; } @@ -2158,7 +2160,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for connector '" << value << "' (config file '" << xodtemplate_config_file_name(temp_connector->_config_file) @@ -2171,7 +2173,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; } } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid command object directive '" << variable << "'."; return ERROR; } @@ -2194,7 +2196,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for contactgroup '" << value << "' (config file '" << xodtemplate_config_file_name(temp_contactgroup->_config_file) @@ -2219,7 +2221,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for contactgroup '" << value << "' (config file '" << xodtemplate_config_file_name(temp_contactgroup->_config_file) @@ -2268,7 +2270,7 @@ int xodtemplate_add_object_property(char* input, int options) { } else if (!strcmp(variable, "register")) temp_contactgroup->register_object = (atoi(value) > 0) ? true : false; else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid contactgroup object directive '" << variable << "'."; return ERROR; @@ -2294,7 +2296,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for hostgroup '" << value << "' (config file '" << xodtemplate_config_file_name(temp_hostgroup->_config_file) @@ -2318,7 +2320,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for hostgroup '" << value << "' (config file '" << xodtemplate_config_file_name(temp_hostgroup->_config_file) @@ -2377,7 +2379,7 @@ int xodtemplate_add_object_property(char* input, int options) { } else if (!strcmp(variable, "register")) temp_hostgroup->register_object = (atoi(value) > 0) ? true : false; else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid hostgroup object directive '" << variable << "'."; return ERROR; @@ -2403,7 +2405,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for servicegroup '" << value << "' (config file '" << xodtemplate_config_file_name(temp_servicegroup->_config_file) @@ -2428,7 +2430,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for servicegroup '" << value << "' (config file '" << xodtemplate_config_file_name(temp_servicegroup->_config_file) @@ -2489,7 +2491,7 @@ int xodtemplate_add_object_property(char* input, int options) { } else if (!strcmp(variable, "register")) temp_servicegroup->register_object = (atoi(value) > 0) ? true : false; else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid servicegroup object directive '" << variable << "'."; return ERROR; @@ -2516,7 +2518,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for service dependency " "'" << variable << "' (config file '" @@ -2657,7 +2659,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_servicedependency->fail_execute_on_critical = true; temp_servicedependency->fail_execute_on_pending = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid execution dependency option '" << temp_ptr << "' in servicedependency definition."; return ERROR; @@ -2691,7 +2693,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_servicedependency->fail_notify_on_critical = true; temp_servicedependency->fail_notify_on_pending = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid notification dependency option '" << temp_ptr << "' in servicedependency definition."; return ERROR; @@ -2702,7 +2704,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_servicedependency->register_object = (atoi(value) > 0) ? true : false; else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid servicedependency object directive '" << variable << "'."; return ERROR; @@ -2728,7 +2730,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for service escalation " "'" << value << "' (config file '" @@ -2849,7 +2851,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_serviceescalation->escalate_on_critical = true; temp_serviceescalation->escalate_on_recovery = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid escalation option '" << temp_ptr << "' in serviceescalation definition."; return ERROR; @@ -2860,7 +2862,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_serviceescalation->register_object = (atoi(value) > 0) ? true : false; else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid serviceescalation object directive '" << variable << "'."; return ERROR; @@ -2887,7 +2889,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for host dependency '" << value << "' (config file '" << xodtemplate_config_file_name( @@ -2972,7 +2974,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_hostdependency->fail_notify_on_unreachable = true; temp_hostdependency->fail_notify_on_pending = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid notification dependency option '" << temp_ptr << "' in hostdependency definition."; return ERROR; @@ -3002,7 +3004,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_hostdependency->fail_execute_on_unreachable = true; temp_hostdependency->fail_execute_on_pending = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid execution dependency option '" << temp_ptr << "' in hostdependency definition."; return ERROR; @@ -3012,7 +3014,7 @@ int xodtemplate_add_object_property(char* input, int options) { } else if (!strcmp(variable, "register")) temp_hostdependency->register_object = (atoi(value) > 0) ? true : false; else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid hostdependency object directive '" << variable << "'."; return ERROR; @@ -3038,7 +3040,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for host escalation '" << value << "' (config file '" << xodtemplate_config_file_name( @@ -3119,7 +3121,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_hostescalation->escalate_on_unreachable = true; temp_hostescalation->escalate_on_recovery = true; } else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid escalation option '" << temp_ptr << "' in hostescalation definition."; return ERROR; @@ -3129,7 +3131,7 @@ int xodtemplate_add_object_property(char* input, int options) { } else if (!strcmp(variable, "register")) temp_hostescalation->register_object = (atoi(value) > 0) ? true : false; else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid hostescalation object directive '" << variable << "'."; return ERROR; @@ -3154,7 +3156,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for extended host info " "'" << value << "' (config file '" @@ -3209,7 +3211,7 @@ int xodtemplate_add_object_property(char* input, int options) { } else if (!strcmp(variable, "2d_coords")) { temp_ptr = strtok(value, ", "); if (temp_ptr == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid 2d_coords value '" << temp_ptr << "' in extended host info definition."; return ERROR; @@ -3217,7 +3219,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_hostextinfo->x_2d = atoi(temp_ptr); temp_ptr = strtok(NULL, ", "); if (temp_ptr == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid 2d_coords value '" << temp_ptr << "' in extended host info definition."; return ERROR; @@ -3227,7 +3229,7 @@ int xodtemplate_add_object_property(char* input, int options) { } else if (!strcmp(variable, "3d_coords")) { temp_ptr = strtok(value, ", "); if (temp_ptr == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid 3d_coords value '" << temp_ptr << "' in extended host info definition."; return ERROR; @@ -3235,7 +3237,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_hostextinfo->x_3d = strtod(temp_ptr, NULL); temp_ptr = strtok(NULL, ", "); if (temp_ptr == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid 3d_coords value '" << temp_ptr << "' in extended host info definition."; return ERROR; @@ -3243,7 +3245,7 @@ int xodtemplate_add_object_property(char* input, int options) { temp_hostextinfo->y_3d = strtod(temp_ptr, NULL); temp_ptr = strtok(NULL, ", "); if (temp_ptr == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid 3d_coords value '" << temp_ptr << "' in extended host info definition."; return ERROR; @@ -3253,7 +3255,7 @@ int xodtemplate_add_object_property(char* input, int options) { } else if (!strcmp(variable, "register")) temp_hostextinfo->register_object = (atoi(value) > 0) ? true : false; else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid hostextinfo object directive '" << variable << "'."; return ERROR; @@ -3278,7 +3280,7 @@ int xodtemplate_add_object_property(char* input, int options) { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for extended service " "info '" << value << "' (config file '" @@ -3329,7 +3331,7 @@ int xodtemplate_add_object_property(char* input, int options) { } else if (!strcmp(variable, "register")) temp_serviceextinfo->register_object = (atoi(value) > 0) ? true : false; else { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Invalid serviceextinfo object directive '" << variable << "'."; return ERROR; @@ -3883,7 +3885,7 @@ int xodtemplate_duplicate_services() { temp_service->hostgroup_name, temp_service->host_name, temp_service->_config_file, temp_service->_start_line); if (temp_memberlist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand hostgroups and/or hosts specified in " "service (config file '" << xodtemplate_config_file_name(temp_service->_config_file) @@ -3948,7 +3950,7 @@ int xodtemplate_duplicate_services() { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for service '" << temp_service->service_description << "' on host '" << temp_service->host_name << "' (config file '" @@ -3990,7 +3992,7 @@ int xodtemplate_duplicate_services() { break; case SKIPLIST_ERROR_DUPLICATE: - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Duplicate definition found for service '" << temp_service->service_description << "' on host '" << temp_service->host_name << "' (config file '" @@ -4048,7 +4050,7 @@ int xodtemplate_duplicate_objects() { temp_hostescalation->hostgroup_name, temp_hostescalation->host_name, temp_hostescalation->_config_file, temp_hostescalation->_start_line); if (master_hostlist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand hostgroups and/or hosts specified " "in host escalation (config file '" << xodtemplate_config_file_name(temp_hostescalation->_config_file) @@ -4099,7 +4101,7 @@ int xodtemplate_duplicate_objects() { temp_serviceescalation->host_name, temp_serviceescalation->_config_file, temp_serviceescalation->_start_line); if (master_hostlist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand hostgroups and/or hosts specified " "in service escalation (config file '" << xodtemplate_config_file_name(temp_serviceescalation->_config_file) @@ -4153,7 +4155,7 @@ int xodtemplate_duplicate_objects() { temp_serviceescalation->_config_file, temp_serviceescalation->_start_line); if (master_servicelist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand services specified in service " "escalation (config file '" << xodtemplate_config_file_name(temp_serviceescalation->_config_file) @@ -4205,7 +4207,7 @@ int xodtemplate_duplicate_objects() { temp_serviceescalation->_config_file, temp_serviceescalation->_start_line); if (master_servicelist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand servicegroups specified in service " "escalation (config file '" << xodtemplate_config_file_name(temp_serviceescalation->_config_file) @@ -4265,7 +4267,7 @@ int xodtemplate_duplicate_objects() { temp_hostdependency->hostgroup_name, temp_hostdependency->host_name, temp_hostdependency->_config_file, temp_hostdependency->_start_line); if (master_hostlist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand master hostgroups and/or hosts " "specified in host dependency (config file '" << xodtemplate_config_file_name(temp_hostdependency->_config_file) @@ -4279,7 +4281,7 @@ int xodtemplate_duplicate_objects() { temp_hostdependency->dependent_host_name, temp_hostdependency->_config_file, temp_hostdependency->_start_line); if (dependent_hostlist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand dependent hostgroups and/or hosts " "specified in host dependency (config file '" << xodtemplate_config_file_name(temp_hostdependency->_config_file) @@ -4338,7 +4340,7 @@ int xodtemplate_duplicate_objects() { temp_servicedependency->_config_file, temp_servicedependency->_start_line); if (master_servicelist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand master servicegroups " "specified in service dependency (config file '" << xodtemplate_config_file_name( @@ -4446,7 +4448,7 @@ int xodtemplate_duplicate_objects() { temp_servicedependency->_config_file, temp_servicedependency->_start_line); if (master_hostlist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand master hostgroups and/or hosts " "specified " "in service dependency (config file '" @@ -4471,7 +4473,7 @@ int xodtemplate_duplicate_objects() { temp_servicedependency->_config_file, temp_servicedependency->_start_line); if (master_servicelist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand master services specified in " "service dependency (config file '" << xodtemplate_config_file_name( @@ -4567,7 +4569,7 @@ int xodtemplate_duplicate_objects() { temp_servicedependency->_config_file, temp_servicedependency->_start_line); if (dependent_servicelist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand dependent servicegroups " "specified in service dependency (config file '" << xodtemplate_config_file_name( @@ -4717,7 +4719,7 @@ int xodtemplate_duplicate_objects() { temp_servicedependency->_config_file, temp_servicedependency->_start_line); if (dependent_hostlist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand dependent hostgroups and/or " "hosts specified in service dependency (config file '" << xodtemplate_config_file_name( @@ -4741,7 +4743,7 @@ int xodtemplate_duplicate_objects() { temp_servicedependency->_config_file, temp_servicedependency->_start_line); if (dependent_servicelist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand dependent services " "specified in service dependency (config file '" << xodtemplate_config_file_name( @@ -4827,7 +4829,7 @@ int xodtemplate_duplicate_objects() { temp_hostextinfo->hostgroup_name, temp_hostextinfo->host_name, temp_hostextinfo->_config_file, temp_hostextinfo->_start_line); if (master_hostlist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand hostgroups and/or hosts " "specified in extended host info (config file '" << xodtemplate_config_file_name(temp_hostextinfo->_config_file) @@ -4879,7 +4881,7 @@ int xodtemplate_duplicate_objects() { temp_serviceextinfo->hostgroup_name, temp_serviceextinfo->host_name, temp_serviceextinfo->_config_file, temp_serviceextinfo->_start_line); if (master_hostlist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand hostgroups and/or hosts " "specified in extended service info (config file '" << xodtemplate_config_file_name(temp_serviceextinfo->_config_file) @@ -6140,7 +6142,7 @@ int xodtemplate_resolve_timeperiod(xodtemplate_timeperiod* this_timeperiod) { temp_ptr = my_strsep(&template_name_ptr, ",")) { template_timeperiod = xodtemplate_find_timeperiod(temp_ptr); if (template_timeperiod == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in " "timeperiod definition could not be not found (config file '" @@ -6261,7 +6263,7 @@ int xodtemplate_resolve_command(xodtemplate_command* this_command) { temp_ptr = my_strsep(&template_name_ptr, ",")) { template_command = xodtemplate_find_command(temp_ptr); if (template_command == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in command " "definition could not be not found (config file '" @@ -6315,7 +6317,7 @@ int xodtemplate_resolve_contactgroup( temp_ptr = my_strsep(&template_name_ptr, ",")) { template_contactgroup = xodtemplate_find_contactgroup(temp_ptr); if (template_contactgroup == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in " "contactgroup definition could not be not found (config file '" @@ -6378,7 +6380,7 @@ int xodtemplate_resolve_hostgroup(xodtemplate_hostgroup* this_hostgroup) { temp_ptr = my_strsep(&template_name_ptr, ",")) { template_hostgroup = xodtemplate_find_hostgroup(temp_ptr); if (template_hostgroup == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in " "hostgroup definition could not be not found (config file '" @@ -6463,7 +6465,7 @@ int xodtemplate_resolve_servicegroup( temp_ptr = my_strsep(&template_name_ptr, ",")) { template_servicegroup = xodtemplate_find_servicegroup(temp_ptr); if (template_servicegroup == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in " "servicegroup definition could not be not found (config file '" @@ -6551,7 +6553,7 @@ int xodtemplate_resolve_servicedependency( temp_ptr = my_strsep(&template_name_ptr, ",")) { template_servicedependency = xodtemplate_find_servicedependency(temp_ptr); if (template_servicedependency == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in service " "dependency definition could not be not found (config file '" @@ -6684,7 +6686,7 @@ int xodtemplate_resolve_serviceescalation( temp_ptr = my_strsep(&template_name_ptr, ",")) { template_serviceescalation = xodtemplate_find_serviceescalation(temp_ptr); if (template_serviceescalation == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in service " "escalation definition could not be not found (config file '" @@ -6803,7 +6805,7 @@ int xodtemplate_resolve_contact(xodtemplate_contact* this_contact) { temp_ptr = my_strsep(&template_name_ptr, ",")) { template_contact = xodtemplate_find_contact(temp_ptr); if (template_contact == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in contact " "definition could not be not found (config file '" @@ -6989,7 +6991,7 @@ int xodtemplate_resolve_host(xodtemplate_host* this_host) { temp_ptr = my_strsep(&template_name_ptr, ",")) { template_host = xodtemplate_find_host(temp_ptr); if (template_host == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in host " "definition could not be not found (config file '" @@ -7293,7 +7295,7 @@ int xodtemplate_resolve_service(xodtemplate_service* this_service) { temp_ptr = my_strsep(&template_name_ptr, ",")) { template_service = xodtemplate_find_service(temp_ptr); if (template_service == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in service " "definition could not be not found (config file '" @@ -7614,7 +7616,7 @@ int xodtemplate_resolve_hostdependency( temp_ptr = my_strsep(&template_name_ptr, ",")) { template_hostdependency = xodtemplate_find_hostdependency(temp_ptr); if (template_hostdependency == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in host " "dependency definition could not be not found (config file '" @@ -7721,7 +7723,7 @@ int xodtemplate_resolve_hostescalation( temp_ptr = my_strsep(&template_name_ptr, ",")) { template_hostescalation = xodtemplate_find_hostescalation(temp_ptr); if (template_hostescalation == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in host " "escalation definition could not be not found (config file '" @@ -7823,7 +7825,7 @@ int xodtemplate_resolve_hostextinfo(xodtemplate_hostextinfo* this_hostextinfo) { temp_ptr = my_strsep(&template_name_ptr, ",")) { template_hostextinfo = xodtemplate_find_hostextinfo(temp_ptr); if (template_hostextinfo == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in extended " "host info definition could not be not found (config file '" @@ -7955,7 +7957,7 @@ int xodtemplate_resolve_serviceextinfo( temp_ptr = my_strsep(&template_name_ptr, ",")) { template_serviceextinfo = xodtemplate_find_serviceextinfo(temp_ptr); if (template_serviceextinfo == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Template '" << temp_ptr << "' specified in extended " "service info definition could not be not found (config file '" @@ -8080,7 +8082,7 @@ int xodtemplate_recombobulate_contactgroups() { /* find the contactgroup */ temp_contactgroup = xodtemplate_find_real_contactgroup(temp_ptr); if (temp_contactgroup == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find contactgroup '" << temp_ptr << "' specified in contact '" << temp_contact->contact_name << "' definition (config file '" @@ -8128,7 +8130,7 @@ int xodtemplate_recombobulate_contactgroups() { /* add all members to the contact group */ if (temp_memberlist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand member contacts specified in " "contactgroup (config file '" << xodtemplate_config_file_name(temp_contactgroup->_config_file) @@ -8187,7 +8189,7 @@ int xodtemplate_recombobulate_contactgroup_subgroups( /* find subgroup and recurse */ xodtemplate_contactgroup* sub_group(NULL); if ((sub_group = xodtemplate_find_real_contactgroup(buf)) == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find member group '" << buf << "' specified in contactgroup (config file '" << xodtemplate_config_file_name(temp_contactgroup->_config_file) @@ -8287,7 +8289,7 @@ int xodtemplate_recombobulate_hostgroups() { /* find the hostgroup */ temp_hostgroup = xodtemplate_find_real_hostgroup(temp_ptr); if (temp_hostgroup == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find hostgroup '" << temp_ptr << "' specified in host '" << temp_host->host_name << "' definition (config file '" @@ -8351,7 +8353,7 @@ int xodtemplate_recombobulate_hostgroups() { /* add all members to the host group */ if (temp_memberlist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand members specified in hostgroup " "(config file '" << xodtemplate_config_file_name(temp_hostgroup->_config_file) @@ -8421,7 +8423,7 @@ int xodtemplate_recombobulate_hostgroup_subgroups( /* find subgroup and recurse */ xodtemplate_hostgroup* sub_group(NULL); if ((sub_group = xodtemplate_find_real_hostgroup(buf)) == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find member group '" << buf << "' specified in hostgroup (config file '" << xodtemplate_config_file_name(temp_hostgroup->_config_file) @@ -8509,7 +8511,7 @@ int xodtemplate_recombobulate_servicegroups() { /* find the servicegroup */ temp_servicegroup = xodtemplate_find_real_servicegroup(temp_ptr); if (temp_servicegroup == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find servicegroup '" << temp_ptr << "' specified in service '" << temp_service->service_description << "' on host '" << temp_service->host_name @@ -8597,7 +8599,7 @@ int xodtemplate_recombobulate_servicegroups() { /* add all members to the service group */ if (temp_memberlist == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not expand member services specified in " "servicegroup (config file '" << xodtemplate_config_file_name(temp_servicegroup->_config_file) @@ -8647,7 +8649,7 @@ int xodtemplate_recombobulate_servicegroups() { /* error if there were an odd number of items specified (unmatched * host/service pair) */ if (host_name != NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Servicegroup members must be specified in " ", pairs (config file '" << xodtemplate_config_file_name(temp_servicegroup->_config_file) @@ -8690,7 +8692,7 @@ int xodtemplate_recombobulate_servicegroup_subgroups( /* find subgroup and recurse */ xodtemplate_servicegroup* sub_group(NULL); if ((sub_group = xodtemplate_find_real_servicegroup(buf)) == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find member group '" << buf << "' specified in servicegroup (config file '" << xodtemplate_config_file_name(temp_servicegroup->_config_file) @@ -9173,7 +9175,7 @@ int xodtemplate_fill_timeperiod(xodtemplate_timeperiod* this_timeperiod, temp_daterange->emon, temp_daterange->emday, temp_daterange->ewday, temp_daterange->ewday_offset, temp_daterange->skip_interval); if (new_daterange == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add date exception to timeperiod " "(config file '" << xodtemplate_config_file_name(this_timeperiod->_config_file) @@ -9193,7 +9195,7 @@ int xodtemplate_fill_timeperiod(xodtemplate_timeperiod* this_timeperiod, if (xodtemplate_get_time_ranges(day_range_start_buffer, &range_start_time, &range_end_time) == ERROR) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not parse timerange #" << range << " of timeperiod (config file '" << xodtemplate_config_file_name(this_timeperiod->_config_file) @@ -9205,7 +9207,7 @@ int xodtemplate_fill_timeperiod(xodtemplate_timeperiod* this_timeperiod, new_timerange = add_timerange_to_daterange( new_daterange, range_start_time, range_end_time); if (new_timerange == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add timerange #" << range << " to timeperiod (config file '" << xodtemplate_config_file_name(this_timeperiod->_config_file) @@ -9233,7 +9235,7 @@ int xodtemplate_fill_timeperiod(xodtemplate_timeperiod* this_timeperiod, /* get time ranges */ if (xodtemplate_get_time_ranges(day_range_start_buffer, &range_start_time, &range_end_time) == ERROR) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not parse timerange #" << range << " for day " << day << " of timeperiod (config file '" << xodtemplate_config_file_name(this_timeperiod->_config_file) @@ -9245,7 +9247,7 @@ int xodtemplate_fill_timeperiod(xodtemplate_timeperiod* this_timeperiod, new_timerange = add_timerange_to_timeperiod( new_timeperiod, day, range_start_time, range_end_time); if (new_timerange == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add timerange #" << range << " for day " << day << " to timeperiod (config file '" << xodtemplate_config_file_name(this_timeperiod->_config_file) @@ -9263,7 +9265,7 @@ int xodtemplate_fill_timeperiod(xodtemplate_timeperiod* this_timeperiod, new_timeperiodexclusion = add_exclusion_to_timeperiod(new_timeperiod, temp_ptr); if (new_timeperiodexclusion == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add excluded timeperiod '" << temp_ptr << "' to timeperiod (config file '" << xodtemplate_config_file_name(this_timeperiod->_config_file) @@ -9299,7 +9301,7 @@ int xodtemplate_register_timeperiod(xodtemplate_timeperiod* this_timeperiod) { // Return with an error if we couldn't add the timeperiod. if (!new_timeperiod) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register timeperiod (config file '" << xodtemplate_config_file_name(this_timeperiod->_config_file) << "', starting on line " << this_timeperiod->_start_line << ")"; @@ -9388,7 +9390,7 @@ int xodtemplate_register_command(xodtemplate_command* this_command) { cmd_set.add_command(cmd); } } catch (std::exception const& e) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register command (config file '" << xodtemplate_config_file_name(this_command->_config_file) << "', starting on line " << this_command->_start_line @@ -9402,7 +9404,7 @@ int xodtemplate_register_command(xodtemplate_command* this_command) { /* return with an error if we couldn't add the command */ if (new_command == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register command (config file '" << xodtemplate_config_file_name(this_command->_config_file) << "', starting on line " << this_command->_start_line << ")"; @@ -9433,7 +9435,7 @@ int xodtemplate_register_connector(xodtemplate_connector* this_connector) { &checks::checker::instance())); commands::set::instance().add_command(cmd); } catch (std::exception const& e) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register connector (config file '" << xodtemplate_config_file_name(this_connector->_config_file) << "', starting on line " << this_connector->_start_line @@ -9457,7 +9459,7 @@ int xodtemplate_register_contactgroup( /* return with an error if we couldn't add the contactgroup */ if (new_contactgroup == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register contactgroup (config file '" << xodtemplate_config_file_name(this_contactgroup->_config_file) << "', starting on line " << this_contactgroup->_start_line << ")"; @@ -9473,7 +9475,7 @@ int xodtemplate_register_contactgroup( contactsmember* new_contactsmember = add_contact_to_contactgroup(new_contactgroup, contact_name); if (new_contactsmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add contact '" << contact_name << "' to contactgroup (config file '" << xodtemplate_config_file_name(this_contactgroup->_config_file) @@ -9500,7 +9502,7 @@ int xodtemplate_register_hostgroup(xodtemplate_hostgroup* this_hostgroup) { /* return with an error if we couldn't add the hostgroup */ if (new_hostgroup == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register hostgroup (config file '" << xodtemplate_config_file_name(this_hostgroup->_config_file) << "', starting on line " << this_hostgroup->_start_line << ")"; @@ -9514,7 +9516,7 @@ int xodtemplate_register_hostgroup(xodtemplate_hostgroup* this_hostgroup) { hostsmember* new_hostsmember = add_host_to_hostgroup(new_hostgroup, host_name); if (new_hostsmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add host '" << host_name << "' to hostgroup (config file '" << xodtemplate_config_file_name(this_hostgroup->_config_file) @@ -9542,7 +9544,7 @@ int xodtemplate_register_servicegroup( /* return with an error if we couldn't add the servicegroup */ if (new_servicegroup == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register servicegroup (config file '" << xodtemplate_config_file_name(this_servicegroup->_config_file) << "', starting on line " << this_servicegroup->_start_line << ")"; @@ -9555,7 +9557,7 @@ int xodtemplate_register_servicegroup( strip(host_name); char* svc_description(strtok(NULL, ",")); if (svc_description == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Missing service name in servicegroup definition " "(config file '" << xodtemplate_config_file_name(this_servicegroup->_config_file) @@ -9567,7 +9569,7 @@ int xodtemplate_register_servicegroup( servicesmember* new_servicesmember = add_service_to_servicegroup( new_servicegroup, host_name, svc_description); if (new_servicesmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add service '" << svc_description << "' on host '" << host_name << "' to servicegroup " @@ -9594,7 +9596,7 @@ int xodtemplate_register_servicedependency( /* throw a warning on servicedeps that have no options */ if (this_servicedependency->have_notification_dependency_options == false && this_servicedependency->have_execution_dependency_options == false) { - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Ignoring lame service dependency (config file '" << xodtemplate_config_file_name(this_servicedependency->_config_file) << "', line " << this_servicedependency->_start_line << ")"; @@ -9618,7 +9620,7 @@ int xodtemplate_register_servicedependency( /* return with an error if we couldn't add the servicedependency */ if (new_servicedependency == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register service execution dependency " "(config file '" << xodtemplate_config_file_name(this_servicedependency->_config_file) @@ -9643,7 +9645,7 @@ int xodtemplate_register_servicedependency( /* return with an error if we couldn't add the servicedependency */ if (new_servicedependency == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register service notification dependency " "(config file '" << xodtemplate_config_file_name(this_servicedependency->_config_file) @@ -9686,7 +9688,7 @@ int xodtemplate_register_serviceescalation( /* return with an error if we couldn't add the serviceescalation */ if (new_serviceescalation == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register service escalation (config file '" << xodtemplate_config_file_name(this_serviceescalation->_config_file) << "', starting on line " << this_serviceescalation->_start_line << ")"; @@ -9703,7 +9705,7 @@ int xodtemplate_register_serviceescalation( add_contactgroup_to_serviceescalation(new_serviceescalation, contact_group); if (new_contactgroupsmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add contactgroup '" << contact_group << "' to service escalation (config file '" << xodtemplate_config_file_name( @@ -9723,7 +9725,7 @@ int xodtemplate_register_serviceescalation( contactsmember* new_contactsmember = add_contact_to_serviceescalation(new_serviceescalation, contact_name); if (new_contactsmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add contact '" << contact_name << "' to service escalation (config file '" << xodtemplate_config_file_name( @@ -9773,7 +9775,7 @@ int xodtemplate_register_contact(xodtemplate_contact* this_contact) { /* return with an error if we couldn't add the contact */ if (new_contact == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register contact (config file '" << xodtemplate_config_file_name(this_contact->_config_file) << "', starting on line " << this_contact->_start_line << ")"; @@ -9787,7 +9789,7 @@ int xodtemplate_register_contact(xodtemplate_contact* this_contact) { new_commandsmember = add_host_notification_command_to_contact(new_contact, command_name); if (new_commandsmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add host notification command '" << command_name << "' to contact (config file '" << xodtemplate_config_file_name(this_contact->_config_file) @@ -9805,7 +9807,7 @@ int xodtemplate_register_contact(xodtemplate_contact* this_contact) { new_commandsmember = add_service_notification_command_to_contact( new_contact, command_name); if (new_commandsmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add service notification command '" << command_name << "' to contact (config file '" << xodtemplate_config_file_name(this_contact->_config_file) @@ -9822,7 +9824,7 @@ int xodtemplate_register_contact(xodtemplate_contact* this_contact) { if ((add_custom_variable_to_contact( new_contact, temp_customvariablesmember->variable_name, temp_customvariablesmember->variable_value)) == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not custom variable to contact (config file '" << xodtemplate_config_file_name(this_contact->_config_file) << "', starting on line " << this_contact->_start_line << ")"; @@ -9883,7 +9885,7 @@ int xodtemplate_register_host(xodtemplate_host* this_host) { /* return with an error if we couldn't add the host */ if (new_host == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register host (config file '" << xodtemplate_config_file_name(this_host->_config_file) << "', starting on line " << this_host->_start_line << ")"; @@ -9897,7 +9899,7 @@ int xodtemplate_register_host(xodtemplate_host* this_host) { strip(parent_host); new_hostsmember = add_parent_host_to_host(new_host, parent_host); if (new_hostsmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add parent host '" << parent_host << "' to host (config file '" << xodtemplate_config_file_name(this_host->_config_file) @@ -9915,7 +9917,7 @@ int xodtemplate_register_host(xodtemplate_host* this_host) { new_contactgroupsmember = add_contactgroup_to_host(new_host, contact_group); if (new_contactgroupsmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add contactgroup '" << contact_group << "' to host (config file '" << xodtemplate_config_file_name(this_host->_config_file) @@ -9932,7 +9934,7 @@ int xodtemplate_register_host(xodtemplate_host* this_host) { strip(contact_name); new_contactsmember = add_contact_to_host(new_host, contact_name); if (new_contactsmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add contact '" << contact_name << "' to host (config file '" << xodtemplate_config_file_name(this_host->_config_file) @@ -9949,7 +9951,7 @@ int xodtemplate_register_host(xodtemplate_host* this_host) { if ((add_custom_variable_to_host( new_host, temp_customvariablesmember->variable_name, temp_customvariablesmember->variable_value)) == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not custom variable to host (config file '" << xodtemplate_config_file_name(this_host->_config_file) << "', starting on line " << this_host->_start_line << ")"; @@ -10004,7 +10006,7 @@ int xodtemplate_register_service(xodtemplate_service* this_service) { /* return with an error if we couldn't add the service */ if (new_service == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register service (config file '" << xodtemplate_config_file_name(this_service->_config_file) << "', starting on line " << this_service->_start_line << ")"; @@ -10019,7 +10021,7 @@ int xodtemplate_register_service(xodtemplate_service* this_service) { new_contactgroupsmember = add_contactgroup_to_service(new_service, contact_group); if (new_contactgroupsmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add contactgroup '" << contact_group << "' to service (config file '" << xodtemplate_config_file_name(this_service->_config_file) @@ -10039,7 +10041,7 @@ int xodtemplate_register_service(xodtemplate_service* this_service) { /* stop adding contacts if we ran into an error */ if (new_contactsmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add contact '" << contact_name << "' to service (config file '" << xodtemplate_config_file_name(this_service->_config_file) @@ -10056,7 +10058,7 @@ int xodtemplate_register_service(xodtemplate_service* this_service) { if ((add_custom_variable_to_service( new_service, temp_customvariablesmember->variable_name, temp_customvariablesmember->variable_value)) == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not custom variable to service (config file '" << xodtemplate_config_file_name(this_service->_config_file) << "', starting on line " << this_service->_start_line << ")"; @@ -10090,7 +10092,7 @@ int xodtemplate_register_hostdependency( /* return with an error if we couldn't add the hostdependency */ if (new_hostdependency == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register host execution dependency " "(config file '" << xodtemplate_config_file_name(this_hostdependency->_config_file) @@ -10113,7 +10115,7 @@ int xodtemplate_register_hostdependency( /* return with an error if we couldn't add the hostdependency */ if (new_hostdependency == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register host notification dependency " "(config file '" << xodtemplate_config_file_name(this_hostdependency->_config_file) @@ -10151,7 +10153,7 @@ int xodtemplate_register_hostescalation( /* return with an error if we couldn't add the hostescalation */ if (new_hostescalation == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not register host escalation (config file '" << xodtemplate_config_file_name(this_hostescalation->_config_file) << "', starting on line " << this_hostescalation->_start_line << ")"; @@ -10167,7 +10169,7 @@ int xodtemplate_register_hostescalation( add_contactgroup_to_host_escalation(new_hostescalation, contact_group); if (new_contactgroupsmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add contactgroup '" << contact_group << "' to host escalation (config file '" << xodtemplate_config_file_name(this_hostescalation->_config_file) @@ -10186,7 +10188,7 @@ int xodtemplate_register_hostescalation( contactsmember* new_contactsmember = add_contact_to_host_escalation(new_hostescalation, contact_name); if (new_contactsmember == NULL) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not add contact '" << contact_name << "' to host escalation (config file '" << xodtemplate_config_file_name(this_hostescalation->_config_file) @@ -11188,7 +11190,7 @@ int xodtemplate_cache_objects(char* cache_file) { /* open the cache file for writing */ fp = fopen(cache_file, "w"); if (fp == NULL) { - logger(log_config_warning, basic) + engine_logger(log_config_warning, basic) << "Warning: Could not open object cache file '" << cache_file << "' for writing!"; return ERROR; @@ -13234,7 +13236,7 @@ int xodtemplate_expand_contactgroups(xodtemplate_memberlist** list, } if (found_match == false) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find any contactgroup matching '" << temp_ptr << "' (config file '" << xodtemplate_config_file_name(_config_file) << "', starting on line " << _start_line << ")"; @@ -13361,7 +13363,7 @@ int xodtemplate_expand_contacts(xodtemplate_memberlist** list, } if (found_match == false) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find any contact matching '" << temp_ptr << "' (config file '" << xodtemplate_config_file_name(_config_file) << "', starting on line " << _start_line << ")"; @@ -13594,7 +13596,7 @@ int xodtemplate_expand_hostgroups(xodtemplate_memberlist** list, } if (found_match == false) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find any hostgroup matching '" << temp_ptr << "' (config file '" << xodtemplate_config_file_name(_config_file) << "', starting on line " << _start_line << ")"; @@ -13720,7 +13722,7 @@ int xodtemplate_expand_hosts(xodtemplate_memberlist** list, } if (found_match == false) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find any host matching '" << temp_ptr << "' (config file '" << xodtemplate_config_file_name(_config_file) << "', starting on line " << _start_line << ")"; @@ -13954,7 +13956,7 @@ int xodtemplate_expand_servicegroups(xodtemplate_memberlist** list, /* we didn't find a matching servicegroup */ if (found_match == false) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find any servicegroup matching '" << temp_ptr << "' (config file '" << xodtemplate_config_file_name(_config_file) << "', starting on line " << _start_line << ")"; @@ -14132,7 +14134,7 @@ int xodtemplate_expand_services(xodtemplate_memberlist** list, /* we didn't find a match */ if (found_match == false && reject_item == false) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find a service matching host name '" << host_name << "' and description '" << temp_ptr << "' (config file '" << xodtemplate_config_file_name(_config_file) @@ -14372,7 +14374,7 @@ int xodtemplate_get_hostgroup_names(xodtemplate_memberlist** list, } if (found_match == false) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find any hostgroup matching '" << temp_ptr << "' (config file '" << xodtemplate_config_file_name(_config_file) << "', starting on line " << _start_line << ")"; @@ -14557,7 +14559,7 @@ int xodtemplate_get_contactgroup_names(xodtemplate_memberlist** list, } if (found_match == false) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find any contactgroup matching '" << temp_ptr << "' (config file '" << xodtemplate_config_file_name(_config_file) << "', starting on line " << _start_line << ")"; @@ -14742,7 +14744,7 @@ int xodtemplate_get_servicegroup_names(xodtemplate_memberlist** list, } if (found_match == false) { - logger(log_config_error, basic) + engine_logger(log_config_error, basic) << "Error: Could not find any servicegroup matching '" << temp_ptr << "' (config file '" << xodtemplate_config_file_name(_config_file) << "', starting on line " << _start_line << ")"; diff --git a/centreon-engine/test/configuration/applier/xrddefault.cc b/centreon-engine/test/configuration/applier/xrddefault.cc index 990938e5733..f49426144a8 100644 --- a/centreon-engine/test/configuration/applier/xrddefault.cc +++ b/centreon-engine/test/configuration/applier/xrddefault.cc @@ -34,6 +34,7 @@ #include "com/centreon/engine/common.hh" #include "com/centreon/engine/flapping.hh" #include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/log_v2.hh" #include "com/centreon/engine/logging/logger.hh" #include "com/centreon/engine/macros.hh" #include "com/centreon/engine/notifications.hh" @@ -63,7 +64,7 @@ int xrddefault_grab_config_info(char const* main_config_file) { /* open the main config file for reading */ if ((thefile = mmap_fopen(main_config_file)) == NULL) { - logger(dbg_retentiondata, most) + engine_logger(dbg_retentiondata, most) << "Error: Cannot open main configuration file '" << main_config_file << "' for reading!"; @@ -157,7 +158,7 @@ int xrddefault_initialize_retention_data(char const* config_file) { if ((xrddefault_retention_file_fd = open(xrddefault_retention_file, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) == -1) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Unable to open retention file '" << xrddefault_retention_file << "': " << strerror(errno); return (ERROR); @@ -189,11 +190,11 @@ int xrddefault_cleanup_retention_data(char const* config_file) { /******************************************************************/ int xrddefault_save_state_information() { - logger(dbg_functions, basic) << "xrddefault_save_state_information()"; + engine_logger(dbg_functions, basic) << "xrddefault_save_state_information()"; /* make sure we have everything */ if (xrddefault_retention_file == NULL || xrddefault_retention_file_fd == -1) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: We don't have the required file names to store " "retention data!"; return (ERROR); @@ -613,7 +614,7 @@ int xrddefault_save_state_information() { (fsync(xrddefault_retention_file_fd) == -1) || (lseek(xrddefault_retention_file_fd, 0, SEEK_SET) == (off_t)-1)) { char const* msg(strerror(errno)); - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Unable to update retention file '" << xrddefault_retention_file << "': " << msg; return (ERROR); @@ -627,7 +628,7 @@ int xrddefault_save_state_information() { ssize_t wb(write(xrddefault_retention_file_fd, data_ptr, size)); if (wb <= 0) { char const* msg(strerror(errno)); - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: Unable to update retention file '" << xrddefault_retention_file << "': " << msg; return (ERROR); @@ -697,11 +698,11 @@ int xrddefault_read_state_information() { double runtime[2]; int found_directive = FALSE; - logger(dbg_functions, basic) << "xrddefault_read_state_information()"; + engine_logger(dbg_functions, basic) << "xrddefault_read_state_information()"; /* make sure we have what we need */ if (xrddefault_retention_file == NULL) { - logger(log_runtime_error, basic) + engine_logger(log_runtime_error, basic) << "Error: We don't have a filename for retention data!"; return (ERROR); } diff --git a/centreon-engine/tests/CMakeLists.txt b/centreon-engine/tests/CMakeLists.txt index d37c38fab9b..61ebcd33a43 100755 --- a/centreon-engine/tests/CMakeLists.txt +++ b/centreon-engine/tests/CMakeLists.txt @@ -60,6 +60,7 @@ if (WITH_TESTING) "${TESTS_DIR}/configuration/applier/applier-contact.cc" "${TESTS_DIR}/configuration/applier/applier-contactgroup.cc" "${TESTS_DIR}/configuration/applier/applier-global.cc" + "${TESTS_DIR}/configuration/applier/applier-log.cc" "${TESTS_DIR}/configuration/applier/applier-host.cc" "${TESTS_DIR}/configuration/applier/applier-hostescalation.cc" "${TESTS_DIR}/configuration/applier/applier-hostdependency.cc" diff --git a/centreon-engine/tests/configuration/applier/applier-log.cc b/centreon-engine/tests/configuration/applier/applier-log.cc new file mode 100644 index 00000000000..6db20d67580 --- /dev/null +++ b/centreon-engine/tests/configuration/applier/applier-log.cc @@ -0,0 +1,543 @@ +/* + * Copyright 2022 Centreon (https://www.centreon.com/) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * For more information : contact@centreon.com + * + */ + +#include +#include +#include +#include +#include +#include "helper.hh" + +using namespace com::centreon; +using namespace com::centreon::engine; + +class ApplierLog : public ::testing::Test { + public: + void SetUp() override { init_config_state(); } + + void TearDown() override { deinit_config_state(); } +}; + +// Given host configuration without host_id +// Then the applier add_object throws an exception. +TEST_F(ApplierLog, logV2Enabled) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_v2_enabled(), true); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_v2_enabled=0" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + std::remove("/tmp/test-config.cfg"); + + ASSERT_EQ(st.log_v2_enabled(), false); +} + +TEST_F(ApplierLog, logLegacyEnabled) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_legacy_enabled(), true); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_legacy_enabled=0" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + std::remove("/tmp/test-config.cfg"); + + ASSERT_EQ(st.log_legacy_enabled(), false); +} + +TEST_F(ApplierLog, logV2Logger) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_v2_logger(), "file"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_v2_logger=syslog" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + std::remove("/tmp/test-config.cfg"); + + ASSERT_EQ(st.log_v2_logger(), "syslog"); +} + +TEST_F(ApplierLog, logLevelFunctions) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_level_functions(), "error"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_level_functions=trace" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + + ASSERT_EQ(st.log_level_functions(), "trace"); + + ofs.open("/tmp/test-config.cfg"); + ofs << "log_level_functions=tracerrrr" << std::endl; + ofs.close(); + + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + std::remove("/tmp/test-config.cfg"); +} + +TEST_F(ApplierLog, logLevelConfig) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_level_config(), "info"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_level_config=debug" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + + ASSERT_EQ(st.log_level_config(), "debug"); + + ofs.open("/tmp/test-config.cfg"); + ofs << "log_level_config=tracerrrr" << std::endl; + ofs.close(); + + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + std::remove("/tmp/test-config.cfg"); + + // testing::internal::CaptureStdout(); + // parser.parse("/tmp/test-config.cfg", st); + // std::remove("/tmp/test-config.cfg"); + + // std::string out{testing::internal::GetCapturedStdout()}; + // std::cout << out << std::endl; + // size_t step1{ + // out.find("[config] [error] error wrong level setted for " + // "log_level_config")}; + // ASSERT_NE(step1, std::string::npos); + // ASSERT_EQ(st.log_level_config(), "debug"); +} + +TEST_F(ApplierLog, logLevelEvents) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_level_events(), "info"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_level_events=warning" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + + ASSERT_EQ(st.log_level_events(), "warning"); + + ofs.open("/tmp/test-config.cfg"); + ofs << "log_level_events=tracerrrr" << std::endl; + ofs.close(); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + std::remove("/tmp/test-config.cfg"); + // testing::internal::CaptureStdout(); + // parser.parse("/tmp/test-config.cfg", st); + // std::remove("/tmp/test-config.cfg"); + + // std::string out{testing::internal::GetCapturedStdout()}; + // std::cout << out << std::endl; + // size_t step1{ + // out.find("[config] [error] error wrong level setted for " + // "log_level_events")}; + // ASSERT_NE(step1, std::string::npos); + // ASSERT_EQ(st.log_level_events(), "warning"); +} + +TEST_F(ApplierLog, logLevelChecks) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_level_checks(), "info"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_level_checks=error" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + + ASSERT_EQ(st.log_level_checks(), "error"); + + ofs.open("/tmp/test-config.cfg"); + ofs << "log_level_checks=tracerrrr" << std::endl; + ofs.close(); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + std::remove("/tmp/test-config.cfg"); + // testing::internal::CaptureStdout(); + // parser.parse("/tmp/test-config.cfg", st); + // std::remove("/tmp/test-config.cfg"); + + // std::string out{testing::internal::GetCapturedStdout()}; + // std::cout << out << std::endl; + // size_t step1{ + // out.find("[config] [error] error wrong level setted for " + // "log_level_checks")}; + // ASSERT_NE(step1, std::string::npos); + // ASSERT_EQ(st.log_level_checks(), "error"); +} + +TEST_F(ApplierLog, logLevelNotifications) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_level_notifications(), "error"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_level_notifications=off" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + + ASSERT_EQ(st.log_level_notifications(), "off"); + + ofs.open("/tmp/test-config.cfg"); + ofs << "log_level_notifications=tracerrrr" << std::endl; + ofs.close(); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + std::remove("/tmp/test-config.cfg"); + // testing::internal::CaptureStdout(); + // parser.parse("/tmp/test-config.cfg", st); + // std::remove("/tmp/test-config.cfg"); + + // std::string out{testing::internal::GetCapturedStdout()}; + // std::cout << out << std::endl; + // size_t step1{ + // out.find("[config] [error] error wrong level setted for " + // "log_level_notifications")}; + // ASSERT_NE(step1, std::string::npos); + // ASSERT_EQ(st.log_level_notifications(), "off"); +} + +TEST_F(ApplierLog, logLevelEventBroker) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_level_eventbroker(), "error"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_level_eventbroker=critical" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + + ASSERT_EQ(st.log_level_eventbroker(), "critical"); + + ofs.open("/tmp/test-config.cfg"); + ofs << "log_level_eventbroker=tracerrrr" << std::endl; + ofs.close(); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + std::remove("/tmp/test-config.cfg"); + // testing::internal::CaptureStdout(); + // parser.parse("/tmp/test-config.cfg", st); + // std::remove("/tmp/test-config.cfg"); + + // std::string out{testing::internal::GetCapturedStdout()}; + // std::cout << out << std::endl; + // size_t step1{ + // out.find("[config] [error] error wrong level setted for " + // "log_level_eventbroker")}; + // ASSERT_NE(step1, std::string::npos); + // ASSERT_EQ(st.log_level_eventbroker(), "critical"); +} + +TEST_F(ApplierLog, logLevelExternalCommand) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_level_external_command(), "error"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_level_external_command=trace" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + + ASSERT_EQ(st.log_level_external_command(), "trace"); + + ofs.open("/tmp/test-config.cfg"); + ofs << "log_level_external_command=tracerrrr" << std::endl; + ofs.close(); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + std::remove("/tmp/test-config.cfg"); + // testing::internal::CaptureStdout(); + // parser.parse("/tmp/test-config.cfg", st); + // std::remove("/tmp/test-config.cfg"); + + // std::string out{testing::internal::GetCapturedStdout()}; + // std::cout << out << std::endl; + // size_t step1{ + // out.find("[config] [error] error wrong level setted for " + // "log_level_external_command")}; + // ASSERT_NE(step1, std::string::npos); + // ASSERT_EQ(st.log_level_external_command(), "trace"); +} + +TEST_F(ApplierLog, logLevelCommands) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_level_commands(), "error"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_level_commands=debug" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + + ASSERT_EQ(st.log_level_commands(), "debug"); + + ofs.open("/tmp/test-config.cfg"); + ofs << "log_level_commands=tracerrrr" << std::endl; + ofs.close(); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + std::remove("/tmp/test-config.cfg"); + // testing::internal::CaptureStdout(); + // parser.parse("/tmp/test-config.cfg", st); + // std::remove("/tmp/test-config.cfg"); + + // std::string out{testing::internal::GetCapturedStdout()}; + // std::cout << out << std::endl; + // size_t step1{ + // out.find("[config] [error] error wrong level setted for " + // "log_level_commands")}; + // ASSERT_NE(step1, std::string::npos); + // ASSERT_EQ(st.log_level_commands(), "debug"); +} + +TEST_F(ApplierLog, logLevelDowntimes) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_level_downtimes(), "error"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_level_downtimes=warning" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + + ASSERT_EQ(st.log_level_downtimes(), "warning"); + + ofs.open("/tmp/test-config.cfg"); + ofs << "log_level_downtimes=tracerrrr" << std::endl; + ofs.close(); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + std::remove("/tmp/test-config.cfg"); + // testing::internal::CaptureStdout(); + // parser.parse("/tmp/test-config.cfg", st); + // std::remove("/tmp/test-config.cfg"); + + // std::string out{testing::internal::GetCapturedStdout()}; + // std::cout << out << std::endl; + // size_t step1{ + // out.find("[config] [error] error wrong level setted for " + // "log_level_downtimes")}; + // ASSERT_NE(step1, std::string::npos); + // ASSERT_EQ(st.log_level_downtimes(), "warning"); +} + +TEST_F(ApplierLog, logLevelComments) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_level_comments(), "error"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_level_comments=error" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + + ASSERT_EQ(st.log_level_comments(), "error"); + + ofs.open("/tmp/test-config.cfg"); + ofs << "log_level_comments=tracerrrr" << std::endl; + ofs.close(); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + std::remove("/tmp/test-config.cfg"); + // testing::internal::CaptureStdout(); + // parser.parse("/tmp/test-config.cfg", st); + // std::remove("/tmp/test-config.cfg"); + + // std::string out{testing::internal::GetCapturedStdout()}; + // std::cout << out << std::endl; + // size_t step1{ + // out.find("[config] [error] error wrong level setted for " + // "log_level_comments")}; + // ASSERT_NE(step1, std::string::npos); + // ASSERT_EQ(st.log_level_comments(), "error"); +} + +TEST_F(ApplierLog, logLevelMacros) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_level_macros(), "error"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_level_macros=critical" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + + ASSERT_EQ(st.log_level_macros(), "critical"); + + ofs.open("/tmp/test-config.cfg"); + ofs << "log_level_macros=tracerrrr" << std::endl; + ofs.close(); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + std::remove("/tmp/test-config.cfg"); + // testing::internal::CaptureStdout(); + // parser.parse("/tmp/test-config.cfg", st); + // std::remove("/tmp/test-config.cfg"); + + // std::string out{testing::internal::GetCapturedStdout()}; + // std::cout << out << std::endl; + // size_t step1{ + // out.find("[config] [error] error wrong level setted for " + // "log_level_macros")}; + // ASSERT_NE(step1, std::string::npos); + // ASSERT_EQ(st.log_level_macros(), "critical"); +} + +TEST_F(ApplierLog, logLevelProcess) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_level_process(), "info"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_level_process=off" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + + ASSERT_EQ(st.log_level_process(), "off"); + + ofs.open("/tmp/test-config.cfg"); + ofs << "log_level_process=tracerrrr" << std::endl; + ofs.close(); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + std::remove("/tmp/test-config.cfg"); + // testing::internal::CaptureStdout(); + // parser.parse("/tmp/test-config.cfg", st); + // std::remove("/tmp/test-config.cfg"); + + // std::string out{testing::internal::GetCapturedStdout()}; + // std::cout << out << std::endl; + // size_t step1{ + // out.find("[config] [error] error wrong level setted for " + // "log_level_process")}; + // ASSERT_NE(step1, std::string::npos); + // ASSERT_EQ(st.log_level_process(), "off"); +} + +TEST_F(ApplierLog, logLevelRuntime) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_level_runtime(), "error"); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_level_runtime=off" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + + ASSERT_EQ(st.log_level_runtime(), "off"); + + ofs.open("/tmp/test-config.cfg"); + ofs << "log_level_runtime=tracerrrr" << std::endl; + ofs.close(); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + std::remove("/tmp/test-config.cfg"); + // testing::internal::CaptureStdout(); + // parser.parse("/tmp/test-config.cfg", st); + // std::remove("/tmp/test-config.cfg"); + + // std::string out{testing::internal::GetCapturedStdout()}; + // std::cout << out << std::endl; + // size_t step1{ + // out.find("[config] [error] error wrong level setted for " + // "log_level_runtime")}; + // ASSERT_NE(step1, std::string::npos); + // ASSERT_EQ(st.log_level_runtime(), "off"); +} + +TEST_F(ApplierLog, logFile) { + configuration::parser parser; + configuration::state st; + + ASSERT_EQ(st.log_file(), DEFAULT_LOG_FILE); + + std::remove("/tmp/test-config.cfg"); + + std::ofstream ofs("/tmp/test-config.cfg"); + ofs << "log_file=/tmp/centengine.log" << std::endl; + ofs.close(); + + parser.parse("/tmp/test-config.cfg", st); + std::remove("/tmp/test-config.cfg"); + + ASSERT_EQ(st.log_file(), "/tmp/centengine.log"); +} diff --git a/centreon-tests/broker-engine/log-v2_engine.robot b/centreon-tests/broker-engine/log-v2_engine.robot new file mode 100644 index 00000000000..1baa2c8b1d7 --- /dev/null +++ b/centreon-tests/broker-engine/log-v2_engine.robot @@ -0,0 +1,338 @@ +*** Settings *** +Resource ../resources/resources.robot +Suite Setup Clean Before Suite +Suite Teardown Clean After Suite +Test Setup Stop Processes + +Documentation Centreon Broker and Engine log_v2 +Library DatabaseLibrary +Library Process +Library OperatingSystem +Library DateTime +Library Collections +Library ../resources/Engine.py +Library ../resources/Broker.py +Library ../resources/Common.py + +*** Test Cases *** +LOGV2EB1 + [Documentation] log-v2 enabled hold log disabled check broker sink + [Tags] Broker Engine log-v2 sink broker + Config Engine ${1} + Config Broker rrd + Config Broker central + Config Broker module + Engine Config Set Value ${0} log_legacy_enabled ${0} + Engine Config Set Value ${0} log_v2_enabled ${1} + + ${start}= Get Current Date UTC exclude_millis=yes + ${time_stamp} Convert Date ${start} epoch exclude_millis=yes + ${time_stamp2} evaluate int(${time_stamp}) + + Start Broker + Start Engine + ${result}= Check Connections + Should Be True ${result} msg=Engine and Broker not connected + + ${pid}= Get Process Id e0 + ${content}= Create List [process] [info] [${pid}] Configuration loaded, main loop starting. + + ${log}= Catenate SEPARATOR= ${ENGINE_LOG} /config0/centengine.log + ${result1}= Find In Log With Timeout ${log} ${start} ${content} 15 + Should Be True ${result1} + + Sleep 10s + + Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort} + Log To Console after connection + ${output}= Query select count(*) from logs where output="Configuration loaded, main loop starting." AND ctime>=${time_stamp2}; + Log To Console ${output} + Should Be Equal As Strings ${output} ((1,),) + Stop Engine + Stop Broker + +LOGV2DB1 + [Documentation] log-v2 disabled hold log enabled check broker sink + [Tags] Broker Engine log-v2 sink broker + Config Engine ${1} + Config Broker rrd + Config Broker central + Config Broker module + Engine Config Set Value ${0} log_legacy_enabled ${1} + Engine Config Set Value ${0} log_v2_enabled ${0} + + ${start}= Get Current Date UTC exclude_millis=yes + ${time_stamp} Convert Date ${start} epoch exclude_millis=yes + ${time_stamp2} evaluate int(${time_stamp}) + + Start Broker + Start Engine + ${result}= Check Connections + Should Be True ${result} msg=Engine and Broker not connected + + ${pid}= Get Process Id e0 + ${content_v2}= Create List [process] [info] [${pid}] Configuration loaded, main loop starting. + ${content_hold}= Create List [${pid}] Configuration loaded, main loop starting. + + ${log}= Catenate SEPARATOR= ${ENGINE_LOG} /config0/centengine.log + ${result1}= Find In Log With Timeout ${log} ${start} ${content_v2} 15 + ${result2}= Find In Log With Timeout ${log} ${start} ${content_hold} 15 + Should Not Be True ${result1} + Should Be True ${result2} + + Sleep 10s + + Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort} + Log To Console after connection + ${output}= Query select count(*) from logs where output="Configuration loaded, main loop starting." AND ctime>=${time_stamp2}; + Log To Console ${output} + Should Be Equal As Strings ${output} ((1,),) + Stop Engine + Stop Broker + +LOGV2DB2 + [Documentation] log-v2 disabled hold log disabled check broker sink + [Tags] Broker Engine log-v2 sink broker + Config Engine ${1} + Config Broker rrd + Config Broker central + Config Broker module + Engine Config Set Value ${0} log_legacy_enabled ${0} + Engine Config Set Value ${0} log_v2_enabled ${0} + + ${start}= Get Current Date UTC exclude_millis=yes + ${time_stamp} Convert Date ${start} epoch exclude_millis=yes + ${time_stamp2} evaluate int(${time_stamp}) + Start Broker + Start Engine + ${result}= Check Connections + Should Be True ${result} msg=Engine and Broker not connected + + ${pid}= Get Process Id e0 + ${content_v2}= Create List [process] [info] [${pid}] Configuration loaded, main loop starting. + ${content_hold}= Create List [${pid}] Configuration loaded, main loop starting. + + ${log}= Catenate SEPARATOR= ${ENGINE_LOG} /config0/centengine.log + ${result1}= Find In Log With Timeout ${log} ${start} ${content_v2} 15 + ${result2}= Find In Log With Timeout ${log} ${start} ${content_hold} 15 + Should Not Be True ${result1} + Should Not Be True ${result2} + + Sleep 10s + + Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort} + Log To Console after connection + ${output}= Query select count(*) from logs where output="Configuration loaded, main loop starting." AND ctime>=${time_stamp2}; + Log To Console ${output} + Should Be Equal As Strings ${output} ((0,),) + Stop Engine + Stop Broker + +LOGV2EB2 + [Documentation] log-v2 enabled hold log enabled check broker sink + [Tags] Broker Engine log-v2 sinkbroker + Config Engine ${1} + Config Broker rrd + Config Broker central + Config Broker module + Engine Config Set Value ${0} log_legacy_enabled ${1} + Engine Config Set Value ${0} log_v2_enabled ${1} + + ${start}= Get Current Date UTC exclude_millis=yes + ${time_stamp} Convert Date ${start} epoch exclude_millis=yes + ${time_stamp2} evaluate int(${time_stamp}) + Start Broker + Start Engine + ${result}= Check Connections + Should Be True ${result} msg=Engine and Broker not connected + + ${pid}= Get Process Id e0 + ${content_v2}= Create List [process] [info] [${pid}] Configuration loaded, main loop starting. + ${content_hold}= Create List [${pid}] Configuration loaded, main loop starting. + + ${log}= Catenate SEPARATOR= ${ENGINE_LOG} /config0/centengine.log + ${result1}= Find In Log With Timeout ${log} ${start} ${content_v2} 15 + ${result2}= Find In Log With Timeout ${log} ${start} ${content_hold} 15 + Should Be True ${result1} + Should Be True ${result2} + + Sleep 20s + + Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort} + Log To Console after connection + ${output}= Query select count(*) from logs where output="Configuration loaded, main loop starting." AND ctime>=${time_stamp2}; + Log To Console ${output} + Should Be Equal As Strings ${output} ((2,),) + + Stop Engine + Stop Broker + +LOGV2EF1 + [Documentation] log-v2 enabled hold log disabled check logfile sink + [Tags] Broker Engine log-v2 + Config Engine ${1} + Config Broker rrd + Config Broker central + Config Broker module + Engine Config Set Value ${0} log_legacy_enabled ${0} + Engine Config Set Value ${0} log_v2_enabled ${1} + + ${start}= Get Current Date + Start Broker + Start Engine + ${result}= Check Connections + Should Be True ${result} msg=Engine and Broker not connected + ${pid}= Get Process Id e0 + ${content_v2}= Create List [process] [info] [${pid}] Configuration loaded, main loop starting. + + ${log}= Catenate SEPARATOR= ${ENGINE_LOG} /config0/centengine.log + ${result1}= Find In Log With Timeout ${log} ${start} ${content_v2} 15 + Should Be True ${result1} + Stop Engine + Stop Broker + +LOGV2DF1 + [Documentation] log-v2 disabled hold log enabled check logfile sink + [Tags] Broker Engine log-v2 + Config Engine ${1} + Config Broker rrd + Config Broker central + Config Broker module + Engine Config Set Value ${0} log_legacy_enabled ${1} + Engine Config Set Value ${0} log_v2_enabled ${0} + + ${start}= Get Current Date + Start Broker + Start Engine + ${result}= Check Connections + Should Be True ${result} msg=Engine and Broker not connected + ${pid}= Get Process Id e0 + ${content_hold}= Create List [${pid}] Configuration loaded, main loop starting. + ${content_v2}= Create List [process] [info] [${pid}] Configuration loaded, main loop starting. + + ${log}= Catenate SEPARATOR= ${ENGINE_LOG} /config0/centengine.log + ${result1}= Find In Log With Timeout ${log} ${start} ${content_hold} 15 + ${result2}= Find In Log With Timeout ${log} ${start} ${content_v2} 15 + Should Be True ${result1} + Should Not Be True ${result2} + Stop Engine + Stop Broker + +LOGV2DF2 + [Documentation] log-v2 disabled hold log disabled check logfile sink + [Tags] Broker Engine log-v2 + Config Engine ${1} + Config Broker rrd + Config Broker central + Config Broker module + Engine Config Set Value ${0} log_legacy_enabled ${0} + Engine Config Set Value ${0} log_v2_enabled ${0} + + ${start}= Get Current Date + Start Broker + Start Engine + ${result}= Check Connections + Should Be True ${result} msg=Engine and Broker not connected + ${pid}= Get Process Id e0 + ${content_v2}= Create List [process] [info] [${pid}] Configuration loaded, main loop starting. + ${content_hold}= Create List [${pid}] Configuration loaded, main loop starting. + + ${log}= Catenate SEPARATOR= ${ENGINE_LOG} /config0/centengine.log + ${result1}= Find In Log With Timeout ${log} ${start} ${content_v2} 15 + ${result2}= Find In Log With Timeout ${log} ${start} ${content_hold} 15 + Should Not Be True ${result1} + Should Not Be True ${result2} + Stop Engine + Stop Broker + +LOGV2EF2 + [Documentation] log-v2 enabled hold log enabled check logfile sink + [Tags] Broker Engine log-v2 + Config Engine ${1} + Config Broker rrd + Config Broker central + Config Broker module + Engine Config Set Value ${0} log_legacy_enabled ${1} + Engine Config Set Value ${0} log_v2_enabled ${1} + + ${start}= Get Current Date + Start Broker + Start Engine + ${result}= Check Connections + Should Be True ${result} msg=Engine and Broker not connected + ${pid}= Get Process Id e0 + ${content_v2}= Create List [process] [info] [${pid}] Configuration loaded, main loop starting. + ${content_hold}= Create List [${pid}] Configuration loaded, main loop starting. + + ${log}= Catenate SEPARATOR= ${ENGINE_LOG} /config0/centengine.log + ${result1}= Find In Log With Timeout ${log} ${start} ${content_v2} 15 + ${result2}= Find In Log With Timeout ${log} ${start} ${content_hold} 15 + Should Be True ${result1} + Should Be True ${result2} + Stop Engine + Stop Broker + +LOGV2BE2 + [Documentation] log-v2 enabled hold log enabled check broker sink is equal + [Tags] Broker Engine log-v2 sinkbroker + Config Engine ${1} + Config Broker rrd + Config Broker central + Config Broker module + Engine Config Set Value ${0} log_legacy_enabled ${1} + Engine Config Set Value ${0} log_v2_enabled ${1} + + ${start}= Get Current Date UTC exclude_millis=yes + ${time_stamp} Convert Date ${start} epoch exclude_millis=yes + ${time_stamp2} evaluate int(${time_stamp}) + Start Broker + Start Engine + ${result}= Check Connections + Should Be True ${result} msg=Engine and Broker not connected + + Sleep 3m + + Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort} + Log To Console after connection + @{output}= Query select count(*) as c, output from logs where ctime>=${time_stamp2} group by output having c<>2 + + ${res}= engine log table duplicate ${output} + Should Be True ${res} msg=one or other log are not duplicate in tables logs + + Stop Engine + Stop Broker + +LOGV2FE2 + [Documentation] log-v2 enabled hold log enabled check logfile sink + [Tags] Broker Engine log-v2 + Config Engine ${1} + Config Broker rrd + Config Broker central + Config Broker module + Engine Config Set Value ${0} log_legacy_enabled ${1} + Engine Config Set Value ${0} log_v2_enabled ${1} + Clear Engine Logs + + ${start}= Get Current Date + Start Broker + Start Engine + ${result}= Check Connections + Should Be True ${result} msg=Engine and Broker not connected + ${pid}= Get Process Id e0 + ${content_v2}= Create List [process] [info] [${pid}] Configuration loaded, main loop starting. + ${content_hold}= Create List [${pid}] Configuration loaded, main loop starting. + + Sleep 2m + + ${log}= Catenate SEPARATOR= ${ENGINE_LOG} /config0/centengine.log + ${res}= engine log file duplicate ${log} ${start} + Should Be True ${res} msg=one or other log are not duplicate in logsfile + Stop Engine + Stop Broker + +*** Variables *** +${DBName} centreon_storage +${DBHost} localhost +${DBUser} centreon +${DBPass} centreon +${DBPort} 3306 diff --git a/centreon-tests/resources/Common.py b/centreon-tests/resources/Common.py index 0a08d20ec12..a0058d8993c 100644 --- a/centreon-tests/resources/Common.py +++ b/centreon-tests/resources/Common.py @@ -140,3 +140,32 @@ def clear_retention(): def clear_cache(): getoutput("find /var -name '*.cache.*' -delete") +def engine_log_table_duplicate(result: list): + dup = True + for i in result: + if (i[0] % 2) != 0: + dup = False + return dup + +def engine_log_file_duplicate(log: str, date): + my_date = parser.parse(date) + try: + f = open(log, "r") + lines = f.readlines() + count_true = 0 + count_false = 0 + q = re.compile(r"\[([^\]]*)\] \[([^\]]*)\] \[([^\]]*)\] \[([^\]]*)\]") + for i in range(0, len(lines)): + m = q.search(lines[i]) + if not m: + count_false += 1 + else: + count_true += 1 + if count_false != count_true: + return False + else: + return True + except IOError: + logger.console("The file '{}' does not exist".format(log)) + return False + diff --git a/centreon-tests/resources/Engine.py b/centreon-tests/resources/Engine.py index 4037cd9bda2..5fb637c509f 100755 --- a/centreon-tests/resources/Engine.py +++ b/centreon-tests/resources/Engine.py @@ -94,6 +94,22 @@ def create_centengine(self, id: int, debug_level=0): "log_host_retries=1\n" "log_event_handlers=1\n" "log_external_commands=1\n" + "log_v2_enabled=1\n" + "log_legacy_enabled=1\n" + "log_v2_logger=file\n" + "log_level_functions=info\n" + "log_level_config=info\n" + "log_level_events=info\n" + "log_level_checks=info\n" + "log_level_notifications=info\n" + "log_level_eventbroker=info\n" + "log_level_external_command=info\n" + "log_level_commands=info\n" + "log_level_downtimes=info\n" + "log_level_comments=info\n" + "log_level_macros=info\n" + "log_level_process=info\n" + "log_level_runtime=info\n" "soft_state_dependencies=0\n" "obsess_over_services=0\n" "process_performance_data=0\n" diff --git a/centreon-tests/resources/resources.robot b/centreon-tests/resources/resources.robot index e9c9dbf8509..ffaabb13755 100644 --- a/centreon-tests/resources/resources.robot +++ b/centreon-tests/resources/resources.robot @@ -46,6 +46,7 @@ Start Engine ${count}= Get Engines Count FOR ${idx} IN RANGE 0 ${count} ${alias}= Catenate SEPARATOR= e ${idx} + Log To Console ${alias} ${conf}= Catenate SEPARATOR= /etc/centreon-engine/config ${idx} /centengine.cfg ${log}= Catenate SEPARATOR= /var/log/centreon-engine/config ${idx} ${lib}= Catenate SEPARATOR= /var/lib/centreon-engine/config ${idx}