Skip to content

Commit

Permalink
fix(engine): configuration module has its own logger (#1408)
Browse files Browse the repository at this point in the history
REFS: MON-111552
  • Loading branch information
bouda1 authored Jun 7, 2024
1 parent f442b02 commit 69c90d4
Show file tree
Hide file tree
Showing 24 changed files with 544 additions and 810 deletions.
2 changes: 2 additions & 0 deletions broker/core/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ int main(int argc, char* argv[]) {
config::parser parsr;
config::state conf{parsr.parse(gl_mainconfigfiles.front())};
auto& log_conf = conf.log_conf();
/* It is important to apply the log conf before broker threads start.
* Otherwise we will have issues with concurrent accesses. */
try {
log_v2::instance().apply(log_conf);
} catch (const std::exception& e) {
Expand Down
37 changes: 18 additions & 19 deletions engine/inc/com/centreon/engine/configuration/connector.hh
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
/*
** Copyright 2011-2013,2017 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
** <http://www.gnu.org/licenses/>.
*/

/**
* Copyright 2011-2013,2017-2024 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 : [email protected]
*
*/
#ifndef CCE_CONFIGURATION_CONNECTOR_HH
#define CCE_CONFIGURATION_CONNECTOR_HH

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class state;
*
*/
class extended_conf {
std::shared_ptr<spdlog::logger> _logger;
std::string _path;
struct stat _file_info;
rapidjson::Document _content;
Expand Down
1 change: 1 addition & 0 deletions engine/inc/com/centreon/engine/configuration/object.hh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class object {
bool _should_register;
list_string _templates;
object_type _type;
std::shared_ptr<spdlog::logger> _logger;
};

typedef std::shared_ptr<object> object_ptr;
Expand Down
41 changes: 21 additions & 20 deletions engine/inc/com/centreon/engine/configuration/parser.hh
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
/*
** Copyright 2011-2013,2017 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
** <http://www.gnu.org/licenses/>.
*/

/**
* Copyright 2011-2013,2017-2024 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 : [email protected]
*
*/
#ifndef CCE_CONFIGURATION_PARSER_HH
#define CCE_CONFIGURATION_PARSER_HH

Expand All @@ -39,6 +38,8 @@ namespace com::centreon::engine {

namespace configuration {
class parser {
std::shared_ptr<spdlog::logger> _logger;

public:
enum read_options {
read_commands = (1 << 0),
Expand All @@ -61,7 +62,7 @@ class parser {
};

parser(unsigned int read_options = read_all);
~parser() throw();
~parser() noexcept = default;
void parse(std::string const& path, state& config);

private:
Expand Down
4 changes: 3 additions & 1 deletion engine/inc/com/centreon/engine/configuration/state.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class setter_base {
* to manage configuration data.
*/
class state {
std::shared_ptr<spdlog::logger> _logger;

public:
/**
* @enum state::date_format
Expand Down Expand Up @@ -101,7 +103,7 @@ class state {

state();
state(state const& right);
~state() noexcept;
~state() noexcept = default;
state& operator=(state const& right);
bool operator==(state const& right) const noexcept;
bool operator!=(state const& right) const noexcept;
Expand Down
12 changes: 8 additions & 4 deletions engine/inc/com/centreon/engine/configuration/whitelist.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
#define CCE_CONFIGURATION_WHITELIST_HH

#include "com/centreon/engine/globals.hh"
#include "common/log_v2/log_v2.hh"

namespace com::centreon::engine::configuration {
using com::centreon::common::log_v2::log_v2;

extern const std::string command_blacklist_output;

Expand All @@ -40,6 +42,8 @@ string
*
*/
class whitelist {
std::shared_ptr<spdlog::logger> _logger;

// don't reorder values
enum e_refresh_result { no_directory, empty_directory, no_rule, rules };

Expand Down Expand Up @@ -82,7 +86,8 @@ class whitelist {
};

template <typename string_iter>
whitelist::whitelist(string_iter dir_path_begin, string_iter dir_path_end) {
whitelist::whitelist(string_iter dir_path_begin, string_iter dir_path_end)
: _logger{log_v2::instance().get(log_v2::CONFIG)} {
init_ryml_error_handler();
e_refresh_result res = e_refresh_result::no_directory;
for (; dir_path_begin != dir_path_end; ++dir_path_begin) {
Expand All @@ -93,12 +98,11 @@ whitelist::whitelist(string_iter dir_path_begin, string_iter dir_path_end) {
switch (res) {
case e_refresh_result::no_directory:
SPDLOG_LOGGER_INFO(
config_logger,
"no whitelist directory found, all commands are accepted");
_logger, "no whitelist directory found, all commands are accepted");
break;
case e_refresh_result::empty_directory:
case e_refresh_result::no_rule:
SPDLOG_LOGGER_INFO(config_logger,
SPDLOG_LOGGER_INFO(_logger,
"whitelist directory found, but no restrictions, "
"all commands are accepted");
break;
Expand Down
Loading

0 comments on commit 69c90d4

Please sign in to comment.