From 2e726ddc4d38203d51465f615ca470357e128f02 Mon Sep 17 00:00:00 2001 From: David Boucher Date: Mon, 24 Jun 2024 17:21:59 +0200 Subject: [PATCH] enh(engine/configuration): globals.hh removed from configuration files (#1465) * enh(engine/configuration): config_warnings and config_errors are removed as global variables. * enh(engine/configuration): almost all globals.hh used in configuration are removed * fix(engine/tests): little change in cfg files comments * cleanup(engine/configuration): headers removed when not needed * enh(collect): copyright info are updated automatically now. * fix(engine/configuration): scheduling configuration is fixed. * fix(engine): errors counts were badly propagated. * fix(engine): not needed headers removed * fix(engine): comments removed * fix(engine): fix after review on sched_info_config REFS: MON-34072 --- CMakeLists.txt | 3 + .../centreon/broker/config/applier/state.hh | 2 +- broker/core/src/main.cc | 4 +- .../com/centreon/engine/anomalydetection.hh | 39 +-- engine/inc/com/centreon/engine/config.hh | 41 ++- .../engine/configuration/anomalydetection.hh | 5 +- .../configuration/applier/anomalydetection.hh | 27 +- .../engine/configuration/applier/command.hh | 26 +- .../engine/configuration/applier/connector.hh | 28 +- .../engine/configuration/applier/contact.hh | 28 +- .../configuration/applier/contactgroup.hh | 28 +- .../engine/configuration/applier/host.hh | 43 ++- .../configuration/applier/hostdependency.hh | 4 +- .../configuration/applier/hostescalation.hh | 3 +- .../engine/configuration/applier/hostgroup.hh | 42 +-- .../engine/configuration/applier/service.hh | 42 +-- .../applier/servicedependency.hh | 5 +- .../applier/serviceescalation.hh | 41 +-- .../configuration/applier/servicegroup.hh | 42 +-- .../engine/configuration/applier/state.hh | 26 +- .../configuration/applier/timeperiod.hh | 3 +- .../centreon/engine/configuration/command.hh | 2 +- .../engine/configuration/connector.hh | 2 +- .../centreon/engine/configuration/contact.hh | 2 +- .../engine/configuration/contactgroup.hh | 2 +- .../com/centreon/engine/configuration/host.hh | 4 +- .../engine/configuration/hostdependency.hh | 2 +- .../engine/configuration/hostescalation.hh | 2 +- .../engine/configuration/hostgroup.hh | 2 +- .../centreon/engine/configuration/object.hh | 12 +- .../centreon/engine/configuration/parser.hh | 16 +- .../centreon/engine/configuration/service.hh | 5 +- .../engine/configuration/servicedependency.hh | 2 +- .../engine/configuration/serviceescalation.hh | 2 +- .../engine/configuration/servicegroup.hh | 2 +- .../centreon/engine/configuration/severity.hh | 2 +- .../centreon/engine/configuration/state.hh | 31 +- .../com/centreon/engine/configuration/tag.hh | 2 +- .../engine/configuration/timeperiod.hh | 2 +- .../engine/configuration/whitelist.hh | 1 - engine/inc/com/centreon/engine/contact.hh | 7 +- .../inc/com/centreon/engine/contactgroup.hh | 43 ++- engine/inc/com/centreon/engine/escalation.hh | 2 +- engine/inc/com/centreon/engine/globals.hh | 44 ++- engine/inc/com/centreon/engine/host.hh | 2 +- .../inc/com/centreon/engine/hostdependency.hh | 2 +- .../inc/com/centreon/engine/hostescalation.hh | 2 +- engine/inc/com/centreon/engine/hostgroup.hh | 41 ++- .../inc/com/centreon/engine/macros/defines.hh | 4 - engine/inc/com/centreon/engine/notifier.hh | 4 +- .../retention/applier/anomalydetection.hh | 39 +-- .../com/centreon/engine/retention/program.hh | 1 - engine/inc/com/centreon/engine/service.hh | 2 +- .../com/centreon/engine/servicedependency.hh | 2 +- .../com/centreon/engine/serviceescalation.hh | 2 +- .../inc/com/centreon/engine/servicegroup.hh | 44 +-- engine/inc/com/centreon/engine/timeperiod.hh | 42 +-- engine/inc/com/centreon/engine/xpddefault.hh | 2 - engine/src/anomalydetection.cc | 2 +- engine/src/config.cc | 8 +- engine/src/configuration/anomalydetection.cc | 59 +--- .../configuration/applier/anomalydetection.cc | 5 +- engine/src/configuration/applier/command.cc | 3 +- engine/src/configuration/applier/connector.cc | 3 +- engine/src/configuration/applier/contact.cc | 9 +- .../src/configuration/applier/contactgroup.cc | 5 +- engine/src/configuration/applier/host.cc | 5 +- .../configuration/applier/hostdependency.cc | 5 +- .../configuration/applier/hostescalation.cc | 5 +- engine/src/configuration/applier/hostgroup.cc | 5 +- engine/src/configuration/applier/scheduler.cc | 16 +- engine/src/configuration/applier/service.cc | 6 +- .../applier/servicedependency.cc | 5 +- .../applier/serviceescalation.cc | 5 +- .../src/configuration/applier/servicegroup.cc | 5 +- engine/src/configuration/applier/state.cc | 206 +++++------ .../src/configuration/applier/timeperiod.cc | 5 +- engine/src/configuration/command.cc | 2 +- engine/src/configuration/connector.cc | 2 +- engine/src/configuration/contact.cc | 2 +- engine/src/configuration/contactgroup.cc | 2 +- engine/src/configuration/extended_conf.cc | 1 - engine/src/configuration/host.cc | 40 +-- engine/src/configuration/hostdependency.cc | 10 +- engine/src/configuration/hostescalation.cc | 2 +- engine/src/configuration/hostgroup.cc | 2 +- engine/src/configuration/parser.cc | 11 +- engine/src/configuration/service.cc | 59 +--- engine/src/configuration/servicedependency.cc | 8 +- engine/src/configuration/serviceescalation.cc | 3 +- engine/src/configuration/servicegroup.cc | 2 +- engine/src/configuration/severity.cc | 2 +- engine/src/configuration/state.cc | 330 +----------------- engine/src/configuration/tag.cc | 2 +- engine/src/configuration/timeperiod.cc | 2 +- engine/src/configuration/whitelist.cc | 2 - engine/src/contact.cc | 5 +- engine/src/contactgroup.cc | 27 +- engine/src/diagnostic.cc | 3 +- engine/src/escalation.cc | 4 +- engine/src/events/loop.cc | 5 +- engine/src/globals.cc | 2 - engine/src/host.cc | 5 +- engine/src/hostdependency.cc | 5 +- engine/src/hostescalation.cc | 5 +- engine/src/hostgroup.cc | 28 +- engine/src/main.cc | 29 +- engine/src/notifier.cc | 29 +- engine/src/retention/program.cc | 11 - engine/src/service.cc | 5 +- engine/src/servicedependency.cc | 5 +- engine/src/serviceescalation.cc | 5 +- engine/src/servicegroup.cc | 29 +- engine/src/timeperiod.cc | 4 +- engine/tests/checks/anomalydetection.cc | 9 +- engine/tests/checks/service_check.cc | 7 +- engine/tests/checks/service_retention.cc | 9 +- .../tests/configuration/applier-severity.cc | 3 - .../configuration/applier/applier-command.cc | 9 +- .../applier/applier-connector.cc | 1 - .../configuration/applier/applier-contact.cc | 68 ++-- .../applier/applier-contactgroup.cc | 18 +- .../configuration/applier/applier-global.cc | 17 +- .../configuration/applier/applier-host.cc | 5 +- .../applier/applier-hostdependency.cc | 25 +- .../applier/applier-hostescalation.cc | 6 +- .../applier/applier-hostgroup.cc | 23 +- .../configuration/applier/applier-log.cc | 78 +++-- .../configuration/applier/applier-service.cc | 32 +- .../applier/applier-serviceescalation.cc | 5 +- .../applier/applier-servicegroup.cc | 35 +- .../configuration/applier/applier-state.cc | 38 +- engine/tests/configuration/contact.cc | 3 +- engine/tests/configuration/severity.cc | 15 +- engine/tests/configuration/tag.cc | 16 +- engine/tests/configuration/timeperiod-test.cc | 11 +- engine/tests/configuration/timeperiods.cfg | 99 ++++-- engine/tests/custom_vars/extcmd.cc | 3 +- engine/tests/downtimes/downtime_finder.cc | 15 +- engine/tests/enginerpc/enginerpc.cc | 15 +- .../external_commands/anomalydetection.cc | 10 +- engine/tests/external_commands/service.cc | 16 +- engine/tests/loop/loop.cc | 7 +- engine/tests/macros/macro.cc | 140 ++++---- engine/tests/macros/macro_hostname.cc | 60 ++-- engine/tests/macros/macro_service.cc | 36 +- .../host_downtime_notification.cc | 5 +- .../host_flapping_notification.cc | 8 +- .../notifications/host_normal_notification.cc | 44 ++- .../service_downtime_notification_test.cc | 7 +- .../service_flapping_notification.cc | 7 +- .../service_normal_notification.cc | 16 +- .../service_timeperiod_notification.cc | 66 ++-- .../opentelemetry/open_telemetry_test.cc | 7 +- .../tests/opentelemetry/otl_converter_test.cc | 7 +- 155 files changed, 1271 insertions(+), 1644 deletions(-) mode change 100755 => 100644 engine/tests/macros/macro.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 27dc8e2264f..0291bc4f58f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,9 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_CXX_STANDARD 17) +string(TIMESTAMP CENTREON_CURRENT_YEAR "%Y") +add_definitions(-DCENTREON_CURRENT_YEAR="${CENTREON_CURRENT_YEAR}") + if(DEFINED ENV{VCPKG_ROOT}) set(VCPKG_ROOT "$ENV{VCPKG_ROOT}") message(STATUS "TOOLCHAIN set to ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake") diff --git a/broker/core/inc/com/centreon/broker/config/applier/state.hh b/broker/core/inc/com/centreon/broker/config/applier/state.hh index 6e11f52b6b9..13be6203c44 100644 --- a/broker/core/inc/com/centreon/broker/config/applier/state.hh +++ b/broker/core/inc/com/centreon/broker/config/applier/state.hh @@ -1,5 +1,5 @@ /** - * Copyright 2011-2012, 2021-2022 Centreon + * Copyright 2011-2012, 2021-2024 Centreon * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/broker/core/src/main.cc b/broker/core/src/main.cc index 6dd584e2c0d..a279dcf2c26 100644 --- a/broker/core/src/main.cc +++ b/broker/core/src/main.cc @@ -247,8 +247,8 @@ int main(int argc, char* argv[]) { core_logger->info(" '-D' Generate a diagnostic file."); core_logger->info(" '-h' Print this help."); core_logger->info(" '-v' Print Centreon Broker version."); - core_logger->info("Centreon Broker {}", CENTREON_BROKER_VERSION); - core_logger->info("Copyright 2009-2021 Centreon"); + core_logger->info("Centreon Broker " CENTREON_BROKER_VERSION); + core_logger->info("Copyright 2009-" CENTREON_CURRENT_YEAR " Centreon"); core_logger->info( "License ASL 2.0 "); retval = 0; diff --git a/engine/inc/com/centreon/engine/anomalydetection.hh b/engine/inc/com/centreon/engine/anomalydetection.hh index d11f3038023..29785ed6bb5 100644 --- a/engine/inc/com/centreon/engine/anomalydetection.hh +++ b/engine/inc/com/centreon/engine/anomalydetection.hh @@ -1,22 +1,21 @@ -/* -** Copyright 2020 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 -** . -*/ - +/** + * Copyright 2020-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 : contact@centreon.com + * + */ #ifndef CCE_ANOMALYDETECTION_HH #define CCE_ANOMALYDETECTION_HH @@ -148,7 +147,7 @@ class anomalydetection : public service { void set_status_change(bool status_change); const std::string& get_metric_name() const; const std::string& get_thresholds_file() const; - void resolve(int& w, int& e); + void resolve(uint32_t& w, uint32_t& e); static const pointer_set& get_anomaly(uint64_t dependent_service_id); }; diff --git a/engine/inc/com/centreon/engine/config.hh b/engine/inc/com/centreon/engine/config.hh index 9b65d752f1e..83cb8240bca 100644 --- a/engine/inc/com/centreon/engine/config.hh +++ b/engine/inc/com/centreon/engine/config.hh @@ -1,23 +1,22 @@ -/* -** Copyright 2002-2006 Ethan Galstad -** Copyright 2011-2019 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 -** . -*/ - +/** + * Copyright 2002-2006 Ethan Galstad + * Copyright 2011-2019 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_CONFIG_HH #define CCE_CONFIG_HH @@ -30,7 +29,7 @@ extern "C" { #endif // C++ // Detects circular dependencies and paths. -int pre_flight_circular_check(int* w, int* e); +int pre_flight_circular_check(uint32_t* w, uint32_t* e); #ifdef __cplusplus } diff --git a/engine/inc/com/centreon/engine/configuration/anomalydetection.hh b/engine/inc/com/centreon/engine/configuration/anomalydetection.hh index 3c297fc5b36..fb331007c8e 100644 --- a/engine/inc/com/centreon/engine/configuration/anomalydetection.hh +++ b/engine/inc/com/centreon/engine/configuration/anomalydetection.hh @@ -51,7 +51,7 @@ class anomalydetection : public object { bool operator==(anomalydetection const& other) const noexcept; bool operator!=(anomalydetection const& other) const noexcept; bool operator<(anomalydetection const& other) const noexcept; - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type key() const; void merge(object const& obj) override; bool parse(char const* key, char const* value) override; @@ -144,8 +144,6 @@ class anomalydetection : public object { bool _set_display_name(std::string const& value); bool _set_event_handler(std::string const& value); bool _set_event_handler_enabled(bool value); - bool _set_failure_prediction_enabled(bool value); - bool _set_failure_prediction_options(std::string const& value); bool _set_first_notification_delay(unsigned int value); bool _set_flap_detection_enabled(bool value); bool _set_flap_detection_options(std::string const& value); @@ -165,7 +163,6 @@ class anomalydetection : public object { bool _set_notification_interval(unsigned int value); bool _set_notification_period(std::string const& value); bool _set_obsess_over_service(bool value); - bool _set_parallelize_check(bool value); bool _set_process_perf_data(bool value); bool _set_retain_nonstatus_information(bool value); bool _set_retain_status_information(bool value); diff --git a/engine/inc/com/centreon/engine/configuration/applier/anomalydetection.hh b/engine/inc/com/centreon/engine/configuration/applier/anomalydetection.hh index 88fc8497f6f..7e8df53d199 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/anomalydetection.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/anomalydetection.hh @@ -1,24 +1,24 @@ /** * Copyright 2020-2024 Centreon * - * This file is part of Centreon Engine. + * 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 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. + * 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 * - * You should have received a copy of the GNU General Public License - * along with Centreon Engine. If not, see - * . */ - #ifndef CCE_CONFIGURATION_APPLIER_ANOMALYDETECTION_HH #define CCE_CONFIGURATION_APPLIER_ANOMALYDETECTION_HH +#include "com/centreon/engine/configuration/applier/state.hh" namespace com::centreon::engine { @@ -43,7 +43,8 @@ class anomalydetection { void modify_object(configuration::anomalydetection const& obj); void remove_object(configuration::anomalydetection const& obj); void expand_objects(configuration::state& s); - void resolve_object(configuration::anomalydetection const& obj); + void resolve_object(configuration::anomalydetection const& obj, + error_cnt& err); }; } // namespace applier } // namespace configuration diff --git a/engine/inc/com/centreon/engine/configuration/applier/command.hh b/engine/inc/com/centreon/engine/configuration/applier/command.hh index 9049e571dad..e55cfdde7bf 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/command.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/command.hh @@ -1,24 +1,24 @@ /** * Copyright 2011-2013,2017,2023-2024 Centreon * - * This file is part of Centreon Engine. + * 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 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. + * 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 * - * You should have received a copy of the GNU General Public License - * along with Centreon Engine. If not, see - * . */ - #ifndef CCE_CONFIGURATION_APPLIER_COMMAND_HH #define CCE_CONFIGURATION_APPLIER_COMMAND_HH +#include "com/centreon/engine/configuration/applier/state.hh" namespace com::centreon::engine { @@ -46,7 +46,7 @@ class command { void expand_objects(configuration::state& s); void modify_object(configuration::command const& obj); void remove_object(configuration::command const& obj); - void resolve_object(configuration::command const& obj); + void resolve_object(configuration::command const& obj, error_cnt& err); }; } // namespace applier } // namespace configuration diff --git a/engine/inc/com/centreon/engine/configuration/applier/connector.hh b/engine/inc/com/centreon/engine/configuration/applier/connector.hh index e7e1ea93490..ad82485acaf 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/connector.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/connector.hh @@ -1,24 +1,24 @@ /** - * Copyright 2011-2013,2017,2023 Centreon + * Copyright 2011-2013,2017,2023-2024 Centreon * - * This file is part of Centreon Engine. + * 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 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. + * 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 * - * You should have received a copy of the GNU General Public License - * along with Centreon Engine. If not, see - * . */ - #ifndef CCE_CONFIGURATION_APPLIER_CONNECTOR_HH #define CCE_CONFIGURATION_APPLIER_CONNECTOR_HH +#include "com/centreon/engine/configuration/applier/state.hh" namespace com::centreon::engine { @@ -44,7 +44,7 @@ class connector { void modify_object(const configuration::connector& obj); void remove_object(configuration::connector const& obj); void expand_objects(configuration::state& s); - void resolve_object(configuration::connector const& obj); + void resolve_object(configuration::connector const& obj, error_cnt& err); }; } // namespace applier } // namespace configuration diff --git a/engine/inc/com/centreon/engine/configuration/applier/contact.hh b/engine/inc/com/centreon/engine/configuration/applier/contact.hh index 76a501889f1..3ece9e9ac74 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/contact.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/contact.hh @@ -1,24 +1,24 @@ /** - * Copyright 2011-2013,2017,2023 Centreon + * Copyright 2011-2013,2017,2023-2024 Centreon * - * This file is part of Centreon Engine. + * 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 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. + * 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 * - * You should have received a copy of the GNU General Public License - * along with Centreon Engine. If not, see - * . */ - #ifndef CCE_CONFIGURATION_APPLIER_CONTACT_HH #define CCE_CONFIGURATION_APPLIER_CONTACT_HH +#include "com/centreon/engine/configuration/applier/state.hh" namespace com::centreon::engine { @@ -46,7 +46,7 @@ class contact { void modify_object(const configuration::contact& obj); void remove_object(const configuration::contact& obj); void expand_objects(configuration::state& s); - void resolve_object(const configuration::contact& obj); + void resolve_object(const configuration::contact& obj, error_cnt& err); }; } // namespace applier } // namespace configuration diff --git a/engine/inc/com/centreon/engine/configuration/applier/contactgroup.hh b/engine/inc/com/centreon/engine/configuration/applier/contactgroup.hh index 642220d8933..26f3cadcc73 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/contactgroup.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/contactgroup.hh @@ -1,25 +1,25 @@ /** - * Copyright 2011-2013,2017,2023 Centreon + * Copyright 2011-2013,2017,2023-2024 Centreon * - * This file is part of Centreon Engine. + * 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 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. + * 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 * - * You should have received a copy of the GNU General Public License - * along with Centreon Engine. If not, see - * . */ - #ifndef CCE_CONFIGURATION_APPLIER_CONTACTGROUP_HH #define CCE_CONFIGURATION_APPLIER_CONTACTGROUP_HH +#include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/configuration/contactgroup.hh" namespace com::centreon::engine { @@ -54,7 +54,7 @@ class contactgroup { void modify_object(configuration::contactgroup const& obj); void remove_object(configuration::contactgroup const& obj); void expand_objects(configuration::state& s); - void resolve_object(configuration::contactgroup const& obj); + void resolve_object(configuration::contactgroup const& obj, error_cnt& err); }; } // namespace applier } // namespace configuration diff --git a/engine/inc/com/centreon/engine/configuration/applier/host.hh b/engine/inc/com/centreon/engine/configuration/applier/host.hh index de0537d71b7..51f0f5d1667 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/host.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/host.hh @@ -1,25 +1,24 @@ -/* -** 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 -** . -*/ - +/** + * 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 : contact@centreon.com + * + */ #ifndef CCE_CONFIGURATION_APPLIER_HOST_HH #define CCE_CONFIGURATION_APPLIER_HOST_HH - +#include "com/centreon/engine/configuration/applier/state.hh" namespace com::centreon::engine { @@ -39,11 +38,11 @@ class host { void expand_objects(configuration::state& s); void modify_object(configuration::host const& obj); void remove_object(configuration::host const& obj); - void resolve_object(configuration::host const& obj); + void resolve_object(configuration::host const& obj, error_cnt& err); }; } // namespace applier } // namespace configuration -} +} // namespace com::centreon::engine #endif // !CCE_CONFIGURATION_APPLIER_HOST_HH diff --git a/engine/inc/com/centreon/engine/configuration/applier/hostdependency.hh b/engine/inc/com/centreon/engine/configuration/applier/hostdependency.hh index 49993874a05..5c4f0278a96 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/hostdependency.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/hostdependency.hh @@ -19,6 +19,8 @@ #ifndef CCE_CONFIGURATION_APPLIER_HOSTDEPENDENCY_HH #define CCE_CONFIGURATION_APPLIER_HOSTDEPENDENCY_HH +#include "com/centreon/engine/configuration/applier/state.hh" + namespace com::centreon::engine { namespace configuration { @@ -42,7 +44,7 @@ class hostdependency { void modify_object(configuration::hostdependency const& obj); void remove_object(configuration::hostdependency const& obj); void expand_objects(configuration::state& s); - void resolve_object(configuration::hostdependency const& obj); + void resolve_object(configuration::hostdependency const& obj, error_cnt& err); }; } // namespace applier } // namespace configuration diff --git a/engine/inc/com/centreon/engine/configuration/applier/hostescalation.hh b/engine/inc/com/centreon/engine/configuration/applier/hostescalation.hh index 868f01f7050..36bc1f51f0f 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/hostescalation.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/hostescalation.hh @@ -17,6 +17,7 @@ */ #ifndef CCE_CONFIGURATION_APPLIER_HOSTESCALATION_HH #define CCE_CONFIGURATION_APPLIER_HOSTESCALATION_HH +#include "com/centreon/engine/configuration/applier/state.hh" namespace com::centreon::engine { @@ -43,7 +44,7 @@ class hostescalation { void modify_object(configuration::hostescalation const& obj); void remove_object(configuration::hostescalation const& obj); void expand_objects(configuration::state& s); - void resolve_object(configuration::hostescalation const& obj); + void resolve_object(configuration::hostescalation const& obj, error_cnt& err); }; } // namespace applier } // namespace configuration diff --git a/engine/inc/com/centreon/engine/configuration/applier/hostgroup.hh b/engine/inc/com/centreon/engine/configuration/applier/hostgroup.hh index 3f6101eec20..fed53baec2f 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/hostgroup.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/hostgroup.hh @@ -1,25 +1,25 @@ -/* -** 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 -** . -*/ - +/** + * 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 : contact@centreon.com + * + */ #ifndef CCE_CONFIGURATION_APPLIER_HOSTGROUP_HH #define CCE_CONFIGURATION_APPLIER_HOSTGROUP_HH +#include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/configuration/hostgroup.hh" namespace com::centreon::engine { @@ -39,7 +39,7 @@ class hostgroup { void expand_objects(configuration::state& s); void modify_object(configuration::hostgroup const& obj); void remove_object(configuration::hostgroup const& obj); - void resolve_object(configuration::hostgroup const& obj); + void resolve_object(configuration::hostgroup const& obj, error_cnt& err); private: typedef std::map @@ -53,6 +53,6 @@ class hostgroup { } // namespace applier } // namespace configuration -} +} // namespace com::centreon::engine #endif // !CCE_CONFIGURATION_APPLIER_HOSTGROUP_HH diff --git a/engine/inc/com/centreon/engine/configuration/applier/service.hh b/engine/inc/com/centreon/engine/configuration/applier/service.hh index e8a4acbb8cf..6461ef6055c 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/service.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/service.hh @@ -1,24 +1,24 @@ -/* -** 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 -** . -*/ - +/** + * 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 : contact@centreon.com + * + */ #ifndef CCE_CONFIGURATION_APPLIER_SERVICE_HH #define CCE_CONFIGURATION_APPLIER_SERVICE_HH +#include "com/centreon/engine/configuration/applier/state.hh" namespace com::centreon::engine { @@ -38,7 +38,7 @@ class service { void expand_objects(configuration::state& s); void modify_object(configuration::service const& obj); void remove_object(configuration::service const& obj); - void resolve_object(configuration::service const& obj); + void resolve_object(configuration::service const& obj, error_cnt& err); private: void _expand_service_memberships(configuration::service& obj, @@ -49,6 +49,6 @@ class service { } // namespace applier } // namespace configuration -} +} // namespace com::centreon::engine #endif // !CCE_CONFIGURATION_APPLIER_SERVICE_HH diff --git a/engine/inc/com/centreon/engine/configuration/applier/servicedependency.hh b/engine/inc/com/centreon/engine/configuration/applier/servicedependency.hh index cc25eefe498..06b83ac0448 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/servicedependency.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/servicedependency.hh @@ -19,6 +19,8 @@ #ifndef CCE_CONFIGURATION_APPLIER_SERVICEDEPENDENCY_HH #define CCE_CONFIGURATION_APPLIER_SERVICEDEPENDENCY_HH +#include "com/centreon/engine/configuration/applier/state.hh" + namespace com::centreon::engine { namespace configuration { @@ -47,7 +49,8 @@ class servicedependency { void modify_object(configuration::servicedependency const& obj); void expand_objects(configuration::state& s); void remove_object(configuration::servicedependency const& obj); - void resolve_object(configuration::servicedependency const& obj); + void resolve_object(configuration::servicedependency const& obj, + error_cnt& err); }; } // namespace applier } // namespace configuration diff --git a/engine/inc/com/centreon/engine/configuration/applier/serviceescalation.hh b/engine/inc/com/centreon/engine/configuration/applier/serviceescalation.hh index 8b6b067a414..dfa3ec3d0be 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/serviceescalation.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/serviceescalation.hh @@ -1,24 +1,24 @@ -/* -** Copyright 2011-2013,2017,2023 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 -** . -*/ - +/** + * Copyright 2011-2013,2017,2023-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 : contact@centreon.com + * + */ #ifndef CCE_CONFIGURATION_APPLIER_SERVICEESCALATION_HH #define CCE_CONFIGURATION_APPLIER_SERVICEESCALATION_HH +#include "com/centreon/engine/configuration/applier/state.hh" namespace com::centreon::engine { @@ -48,7 +48,8 @@ class serviceescalation { void modify_object(const configuration::serviceescalation& obj); void remove_object(const configuration::serviceescalation& obj); void expand_objects(configuration::state& s); - void resolve_object(const configuration::serviceescalation& obj); + void resolve_object(const configuration::serviceescalation& obj, + error_cnt& err); }; } // namespace applier } // namespace configuration diff --git a/engine/inc/com/centreon/engine/configuration/applier/servicegroup.hh b/engine/inc/com/centreon/engine/configuration/applier/servicegroup.hh index b542505abbb..a4eefe860f0 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/servicegroup.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/servicegroup.hh @@ -1,25 +1,25 @@ -/* -** 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 -** . -*/ - +/** + * 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 : contact@centreon.com + * + */ #ifndef CCE_CONFIGURATION_APPLIER_SERVICEGROUP_HH #define CCE_CONFIGURATION_APPLIER_SERVICEGROUP_HH +#include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/configuration/servicegroup.hh" namespace com::centreon::engine { @@ -39,7 +39,7 @@ class servicegroup { void expand_objects(configuration::state& s); void modify_object(configuration::servicegroup const& obj); void remove_object(configuration::servicegroup const& obj); - void resolve_object(configuration::servicegroup const& obj); + void resolve_object(configuration::servicegroup const& obj, error_cnt& err); private: typedef std::map - void _apply(difference> const& diff); - void _apply(configuration::state& new_cfg, retention::state& state); + void _apply(difference> const& diff, + error_cnt& err); + void _apply(configuration::state& new_cfg, + retention::state& state, + error_cnt& err); template - void _expand(configuration::state& new_state); + void _expand(configuration::state& new_state, error_cnt& err); void _processing(configuration::state& new_cfg, - retention::state* state = NULL); + error_cnt& err, + retention::state* state = nullptr); template - void _resolve(std::set& cfg); + void _resolve(std::set& cfg, error_cnt& err); std::mutex _apply_lock; state* _config; diff --git a/engine/inc/com/centreon/engine/configuration/applier/timeperiod.hh b/engine/inc/com/centreon/engine/configuration/applier/timeperiod.hh index 206616c6077..3a47437b3e0 100644 --- a/engine/inc/com/centreon/engine/configuration/applier/timeperiod.hh +++ b/engine/inc/com/centreon/engine/configuration/applier/timeperiod.hh @@ -18,6 +18,7 @@ #ifndef CCE_CONFIGURATION_APPLIER_TIMEPERIOD_HH #define CCE_CONFIGURATION_APPLIER_TIMEPERIOD_HH +#include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/timeperiod.hh" // Forward declaration. @@ -49,7 +50,7 @@ class timeperiod { void expand_objects(configuration::state& s); void modify_object(configuration::timeperiod const& obj); void remove_object(configuration::timeperiod const& obj); - void resolve_object(configuration::timeperiod const& obj); + void resolve_object(configuration::timeperiod const& obj, error_cnt& err); }; } // namespace applier } // namespace configuration diff --git a/engine/inc/com/centreon/engine/configuration/command.hh b/engine/inc/com/centreon/engine/configuration/command.hh index ebca31ad7f3..2ad5e998983 100644 --- a/engine/inc/com/centreon/engine/configuration/command.hh +++ b/engine/inc/com/centreon/engine/configuration/command.hh @@ -35,7 +35,7 @@ class command : public object { bool operator==(command const& right) const throw(); bool operator!=(command const& right) const throw(); bool operator<(command const& right) const throw(); - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type const& key() const throw(); void merge(object const& obj) override; bool parse(char const* key, char const* value) override; diff --git a/engine/inc/com/centreon/engine/configuration/connector.hh b/engine/inc/com/centreon/engine/configuration/connector.hh index b9c784465e5..adc1d5601a1 100644 --- a/engine/inc/com/centreon/engine/configuration/connector.hh +++ b/engine/inc/com/centreon/engine/configuration/connector.hh @@ -35,7 +35,7 @@ class connector : public object { bool operator==(connector const& right) const throw(); bool operator!=(connector const& right) const throw(); bool operator<(connector const& right) const throw(); - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type const& key() const throw(); void merge(object const& obj) override; bool parse(char const* key, char const* value) override; diff --git a/engine/inc/com/centreon/engine/configuration/contact.hh b/engine/inc/com/centreon/engine/configuration/contact.hh index 987dcdb2b77..324f20c80a5 100644 --- a/engine/inc/com/centreon/engine/configuration/contact.hh +++ b/engine/inc/com/centreon/engine/configuration/contact.hh @@ -44,7 +44,7 @@ class contact : public object { bool operator==(contact const& other) const noexcept; bool operator!=(contact const& other) const noexcept; bool operator<(contact const& other) const noexcept; - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type const& key() const noexcept; void merge(object const& obj) override; bool parse(const char* key, const char* value) override; diff --git a/engine/inc/com/centreon/engine/configuration/contactgroup.hh b/engine/inc/com/centreon/engine/configuration/contactgroup.hh index 0eaae3987df..356731a8c34 100644 --- a/engine/inc/com/centreon/engine/configuration/contactgroup.hh +++ b/engine/inc/com/centreon/engine/configuration/contactgroup.hh @@ -36,7 +36,7 @@ class contactgroup : public object { bool operator==(contactgroup const& right) const noexcept; bool operator!=(contactgroup const& right) const noexcept; bool operator<(contactgroup const& right) const noexcept; - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type const& key() const noexcept; void merge(object const& obj) override; bool parse(char const* key, char const* value) override; diff --git a/engine/inc/com/centreon/engine/configuration/host.hh b/engine/inc/com/centreon/engine/configuration/host.hh index f91cfb8e844..c6498e666b2 100644 --- a/engine/inc/com/centreon/engine/configuration/host.hh +++ b/engine/inc/com/centreon/engine/configuration/host.hh @@ -50,7 +50,7 @@ class host : public object { bool operator==(host const& other) const noexcept; bool operator!=(host const& other) const noexcept; bool operator<(host const& other) const noexcept; - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type key() const noexcept; void merge(object const& obj) override; bool parse(char const* key, char const* value) override; @@ -134,8 +134,6 @@ class host : public object { bool _set_display_name(std::string const& value); bool _set_event_handler(std::string const& value); bool _set_event_handler_enabled(bool value); - bool _set_failure_prediction_enabled(bool value); - bool _set_failure_prediction_options(std::string const& value); bool _set_first_notification_delay(unsigned int value); bool _set_flap_detection_enabled(bool value); bool _set_flap_detection_options(std::string const& value); diff --git a/engine/inc/com/centreon/engine/configuration/hostdependency.hh b/engine/inc/com/centreon/engine/configuration/hostdependency.hh index 1f708e47c94..e7862ee2e59 100644 --- a/engine/inc/com/centreon/engine/configuration/hostdependency.hh +++ b/engine/inc/com/centreon/engine/configuration/hostdependency.hh @@ -52,7 +52,7 @@ class hostdependency : public object { bool operator==(hostdependency const& right) const throw(); bool operator!=(hostdependency const& right) const throw(); bool operator<(hostdependency const& right) const; - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type const& key() const throw(); void merge(object const& obj) override; bool parse(char const* key, char const* value) override; diff --git a/engine/inc/com/centreon/engine/configuration/hostescalation.hh b/engine/inc/com/centreon/engine/configuration/hostescalation.hh index 87b6038e9bd..ce8a6ca90ef 100644 --- a/engine/inc/com/centreon/engine/configuration/hostescalation.hh +++ b/engine/inc/com/centreon/engine/configuration/hostescalation.hh @@ -45,7 +45,7 @@ class hostescalation : public object { bool operator==(hostescalation const& right) const throw(); bool operator!=(hostescalation const& right) const throw(); bool operator<(hostescalation const& right) const; - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type const& key() const throw(); void merge(object const& obj) override; bool parse(char const* key, char const* value) override; diff --git a/engine/inc/com/centreon/engine/configuration/hostgroup.hh b/engine/inc/com/centreon/engine/configuration/hostgroup.hh index e3d5bd538f3..680abb59949 100644 --- a/engine/inc/com/centreon/engine/configuration/hostgroup.hh +++ b/engine/inc/com/centreon/engine/configuration/hostgroup.hh @@ -37,7 +37,7 @@ class hostgroup : public object { bool operator==(hostgroup const& right) const throw(); bool operator!=(hostgroup const& right) const throw(); bool operator<(hostgroup const& right) const throw(); - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type const& key() const throw(); void merge(object const& obj) override; bool parse(char const* key, char const* value) override; diff --git a/engine/inc/com/centreon/engine/configuration/object.hh b/engine/inc/com/centreon/engine/configuration/object.hh index 534f467c7c0..db155f96e87 100644 --- a/engine/inc/com/centreon/engine/configuration/object.hh +++ b/engine/inc/com/centreon/engine/configuration/object.hh @@ -26,6 +26,16 @@ typedef std::set set_string; namespace com::centreon::engine { namespace configuration { + +/** + * @brief Error counter, it contains two attributes, one for warnings and + * another for errors. + */ +struct error_cnt { + uint32_t config_warnings = 0; + uint32_t config_errors = 0; +}; + class object { public: enum object_type { @@ -55,7 +65,7 @@ class object { object& operator=(object const& right); bool operator==(object const& right) const noexcept; bool operator!=(object const& right) const noexcept; - virtual void check_validity() const = 0; + virtual void check_validity(error_cnt& err) const = 0; static std::shared_ptr create(std::string const& type_name); virtual void merge(object const& obj) = 0; const std::string& name() const noexcept; diff --git a/engine/inc/com/centreon/engine/configuration/parser.hh b/engine/inc/com/centreon/engine/configuration/parser.hh index ee6b3e41048..42d9c052db3 100644 --- a/engine/inc/com/centreon/engine/configuration/parser.hh +++ b/engine/inc/com/centreon/engine/configuration/parser.hh @@ -20,23 +20,13 @@ #define CCE_CONFIGURATION_PARSER_HH #include -#include "com/centreon/engine/configuration/command.hh" -#include "com/centreon/engine/configuration/connector.hh" -#include "com/centreon/engine/configuration/contact.hh" #include "com/centreon/engine/configuration/file_info.hh" -#include "com/centreon/engine/configuration/host.hh" -#include "com/centreon/engine/configuration/hostdependency.hh" -#include "com/centreon/engine/configuration/hostescalation.hh" -#include "com/centreon/engine/configuration/object.hh" -#include "com/centreon/engine/configuration/service.hh" -#include "com/centreon/engine/configuration/servicedependency.hh" -#include "com/centreon/engine/configuration/serviceescalation.hh" #include "com/centreon/engine/configuration/state.hh" -#include "com/centreon/engine/configuration/timeperiod.hh" namespace com::centreon::engine { namespace configuration { + class parser { std::shared_ptr _logger; @@ -61,7 +51,7 @@ class parser { parser(unsigned int read_options = read_all); ~parser() noexcept = default; - void parse(const std::string& path, state& config); + void parse(const std::string& path, state& config, error_cnt& err); private: typedef void (parser::*store)(object_ptr obj); @@ -90,7 +80,7 @@ class parser { void _parse_global_configuration(const std::string& path); void _parse_object_definitions(const std::string& path); void _parse_resource_file(std::string const& path); - void _resolve_template(); + void _resolve_template(error_cnt& err); void _store_into_list(object_ptr obj); template void _store_into_map(object_ptr obj); diff --git a/engine/inc/com/centreon/engine/configuration/service.hh b/engine/inc/com/centreon/engine/configuration/service.hh index 90ff383f511..109d6878ef8 100644 --- a/engine/inc/com/centreon/engine/configuration/service.hh +++ b/engine/inc/com/centreon/engine/configuration/service.hh @@ -47,7 +47,7 @@ class service : public object { bool operator==(service const& other) const noexcept; bool operator!=(service const& other) const noexcept; bool operator<(service const& other) const noexcept; - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type key() const; void merge(object const& obj) override; bool parse(char const* key, char const* value) override; @@ -134,8 +134,6 @@ class service : public object { bool _set_display_name(std::string const& value); bool _set_event_handler(std::string const& value); bool _set_event_handler_enabled(bool value); - bool _set_failure_prediction_enabled(bool value); - bool _set_failure_prediction_options(std::string const& value); bool _set_first_notification_delay(unsigned int value); bool _set_flap_detection_enabled(bool value); bool _set_flap_detection_options(std::string const& value); @@ -155,7 +153,6 @@ class service : public object { bool _set_notification_interval(unsigned int value); bool _set_notification_period(std::string const& value); bool _set_obsess_over_service(bool value); - bool _set_parallelize_check(bool value); bool _set_process_perf_data(bool value); bool _set_retain_nonstatus_information(bool value); bool _set_retain_status_information(bool value); diff --git a/engine/inc/com/centreon/engine/configuration/servicedependency.hh b/engine/inc/com/centreon/engine/configuration/servicedependency.hh index 61ea8f77c10..7cb9c5a1594 100644 --- a/engine/inc/com/centreon/engine/configuration/servicedependency.hh +++ b/engine/inc/com/centreon/engine/configuration/servicedependency.hh @@ -53,7 +53,7 @@ class servicedependency : public object { bool operator==(servicedependency const& right) const throw(); bool operator!=(servicedependency const& right) const throw(); bool operator<(servicedependency const& right) const; - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type const& key() const throw(); void merge(object const& obj) override; bool parse(char const* key, char const* value) override; diff --git a/engine/inc/com/centreon/engine/configuration/serviceescalation.hh b/engine/inc/com/centreon/engine/configuration/serviceescalation.hh index e093fce58e5..7dcdb838bc5 100644 --- a/engine/inc/com/centreon/engine/configuration/serviceescalation.hh +++ b/engine/inc/com/centreon/engine/configuration/serviceescalation.hh @@ -71,7 +71,7 @@ class serviceescalation : public object { bool operator==(serviceescalation const& right) const noexcept; bool operator!=(serviceescalation const& right) const noexcept; bool operator<(serviceescalation const& right) const; - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type const& key() const noexcept; void merge(object const& obj) override; bool parse(char const* key, char const* value) override; diff --git a/engine/inc/com/centreon/engine/configuration/servicegroup.hh b/engine/inc/com/centreon/engine/configuration/servicegroup.hh index 879eacf999e..caa2147f79e 100644 --- a/engine/inc/com/centreon/engine/configuration/servicegroup.hh +++ b/engine/inc/com/centreon/engine/configuration/servicegroup.hh @@ -39,7 +39,7 @@ class servicegroup : public object { bool operator==(servicegroup const& right) const throw(); bool operator!=(servicegroup const& right) const throw(); bool operator<(servicegroup const& right) const throw(); - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type const& key() const throw(); void merge(object const& obj) override; bool parse(char const* key, char const* value) override; diff --git a/engine/inc/com/centreon/engine/configuration/severity.hh b/engine/inc/com/centreon/engine/configuration/severity.hh index 5cd3e04e7e7..78f290c5540 100644 --- a/engine/inc/com/centreon/engine/configuration/severity.hh +++ b/engine/inc/com/centreon/engine/configuration/severity.hh @@ -55,7 +55,7 @@ class severity : public object { bool operator==(const severity& other) const noexcept; bool operator!=(const severity& other) const noexcept; bool operator<(const severity& other) const noexcept; - void check_validity() const override; + void check_validity(error_cnt& err) const override; const key_type& key() const noexcept; void merge(const object& obj) override; bool parse(const char* key, const char* value) override; diff --git a/engine/inc/com/centreon/engine/configuration/state.hh b/engine/inc/com/centreon/engine/configuration/state.hh index c2e412f1ea2..33af15d6389 100644 --- a/engine/inc/com/centreon/engine/configuration/state.hh +++ b/engine/inc/com/centreon/engine/configuration/state.hh @@ -74,6 +74,12 @@ class state { std::shared_ptr _logger; public: + struct sched_info_config { + double host_inter_check_delay; + double service_inter_check_delay; + int32_t service_interleave_factor; + } _scheduling_info; + /** * @enum state::date_format * Date format types @@ -461,6 +467,7 @@ class state { void use_timezone(std::string const& value); bool use_true_regexp_matching() const noexcept; void use_true_regexp_matching(bool value); + sched_info_config& sched_info_config() { return _scheduling_info; } bool use_send_recovery_notifications_anyways() const; void use_send_recovery_notifications_anyways(bool value); bool use_host_down_disable_service_checks() const; @@ -475,43 +482,19 @@ class state { private: static void _init_setter(); - void _set_aggregate_status_updates(std::string const& value); - void _set_auth_file(std::string const& value); - void _set_bare_update_check(std::string const& value); void _set_broker_module(std::string const& value); void _set_cfg_dir(std::string const& value); void _set_cfg_file(std::string const& value); - void _set_check_for_updates(std::string const& value); - void _set_child_processes_fork_twice(std::string const& value); void _set_command_check_interval(std::string const& value); - void _set_comment_file(std::string const& value); - void _set_daemon_dumps_core(std::string const& value); void _set_date_format(std::string const& value); - void _set_downtime_file(std::string const& value); - void _set_enable_embedded_perl(std::string const& value); - void _set_enable_failure_prediction(std::string const& value); void _set_event_broker_options(std::string const& value); - void _set_free_child_process_memory(std::string const& value); void _set_host_inter_check_delay_method(std::string const& value); void _set_host_perfdata_file_mode(std::string const& value); - void _set_lock_file(std::string const& value); - void _set_log_archive_path(std::string const& value); - void _set_log_initial_states(std::string const& value); - void _set_log_rotation_method(std::string const& value); - void _set_nagios_group(std::string const& value); - void _set_nagios_user(std::string const& value); void _set_object_cache_file(std::string const& value); - void _set_p1_file(std::string const& value); - void _set_precached_object_file(std::string const& value); void _set_resource_file(std::string const& value); - void _set_retained_process_service_attribute_mask(std::string const& value); - void _set_retained_service_attribute_mask(std::string const& value); void _set_service_inter_check_delay_method(std::string const& value); void _set_service_interleave_factor_method(std::string const& value); void _set_service_perfdata_file_mode(std::string const& value); - void _set_temp_file(std::string const& value); - void _set_temp_path(std::string const& value); - void _set_use_embedded_perl_implicitly(std::string const& value); bool _accept_passive_host_checks; bool _accept_passive_service_checks; diff --git a/engine/inc/com/centreon/engine/configuration/tag.hh b/engine/inc/com/centreon/engine/configuration/tag.hh index c1697c2b3df..d40d9c9a14f 100644 --- a/engine/inc/com/centreon/engine/configuration/tag.hh +++ b/engine/inc/com/centreon/engine/configuration/tag.hh @@ -55,7 +55,7 @@ class tag : public object { bool operator==(const tag& other) const noexcept; bool operator!=(const tag& other) const noexcept; bool operator<(const tag& other) const noexcept; - void check_validity() const override; + void check_validity(error_cnt& err) const override; const key_type& key() const noexcept; void merge(const object& obj) override; bool parse(const char* key, const char* value) override; diff --git a/engine/inc/com/centreon/engine/configuration/timeperiod.hh b/engine/inc/com/centreon/engine/configuration/timeperiod.hh index 7b09612bdf4..b179a71d113 100644 --- a/engine/inc/com/centreon/engine/configuration/timeperiod.hh +++ b/engine/inc/com/centreon/engine/configuration/timeperiod.hh @@ -41,7 +41,7 @@ class timeperiod : public object { bool operator==(timeperiod const& right) const; bool operator!=(timeperiod const& right) const; bool operator<(timeperiod const& right) const; - void check_validity() const override; + void check_validity(error_cnt& err) const override; key_type const& key() const throw(); void merge(object const& obj) override; bool parse(char const* key, char const* value) override; diff --git a/engine/inc/com/centreon/engine/configuration/whitelist.hh b/engine/inc/com/centreon/engine/configuration/whitelist.hh index 7936621be18..26991502388 100644 --- a/engine/inc/com/centreon/engine/configuration/whitelist.hh +++ b/engine/inc/com/centreon/engine/configuration/whitelist.hh @@ -19,7 +19,6 @@ #ifndef CCE_CONFIGURATION_WHITELIST_HH #define CCE_CONFIGURATION_WHITELIST_HH -#include "com/centreon/engine/globals.hh" #include "common/log_v2/log_v2.hh" namespace com::centreon::engine::configuration { diff --git a/engine/inc/com/centreon/engine/contact.hh b/engine/inc/com/centreon/engine/contact.hh index 8476a312443..b9f3b26d9c7 100644 --- a/engine/inc/com/centreon/engine/contact.hh +++ b/engine/inc/com/centreon/engine/contact.hh @@ -20,9 +20,6 @@ #ifndef CCE_CONTACT_HH #define CCE_CONTACT_HH -#include -#include "com/centreon/engine/contactgroup.hh" -#include "com/centreon/engine/customvariable.hh" #include "com/centreon/engine/notifier.hh" /* Max number of custom addresses a contact can have. */ @@ -127,7 +124,7 @@ class contact { bool should_be_notified(notifier::notification_category cat, notifier::reason_type type, notifier const& notif) const; - void resolve(int& w, int& e); + void resolve(uint32_t& w, uint32_t& e); map_customvar const& get_custom_variables() const; map_customvar& get_custom_variables(); timeperiod* get_host_notification_period_ptr() const; @@ -180,7 +177,7 @@ class contact { timeperiod* _service_notification_period_ptr; }; -} +} // namespace com::centreon::engine std::shared_ptr add_contact( std::string const& name, diff --git a/engine/inc/com/centreon/engine/contactgroup.hh b/engine/inc/com/centreon/engine/contactgroup.hh index 1a297aabe97..66345a29e60 100644 --- a/engine/inc/com/centreon/engine/contactgroup.hh +++ b/engine/inc/com/centreon/engine/contactgroup.hh @@ -1,22 +1,21 @@ -/* -** Copyright 2011-2019 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 -** . -*/ - +/** + * Copyright 2011-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 : contact@centreon.com + * + */ #ifndef CCE_OBJECTS_CONTACTGROUP_HH #define CCE_OBJECTS_CONTACTGROUP_HH @@ -33,7 +32,7 @@ class contactgroup; namespace configuration { class contactgroup; } -} +} // namespace com::centreon::engine using contactgroup_map = absl::flat_hash_map. -*/ - +/** + * Copyright 1999-2009 Ethan Galstad + * Copyright 2009-2010 Nagios Core Development Team and Community Contributors + * Copyright 2011-2024 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_GLOBALS_HH #define CCE_GLOBALS_HH @@ -33,9 +32,6 @@ #include "com/centreon/engine/utils.hh" #include "common/log_v2/log_v2.hh" -extern int config_errors; -extern int config_warnings; - /* Start/Restart statistics */ extern com::centreon::engine::restart_stats restart_apply_stats; diff --git a/engine/inc/com/centreon/engine/host.hh b/engine/inc/com/centreon/engine/host.hh index 61c533c27ea..20366362956 100644 --- a/engine/inc/com/centreon/engine/host.hh +++ b/engine/inc/com/centreon/engine/host.hh @@ -245,7 +245,7 @@ class host : public notifier { timeperiod* get_notification_timeperiod() const override; bool get_notify_on_current_state() const override; bool is_in_downtime() const override; - void resolve(int& w, int& e); + void resolve(uint32_t& w, uint32_t& e); void set_check_command_ptr( const std::shared_ptr& cmd) override; diff --git a/engine/inc/com/centreon/engine/hostdependency.hh b/engine/inc/com/centreon/engine/hostdependency.hh index ec72dca3651..7ee9b336304 100644 --- a/engine/inc/com/centreon/engine/hostdependency.hh +++ b/engine/inc/com/centreon/engine/hostdependency.hh @@ -57,7 +57,7 @@ class hostdependency : public dependency { bool check_for_circular_hostdependency_path(hostdependency* dep, types dependency_type); - void resolve(int& w, int& e); + void resolve(uint32_t& w, uint32_t& e); bool get_fail_on(int state) const override; bool operator==(hostdependency const& obj) = delete; diff --git a/engine/inc/com/centreon/engine/hostescalation.hh b/engine/inc/com/centreon/engine/hostescalation.hh index efdb316c222..f5e24720c18 100644 --- a/engine/inc/com/centreon/engine/hostescalation.hh +++ b/engine/inc/com/centreon/engine/hostescalation.hh @@ -48,7 +48,7 @@ class hostescalation : public escalation { std::string const& get_hostname() const; bool is_viable(int state, uint32_t notification_number) const override; - void resolve(int& w, int& e) override; + void resolve(uint32_t& w, uint32_t& e) override; bool matches(const configuration::hostescalation& obj) const; diff --git a/engine/inc/com/centreon/engine/hostgroup.hh b/engine/inc/com/centreon/engine/hostgroup.hh index 52fa4a00d7a..7d12ef50a06 100644 --- a/engine/inc/com/centreon/engine/hostgroup.hh +++ b/engine/inc/com/centreon/engine/hostgroup.hh @@ -1,22 +1,21 @@ -/* -** Copyright 2011-2019 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 -** . -*/ - +/** + * Copyright 2011-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 : contact@centreon.com + * + */ #ifndef CCE_OBJECTS_HOSTGROUP_HH #define CCE_OBJECTS_HOSTGROUP_HH @@ -55,7 +54,7 @@ class hostgroup { void set_action_url(std::string const& action_url); bool operator==(hostgroup const& obj) = delete; bool operator!=(hostgroup const& obj1) = delete; - void resolve(int& w, int& e); + void resolve(uint32_t& w, uint32_t& e); host_map_unsafe members; @@ -69,7 +68,7 @@ class hostgroup { std::string _notes_url; std::string _action_url; }; -} +} // namespace com::centreon::engine std::ostream& operator<<(std::ostream& os, com::centreon::engine::hostgroup const& obj); diff --git a/engine/inc/com/centreon/engine/macros/defines.hh b/engine/inc/com/centreon/engine/macros/defines.hh index cb09fa59892..0d92a4634a7 100644 --- a/engine/inc/com/centreon/engine/macros/defines.hh +++ b/engine/inc/com/centreon/engine/macros/defines.hh @@ -22,11 +22,7 @@ #define CCE_MACROS_DEFINES_HH_ #include "com/centreon/engine/contact.hh" -#include "com/centreon/engine/contactgroup.hh" -#include "com/centreon/engine/customvariable.hh" -#include "com/centreon/engine/host.hh" #include "com/centreon/engine/hostgroup.hh" -#include "com/centreon/engine/service.hh" #include "com/centreon/engine/servicegroup.hh" // Length Limitations diff --git a/engine/inc/com/centreon/engine/notifier.hh b/engine/inc/com/centreon/engine/notifier.hh index 329eb98b137..8705f069bbb 100644 --- a/engine/inc/com/centreon/engine/notifier.hh +++ b/engine/inc/com/centreon/engine/notifier.hh @@ -258,7 +258,7 @@ class notifier : public checkable { const absl::flat_hash_map& contacts() const noexcept; contactgroup_map_unsafe& get_contactgroups() noexcept; contactgroup_map_unsafe const& get_contactgroups() const noexcept; - void resolve(int& w, int& e); + void resolve(uint32_t& w, uint32_t& e); std::array const& get_state_history() const; std::array& get_state_history(); std::array, 6> const& @@ -340,7 +340,7 @@ class notifier : public checkable { int _pending_flex_downtime; }; -} +} // namespace com::centreon::engine bool is_contact_for_notifier(com::centreon::engine::notifier* notif, com::centreon::engine::contact* cntct); diff --git a/engine/inc/com/centreon/engine/retention/applier/anomalydetection.hh b/engine/inc/com/centreon/engine/retention/applier/anomalydetection.hh index 5a1b7e57f3e..2a1e7be6cc4 100644 --- a/engine/inc/com/centreon/engine/retention/applier/anomalydetection.hh +++ b/engine/inc/com/centreon/engine/retention/applier/anomalydetection.hh @@ -1,22 +1,21 @@ -/* -** Copyright 2022 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 -** . -*/ - +/** + * Copyright 2022-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 : contact@centreon.com + * + */ #ifndef CCE_RETENTION_APPLIER_ANOMALYDETECTION_HH #define CCE_RETENTION_APPLIER_ANOMALYDETECTION_HH @@ -49,6 +48,6 @@ class anomalydetection { } // namespace applier } // namespace retention -} +} // namespace com::centreon::engine #endif // !CCE_RETENTION_APPLIER_ANOMALYDETECTION_HH diff --git a/engine/inc/com/centreon/engine/retention/program.hh b/engine/inc/com/centreon/engine/retention/program.hh index 565345aa2d4..d65832bf65b 100644 --- a/engine/inc/com/centreon/engine/retention/program.hh +++ b/engine/inc/com/centreon/engine/retention/program.hh @@ -71,7 +71,6 @@ class program : public object { bool _set_check_host_freshness(bool value); bool _set_check_service_freshness(bool value); bool _set_enable_event_handlers(bool value); - bool _set_enable_failure_prediction(bool value); bool _set_enable_flap_detection(bool value); bool _set_enable_notifications(bool value); bool _set_global_host_event_handler(std::string const& value); diff --git a/engine/inc/com/centreon/engine/service.hh b/engine/inc/com/centreon/engine/service.hh index b602224dc46..c2c1e853c7f 100644 --- a/engine/inc/com/centreon/engine/service.hh +++ b/engine/inc/com/centreon/engine/service.hh @@ -205,7 +205,7 @@ class service : public notifier { static void check_for_orphaned(); static void check_result_freshness(); bool is_in_downtime() const override; - void resolve(int& w, int& e); + void resolve(uint32_t& w, uint32_t& e); std::list const& get_parent_groups() const; std::list& get_parent_groups(); diff --git a/engine/inc/com/centreon/engine/servicedependency.hh b/engine/inc/com/centreon/engine/servicedependency.hh index 94647358442..de2b2b733a3 100644 --- a/engine/inc/com/centreon/engine/servicedependency.hh +++ b/engine/inc/com/centreon/engine/servicedependency.hh @@ -76,7 +76,7 @@ class servicedependency : public dependency { bool check_for_circular_servicedependency_path(servicedependency* dep, types dependency_type); - void resolve(int& w, int& e); + void resolve(uint32_t& w, uint32_t& e); bool get_fail_on(int state) const override; bool operator==(servicedependency const& obj) = delete; diff --git a/engine/inc/com/centreon/engine/serviceescalation.hh b/engine/inc/com/centreon/engine/serviceescalation.hh index abe959912cd..f634f32b83c 100644 --- a/engine/inc/com/centreon/engine/serviceescalation.hh +++ b/engine/inc/com/centreon/engine/serviceescalation.hh @@ -52,7 +52,7 @@ class serviceescalation : public escalation { std::string const& get_hostname() const; std::string const& get_description() const; bool is_viable(int state, uint32_t notification_number) const override; - void resolve(int& w, int& e) override; + void resolve(uint32_t& w, uint32_t& e) override; bool matches(const configuration::serviceescalation& obj) const; static serviceescalation_mmap serviceescalations; diff --git a/engine/inc/com/centreon/engine/servicegroup.hh b/engine/inc/com/centreon/engine/servicegroup.hh index 653c4324dc8..25308bb1141 100644 --- a/engine/inc/com/centreon/engine/servicegroup.hh +++ b/engine/inc/com/centreon/engine/servicegroup.hh @@ -1,22 +1,22 @@ -/* -** Copyright 2011-2013 Merethis -** -** 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 -** . -*/ - +/** + * Copyright 2011-2013 Merethis + * Copyright 2014-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 : contact@centreon.com + * + */ #ifndef CCE_OBJECTS_SERVICEGROUP_HH #define CCE_OBJECTS_SERVICEGROUP_HH @@ -26,7 +26,7 @@ namespace com::centreon::engine { class host; class servicegroup; -} +} // namespace com::centreon::engine using servicegroup_map = absl::flat_hash_map. -*/ - +/** + * Copyright 2011-2013 Merethis + * Copyright 2014-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 : contact@centreon.com + * + */ #ifndef CCE_OBJECTS_TIMEPERIOD_HH #define CCE_OBJECTS_TIMEPERIOD_HH @@ -52,7 +52,7 @@ class timeperiod { time_t* invalid_time, bool notif_timeperiod); - void resolve(int& w, int& e); + void resolve(uint32_t& w, uint32_t& e); bool operator==(timeperiod const& obj) throw(); bool operator!=(timeperiod const& obj) throw(); @@ -68,7 +68,7 @@ class timeperiod { timeperiodexclusion _exclusions; }; -} +} // namespace com::centreon::engine bool check_time_against_period(time_t test_time, com::centreon::engine::timeperiod* tperiod); diff --git a/engine/inc/com/centreon/engine/xpddefault.hh b/engine/inc/com/centreon/engine/xpddefault.hh index dc78ca827e7..6fce4315790 100644 --- a/engine/inc/com/centreon/engine/xpddefault.hh +++ b/engine/inc/com/centreon/engine/xpddefault.hh @@ -21,9 +21,7 @@ #ifndef CCE_XPDDEFAULT_HH #define CCE_XPDDEFAULT_HH -#include "com/centreon/engine/host.hh" #include "com/centreon/engine/macros/defines.hh" -#include "com/centreon/engine/service.hh" #ifdef __cplusplus extern "C" { diff --git a/engine/src/anomalydetection.cc b/engine/src/anomalydetection.cc index 2aca85a1275..df1a6956e69 100644 --- a/engine/src/anomalydetection.cc +++ b/engine/src/anomalydetection.cc @@ -1397,7 +1397,7 @@ const std::string& anomalydetection::get_thresholds_file() const { return _thresholds_file; } -void anomalydetection::resolve(int& w, int& e) { +void anomalydetection::resolve(uint32_t& w, uint32_t& e) { set_check_period(_dependent_service->check_period()); service::resolve(w, e); } diff --git a/engine/src/config.cc b/engine/src/config.cc index 87cd3d99014..cdbb2421cb2 100644 --- a/engine/src/config.cc +++ b/engine/src/config.cc @@ -99,10 +99,10 @@ static int dfs_host_path(host* root) { } /* check for circular paths and dependencies */ -int pre_flight_circular_check(int* w, int* e) { - int found(false); - int warnings(0); - int errors(0); +int pre_flight_circular_check(uint32_t* w, uint32_t* e) { + int found = false; + uint32_t warnings = 0; + uint32_t errors = 0; /* bail out if we aren't supposed to verify circular paths */ if (!verify_circular_paths) diff --git a/engine/src/configuration/anomalydetection.cc b/engine/src/configuration/anomalydetection.cc index 8e5c84f74ea..30ba75b5a32 100644 --- a/engine/src/configuration/anomalydetection.cc +++ b/engine/src/configuration/anomalydetection.cc @@ -23,9 +23,6 @@ #include #include "com/centreon/exceptions/msg_fmt.hh" -extern int config_warnings; -extern int config_errors; - using namespace com::centreon; using namespace com::centreon::engine::configuration; using com::centreon::exceptions::msg_fmt; @@ -56,8 +53,6 @@ std::unordered_map const SETTER(std::string const&, _set_notification_period)}, {"contact_groups", SETTER(std::string const&, _set_contactgroups)}, {"contacts", SETTER(std::string const&, _set_contacts)}, - {"failure_prediction_options", - SETTER(std::string const&, _set_failure_prediction_options)}, {"notes", SETTER(std::string const&, _set_notes)}, {"notes_url", SETTER(std::string const&, _set_notes_url)}, {"action_url", SETTER(std::string const&, _set_action_url)}, @@ -74,7 +69,6 @@ std::unordered_map const {"status_change", SETTER(bool, _set_status_change)}, {"active_checks_enabled", SETTER(bool, _set_checks_active)}, {"passive_checks_enabled", SETTER(bool, _set_checks_passive)}, - {"parallelize_check", SETTER(bool, _set_parallelize_check)}, {"is_volatile", SETTER(bool, _set_is_volatile)}, {"obsess_over_service", SETTER(bool, _set_obsess_over_service)}, {"event_handler_enabled", SETTER(bool, _set_event_handler_enabled)}, @@ -94,8 +88,6 @@ std::unordered_map const SETTER(unsigned int, _set_first_notification_delay)}, {"stalking_options", SETTER(std::string const&, _set_stalking_options)}, {"process_perf_data", SETTER(bool, _set_process_perf_data)}, - {"failure_prediction_enabled", - SETTER(bool, _set_failure_prediction_enabled)}, {"retain_status_information", SETTER(bool, _set_retain_status_information)}, {"retain_nonstatus_information", @@ -756,7 +748,7 @@ bool anomalydetection::operator<(anomalydetection const& other) const noexcept { * * @exception msg_fmt if this anomalydetection is an invalid object. */ -void anomalydetection::check_validity() const { +void anomalydetection::check_validity(error_cnt& err) const { if (_service_description.empty()) throw msg_fmt( "Service has no description (property 'service_description')"); @@ -1606,39 +1598,6 @@ bool anomalydetection::_set_event_handler_enabled(bool value) { return true; } -/** - * Set failure_prediction_enabled value. - * - * @param[in] value The new failure_prediction_enabled value. - * - * @return True on success, otherwise false. - */ -bool anomalydetection::_set_failure_prediction_enabled(bool value) { - (void)value; - _logger->warn( - "Warning: anomalydetection failure_prediction_enabled is deprecated. " - "This option will not be supported in 20.04."); - ++config_warnings; - return true; -} - -/** - * Set failure_prediction_options value. - * - * @param[in] value The new failure_prediction_options value. - * - * @return True on success, otherwise false. - */ -bool anomalydetection::_set_failure_prediction_options( - std::string const& value) { - (void)value; - _logger->warn( - "Warning: anomalydetection failure_prediction_options is deprecated. " - "This option will not be supported in 20.04."); - ++config_warnings; - return true; -} - /** * Set first_notification_delay value. * @@ -1922,22 +1881,6 @@ bool anomalydetection::_set_obsess_over_service(bool value) { return true; } -/** - * Set parallelize_check value. - * - * @param[in] value The new parallelize_check value. - * - * @return True on success, otherwise false. - */ -bool anomalydetection::_set_parallelize_check(bool value) { - (void)value; - _logger->warn( - "Warning: anomalydetection parallelize_check is deprecated This option " - "will not be supported in 20.04."); - ++config_warnings; - return true; -} - /** * Set process_perf_data value. * diff --git a/engine/src/configuration/applier/anomalydetection.cc b/engine/src/configuration/applier/anomalydetection.cc index 35f1de0b428..78d062bc6f0 100644 --- a/engine/src/configuration/applier/anomalydetection.cc +++ b/engine/src/configuration/applier/anomalydetection.cc @@ -459,7 +459,8 @@ void applier::anomalydetection::remove_object( * @param[in] obj Service object. */ void applier::anomalydetection::resolve_object( - configuration::anomalydetection const& obj) { + configuration::anomalydetection const& obj, + error_cnt& err) { // Logging. engine_logger(logging::dbg_config, logging::more) << "Resolving anomalydetection '" << obj.service_description() @@ -489,7 +490,7 @@ void applier::anomalydetection::resolve_object( } // Resolve anomalydetection. - it->second->resolve(config_warnings, config_errors); + it->second->resolve(err.config_warnings, err.config_errors); } /** diff --git a/engine/src/configuration/applier/command.cc b/engine/src/configuration/applier/command.cc index c8bd72bdf67..d2b0c82c9f2 100644 --- a/engine/src/configuration/applier/command.cc +++ b/engine/src/configuration/applier/command.cc @@ -209,7 +209,8 @@ void applier::command::remove_object(configuration::command const& obj) { * * @param[in] obj Command object. */ -void applier::command::resolve_object(configuration::command const& obj) { +void applier::command::resolve_object(configuration::command const& obj, + error_cnt& err) { if (!obj.connector().empty()) { connector_map::iterator found{ commands::connector::connectors.find(obj.connector())}; diff --git a/engine/src/configuration/applier/connector.cc b/engine/src/configuration/applier/connector.cc index 4c51c1f5e1f..67039caf1ac 100644 --- a/engine/src/configuration/applier/connector.cc +++ b/engine/src/configuration/applier/connector.cc @@ -189,6 +189,7 @@ void applier::connector::remove_object(configuration::connector const& obj) { * * @param[in] obj Unused. */ -void applier::connector::resolve_object(configuration::connector const& obj) { +void applier::connector::resolve_object(configuration::connector const& obj, + error_cnt& err) { (void)obj; } diff --git a/engine/src/configuration/applier/contact.cc b/engine/src/configuration/applier/contact.cc index 59df873f2bc..b96e9a03880 100644 --- a/engine/src/configuration/applier/contact.cc +++ b/engine/src/configuration/applier/contact.cc @@ -371,7 +371,8 @@ void applier::contact::expand_objects(configuration::state& s) { * * @param[in,out] obj Object to resolve. */ -void applier::contact::resolve_object(const configuration::contact& obj) { +void applier::contact::resolve_object(const configuration::contact& obj, + error_cnt& err) { // Logging. engine_logger(logging::dbg_config, logging::more) << "Resolving contact '" << obj.contact_name() << "'."; @@ -394,7 +395,7 @@ void applier::contact::resolve_object(const configuration::contact& obj) { if (itt != commands::command::commands.end()) ct_it->second->get_host_notification_commands().push_back(itt->second); else { - ++config_errors; + ++err.config_errors; throw(engine_error() << "Could not add host notification command '" << *it << "' to contact '" << obj.contact_name() << "': the command does not exist"); @@ -412,7 +413,7 @@ void applier::contact::resolve_object(const configuration::contact& obj) { if (itt != commands::command::commands.end()) ct_it->second->get_service_notification_commands().push_back(itt->second); else { - ++config_errors; + ++err.config_errors; throw(engine_error() << "Could not add service notification command '" << *it << "' to contact '" << obj.contact_name() << "': the command does not exist"); @@ -423,5 +424,5 @@ void applier::contact::resolve_object(const configuration::contact& obj) { ct_it->second->get_parent_groups().clear(); // Resolve contact. - ct_it->second->resolve(config_warnings, config_errors); + ct_it->second->resolve(err.config_warnings, err.config_errors); } diff --git a/engine/src/configuration/applier/contactgroup.cc b/engine/src/configuration/applier/contactgroup.cc index ebb743a3281..38c8522ccbd 100644 --- a/engine/src/configuration/applier/contactgroup.cc +++ b/engine/src/configuration/applier/contactgroup.cc @@ -199,7 +199,8 @@ void applier::contactgroup::remove_object( * @param[in] obj Contact group object. */ void applier::contactgroup::resolve_object( - configuration::contactgroup const& obj) { + configuration::contactgroup const& obj, + error_cnt& err) { // Logging. engine_logger(logging::dbg_config, logging::more) << "Resolving contact group '" << obj.contactgroup_name() << "'"; @@ -213,7 +214,7 @@ void applier::contactgroup::resolve_object( << "contact group '" << obj.contactgroup_name() << "'"; // Resolve contact group. - it->second->resolve(config_warnings, config_errors); + it->second->resolve(err.config_warnings, err.config_errors); } /** diff --git a/engine/src/configuration/applier/host.cc b/engine/src/configuration/applier/host.cc index 6577915df86..bf0df59a090 100644 --- a/engine/src/configuration/applier/host.cc +++ b/engine/src/configuration/applier/host.cc @@ -460,7 +460,8 @@ void applier::host::remove_object(configuration::host const& obj) { * * @param[in] obj Host object. */ -void applier::host::resolve_object(configuration::host const& obj) { +void applier::host::resolve_object(const configuration::host& obj, + error_cnt& err) { // Logging. engine_logger(logging::dbg_config, logging::more) << "Resolving host '" << obj.host_name() << "'."; @@ -494,7 +495,7 @@ void applier::host::resolve_object(configuration::host const& obj) { it->second->set_total_service_check_interval(0); // Resolve host. - it->second->resolve(config_warnings, config_errors); + it->second->resolve(err.config_warnings, err.config_errors); } /** diff --git a/engine/src/configuration/applier/hostdependency.cc b/engine/src/configuration/applier/hostdependency.cc index 50a071559d1..64cd39262d5 100644 --- a/engine/src/configuration/applier/hostdependency.cc +++ b/engine/src/configuration/applier/hostdependency.cc @@ -224,7 +224,8 @@ void applier::hostdependency::remove_object( * @param[in] obj Hostdependency object. */ void applier::hostdependency::resolve_object( - configuration::hostdependency const& obj) { + configuration::hostdependency const& obj, + error_cnt& err) { // Logging. engine_logger(logging::dbg_config, logging::more) << "Resolving a host dependency."; @@ -238,7 +239,7 @@ void applier::hostdependency::resolve_object( throw engine_error() << "Cannot resolve non-existing host escalation"; // Resolve host dependency. - it->second->resolve(config_warnings, config_errors); + it->second->resolve(err.config_warnings, err.config_errors); } /** diff --git a/engine/src/configuration/applier/hostescalation.cc b/engine/src/configuration/applier/hostescalation.cc index 4337dde13cb..39a09b2e2ba 100644 --- a/engine/src/configuration/applier/hostescalation.cc +++ b/engine/src/configuration/applier/hostescalation.cc @@ -224,7 +224,8 @@ void applier::hostescalation::remove_object( * @param[in] obj Hostescalation object. */ void applier::hostescalation::resolve_object( - configuration::hostescalation const& obj) { + configuration::hostescalation const& obj, + error_cnt& err) { // Logging. engine_logger(logging::dbg_config, logging::more) << "Resolving a host escalation."; @@ -246,7 +247,7 @@ void applier::hostescalation::resolve_object( if (it->second->internal_key() == key && it->second->matches(obj)) { found = true; // Resolve host escalation. - it->second->resolve(config_warnings, config_errors); + it->second->resolve(err.config_warnings, err.config_errors); break; } } diff --git a/engine/src/configuration/applier/hostgroup.cc b/engine/src/configuration/applier/hostgroup.cc index b3b1b8c2303..e304c6b350e 100644 --- a/engine/src/configuration/applier/hostgroup.cc +++ b/engine/src/configuration/applier/hostgroup.cc @@ -190,7 +190,8 @@ void applier::hostgroup::remove_object(configuration::hostgroup const& obj) { * * @param[in] obj Object to resolved. */ -void applier::hostgroup::resolve_object(configuration::hostgroup const& obj) { +void applier::hostgroup::resolve_object(configuration::hostgroup const& obj, + error_cnt& err) { // Logging. engine_logger(logging::dbg_config, logging::more) << "Resolving host group '" << obj.hostgroup_name() << "'"; @@ -203,7 +204,7 @@ void applier::hostgroup::resolve_object(configuration::hostgroup const& obj) { << "host group '" << obj.hostgroup_name() << "'"; // Resolve host group. - it->second->resolve(config_warnings, config_errors); + it->second->resolve(err.config_warnings, err.config_errors); } /** diff --git a/engine/src/configuration/applier/scheduler.cc b/engine/src/configuration/applier/scheduler.cc index c28f7812ce4..2b05898ba13 100644 --- a/engine/src/configuration/applier/scheduler.cc +++ b/engine/src/configuration/applier/scheduler.cc @@ -161,25 +161,19 @@ void applier::scheduler::apply( // Check if we need to add or modify objects into the scheduler. if (!hst_to_schedule.empty() || !svc_to_schedule.empty() || !ad_to_schedule.empty()) { - // Reset scheduling info. - // Keep data that has been set manually by the user - // (service interleave and intercheck delays). - int old_service_leave_factor = scheduling_info.service_interleave_factor; - double old_service_inter_check_delay = - scheduling_info.service_inter_check_delay; - double old_host_inter_check_delay_method = - scheduling_info.host_inter_check_delay; memset(&scheduling_info, 0, sizeof(scheduling_info)); if (config.service_interleave_factor_method() == configuration::state::ilf_user) - scheduling_info.service_interleave_factor = old_service_leave_factor; + scheduling_info.service_interleave_factor = + config.sched_info_config().service_interleave_factor; if (config.service_inter_check_delay_method() == configuration::state::icd_user) - scheduling_info.service_inter_check_delay = old_service_inter_check_delay; + scheduling_info.service_inter_check_delay = + config.sched_info_config().service_inter_check_delay; if (config.host_inter_check_delay_method() == configuration::state::icd_user) scheduling_info.host_inter_check_delay = - old_host_inter_check_delay_method; + config.sched_info_config().host_inter_check_delay; // Calculate scheduling parameters. _calculate_host_scheduling_params(); diff --git a/engine/src/configuration/applier/service.cc b/engine/src/configuration/applier/service.cc index 76d915b9ad6..7cdeb69ea28 100644 --- a/engine/src/configuration/applier/service.cc +++ b/engine/src/configuration/applier/service.cc @@ -22,6 +22,7 @@ #include "com/centreon/engine/broker.hh" #include "com/centreon/engine/config.hh" #include "com/centreon/engine/configuration/applier/scheduler.hh" +#include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/downtimes/downtime_manager.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" @@ -547,7 +548,8 @@ void applier::service::remove_object(configuration::service const& obj) { * * @param[in] obj Service object. */ -void applier::service::resolve_object(configuration::service const& obj) { +void applier::service::resolve_object(configuration::service const& obj, + error_cnt& err) { // Logging. engine_logger(logging::dbg_config, logging::more) << "Resolving service '" << obj.service_description() << "' of host '" @@ -575,7 +577,7 @@ void applier::service::resolve_object(configuration::service const& obj) { } // Resolve service. - it->second->resolve(config_warnings, config_errors); + it->second->resolve(err.config_warnings, err.config_errors); } /** diff --git a/engine/src/configuration/applier/servicedependency.cc b/engine/src/configuration/applier/servicedependency.cc index c256b3e8303..777334486f8 100644 --- a/engine/src/configuration/applier/servicedependency.cc +++ b/engine/src/configuration/applier/servicedependency.cc @@ -264,7 +264,8 @@ void applier::servicedependency::remove_object( * @param[in] obj Servicedependency object. */ void applier::servicedependency::resolve_object( - configuration::servicedependency const& obj) { + const configuration::servicedependency& obj, + error_cnt& err) { // Logging. engine_logger(logging::dbg_config, logging::more) << "Resolving a service dependency."; @@ -277,7 +278,7 @@ void applier::servicedependency::resolve_object( throw engine_error() << "Cannot resolve non-existing service dependency"; // Resolve service dependency. - it->second->resolve(config_warnings, config_errors); + it->second->resolve(err.config_warnings, err.config_errors); } /** diff --git a/engine/src/configuration/applier/serviceescalation.cc b/engine/src/configuration/applier/serviceescalation.cc index 0141abb6f49..fb1eee822c6 100644 --- a/engine/src/configuration/applier/serviceescalation.cc +++ b/engine/src/configuration/applier/serviceescalation.cc @@ -239,7 +239,8 @@ void applier::serviceescalation::remove_object( * @param[in] obj Serviceescalation object. */ void applier::serviceescalation::resolve_object( - configuration::serviceescalation const& obj) { + configuration::serviceescalation const& obj, + error_cnt& err) { // Logging. engine_logger(logging::dbg_config, logging::more) << "Resolving a service escalation."; @@ -260,7 +261,7 @@ void applier::serviceescalation::resolve_object( if (it->second->internal_key() == key && it->second->matches(obj)) { found = true; // Resolve service escalation. - it->second->resolve(config_warnings, config_errors); + it->second->resolve(err.config_warnings, err.config_errors); break; } } diff --git a/engine/src/configuration/applier/servicegroup.cc b/engine/src/configuration/applier/servicegroup.cc index 2f18c2ae047..8f8e42bf855 100644 --- a/engine/src/configuration/applier/servicegroup.cc +++ b/engine/src/configuration/applier/servicegroup.cc @@ -214,7 +214,8 @@ void applier::servicegroup::remove_object( * @param[in,out] obj Servicegroup object. */ void applier::servicegroup::resolve_object( - configuration::servicegroup const& obj) { + configuration::servicegroup const& obj, + error_cnt& err) { // Logging. engine_logger(logging::dbg_config, logging::more) << "Removing service group '" << obj.servicegroup_name() << "'"; @@ -228,7 +229,7 @@ void applier::servicegroup::resolve_object( << "service group '" << obj.servicegroup_name() << "'"; // Resolve service group. - it->second->resolve(config_warnings, config_errors); + it->second->resolve(err.config_warnings, err.config_errors); } /** diff --git a/engine/src/configuration/applier/state.cc b/engine/src/configuration/applier/state.cc index 6c338127ab3..0fe5e5c5e00 100644 --- a/engine/src/configuration/applier/state.cc +++ b/engine/src/configuration/applier/state.cc @@ -45,14 +45,10 @@ #include "com/centreon/engine/configuration/applier/timeperiod.hh" #include "com/centreon/engine/configuration/command.hh" #include "com/centreon/engine/configuration/whitelist.hh" -#include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/globals.hh" -#include "com/centreon/engine/logging.hh" #include "com/centreon/engine/logging/broker_sink.hh" #include "com/centreon/engine/logging/logger.hh" -#include "com/centreon/engine/objects.hh" #include "com/centreon/engine/retention/applier/state.hh" -#include "com/centreon/engine/retention/state.hh" #include "com/centreon/engine/version.hh" #include "com/centreon/engine/xpddefault.hh" #include "com/centreon/engine/xsddefault.hh" @@ -71,47 +67,16 @@ static bool has_already_been_loaded(false); * Apply new configuration. * * @param[in] new_cfg The new configuration. - * @param[in] waiting_thread True to wait thread after calulate differencies. - */ -void applier::state::apply(configuration::state& new_cfg) { - configuration::state save(*config); - try { - _processing_state = state_ready; - _processing(new_cfg); - } catch (std::exception const& e) { - // If is the first time to load configuration, we don't - // have a valid configuration to restore. - if (!has_already_been_loaded) - throw; - - // If is not the first time, we can restore the old one. - engine_logger(log_config_error, basic) - << "Error: Could not apply new configuration: " << e.what(); - config_logger->error("Error: Could not apply new configuration: {}", - e.what()); - - // Check if we need to restore old configuration. - if (_processing_state == state_error) { - engine_logger(dbg_config, more) - << "configuration: try to restore old configuration"; - config_logger->debug("configuration: try to restore old configuration"); - _processing(save); - } - } -} - -/** - * Apply new configuration. - * - * @param[in] new_cfg The new configuration. + * @param[out] err The configuration error counter. * @param[in] state The retention to use. */ void applier::state::apply(configuration::state& new_cfg, - retention::state& state) { + error_cnt& err, + retention::state* state) { configuration::state save(*config); try { _processing_state = state_ready; - _processing(new_cfg, &state); + _processing(new_cfg, err, state); } catch (std::exception const& e) { // If is the first time to load configuration, we don't // have a valid configuration to restore. @@ -128,7 +93,7 @@ void applier::state::apply(configuration::state& new_cfg, engine_logger(dbg_config, more) << "configuration: try to restore old configuration"; config_logger->debug("configuration: try to restore old configuration"); - _processing(save, &state); + _processing(save, err, state); } } } @@ -247,7 +212,8 @@ void applier::state::unlock() { * * @param[in] new_cfg The new configuration state. */ -void applier::state::_apply(configuration::state const& new_cfg) { +void applier::state::_apply(configuration::state const& new_cfg, + error_cnt& err) { // Check variables should not be change after the first execution. if (has_already_been_loaded) { if (config->broker_module() != new_cfg.broker_module()) { @@ -255,20 +221,20 @@ void applier::state::_apply(configuration::state const& new_cfg) { << "Warning: Broker modules cannot be changed nor reloaded"; config_logger->warn( "Warning: Broker modules cannot be changed nor reloaded"); - ++config_warnings; + ++err.config_warnings; } if (config->broker_module_directory() != new_cfg.broker_module_directory()) { engine_logger(log_config_warning, basic) << "Warning: Broker module directory cannot be changed"; config_logger->warn("Warning: Broker module directory cannot be changed"); - ++config_warnings; + ++err.config_warnings; } if (config->command_file() != new_cfg.command_file()) { engine_logger(log_config_warning, basic) << "Warning: Command file cannot be changed"; config_logger->warn("Warning: Command file cannot be changed"); - ++config_warnings; + ++err.config_warnings; } if (config->external_command_buffer_slots() != new_cfg.external_command_buffer_slots()) { @@ -276,13 +242,13 @@ void applier::state::_apply(configuration::state const& new_cfg) { << "Warning: External command buffer slots cannot be changed"; config_logger->warn( "Warning: External command buffer slots cannot be changed"); - ++config_warnings; + ++err.config_warnings; } if (config->use_timezone() != new_cfg.use_timezone()) { engine_logger(log_config_warning, basic) << "Warning: Timezone can not be changed"; config_logger->warn("Warning: Timezone can not be changed"); - ++config_warnings; + ++err.config_warnings; } } @@ -503,7 +469,7 @@ void applier::state::_apply(configuration::state const& new_cfg) { "Error: Global host event handler command '{}' is not defined " "anywhere!", temp_command_name); - ++config_errors; + ++err.config_errors; global_host_event_handler_ptr = nullptr; } else global_host_event_handler_ptr = found->second.get(); @@ -522,7 +488,7 @@ void applier::state::_apply(configuration::state const& new_cfg) { "Error: Global service event handler command '{}' is not defined " "anywhere!", temp_command_name); - ++config_errors; + ++err.config_errors; global_service_event_handler_ptr = nullptr; } else global_service_event_handler_ptr = found->second.get(); @@ -547,7 +513,7 @@ void applier::state::_apply(configuration::state const& new_cfg) { "Error: Obsessive compulsive service processor command '{}' is not " "defined anywhere!", temp_command_name); - ++config_errors; + ++err.config_errors; ocsp_command_ptr = nullptr; } else ocsp_command_ptr = found->second.get(); @@ -565,7 +531,7 @@ void applier::state::_apply(configuration::state const& new_cfg) { "Error: Obsessive compulsive host processor command '{}' is not " "defined anywhere!", temp_command_name); - ++config_errors; + ++err.config_errors; ochp_command_ptr = nullptr; } else ochp_command_ptr = found->second.get(); @@ -585,7 +551,8 @@ void applier::state::_apply(configuration::state const& new_cfg) { */ template void applier::state::_apply( - difference > const& diff) { + difference > const& diff, + error_cnt& err) { // Type alias. typedef std::set cfg_set; @@ -606,7 +573,7 @@ void applier::state::_apply( try { aplyr.remove_object(*it_delete); } catch (std::exception const& e) { - ++config_errors; + ++err.config_errors; engine_logger(log_info_message, basic) << e.what(); events_logger->info(e.what()); } @@ -623,7 +590,7 @@ void applier::state::_apply( try { aplyr.add_object(*it_create); } catch (std::exception const& e) { - ++config_errors; + ++err.config_errors; engine_logger(log_info_message, basic) << e.what(); events_logger->info(e.what()); } @@ -640,7 +607,7 @@ void applier::state::_apply( try { aplyr.modify_object(*it_modify); } catch (std::exception const& e) { - ++config_errors; + ++err.config_errors; engine_logger(log_info_message, basic) << e.what(); events_logger->info(e.what()); } @@ -1216,7 +1183,8 @@ void applier::state::apply_log_config(configuration::state& new_cfg) { * @param[in] state The retention state to use. */ void applier::state::_apply(configuration::state& new_cfg, - retention::state& state) { + retention::state& state, + error_cnt& err) { retention::applier::state app_state; if (!verify_config) app_state.apply(new_cfg, state); @@ -1224,7 +1192,7 @@ void applier::state::_apply(configuration::state& new_cfg, try { app_state.apply(new_cfg, state); } catch (std::exception const& e) { - ++config_errors; + ++err.config_errors; std::cout << e.what(); } } @@ -1237,13 +1205,13 @@ void applier::state::_apply(configuration::state& new_cfg, * @param[in,out] cfg Configuration objects. */ template -void applier::state::_expand(configuration::state& new_state) { +void applier::state::_expand(configuration::state& new_state, error_cnt& err) { ApplierType aplyr; try { aplyr.expand_objects(new_state); } catch (std::exception const& e) { if (verify_config) { - ++config_errors; + ++err.config_errors; std::cout << e.what(); } else throw; @@ -1254,9 +1222,11 @@ void applier::state::_expand(configuration::state& new_state) { * Process new configuration and apply it. * * @param[in] new_cfg The new configuration. + * @param[out] err The configuration error counter. * @param[in] state The retention to use. */ void applier::state::_processing(configuration::state& new_cfg, + error_cnt& err, retention::state* state) { // Timing. struct timeval tv[5]; @@ -1271,48 +1241,49 @@ void applier::state::_processing(configuration::state& new_cfg, gettimeofday(tv, nullptr); // Expand timeperiods. - _expand(new_cfg); + _expand(new_cfg, err); // Expand connectors. - _expand(new_cfg); + _expand(new_cfg, err); // Expand commands. - _expand(new_cfg); + _expand(new_cfg, err); // Expand contacts. - _expand(new_cfg); + _expand(new_cfg, err); // Expand contactgroups. - _expand(new_cfg); + _expand(new_cfg, err); // Expand hosts. - _expand(new_cfg); + _expand(new_cfg, err); // Expand hostgroups. - _expand(new_cfg); + _expand(new_cfg, err); // Expand services. - _expand(new_cfg); + _expand(new_cfg, err); // Expand anomalydetections. - _expand(new_cfg); + _expand(new_cfg, + err); // Expand servicegroups. - _expand(new_cfg); + _expand(new_cfg, err); // Expand hostdependencies. - _expand(new_cfg); + _expand(new_cfg, err); // Expand servicedependencies. - _expand( - new_cfg); + _expand(new_cfg, + err); // Expand hostescalations. - _expand(new_cfg); + _expand(new_cfg, err); // Expand serviceescalations. - _expand( - new_cfg); + _expand(new_cfg, + err); // // Build difference for all objects. @@ -1431,87 +1402,89 @@ void applier::state::_processing(configuration::state& new_cfg, // // Apply timeperiods. - _apply(diff_timeperiods); + _apply(diff_timeperiods, + err); _resolve( - config->timeperiods()); + config->timeperiods(), err); // Apply connectors. - _apply(diff_connectors); - _resolve( - config->connectors()); + _apply(diff_connectors, err); + _resolve(config->connectors(), + err); // Apply commands. - _apply(diff_commands); - _resolve(config->commands()); + _apply(diff_commands, err); + _resolve(config->commands(), err); // Apply contacts and contactgroups. - _apply(diff_contacts); + _apply(diff_contacts, err); _apply( - diff_contactgroups); + diff_contactgroups, err); _resolve( - config->contactgroups()); - _resolve(config->contacts()); + config->contactgroups(), err); + _resolve(config->contacts(), err); // Apply severities. - _apply(diff_severities); + _apply(diff_severities, err); // Apply tags. - _apply(diff_tags); + _apply(diff_tags, err); // Apply hosts and hostgroups. - _apply(diff_hosts); - _apply(diff_hostgroups); + _apply(diff_hosts, err); + _apply(diff_hostgroups, err); // Apply services. - _apply(diff_services); + _apply(diff_services, err); // Apply anomalydetections. _apply( - diff_anomalydetections); + diff_anomalydetections, err); // Apply servicegroups. _apply( - diff_servicegroups); + diff_servicegroups, err); // Resolve hosts, services, host groups. - _resolve(config->hosts()); - _resolve( - config->hostgroups()); + _resolve(config->hosts(), err); + _resolve(config->hostgroups(), + err); // Resolve services. - _resolve(config->mut_services()); + _resolve(config->mut_services(), + err); // Resolve anomalydetections. _resolve( - config->anomalydetections()); + config->anomalydetections(), err); // Resolve service groups. _resolve( - config->servicegroups()); + config->servicegroups(), err); // Apply host dependencies. _apply( - diff_hostdependencies); + diff_hostdependencies, err); _resolve( - config->hostdependencies()); + config->hostdependencies(), err); // Apply service dependencies. _apply( - diff_servicedependencies); + diff_servicedependencies, err); _resolve( - config->servicedependencies()); + config->servicedependencies(), err); // Apply host escalations. _apply( - diff_hostescalations); + diff_hostescalations, err); _resolve( - config->hostescalations()); + config->hostescalations(), err); // Apply service escalations. _apply( - diff_serviceescalations); + diff_serviceescalations, err); _resolve( - config->serviceescalations()); + config->serviceescalations(), err); #ifdef DEBUG_CONFIG std::cout << "WARNING!! You are using a version of " @@ -1528,7 +1501,7 @@ void applier::state::_processing(configuration::state& new_cfg, // Load retention. if (state) - _apply(new_cfg, *state); + _apply(new_cfg, *state, err); // Apply scheduler. if (!verify_config) @@ -1537,13 +1510,13 @@ void applier::state::_processing(configuration::state& new_cfg, // Apply new global on the current state. if (!verify_config) { - _apply(new_cfg); + _apply(new_cfg, err); whitelist::reload(); } else { try { - _apply(new_cfg); + _apply(new_cfg, err); } catch (std::exception const& e) { - ++config_errors; + ++err.config_errors; engine_logger(log_info_message, basic) << e.what(); events_logger->info(e.what()); } @@ -1553,7 +1526,7 @@ void applier::state::_processing(configuration::state& new_cfg, gettimeofday(tv + 3, nullptr); // Check for circular paths between hosts. - pre_flight_circular_check(&config_warnings, &config_errors); + pre_flight_circular_check(&err.config_warnings, &err.config_errors); // Call start broker event the first time to run applier state. if (!has_already_been_loaded) { @@ -1633,16 +1606,17 @@ void applier::state::_processing(configuration::state& new_cfg, * @param[in] cfg Configuration objects. */ template -void applier::state::_resolve(std::set& cfg) { +void applier::state::_resolve(std::set& cfg, + error_cnt& err) { ApplierType aplyr; - for (typename std::set::const_iterator it(cfg.begin()), - end(cfg.end()); + for (typename std::set::const_iterator it = cfg.begin(), + end = cfg.end(); it != end; ++it) { try { - aplyr.resolve_object(*it); + aplyr.resolve_object(*it, err); } catch (std::exception const& e) { if (verify_config) { - ++config_errors; + ++err.config_errors; std::cout << e.what() << std::endl; } else throw; diff --git a/engine/src/configuration/applier/timeperiod.cc b/engine/src/configuration/applier/timeperiod.cc index 3140a879660..df738fc3bee 100644 --- a/engine/src/configuration/applier/timeperiod.cc +++ b/engine/src/configuration/applier/timeperiod.cc @@ -167,7 +167,8 @@ void applier::timeperiod::remove_object(configuration::timeperiod const& obj) { * * @param[in] obj Unused. */ -void applier::timeperiod::resolve_object(configuration::timeperiod const& obj) { +void applier::timeperiod::resolve_object(configuration::timeperiod const& obj, + error_cnt& err) { // Logging. engine_logger(logging::dbg_config, logging::more) << "Resolving time period '" << obj.timeperiod_name() << "'."; @@ -180,7 +181,7 @@ void applier::timeperiod::resolve_object(configuration::timeperiod const& obj) { << "time period '" << obj.timeperiod_name() << "'"; // Resolve time period. - it->second->resolve(config_warnings, config_errors); + it->second->resolve(err.config_warnings, err.config_errors); } /** diff --git a/engine/src/configuration/command.cc b/engine/src/configuration/command.cc index 28bf2b34856..9be403106ba 100644 --- a/engine/src/configuration/command.cc +++ b/engine/src/configuration/command.cc @@ -113,7 +113,7 @@ bool command::operator<(command const& right) const throw() { * * If the object is not valid, an exception is thrown. */ -void command::check_validity() const { +void command::check_validity(error_cnt& err [[maybe_unused]]) const { if (_command_name.empty()) throw msg_fmt("Command has no name (property 'command_name')"); if (_command_line.empty()) diff --git a/engine/src/configuration/connector.cc b/engine/src/configuration/connector.cc index 5f67da8927a..3a26096f0da 100644 --- a/engine/src/configuration/connector.cc +++ b/engine/src/configuration/connector.cc @@ -112,7 +112,7 @@ bool connector::operator<(connector const& right) const throw() { * * If the object is not valid, an exception is thrown. */ -void connector::check_validity() const { +void connector::check_validity(error_cnt& err [[maybe_unused]]) const { if (_connector_name.empty()) throw msg_fmt("Connector has no name (property 'connector_name')"); if (_connector_line.empty()) diff --git a/engine/src/configuration/contact.cc b/engine/src/configuration/contact.cc index 65900b90d60..931d2f02fb4 100644 --- a/engine/src/configuration/contact.cc +++ b/engine/src/configuration/contact.cc @@ -230,7 +230,7 @@ bool contact::operator<(contact const& other) const noexcept { * * If the object is not valid, an exception is thrown. */ -void contact::check_validity() const { +void contact::check_validity(error_cnt& err [[maybe_unused]]) const { if (_contact_name.empty()) throw msg_fmt("Contact has no name (property 'contact_name')"); } diff --git a/engine/src/configuration/contactgroup.cc b/engine/src/configuration/contactgroup.cc index 9e0e4a484c6..178f1ff65ee 100644 --- a/engine/src/configuration/contactgroup.cc +++ b/engine/src/configuration/contactgroup.cc @@ -121,7 +121,7 @@ bool contactgroup::operator<(contactgroup const& right) const throw() { * * If the object is not valid, an exception is thrown. */ -void contactgroup::check_validity() const { +void contactgroup::check_validity(error_cnt& err [[maybe_unused]]) const { if (_contactgroup_name.empty()) throw msg_fmt("Contact group has no name (property 'contactgroup_name')"); } diff --git a/engine/src/configuration/extended_conf.cc b/engine/src/configuration/extended_conf.cc index 84d85c07ca0..a350cf51764 100644 --- a/engine/src/configuration/extended_conf.cc +++ b/engine/src/configuration/extended_conf.cc @@ -18,7 +18,6 @@ #include "com/centreon/engine/configuration/extended_conf.hh" #include "com/centreon/engine/configuration/state.hh" -#include "com/centreon/engine/globals.hh" #include "com/centreon/exceptions/msg_fmt.hh" #include "common/log_v2/log_v2.hh" diff --git a/engine/src/configuration/host.cc b/engine/src/configuration/host.cc index 7d255c874ff..5f3b47c4588 100644 --- a/engine/src/configuration/host.cc +++ b/engine/src/configuration/host.cc @@ -25,9 +25,6 @@ #include "bbdo/neb.pb.h" #include "com/centreon/exceptions/msg_fmt.hh" -extern int config_warnings; -extern int config_errors; - using namespace com::centreon; using namespace com::centreon::engine::configuration; using com::centreon::exceptions::msg_fmt; @@ -52,8 +49,6 @@ std::unordered_map const host::_setters{ {"check_command", SETTER(std::string const&, _set_check_command)}, {"check_period", SETTER(std::string const&, _set_check_period)}, {"event_handler", SETTER(std::string const&, _set_event_handler)}, - {"failure_prediction_options", - SETTER(std::string const&, _set_failure_prediction_options)}, {"notes", SETTER(std::string const&, _set_notes)}, {"notes_url", SETTER(std::string const&, _set_notes_url)}, {"action_url", SETTER(std::string const&, _set_action_url)}, @@ -89,8 +84,6 @@ std::unordered_map const host::_setters{ SETTER(unsigned int, _set_first_notification_delay)}, {"stalking_options", SETTER(std::string const&, _set_stalking_options)}, {"process_perf_data", SETTER(bool, _set_process_perf_data)}, - {"failure_prediction_enabled", - SETTER(bool, _set_failure_prediction_enabled)}, {"2d_coords", SETTER(std::string const&, _set_coords_2d)}, {"3d_coords", SETTER(std::string const&, _set_coords_3d)}, {"obsess_over_host", SETTER(bool, _set_obsess_over_host)}, @@ -430,7 +423,7 @@ bool host::operator<(host const& other) const noexcept { * * If the object is not valid, an exception is thrown. */ -void host::check_validity() const { +void host::check_validity(error_cnt& err [[maybe_unused]]) const { if (_host_name.empty()) throw msg_fmt("Host has no name (property 'host_name')"); if (_address.empty()) @@ -1258,37 +1251,6 @@ bool host::_set_event_handler_enabled(bool value) { return true; } -/** - * Set failure_prediction_enabled value. - * - * @param[in] value The new failure_prediction_enabled value. - * - * @return True on success, otherwise false. - */ -bool host::_set_failure_prediction_enabled(bool value [[maybe_unused]]) { - _logger->warn( - "Warning: host failure_prediction_enabled is deprecated This option will " - "not be supported in 20.04."); - ++config_warnings; - return true; -} - -/** - * Set failure_prediction_options value. - * - * @param[in] value The new failure_prediction_options value. - * - * @return True on success, otherwise false. - */ -bool host::_set_failure_prediction_options(const std::string& value - [[maybe_unused]]) { - _logger->warn( - "Warning: service failure_prediction_options is deprecated This option " - "will not be supported in 20.04."); - ++config_warnings; - return (true); -} - /** * Set first_notification_delay value. * diff --git a/engine/src/configuration/hostdependency.cc b/engine/src/configuration/hostdependency.cc index 5ccf7ddb8aa..5993c8f0166 100644 --- a/engine/src/configuration/hostdependency.cc +++ b/engine/src/configuration/hostdependency.cc @@ -18,13 +18,9 @@ * */ -#include "com/centreon/engine/configuration/hostdependency.hh" -#include "com/centreon/engine/globals.hh" +#include "com/centreon/engine/configuration/state.hh" #include "com/centreon/exceptions/msg_fmt.hh" -extern int config_warnings; -extern int config_errors; - using namespace com::centreon; using namespace com::centreon::engine::configuration; using com::centreon::exceptions::msg_fmt; @@ -181,7 +177,7 @@ bool hostdependency::operator<(hostdependency const& right) const { * * If the object is not valid, an exception is thrown. */ -void hostdependency::check_validity() const { +void hostdependency::check_validity(configuration::error_cnt& err) const { if (_hosts->empty() && _hostgroups->empty()) throw msg_fmt( "Host dependency is not attached to any host or host group (properties " @@ -193,7 +189,7 @@ void hostdependency::check_validity() const { "'dependent_hostgroup_name', respectively)"); if (!_execution_failure_options && !_notification_failure_options) { - ++config_warnings; + ++err.config_warnings; std::string host_name(!_hosts->empty() ? *_hosts->begin() : *_hostgroups->begin()); std::string dependend_host_name(!_dependent_hosts->empty() diff --git a/engine/src/configuration/hostescalation.cc b/engine/src/configuration/hostescalation.cc index 8c9853c99b6..24df969ace6 100644 --- a/engine/src/configuration/hostescalation.cc +++ b/engine/src/configuration/hostescalation.cc @@ -162,7 +162,7 @@ bool hostescalation::operator<(hostescalation const& right) const { * * If the object is not valid, an exception is thrown. */ -void hostescalation::check_validity() const { +void hostescalation::check_validity(error_cnt& err [[maybe_unused]]) const { if (_hosts->empty() && _hostgroups->empty()) throw msg_fmt( "Host escalation is not attached to any host or host group (properties " diff --git a/engine/src/configuration/hostgroup.cc b/engine/src/configuration/hostgroup.cc index b8ea44beccd..7182bb2cdc2 100644 --- a/engine/src/configuration/hostgroup.cc +++ b/engine/src/configuration/hostgroup.cc @@ -167,7 +167,7 @@ bool hostgroup::operator<(hostgroup const& right) const throw() { * * If the object is not valid, an exception is thrown. */ -void hostgroup::check_validity() const { +void hostgroup::check_validity(error_cnt& err [[maybe_unused]]) const { if (_hostgroup_name.empty()) throw msg_fmt("Host group has no name (property 'hostgroup_name')"); } diff --git a/engine/src/configuration/parser.cc b/engine/src/configuration/parser.cc index d893b3665e1..f5e737873e1 100644 --- a/engine/src/configuration/parser.cc +++ b/engine/src/configuration/parser.cc @@ -17,7 +17,6 @@ * */ #include "com/centreon/engine/configuration/parser.hh" -#include "com/centreon/engine/globals.hh" #include "com/centreon/exceptions/msg_fmt.hh" #include "com/centreon/io/directory_entry.hh" #include "common/log_v2/log_v2.hh" @@ -89,7 +88,7 @@ parser::parser(unsigned int read_options) * @param[in] path The configuration file path. * @param[in] config The state configuration to fill. */ -void parser::parse(std::string const& path, state& config) { +void parser::parse(std::string const& path, state& config, error_cnt& err) { _config = &config; // parse the global configuration file. @@ -103,7 +102,7 @@ void parser::parse(std::string const& path, state& config) { _apply(config.cfg_dir(), &parser::_parse_directory_configuration); // Apply template. - _resolve_template(); + _resolve_template(err); // Fill state. _insert(_map_objects[object::command], config.commands()); @@ -455,7 +454,7 @@ void parser::_parse_resource_file(std::string const& path) { /** * Resolve template for register objects. */ -void parser::_resolve_template() { +void parser::_resolve_template(error_cnt& err) { for (map_object& templates : _templates) { for (map_object::iterator it = templates.begin(), end = templates.end(); it != end; ++it) @@ -469,7 +468,7 @@ void parser::_resolve_template() { it != end; ++it) { (*it)->resolve_template(templates); try { - (*it)->check_validity(); + (*it)->check_validity(err); } catch (std::exception const& e) { throw msg_fmt("Configuration parsing failed {}: {}", _get_file_info(it->get()), e.what()); @@ -484,7 +483,7 @@ void parser::_resolve_template() { it != end; ++it) { it->second->resolve_template(templates); try { - it->second->check_validity(); + it->second->check_validity(err); } catch (std::exception const& e) { throw msg_fmt("Configuration parsing failed {}: {}", _get_file_info(it->second.get()), e.what()); diff --git a/engine/src/configuration/service.cc b/engine/src/configuration/service.cc index 916eddbae91..73efe5d04e7 100644 --- a/engine/src/configuration/service.cc +++ b/engine/src/configuration/service.cc @@ -21,13 +21,9 @@ #include #include #include -#include "com/centreon/engine/globals.hh" #include "com/centreon/engine/host.hh" #include "com/centreon/exceptions/msg_fmt.hh" -extern int config_warnings; -extern int config_errors; - using namespace com::centreon; using namespace com::centreon::engine::configuration; using com::centreon::exceptions::msg_fmt; @@ -55,8 +51,6 @@ std::unordered_map const service::_setters{ SETTER(std::string const&, _set_notification_period)}, {"contact_groups", SETTER(std::string const&, _set_contactgroups)}, {"contacts", SETTER(std::string const&, _set_contacts)}, - {"failure_prediction_options", - SETTER(std::string const&, _set_failure_prediction_options)}, {"notes", SETTER(std::string const&, _set_notes)}, {"notes_url", SETTER(std::string const&, _set_notes_url)}, {"action_url", SETTER(std::string const&, _set_action_url)}, @@ -72,7 +66,6 @@ std::unordered_map const service::_setters{ SETTER(unsigned int, _set_recovery_notification_delay)}, {"active_checks_enabled", SETTER(bool, _set_checks_active)}, {"passive_checks_enabled", SETTER(bool, _set_checks_passive)}, - {"parallelize_check", SETTER(bool, _set_parallelize_check)}, {"is_volatile", SETTER(bool, _set_is_volatile)}, {"obsess_over_service", SETTER(bool, _set_obsess_over_service)}, {"event_handler_enabled", SETTER(bool, _set_event_handler_enabled)}, @@ -91,8 +84,6 @@ std::unordered_map const service::_setters{ SETTER(unsigned int, _set_first_notification_delay)}, {"stalking_options", SETTER(std::string const&, _set_stalking_options)}, {"process_perf_data", SETTER(bool, _set_process_perf_data)}, - {"failure_prediction_enabled", - SETTER(bool, _set_failure_prediction_enabled)}, {"retain_status_information", SETTER(bool, _set_retain_status_information)}, {"retain_nonstatus_information", SETTER(bool, _set_retain_nonstatus_information)}, @@ -676,7 +667,7 @@ bool service::operator<(service const& other) const noexcept { * * @return True if is a valid object, otherwise false. */ -void service::check_validity() const { +void service::check_validity(error_cnt& err [[maybe_unused]]) const { if (_service_description.empty()) throw msg_fmt( "Service has no description (property 'service_description')"); @@ -1481,38 +1472,6 @@ bool service::_set_event_handler_enabled(bool value) { return true; } -/** - * Set failure_prediction_enabled value. - * - * @param[in] value The new failure_prediction_enabled value. - * - * @return True on success, otherwise false. - */ -bool service::_set_failure_prediction_enabled(bool value) { - (void)value; - _logger->warn( - "Warning: service failure_prediction_enabled is deprecated. This option " - "will not be supported in 20.04."); - ++config_warnings; - return true; -} - -/** - * Set failure_prediction_options value. - * - * @param[in] value The new failure_prediction_options value. - * - * @return True on success, otherwise false. - */ -bool service::_set_failure_prediction_options(std::string const& value) { - (void)value; - _logger->warn( - "Warning: service failure_prediction_options is deprecated. This option " - "will not be supported in 20.04."); - ++config_warnings; - return true; -} - /** * Set first_notification_delay value. * @@ -1796,22 +1755,6 @@ bool service::_set_obsess_over_service(bool value) { return true; } -/** - * Set parallelize_check value. - * - * @param[in] value The new parallelize_check value. - * - * @return True on success, otherwise false. - */ -bool service::_set_parallelize_check(bool value) { - (void)value; - _logger->warn( - "Warning: service parallelize_check is deprecated This option will not " - "be supported in 20.04."); - ++config_warnings; - return true; -} - /** * Set process_perf_data value. * diff --git a/engine/src/configuration/servicedependency.cc b/engine/src/configuration/servicedependency.cc index 98f00491d1a..1f70031d1a7 100644 --- a/engine/src/configuration/servicedependency.cc +++ b/engine/src/configuration/servicedependency.cc @@ -19,12 +19,8 @@ */ #include "com/centreon/engine/configuration/servicedependency.hh" -#include "com/centreon/engine/globals.hh" #include "com/centreon/exceptions/msg_fmt.hh" -extern int config_warnings; -extern int config_errors; - using namespace com::centreon; using namespace com::centreon::engine::configuration; using com::centreon::exceptions::msg_fmt; @@ -230,7 +226,7 @@ bool servicedependency::operator<(servicedependency const& right) const { * * If the object is not valid, an exception is thrown. */ -void servicedependency::check_validity() const { +void servicedependency::check_validity(error_cnt& err) const { // Check base service(s). if (_servicegroups->empty()) { if (_service_description->empty()) @@ -260,7 +256,7 @@ void servicedependency::check_validity() const { // With no execution or failure options this dependency is useless. if (!_execution_failure_options && !_notification_failure_options) { - ++config_warnings; + ++err.config_warnings; std::ostringstream msg; msg << "Warning: Ignoring lame service dependency of "; if (!_dependent_servicegroups->empty()) diff --git a/engine/src/configuration/serviceescalation.cc b/engine/src/configuration/serviceescalation.cc index 4cf59dcb8f5..f41fc9a3571 100644 --- a/engine/src/configuration/serviceescalation.cc +++ b/engine/src/configuration/serviceescalation.cc @@ -18,7 +18,6 @@ */ #include "com/centreon/engine/configuration/serviceescalation.hh" -#include "com/centreon/engine/globals.hh" #include "com/centreon/exceptions/msg_fmt.hh" using namespace com::centreon; @@ -238,7 +237,7 @@ bool serviceescalation::operator<(serviceescalation const& right) const { * * If the object is not valid, an exception is thrown. */ -void serviceescalation::check_validity() const { +void serviceescalation::check_validity(error_cnt& err [[maybe_unused]]) const { if (_servicegroups->empty()) { if (_service_description->empty()) throw msg_fmt( diff --git a/engine/src/configuration/servicegroup.cc b/engine/src/configuration/servicegroup.cc index c15dceb50bf..39ff98ffe09 100644 --- a/engine/src/configuration/servicegroup.cc +++ b/engine/src/configuration/servicegroup.cc @@ -141,7 +141,7 @@ bool servicegroup::operator<(servicegroup const& right) const throw() { * * If the object is not valid, an exception is thrown. */ -void servicegroup::check_validity() const { +void servicegroup::check_validity(error_cnt& err [[maybe_unused]]) const { if (_servicegroup_name.empty()) throw msg_fmt("Service group has no name (property 'servicegroup_name')"); } diff --git a/engine/src/configuration/severity.cc b/engine/src/configuration/severity.cc index 3ec4ace32e5..6df971be114 100644 --- a/engine/src/configuration/severity.cc +++ b/engine/src/configuration/severity.cc @@ -129,7 +129,7 @@ bool severity::operator<(const severity& other) const noexcept { * * If the object is not valid, an exception is thrown. */ -void severity::check_validity() const { +void severity::check_validity(error_cnt& err [[maybe_unused]]) const { if (_severity_name.empty()) throw msg_fmt("Severity has no name (property 'severity_name')"); if (_key.first == 0) diff --git a/engine/src/configuration/state.cc b/engine/src/configuration/state.cc index 47eb38de128..2ee1415a225 100644 --- a/engine/src/configuration/state.cc +++ b/engine/src/configuration/state.cc @@ -19,10 +19,9 @@ #include "com/centreon/engine/configuration/state.hh" #include "com/centreon/common/rapidjson_helper.hh" #include "com/centreon/engine/broker.hh" -#include "com/centreon/engine/globals.hh" #include "com/centreon/exceptions/msg_fmt.hh" #include "com/centreon/io/file_entry.hh" -#include "compatibility/locations.h" +#include "common/log_v2/log_v2.hh" using namespace com::centreon; using namespace com::centreon::engine; @@ -137,16 +136,12 @@ void state::_init_setter() { SETTER(int, additional_freshness_latency, "additional_freshness_latency"); SETTER(const std::string&, admin_email, "admin_email"); SETTER(const std::string&, admin_pager, "admin_pager"); - SETTER(const std::string&, _set_aggregate_status_updates, - "aggregate_status_updates"); SETTER(bool, allow_empty_hostgroup_assignment, "allow_empty_hostgroup_assignment"); - SETTER(const std::string&, _set_auth_file, "auth_file"); SETTER(bool, auto_reschedule_checks, "auto_reschedule_checks"); SETTER(unsigned int, auto_rescheduling_interval, "auto_rescheduling_interval"); SETTER(unsigned int, auto_rescheduling_window, "auto_rescheduling_window"); - SETTER(const std::string&, _set_bare_update_check, "bare_update_check"); SETTER(const std::string&, broker_module_directory, "broker_module_directory"); SETTER(const std::string&, _set_broker_module, "broker_module"); @@ -158,27 +153,18 @@ void state::_init_setter() { SETTER(bool, check_external_commands, "check_external_commands"); SETTER(bool, check_orphaned_hosts, "check_for_orphaned_hosts"); SETTER(bool, check_orphaned_services, "check_for_orphaned_services"); - SETTER(const std::string&, _set_check_for_updates, "check_for_updates"); SETTER(bool, check_host_freshness, "check_host_freshness"); SETTER(unsigned int, check_reaper_interval, "check_result_reaper_frequency"); SETTER(bool, check_service_freshness, "check_service_freshness"); - SETTER(const std::string&, _set_child_processes_fork_twice, - "child_processes_fork_twice"); SETTER(const std::string&, _set_command_check_interval, "command_check_interval"); SETTER(const std::string&, command_file, "command_file"); - SETTER(const std::string&, _set_comment_file, "comment_file"); - SETTER(const std::string&, _set_daemon_dumps_core, "daemon_dumps_core"); SETTER(const std::string&, _set_date_format, "date_format"); SETTER(const std::string&, debug_file, "debug_file"); SETTER(int64_t, debug_level, "debug_level"); SETTER(unsigned int, debug_verbosity, "debug_verbosity"); - SETTER(const std::string&, _set_downtime_file, "downtime_file"); - SETTER(const std::string&, _set_enable_embedded_perl, "enable_embedded_perl"); SETTER(bool, enable_environment_macros, "enable_environment_macros"); SETTER(bool, enable_event_handlers, "enable_event_handlers"); - SETTER(const std::string&, _set_enable_failure_prediction, - "enable_failure_prediction"); SETTER(bool, enable_flap_detection, "enable_flap_detection"); SETTER(bool, enable_macros_filter, "enable_macros_filter"); SETTER(bool, enable_notifications, "enable_notifications"); @@ -191,8 +177,6 @@ void state::_init_setter() { SETTER(bool, execute_host_checks, "execute_host_checks"); SETTER(bool, execute_service_checks, "execute_service_checks"); SETTER(int, external_command_buffer_slots, "external_command_buffer_slots"); - SETTER(const std::string&, _set_free_child_process_memory, - "free_child_process_memory"); SETTER(const std::string&, global_host_event_handler, "global_host_event_handler"); SETTER(const std::string&, global_service_event_handler, @@ -218,18 +202,14 @@ void state::_init_setter() { "illegal_macro_output_chars"); SETTER(const std::string&, illegal_object_chars, "illegal_object_name_chars"); SETTER(unsigned int, interval_length, "interval_length"); - SETTER(const std::string&, _set_lock_file, "lock_file"); - SETTER(const std::string&, _set_log_archive_path, "log_archive_path"); SETTER(bool, log_event_handlers, "log_event_handlers"); SETTER(bool, log_external_commands, "log_external_commands"); SETTER(const std::string&, log_file, "log_file"); SETTER(bool, log_host_retries, "log_host_retries"); - SETTER(const std::string&, _set_log_initial_states, "log_initial_states"); SETTER(bool, log_notifications, "log_notifications"); SETTER(bool, log_passive_checks, "log_passive_checks"); SETTER(bool, log_pid, "log_pid"); SETTER(bool, log_file_line, "log_file_line"); - SETTER(const std::string&, _set_log_rotation_method, "log_rotation_method"); SETTER(bool, log_service_retries, "log_service_retries"); SETTER(float, low_host_flap_threshold, "low_host_flap_threshold"); SETTER(float, low_service_flap_threshold, "low_service_flap_threshold"); @@ -240,24 +220,18 @@ void state::_init_setter() { SETTER(unsigned long, max_log_file_size, "max_log_file_size"); SETTER(uint32_t, log_flush_period, "log_flush_period"); SETTER(unsigned int, max_service_check_spread, "max_service_check_spread"); - SETTER(const std::string&, _set_nagios_group, "nagios_group"); - SETTER(const std::string&, _set_nagios_user, "nagios_user"); SETTER(unsigned int, notification_timeout, "notification_timeout"); - SETTER(const std::string&, _set_object_cache_file, "object_cache_file"); SETTER(bool, obsess_over_hosts, "obsess_over_hosts"); SETTER(bool, obsess_over_services, "obsess_over_services"); SETTER(const std::string&, ochp_command, "ochp_command"); SETTER(unsigned int, ochp_timeout, "ochp_timeout"); SETTER(const std::string&, ocsp_command, "ocsp_command"); SETTER(unsigned int, ocsp_timeout, "ocsp_timeout"); - SETTER(const std::string&, _set_p1_file, "p1_file"); SETTER(int, perfdata_timeout, "perfdata_timeout"); SETTER(const std::string&, poller_name, "poller_name"); SETTER(uint32_t, poller_id, "poller_id"); SETTER(uint16_t, rpc_port, "rpc_port"); SETTER(const std::string&, rpc_listen_address, "rpc_listen_address"); - SETTER(const std::string&, _set_precached_object_file, - "precached_object_file"); SETTER(bool, process_performance_data, "process_performance_data"); SETTER(const std::string&, _set_resource_file, "resource_file"); SETTER(unsigned long, retained_contact_host_attribute_mask, @@ -268,10 +242,6 @@ void state::_init_setter() { "retained_host_attribute_mask"); SETTER(unsigned long, retained_process_host_attribute_mask, "retained_process_host_attribute_mask"); - SETTER(const std::string&, _set_retained_process_service_attribute_mask, - "retained_process_service_attribute_mask"); - SETTER(const std::string&, _set_retained_service_attribute_mask, - "retained_service_attribute_mask"); SETTER(bool, retain_state_information, "retain_state_information"); SETTER(unsigned int, retention_scheduling_horizon, "retention_scheduling_horizon"); @@ -300,13 +270,7 @@ void state::_init_setter() { SETTER(const std::string&, state_retention_file, "state_retention_file"); SETTER(const std::string&, status_file, "status_file"); SETTER(unsigned int, status_update_interval, "status_update_interval"); - SETTER(const std::string&, _set_temp_file, "temp_file"); - SETTER(const std::string&, _set_temp_path, "temp_path"); SETTER(unsigned int, time_change_threshold, "time_change_threshold"); - SETTER(bool, use_aggressive_host_checking, "use_aggressive_host_checking"); - SETTER(bool, use_aggressive_host_checking, "use_agressive_host_checking"); - SETTER(const std::string&, _set_use_embedded_perl_implicitly, - "use_embedded_perl_implicitly"); SETTER(bool, use_large_installation_tweaks, "use_large_installation_tweaks"); SETTER(uint32_t, instance_heartbeat_interval, "instance_heartbeat_interval"); SETTER(bool, use_regexp_matches, "use_regexp_matching"); @@ -335,8 +299,6 @@ void state::_init_setter() { SETTER(const std::string&, log_level_otl, "log_level_otl"); SETTER(const std::string&, use_timezone, "use_timezone"); SETTER(bool, use_true_regexp_matching, "use_true_regexp_matching"); - SETTER(const std::string&, _set_comment_file, "xcddefault_comment_file"); - SETTER(const std::string&, _set_downtime_file, "xdddefault_downtime_file"); SETTER(bool, use_send_recovery_notifications_anyways, "send_recovery_notifications_anyways"); SETTER(bool, use_host_down_disable_service_checks, @@ -3786,20 +3748,6 @@ void state::user(unsigned int key, const std::string& value) { _users[fmt::format("{}", key)] = value; } -/** - * Set use_aggressive_host_checking value. This function is still there just - * to warn the user. It should be removed soon. - * - * @param[in] value The new use_aggressive_host_checking value. - */ -void state::use_aggressive_host_checking(bool value __attribute__((unused))) { - _logger->warn( - "Warning: use_aggressive_host_checking is deprecated. This option is " - "no " - "more supported since version 21.04."); - ++config_warnings; -} - /** * Get use_large_installation_tweaks value. * @@ -4313,37 +4261,6 @@ void state::use_true_regexp_matching(bool value) { _use_true_regexp_matching = value; } -/** - * Unused variable aggregate_status_updates. - * - * @param[in] value Unused. - */ -void state::_set_aggregate_status_updates(const std::string& value - [[maybe_unused]]) { - _logger->warn("Warning: aggregate_status_updates variable ignored"); - ++config_warnings; -} - -/** - * Unused variable auth_file. - * - * @param[in] value Unused. - */ -void state::_set_auth_file(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: auth_file variable ignored"); - ++config_warnings; -} - -/** - * Unused variable bare_update_check. - * - * @param[in] value Unused. - */ -void state::_set_bare_update_check(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: bare_update_check variable ignored"); - ++config_warnings; -} - /** * Add broker module. * @@ -4383,27 +4300,6 @@ void state::_set_cfg_file(const std::string& value) { } } -/** - * Unused variable check_for_updates. - * - * @param[in] value Unused. - */ -void state::_set_check_for_updates(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: check_for_updates variable ignored"); - ++config_warnings; -} - -/** - * Unused variable child_processes_fork_twice. - * - * @param[in] value Unused. - */ -void state::_set_child_processes_fork_twice(const std::string& value - [[maybe_unused]]) { - _logger->warn("Warning: child_processes_fork_twice variable ignored"); - ++config_warnings; -} - /** * Set command check interval. * @@ -4422,26 +4318,6 @@ void state::_set_command_check_interval(const std::string& value) { *this, val.c_str()); } -/** - * Unused variable comment_file. - * - * @param[in] value Unused. - */ -void state::_set_comment_file(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: comment_file variable ignored"); - ++config_warnings; -} - -/** - * Unused variable daemon_dumps_core. - * - * @param[in] value Unused. - */ -void state::_set_daemon_dumps_core(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: daemon_dumps_core variable ignored"); - ++config_warnings; -} - /** * Set date format. * @@ -4458,38 +4334,6 @@ void state::_set_date_format(const std::string& value) { _date_format = us; } -/** - * Unused variable downtime_file. - * - * @param[in] value Unused. - */ -void state::_set_downtime_file(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: downtime_file variable ignored"); - ++config_warnings; -} - -/** - * Unused variable enable_embedded_perl. - * - * @param[in] value Unused. - */ -void state::_set_enable_embedded_perl(const std::string& value - [[maybe_unused]]) { - _logger->warn("Warning: enable_embedded_perl variable ignored"); - ++config_warnings; -} - -/** - * Unused variable enable_failure_prediction. - * - * @param[in] value Unused. - */ -void state::_set_enable_failure_prediction(const std::string& value - [[maybe_unused]]) { - _logger->warn("Warning: enable_failure_prediction variable ignored"); - ++config_warnings; -} - /** * Set event_broker_options. * @@ -4504,17 +4348,6 @@ void state::_set_event_broker_options(const std::string& value) { } } -/** - * Unused variable free_child_process_memory. - * - * @param[in] value Unused. - */ -void state::_set_free_child_process_memory(const std::string& value - [[maybe_unused]]) { - _logger->warn("Warning: free_child_process_memory variable ignored"); - ++config_warnings; -} - /** * Set host_inter_check_delay_method. * @@ -4529,8 +4362,8 @@ void state::_set_host_inter_check_delay_method(const std::string& value) { _host_inter_check_delay_method = icd_smart; else { _host_inter_check_delay_method = icd_user; - if (!absl::SimpleAtod(value, &scheduling_info.host_inter_check_delay) || - scheduling_info.host_inter_check_delay <= 0.0) + if (!absl::SimpleAtod(value, &_scheduling_info.host_inter_check_delay) || + _scheduling_info.host_inter_check_delay <= 0.0) throw msg_fmt( "Invalid value for host_inter_check_delay_method, must be one of 'n' " "(none), 'd' (dumb), 's' (smart) or a stricly positive value ({} " @@ -4553,99 +4386,6 @@ void state::_set_host_perfdata_file_mode(const std::string& value) { _host_perfdata_file_mode = mode_file_append; } -/** - * Unused variable lock_file. - * - * @param[in] value Unused. - */ -void state::_set_lock_file(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: lock_file variable ignored"); - ++config_warnings; -} - -/** - * Unused variable log_archive_path. - * - * @param[in] value Unused. - */ -void state::_set_log_archive_path(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: log_archive_path variable ignored"); - ++config_warnings; -} - -/** - * Unused variable log_initial_states. - * - * @param[in] value Unused. - */ -void state::_set_log_initial_states(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: log_initial_states variable ignored"); - ++config_warnings; -} - -/** - * Unused variable log_rotation_method. - * - * @param[in] value Unused. - */ -void state::_set_log_rotation_method(const std::string& value - [[maybe_unused]]) { - _logger->warn("Warning: log_rotation_method variable ignored"); - ++config_warnings; -} - -/** - * Unused variable nagios_group. - * - * @param[in] value Unused. - */ -void state::_set_nagios_group(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: nagios_group variable ignored"); - ++config_warnings; -} - -/** - * Unused variable nagios_user. - * - * @param[in] value Unused. - */ -void state::_set_nagios_user(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: nagios_user variable ignored"); - ++config_warnings; -} - -/** - * Set object_cache_file value. - * - * @param[in] value Unused. - */ -void state::_set_object_cache_file(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: object_cache_file variable ignored"); - ++config_warnings; -} - -/** - * Unused variable p1_file. - * - * @param[in] value Unused. - */ -void state::_set_p1_file(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: p1_file variable ignored"); - - ++config_warnings; -} - -/** - * Set precached_object_file value. - * - * @param[in] value Unused. - */ -void state::_set_precached_object_file(const std::string& value - [[maybe_unused]]) { - _logger->warn("Warning: precached_object_file variable ignored"); - ++config_warnings; -} - /** * Set resource_file. * @@ -4661,29 +4401,6 @@ void state::_set_resource_file(const std::string& value) { } } -/** - * Unused variable retained_process_service_attribute_mask. - * - * @param[in] value Unused. - */ -void state::_set_retained_process_service_attribute_mask( - const std::string& value [[maybe_unused]]) { - _logger->warn( - "Warning: retained_process_service_attribute_mask variable ignored"); - ++config_warnings; -} - -/** - * Unused variable retained_service_attribute_mask. - * - * @param[in] value Unused. - */ -void state::_set_retained_service_attribute_mask(const std::string& value - [[maybe_unused]]) { - _logger->warn("Warning: retained_service_attribute_mask variable ignored"); - ++config_warnings; -} - /** * Set service_inter_check_delay_method * @@ -4698,8 +4415,8 @@ void state::_set_service_inter_check_delay_method(const std::string& value) { _service_inter_check_delay_method = icd_smart; else { _service_inter_check_delay_method = icd_user; - if (!absl::SimpleAtod(value, &scheduling_info.service_inter_check_delay) || - scheduling_info.service_inter_check_delay <= 0.0) + if (!absl::SimpleAtod(value, &_scheduling_info.service_inter_check_delay) || + _scheduling_info.service_inter_check_delay <= 0.0) throw msg_fmt( "Invalid value for service_inter_check_delay_method, must be one of " "'n' (none), 'd' (dumb), 's' (smart) or a strictly positive value " @@ -4718,9 +4435,9 @@ void state::_set_service_interleave_factor_method(const std::string& value) { _service_interleave_factor_method = ilf_smart; else { _service_interleave_factor_method = ilf_user; - if (!absl::SimpleAtoi(value, &scheduling_info.service_interleave_factor) || - scheduling_info.service_interleave_factor < 1) - scheduling_info.service_interleave_factor = 1; + if (!absl::SimpleAtoi(value, &_scheduling_info.service_interleave_factor) || + _scheduling_info.service_interleave_factor < 1) + _scheduling_info.service_interleave_factor = 1; } } @@ -4738,37 +4455,6 @@ void state::_set_service_perfdata_file_mode(const std::string& value) { _service_perfdata_file_mode = mode_file_append; } -/** - * Unused variable temp_file. - * - * @param[in] value Unused. - */ -void state::_set_temp_file(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: temp_file variable ignored"); - ++config_warnings; -} - -/** - * Unused variable temp_path. - * - * @param[in] value Unused. - */ -void state::_set_temp_path(const std::string& value [[maybe_unused]]) { - _logger->warn("Warning: temp_path variable ignored"); - ++config_warnings; -} - -/** - * Unused variable use_embedded_perl_implicitly. - * - * @param[in] value Unused. - */ -void state::_set_use_embedded_perl_implicitly(const std::string& value - [[maybe_unused]]) { - _logger->warn("Warning: use_embedded_perl_implicitly variable ignored"); - ++config_warnings; -} - void state::macros_filter(const std::string& value) { size_t previous(0), first, last; size_t current(value.find(',')); diff --git a/engine/src/configuration/tag.cc b/engine/src/configuration/tag.cc index c25b2a53194..f17fd214a78 100644 --- a/engine/src/configuration/tag.cc +++ b/engine/src/configuration/tag.cc @@ -110,7 +110,7 @@ bool tag::operator<(const tag& other) const noexcept { * * If the object is not valid, an exception is thrown. */ -void tag::check_validity() const { +void tag::check_validity(error_cnt& err [[maybe_unused]]) const { if (_tag_name.empty()) throw msg_fmt("Tag has no name (property 'tag_name')"); if (_key.first == 0) diff --git a/engine/src/configuration/timeperiod.cc b/engine/src/configuration/timeperiod.cc index 9b6afdb1f65..c4eb591f57f 100644 --- a/engine/src/configuration/timeperiod.cc +++ b/engine/src/configuration/timeperiod.cc @@ -126,7 +126,7 @@ bool timeperiod::operator<(timeperiod const& right) const { * * If the object is not valid, an exception is thrown. */ -void timeperiod::check_validity() const { +void timeperiod::check_validity(error_cnt& err [[maybe_unused]]) const { if (_timeperiod_name.empty()) throw msg_fmt("Time period has no name (property 'timeperiod_name')"); } diff --git a/engine/src/configuration/whitelist.cc b/engine/src/configuration/whitelist.cc index f9849a0bbe8..ae2780b75a7 100644 --- a/engine/src/configuration/whitelist.cc +++ b/engine/src/configuration/whitelist.cc @@ -17,7 +17,6 @@ * */ -#include "common/log_v2/log_v2.hh" #define C4_NO_DEBUG_BREAK 1 #include "com/centreon/engine/configuration/whitelist.hh" @@ -31,7 +30,6 @@ #include #include "absl/base/call_once.h" -#include "com/centreon/engine/globals.hh" #include "com/centreon/exceptions/msg_fmt.hh" #include "common/log_v2/log_v2.hh" diff --git a/engine/src/contact.cc b/engine/src/contact.cc index 0a2ac083a0a..3873f6854e5 100644 --- a/engine/src/contact.cc +++ b/engine/src/contact.cc @@ -1043,8 +1043,9 @@ bool contact::_to_notify_custom(notifier::reason_type type return true; } -void contact::resolve(int& w, int& e) { - int warnings{0}, errors{0}; +void contact::resolve(uint32_t& w, uint32_t& e) { + uint32_t warnings = 0; + uint32_t errors = 0; /* check service notification commands */ if (get_service_notification_commands().empty()) { diff --git a/engine/src/contactgroup.cc b/engine/src/contactgroup.cc index 6cd17d3388c..63e819c0f8c 100644 --- a/engine/src/contactgroup.cc +++ b/engine/src/contactgroup.cc @@ -1,22 +1,21 @@ /** * Copyright 2011-2019,2024 Centreon * - * This file is part of Centreon Engine. + * 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 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. + * 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 * - * You should have received a copy of the GNU General Public License - * along with Centreon Engine. If not, see - * . */ - #include "com/centreon/engine/configuration/contactgroup.hh" #include "com/centreon/engine/broker.hh" #include "com/centreon/engine/configuration/applier/state.hh" @@ -111,8 +110,8 @@ std::ostream& operator<<(std::ostream& os, contactgroup_map_unsafe const& obj) { return os; } -void contactgroup::resolve(int& w __attribute__((unused)), int& e) { - int errors{0}; +void contactgroup::resolve(uint32_t& w __attribute__((unused)), uint32_t& e) { + uint32_t errors = 0; for (contact_map_unsafe::iterator it{_members.begin()}, end{_members.end()}; it != end; ++it) { diff --git a/engine/src/diagnostic.cc b/engine/src/diagnostic.cc index e8a00107a18..0c2d3f443ef 100644 --- a/engine/src/diagnostic.cc +++ b/engine/src/diagnostic.cc @@ -156,8 +156,9 @@ void diagnostic::generate(std::string const& cfg_file, << std::endl; configuration::state conf; try { + configuration::error_cnt err; configuration::parser parsr; - parsr.parse(cfg_file, conf); + parsr.parse(cfg_file, conf, err); } catch (std::exception const& e) { std::cerr << "Diagnostic: configuration file '" << cfg_file << "' parsing failed: " << e.what() << std::endl; diff --git a/engine/src/escalation.cc b/engine/src/escalation.cc index eeedd11aefb..088ce33eb23 100644 --- a/engine/src/escalation.cc +++ b/engine/src/escalation.cc @@ -113,8 +113,8 @@ bool escalation::is_viable(int state __attribute__((unused)), return true; } -void escalation::resolve(int& w __attribute__((unused)), int& e) { - int errors{0}; +void escalation::resolve(uint32_t& w [[maybe_unused]], uint32_t& e) { + uint32_t errors = 0; // Find the timeperiod. if (!get_escalation_period().empty()) { timeperiod_map::const_iterator it{ diff --git a/engine/src/events/loop.cc b/engine/src/events/loop.cc index 59cd5fe765a..7a3c981f435 100644 --- a/engine/src/events/loop.cc +++ b/engine/src/events/loop.cc @@ -92,6 +92,7 @@ void loop::run() { loop::loop() : _need_reload(0), _reload_running(false) {} static void apply_conf(std::atomic* reloading) { + configuration::error_cnt err; engine_logger(log_info_message, more) << "Starting to reload configuration."; process_logger->info("Starting to reload configuration."); try { @@ -99,10 +100,10 @@ static void apply_conf(std::atomic* reloading) { { configuration::parser p; std::string path(::config->cfg_main()); - p.parse(path, config); + p.parse(path, config, err); } configuration::extended_conf::update_state(config); - configuration::applier::state::instance().apply(config); + configuration::applier::state::instance().apply(config, err); engine_logger(log_info_message, basic) << "Configuration reloaded, main loop continuing."; process_logger->info("Configuration reloaded, main loop continuing."); diff --git a/engine/src/globals.cc b/engine/src/globals.cc index e00e0736d06..99346e158e1 100644 --- a/engine/src/globals.cc +++ b/engine/src/globals.cc @@ -73,8 +73,6 @@ com::centreon::engine::commands::command* global_service_event_handler_ptr( com::centreon::engine::commands::command* ochp_command_ptr(NULL); com::centreon::engine::commands::command* ocsp_command_ptr(NULL); int additional_freshness_latency(15); -int config_errors(0); -int config_warnings(0); int sig_id(0); bool sighup{false}; int sigrestart(false); diff --git a/engine/src/host.cc b/engine/src/host.cc index 802b4c85ceb..023fe969f6f 100644 --- a/engine/src/host.cc +++ b/engine/src/host.cc @@ -3951,8 +3951,9 @@ bool host::is_in_downtime() const { * @param e Errors given by the method. An exception is thrown is at less an * error is rised. */ -void host::resolve(int& w, int& e) { - int warnings{0}, errors{0}; +void host::resolve(uint32_t& w, uint32_t& e) { + uint32_t warnings = 0; + uint32_t errors = 0; try { notifier::resolve(warnings, errors); diff --git a/engine/src/hostdependency.cc b/engine/src/hostdependency.cc index d96c8cb99ab..497ac2695ab 100644 --- a/engine/src/hostdependency.cc +++ b/engine/src/hostdependency.cc @@ -228,9 +228,8 @@ bool hostdependency::check_for_circular_hostdependency_path( return false; } -void hostdependency::resolve(int& w, int& e) { - (void)w; - int errors{0}; +void hostdependency::resolve(uint32_t& w [[maybe_unused]], uint32_t& e) { + int errors = 0; // Find the dependent host. host_map::const_iterator it = host::hosts.find(_dependent_hostname); diff --git a/engine/src/hostescalation.cc b/engine/src/hostescalation.cc index 5d0e4bba3ce..d3bd6bf6064 100644 --- a/engine/src/hostescalation.cc +++ b/engine/src/hostescalation.cc @@ -91,9 +91,8 @@ bool hostescalation::is_viable(int state, uint32_t notification_number) const { return retval; } -void hostescalation::resolve(int& w, int& e) { - (void)w; - int errors{0}; +void hostescalation::resolve(uint32_t& w [[maybe_unused]], uint32_t& e) { + uint32_t errors = 0; // Find the host. host_map::const_iterator found(host::hosts.find(this->get_hostname())); diff --git a/engine/src/hostgroup.cc b/engine/src/hostgroup.cc index 54a911fb717..e533bc9c30f 100644 --- a/engine/src/hostgroup.cc +++ b/engine/src/hostgroup.cc @@ -1,22 +1,21 @@ /** * Copyright 2011-2024 Centreon * - * This file is part of Centreon Engine. + * 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 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. + * 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 * - * You should have received a copy of the GNU General Public License - * along with Centreon Engine. If not, see - * . */ - #include "com/centreon/engine/hostgroup.hh" #include "com/centreon/engine/broker.hh" #include "com/centreon/engine/configuration/applier/state.hh" @@ -155,9 +154,8 @@ std::ostream& operator<<(std::ostream& os, return (os); } -void hostgroup::resolve(int& w, int& e) { - (void)w; - int errors{0}; +void hostgroup::resolve(uint32_t& w [[maybe_unused]], uint32_t& e) { + uint32_t errors = 0; // Check all group members. for (host_map_unsafe::iterator it{members.begin()}, end{members.end()}; diff --git a/engine/src/main.cc b/engine/src/main.cc index 53dbe0d08e1..7ea59d82e0a 100644 --- a/engine/src/main.cc +++ b/engine/src/main.cc @@ -207,13 +207,14 @@ int main(int argc, char* argv[]) { // Just display the license. if (display_license) { std::cout - << "Centreon Engine " << CENTREON_ENGINE_VERSION_STRING - << "\n" + << "Centreon Engine " CENTREON_ENGINE_VERSION_STRING + "\n" "\n" "Copyright 1999-2009 Ethan Galstad\n" "Copyright 2009-2010 Nagios Core Development Team and Community " "Contributors\n" - "Copyright 2011-2021 Centreon\n" + "Copyright 2011-" CENTREON_CURRENT_YEAR + " 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 " @@ -275,13 +276,14 @@ int main(int argc, char* argv[]) { try { // Read in the configuration files (main config file, // resource and object config files). + configuration::error_cnt err; configuration::state config; { configuration::parser p; - p.parse(config_file, config); + p.parse(config_file, config, err); } - configuration::applier::state::instance().apply(config); + configuration::applier::state::instance().apply(config, err); std::cout << "\n Checked " << commands::command::commands.size() << " commands.\n Checked " @@ -301,9 +303,10 @@ int main(int argc, char* argv[]) { << 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; + << " time periods.\n\n Total Warnings: " + << err.config_warnings + << "\n Total Errors: " << err.config_errors << std::endl; + retval = err.config_errors ? EXIT_FAILURE : EXIT_SUCCESS; } catch (const std::exception& e) { std::cout << "Error while processing a config file: " << e.what() << std::endl; @@ -330,9 +333,10 @@ int main(int argc, char* argv[]) { try { // Parse configuration. configuration::state config; + configuration::error_cnt err; { configuration::parser p; - p.parse(config_file, config); + p.parse(config_file, config, err); } // Parse retention. @@ -348,7 +352,7 @@ int main(int argc, char* argv[]) { } // Apply configuration. - configuration::applier::state::instance().apply(config, state); + configuration::applier::state::instance().apply(config, err, &state); display_scheduling_info(); retval = EXIT_SUCCESS; @@ -365,10 +369,11 @@ int main(int argc, char* argv[]) { else { try { // Parse configuration. + configuration::error_cnt err; configuration::state config; { configuration::parser p; - p.parse(config_file, config); + p.parse(config_file, config, err); } configuration::extended_conf::load_all(extended_conf_file.begin(), @@ -432,7 +437,7 @@ int main(int argc, char* argv[]) { &backend_broker_log, logging::log_all, logging::basic); // Apply configuration. - configuration::applier::state::instance().apply(config, state); + configuration::applier::state::instance().apply(config, err, &state); // Handle signals (interrupts). setup_sighandler(); diff --git a/engine/src/notifier.cc b/engine/src/notifier.cc index 9f99a71a7fa..418229df236 100644 --- a/engine/src/notifier.cc +++ b/engine/src/notifier.cc @@ -1,22 +1,21 @@ /** - * Copyright 2011-2019 Centreon + * Copyright 2011-2024 Centreon * - * This file is part of Centreon Engine. + * 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 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. + * 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 * - * You should have received a copy of the GNU General Public License - * along with Centreon Engine. If not, see - * . */ - #include "com/centreon/engine/notifier.hh" #include "com/centreon/engine/broker.hh" @@ -1371,8 +1370,8 @@ bool is_contact_for_notifier(com::centreon::engine::notifier* notif, * @param e Errors given by the method. An exception is thrown is at less an * error is rised. */ -void notifier::resolve(int& w, int& e) { - int warnings{0}, errors{0}; +void notifier::resolve(uint32_t& w, uint32_t& e) { + uint32_t warnings = 0, errors = 0; /* This list will be filled in {hostescalation,serviceescalation}::resolve */ _escalations.clear(); diff --git a/engine/src/retention/program.cc b/engine/src/retention/program.cc index 6d571448095..06f0cbd186d 100644 --- a/engine/src/retention/program.cc +++ b/engine/src/retention/program.cc @@ -32,7 +32,6 @@ program::setters const program::_setters[] = { {"check_host_freshness", SETTER(bool, _set_check_host_freshness)}, {"check_service_freshness", SETTER(bool, _set_check_service_freshness)}, {"enable_event_handlers", SETTER(bool, _set_enable_event_handlers)}, - {"enable_failure_prediction", SETTER(bool, _set_enable_failure_prediction)}, {"enable_flap_detection", SETTER(bool, _set_enable_flap_detection)}, {"enable_notifications", SETTER(bool, _set_enable_notifications)}, {"global_host_event_handler", @@ -409,16 +408,6 @@ bool program::_set_enable_event_handlers(bool value) { return (true); } -/** - * Deprecated. - * - * @param[in] value Unused. - */ -bool program::_set_enable_failure_prediction(bool value) { - (void)value; - return (true); -} - /** * Set enable_flap_detection. * diff --git a/engine/src/service.cc b/engine/src/service.cc index c4b96d2962c..3ca52aa723d 100644 --- a/engine/src/service.cc +++ b/engine/src/service.cc @@ -3864,8 +3864,9 @@ host* service::get_host_ptr() { return _host_ptr; } -void service::resolve(int& w, int& e) { - int warnings{0}, errors{0}; +void service::resolve(uint32_t& w, uint32_t& e) { + uint32_t warnings = 0; + uint32_t errors = 0; try { notifier::resolve(warnings, errors); diff --git a/engine/src/servicedependency.cc b/engine/src/servicedependency.cc index 80a73c55dc7..07de74d3558 100644 --- a/engine/src/servicedependency.cc +++ b/engine/src/servicedependency.cc @@ -289,9 +289,8 @@ bool servicedependency::check_for_circular_servicedependency_path( return false; } -void servicedependency::resolve(int& w, int& e) { - (void)w; - int errors{0}; +void servicedependency::resolve(uint32_t& w [[maybe_unused]], uint32_t& e) { + uint32_t errors = 0; // Find the dependent service. service_map::const_iterator found{service::services.find( diff --git a/engine/src/serviceescalation.cc b/engine/src/serviceescalation.cc index 41db8011492..27751dfc13f 100644 --- a/engine/src/serviceescalation.cc +++ b/engine/src/serviceescalation.cc @@ -86,9 +86,8 @@ bool serviceescalation::is_viable(int state, return retval; } -void serviceescalation::resolve(int& w, int& e) { - (void)w; - int errors{0}; +void serviceescalation::resolve(uint32_t& w [[maybe_unused]], uint32_t& e) { + uint32_t errors = 0; // Find the service. service_map::const_iterator found{ diff --git a/engine/src/servicegroup.cc b/engine/src/servicegroup.cc index c8b24fcf126..1c1cfbb6415 100644 --- a/engine/src/servicegroup.cc +++ b/engine/src/servicegroup.cc @@ -1,22 +1,22 @@ /** * Copyright 2011-2013 Merethis + * Copyright 2014-2024 Centreon * - * This file is part of Centreon Engine. + * 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 * - * 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. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 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. + * 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 * - * You should have received a copy of the GNU General Public License - * along with Centreon Engine. If not, see - * . */ - #include "com/centreon/engine/servicegroup.hh" #include "com/centreon/engine/broker.hh" #include "com/centreon/engine/configuration/applier/state.hh" @@ -161,9 +161,8 @@ bool engine::is_servicegroup_exist(std::string const& name) throw() { return it != servicegroup::servicegroups.end(); } -void servicegroup::resolve(int& w, int& e) { - (void)w; - int errors{0}; +void servicegroup::resolve(uint32_t& w [[maybe_unused]], uint32_t& e) { + uint32_t errors = 0; // Check all group members. for (service_map_unsafe::iterator it(members.begin()), end(members.end()); diff --git a/engine/src/timeperiod.cc b/engine/src/timeperiod.cc index e156edd99f2..c95bd84957c 100644 --- a/engine/src/timeperiod.cc +++ b/engine/src/timeperiod.cc @@ -1149,8 +1149,8 @@ void get_next_valid_time(time_t pref_time, * @param e[out] Number of errors produced during this resolution. * */ -void timeperiod::resolve(int& w __attribute__((unused)), int& e) { - int errors{0}; +void timeperiod::resolve(uint32_t& w __attribute__((unused)), uint32_t& e) { + uint32_t errors = 0; // Check for illegal characters in timeperiod name. if (contains_illegal_object_chars(_name.c_str())) { diff --git a/engine/tests/checks/anomalydetection.cc b/engine/tests/checks/anomalydetection.cc index d210bd77ea6..cb78afc4717 100644 --- a/engine/tests/checks/anomalydetection.cc +++ b/engine/tests/checks/anomalydetection.cc @@ -54,11 +54,12 @@ class AnomalydetectionCheck : public TestEngine { checks_logger->set_level(spdlog::level::trace); commands_logger->set_level(spdlog::level::trace); + error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -69,8 +70,8 @@ class AnomalydetectionCheck : public TestEngine { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); configuration::anomalydetection ad{new_configuration_anomalydetection( "test_host", "test_ad", "admin", 9, 8, @@ -78,7 +79,7 @@ class AnomalydetectionCheck : public TestEngine { configuration::applier::anomalydetection ad_aply; ad_aply.add_object(ad); - ad_aply.resolve_object(ad); + ad_aply.resolve_object(ad, err); host_map const& hm{engine::host::hosts}; _host = hm.begin()->second; diff --git a/engine/tests/checks/service_check.cc b/engine/tests/checks/service_check.cc index a58e4185eb4..3046a65960f 100644 --- a/engine/tests/checks/service_check.cc +++ b/engine/tests/checks/service_check.cc @@ -52,6 +52,7 @@ extern configuration::state* config; class ServiceCheck : public TestEngine { public: void SetUp() override { + configuration::error_cnt err; init_config_state(); config->contacts().clear(); @@ -59,7 +60,7 @@ class ServiceCheck : public TestEngine { configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -70,8 +71,8 @@ class ServiceCheck : public TestEngine { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); host_map const& hm{engine::host::hosts}; _host = hm.begin()->second; diff --git a/engine/tests/checks/service_retention.cc b/engine/tests/checks/service_retention.cc index 39c95bfbb5f..22e1fd35fef 100644 --- a/engine/tests/checks/service_retention.cc +++ b/engine/tests/checks/service_retention.cc @@ -52,6 +52,9 @@ using namespace com::centreon::engine::configuration::applier; extern configuration::state* config; class ServiceRetention : public TestEngine { + protected: + error_cnt _err; + public: void SetUp() override { init_config_state(); @@ -63,7 +66,7 @@ class ServiceRetention : public TestEngine { configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, _err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -74,8 +77,8 @@ class ServiceRetention : public TestEngine { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, _err); + svc_aply.resolve_object(svc, _err); host_map const& hm{engine::host::hosts}; _host = hm.begin()->second; diff --git a/engine/tests/configuration/applier-severity.cc b/engine/tests/configuration/applier-severity.cc index 2fc28b857a1..8c47ac08900 100644 --- a/engine/tests/configuration/applier-severity.cc +++ b/engine/tests/configuration/applier-severity.cc @@ -26,9 +26,6 @@ using namespace com::centreon::engine; using namespace com::centreon::engine::configuration; using namespace com::centreon::engine::configuration::applier; -extern int config_errors; -extern int config_warnings; - class ApplierSeverity : public ::testing::Test { public: void SetUp() override { diff --git a/engine/tests/configuration/applier/applier-command.cc b/engine/tests/configuration/applier/applier-command.cc index 3c530d44896..3035c263a09 100755 --- a/engine/tests/configuration/applier/applier-command.cc +++ b/engine/tests/configuration/applier/applier-command.cc @@ -122,6 +122,7 @@ TEST_F(ApplierCommand, NewCommandWithConnectorFromConfig) { // Then the applier add_object adds the command into the configuration set // but not in the commands map (the connector is not defined). TEST_F(ApplierCommand, NewCommandAndConnectorWithSameName) { + error_cnt err; configuration::applier::command aply; configuration::applier::connector cnn_aply; configuration::command cmd("cmd"); @@ -141,7 +142,7 @@ TEST_F(ApplierCommand, NewCommandAndConnectorWithSameName) { ASSERT_EQ(found->second->get_name(), "cmd"); ASSERT_EQ(found->second->get_command_line(), "echo 1"); - aply.resolve_object(cmd); + aply.resolve_object(cmd, err); connector_map::iterator found_con{ commands::connector::connectors.find("cmd")}; ASSERT_TRUE(found_con != commands::connector::connectors.end()); @@ -227,6 +228,7 @@ TEST_F(ApplierCommand, RemoveCommandWithConnector) { // When the command is removed from the configuration, // Then the command is totally removed. TEST_F(ApplierCommand, ComplexCommand) { + error_cnt err; configuration::applier::command cmd_aply; configuration::applier::host hst_aply; @@ -256,7 +258,7 @@ TEST_F(ApplierCommand, ComplexCommand) { ASSERT_TRUE(config->hosts().size() == 1); hst_aply.expand_objects(*config); - hst_aply.resolve_object(hst); + hst_aply.resolve_object(hst, err); ASSERT_TRUE(hst_found->second->custom_variables.size() == 3); nagios_macros* macros(get_global_macros()); grab_host_macros_r(macros, hst_found->second.get()); @@ -271,6 +273,7 @@ TEST_F(ApplierCommand, ComplexCommand) { // When the command is removed from the configuration, // Then the command is totally removed. TEST_F(ApplierCommand, ComplexCommandWithContact) { + error_cnt err; configuration::applier::command cmd_aply; configuration::applier::host hst_aply; configuration::applier::contact cnt_aply; @@ -310,7 +313,7 @@ TEST_F(ApplierCommand, ComplexCommandWithContact) { ASSERT_TRUE(config->hosts().size() == 1); hst_aply.expand_objects(*config); - hst_aply.resolve_object(hst); + hst_aply.resolve_object(hst, err); ASSERT_TRUE(hst_found->second->custom_variables.size() == 3); nagios_macros* macros(get_global_macros()); grab_host_macros_r(macros, hst_found->second.get()); diff --git a/engine/tests/configuration/applier/applier-connector.cc b/engine/tests/configuration/applier/applier-connector.cc index ff183e871f8..c0bc411371b 100644 --- a/engine/tests/configuration/applier/applier-connector.cc +++ b/engine/tests/configuration/applier/applier-connector.cc @@ -84,7 +84,6 @@ TEST_F(ApplierConnector, ModifyNonExistingConnector) { // When a non existing connector is removed // Then nothing is done. TEST_F(ApplierConnector, RemoveNonExistingConnector) { - configuration::applier::connector aply; configuration::connector cnn("connector"); cnn.parse("connector_line", "echo 1"); diff --git a/engine/tests/configuration/applier/applier-contact.cc b/engine/tests/configuration/applier/applier-contact.cc index 001cfed503c..bff735f72ab 100644 --- a/engine/tests/configuration/applier/applier-contact.cc +++ b/engine/tests/configuration/applier/applier-contact.cc @@ -34,16 +34,9 @@ using namespace com::centreon::engine; using namespace com::centreon::engine::configuration; using namespace com::centreon::engine::configuration::applier; -extern int config_errors; -extern int config_warnings; - class ApplierContact : public ::testing::Test { public: - void SetUp() override { - config_errors = 0; - config_warnings = 0; - init_config_state(); - } + void SetUp() override { init_config_state(); } void TearDown() override { deinit_config_state(); } @@ -200,7 +193,8 @@ TEST_F(ApplierContact, ResolveContactFromConfig) { aply_grp.add_object(grp); aply.add_object(ctct); aply.expand_objects(*config); - ASSERT_THROW(aply.resolve_object(ctct), std::exception); + error_cnt err; + ASSERT_THROW(aply.resolve_object(ctct, err), std::exception); } // Given a contact @@ -217,9 +211,10 @@ TEST_F(ApplierContact, ResolveContactNoNotification) { configuration::contact ctct("test"); aply.add_object(ctct); aply.expand_objects(*config); - ASSERT_THROW(aply.resolve_object(ctct), std::exception); - ASSERT_EQ(config_warnings, 2); - ASSERT_EQ(config_errors, 2); + error_cnt err; + ASSERT_THROW(aply.resolve_object(ctct, err), std::exception); + ASSERT_EQ(err.config_warnings, 2); + ASSERT_EQ(err.config_errors, 2); } // Given a valid contact @@ -237,9 +232,10 @@ TEST_F(ApplierContact, ResolveValidContact) { configuration::contact ctct(valid_contact_config()); aply.add_object(ctct); aply.expand_objects(*config); - ASSERT_NO_THROW(aply.resolve_object(ctct)); - ASSERT_EQ(config_warnings, 0); - ASSERT_EQ(config_errors, 0); + error_cnt err; + ASSERT_NO_THROW(aply.resolve_object(ctct, err)); + ASSERT_EQ(err.config_warnings, 0); + ASSERT_EQ(err.config_errors, 0); } // Given a valid contact @@ -253,9 +249,10 @@ TEST_F(ApplierContact, ResolveNonExistingServiceNotificationTimeperiod) { ctct.parse("service_notification_period", "non_existing_period"); aply.add_object(ctct); aply.expand_objects(*config); - ASSERT_THROW(aply.resolve_object(ctct), std::exception); - ASSERT_EQ(config_warnings, 0); - ASSERT_EQ(config_errors, 1); + error_cnt err; + ASSERT_THROW(aply.resolve_object(ctct, err), std::exception); + ASSERT_EQ(err.config_warnings, 0); + ASSERT_EQ(err.config_errors, 1); } // Given a valid contact @@ -269,9 +266,10 @@ TEST_F(ApplierContact, ResolveNonExistingHostNotificationTimeperiod) { ctct.parse("host_notification_period", "non_existing_period"); aply.add_object(ctct); aply.expand_objects(*config); - ASSERT_THROW(aply.resolve_object(ctct), std::exception); - ASSERT_EQ(config_warnings, 0); - ASSERT_EQ(config_errors, 1); + error_cnt err; + ASSERT_THROW(aply.resolve_object(ctct, err), std::exception); + ASSERT_EQ(err.config_warnings, 0); + ASSERT_EQ(err.config_errors, 1); } // Given a valid contact @@ -285,9 +283,10 @@ TEST_F(ApplierContact, ResolveNonExistingServiceCommand) { ctct.parse("service_notification_commands", "non_existing_command"); aply.add_object(ctct); aply.expand_objects(*config); - ASSERT_THROW(aply.resolve_object(ctct), std::exception); - ASSERT_EQ(config_warnings, 0); - ASSERT_EQ(config_errors, 1); + error_cnt err; + ASSERT_THROW(aply.resolve_object(ctct, err), std::exception); + ASSERT_EQ(err.config_warnings, 0); + ASSERT_EQ(err.config_errors, 1); } // Given a valid contact @@ -301,9 +300,10 @@ TEST_F(ApplierContact, ResolveNonExistingHostCommand) { ctct.parse("host_notification_commands", "non_existing_command"); aply.add_object(ctct); aply.expand_objects(*config); - ASSERT_THROW(aply.resolve_object(ctct), std::exception); - ASSERT_EQ(config_warnings, 0); - ASSERT_EQ(config_errors, 1); + error_cnt err; + ASSERT_THROW(aply.resolve_object(ctct, err), std::exception); + ASSERT_EQ(err.config_warnings, 0); + ASSERT_EQ(err.config_errors, 1); } // Given a valid contact configuration @@ -366,9 +366,10 @@ TEST_F(ApplierContact, ContactWithOnlyHostRecoveryNotification) { ctct.parse("service_notifications_enabled", "1"); aply.add_object(ctct); aply.expand_objects(*config); - aply.resolve_object(ctct); - ASSERT_EQ(config_warnings, 1); - ASSERT_EQ(config_errors, 0); + error_cnt err; + aply.resolve_object(ctct, err); + ASSERT_EQ(err.config_warnings, 1); + ASSERT_EQ(err.config_errors, 0); } // Given a valid contact @@ -385,7 +386,8 @@ TEST_F(ApplierContact, ContactWithOnlyServiceRecoveryNotification) { ctct.parse("service_notifications_enabled", "1"); aply.add_object(ctct); aply.expand_objects(*config); - aply.resolve_object(ctct); - ASSERT_EQ(config_warnings, 1); - ASSERT_EQ(config_errors, 0); + error_cnt err; + aply.resolve_object(ctct, err); + ASSERT_EQ(err.config_warnings, 1); + ASSERT_EQ(err.config_errors, 0); } diff --git a/engine/tests/configuration/applier/applier-contactgroup.cc b/engine/tests/configuration/applier/applier-contactgroup.cc index 98c27920e44..ccbef264891 100644 --- a/engine/tests/configuration/applier/applier-contactgroup.cc +++ b/engine/tests/configuration/applier/applier-contactgroup.cc @@ -30,16 +30,9 @@ using namespace com::centreon::engine; using namespace com::centreon::engine::configuration; using namespace com::centreon::engine::configuration::applier; -extern int config_errors; -extern int config_warnings; - class ApplierContactgroup : public ::testing::Test { public: - void SetUp() override { - config_errors = 0; - config_warnings = 0; - init_config_state(); - } + void SetUp() override { init_config_state(); } void TearDown() override { deinit_config_state(); } }; @@ -146,6 +139,7 @@ TEST_F(ApplierContactgroup, ResolveInexistentContact) { // When the resolve_object() method is called // Then the contact is really added to the contact group. TEST_F(ApplierContactgroup, ResolveContactgroup) { + error_cnt err; configuration::applier::contact aply; configuration::applier::contactgroup aply_grp; configuration::contactgroup grp("test_group"); @@ -155,7 +149,7 @@ TEST_F(ApplierContactgroup, ResolveContactgroup) { grp.parse("members", "test"); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - ASSERT_NO_THROW(aply_grp.resolve_object(grp)); + ASSERT_NO_THROW(aply_grp.resolve_object(grp, err)); } // Given a contactgroup with a contact already configured @@ -164,6 +158,7 @@ TEST_F(ApplierContactgroup, ResolveContactgroup) { // Then the parse method returns true and set the first one contacts // to the second one. TEST_F(ApplierContactgroup, SetContactgroupMembers) { + error_cnt err; configuration::applier::contact aply; configuration::applier::contactgroup aply_grp; configuration::contactgroup grp("test_group"); @@ -172,7 +167,7 @@ TEST_F(ApplierContactgroup, SetContactgroupMembers) { grp.parse("members", "test"); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - aply_grp.resolve_object(grp); + aply_grp.resolve_object(grp, err); ASSERT_TRUE(grp.members().size() == 1); configuration::contactgroup grp1("big_group"); @@ -185,6 +180,7 @@ TEST_F(ApplierContactgroup, SetContactgroupMembers) { } TEST_F(ApplierContactgroup, ContactRemove) { + error_cnt err; configuration::applier::contact aply; configuration::applier::contactgroup aply_grp; configuration::contactgroup grp("test_group"); @@ -198,7 +194,7 @@ TEST_F(ApplierContactgroup, ContactRemove) { grp.parse("members", "test, test2"); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - aply_grp.resolve_object(grp); + aply_grp.resolve_object(grp, err); ASSERT_EQ( engine::contactgroup::contactgroups["test_group"]->get_members().size(), 2u); diff --git a/engine/tests/configuration/applier/applier-global.cc b/engine/tests/configuration/applier/applier-global.cc index ac272cae031..107abebe923 100644 --- a/engine/tests/configuration/applier/applier-global.cc +++ b/engine/tests/configuration/applier/applier-global.cc @@ -21,6 +21,8 @@ #include #include #include +#include "com/centreon/engine/configuration/state.hh" +#include "com/centreon/engine/globals.hh" #include "helper.hh" using namespace com::centreon; @@ -38,6 +40,7 @@ class ApplierGlobal : public ::testing::Test { TEST_F(ApplierGlobal, pollerName) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.poller_name(), "unknown"); @@ -47,7 +50,7 @@ TEST_F(ApplierGlobal, pollerName) { ofs << "poller_name=poller-test" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); std::remove("/tmp/test-config.cfg"); ASSERT_EQ(st.poller_name(), "poller-test"); @@ -56,6 +59,7 @@ TEST_F(ApplierGlobal, pollerName) { TEST_F(ApplierGlobal, pollerId) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.poller_id(), 0u); @@ -65,7 +69,7 @@ TEST_F(ApplierGlobal, pollerId) { ofs << "poller_id=42" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); std::remove("/tmp/test-config.cfg"); ASSERT_EQ(st.poller_id(), 42u); @@ -74,6 +78,7 @@ TEST_F(ApplierGlobal, pollerId) { TEST_F(ApplierGlobal, RpcPort) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.rpc_port(), 0u); @@ -83,7 +88,7 @@ TEST_F(ApplierGlobal, RpcPort) { ofs << "rpc_port=42" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); std::remove("/tmp/test-config.cfg"); ASSERT_EQ(st.rpc_port(), 42u); @@ -92,6 +97,7 @@ TEST_F(ApplierGlobal, RpcPort) { TEST_F(ApplierGlobal, RpcListenAddress) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.rpc_port(), 0u); @@ -101,7 +107,7 @@ TEST_F(ApplierGlobal, RpcListenAddress) { ofs << "rpc_listen_address=10.11.12.13" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); std::remove("/tmp/test-config.cfg"); ASSERT_EQ(st.rpc_listen_address(), "10.11.12.13"); @@ -110,6 +116,7 @@ TEST_F(ApplierGlobal, RpcListenAddress) { TEST_F(ApplierGlobal, NotDefinedRpcListenAddress) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.rpc_port(), 0u); @@ -119,7 +126,7 @@ TEST_F(ApplierGlobal, NotDefinedRpcListenAddress) { ofs << "rpc_port=42" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); std::remove("/tmp/test-config.cfg"); ASSERT_EQ(st.rpc_listen_address(), "localhost"); diff --git a/engine/tests/configuration/applier/applier-host.cc b/engine/tests/configuration/applier/applier-host.cc index 88b6be736a0..7250d45dc3f 100644 --- a/engine/tests/configuration/applier/applier-host.cc +++ b/engine/tests/configuration/applier/applier-host.cc @@ -102,6 +102,7 @@ TEST_F(ApplierHost, HostRemoved) { } TEST_F(ApplierHost, HostParentChildUnreachable) { + error_cnt err; configuration::applier::host hst_aply; configuration::applier::command cmd_aply; configuration::host hst_child; @@ -135,8 +136,8 @@ TEST_F(ApplierHost, HostParentChildUnreachable) { ASSERT_EQ(engine::host::hosts.size(), 2u); hst_aply.expand_objects(*config); - hst_aply.resolve_object(hst_child); - hst_aply.resolve_object(hst_parent); + hst_aply.resolve_object(hst_child, err); + hst_aply.resolve_object(hst_parent, err); host_map::iterator child = engine::host::hosts.find("child_host"); host_map::iterator parent = engine::host::hosts.find("parent_host"); diff --git a/engine/tests/configuration/applier/applier-hostdependency.cc b/engine/tests/configuration/applier/applier-hostdependency.cc index 06707899e0f..6429646d270 100644 --- a/engine/tests/configuration/applier/applier-hostdependency.cc +++ b/engine/tests/configuration/applier/applier-hostdependency.cc @@ -52,70 +52,73 @@ extern configuration::state* config; class HostDependency : public TestEngine { public: void SetUp() override { + error_cnt err; init_config_state(); configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::host hst_aply; configuration::host hst1{new_configuration_host("host1", "admin", 18)}; hst_aply.add_object(hst1); - hst_aply.resolve_object(hst1); + hst_aply.resolve_object(hst1, err); configuration::host hst2{new_configuration_host("host2", "admin", 19)}; hst_aply.add_object(hst2); - hst_aply.resolve_object(hst2); + hst_aply.resolve_object(hst2, err); configuration::host hst3{new_configuration_host("host3", "admin", 20)}; hst_aply.add_object(hst3); - hst_aply.resolve_object(hst3); + hst_aply.resolve_object(hst3, err); } void TearDown() override { deinit_config_state(); } }; TEST_F(HostDependency, CircularDependency2) { + error_cnt err; configuration::applier::hostdependency hd_aply; configuration::hostdependency hd1{ new_configuration_hostdependency("host1", "host2")}; hd_aply.expand_objects(*config); hd_aply.add_object(hd1); - hd_aply.resolve_object(hd1); + hd_aply.resolve_object(hd1, err); configuration::hostdependency hd2{ new_configuration_hostdependency("host2", "host1")}; hd_aply.expand_objects(*config); hd_aply.add_object(hd2); - hd_aply.resolve_object(hd2); + hd_aply.resolve_object(hd2, err); - int w{0}, e{0}; + uint32_t w = 0, e = 0; ASSERT_EQ(pre_flight_circular_check(&w, &e), ERROR); } TEST_F(HostDependency, CircularDependency3) { + error_cnt err; configuration::applier::hostdependency hd_aply; configuration::hostdependency hd1{ new_configuration_hostdependency("host1", "host2")}; hd_aply.expand_objects(*config); hd_aply.add_object(hd1); - hd_aply.resolve_object(hd1); + hd_aply.resolve_object(hd1, err); configuration::hostdependency hd2{ new_configuration_hostdependency("host2", "host3")}; hd_aply.expand_objects(*config); hd_aply.add_object(hd2); - hd_aply.resolve_object(hd2); + hd_aply.resolve_object(hd2, err); configuration::hostdependency hd3{ new_configuration_hostdependency("host3", "host1")}; hd_aply.expand_objects(*config); hd_aply.add_object(hd3); - hd_aply.resolve_object(hd3); + hd_aply.resolve_object(hd3, err); - int w{0}, e{0}; + uint32_t w{0}, e{0}; ASSERT_EQ(pre_flight_circular_check(&w, &e), ERROR); } diff --git a/engine/tests/configuration/applier/applier-hostescalation.cc b/engine/tests/configuration/applier/applier-hostescalation.cc index 42a647a5be1..8cdee2a6141 100644 --- a/engine/tests/configuration/applier/applier-hostescalation.cc +++ b/engine/tests/configuration/applier/applier-hostescalation.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,7 @@ TEST_F(ApplierHostEscalation, AddEscalation) { } TEST_F(ApplierHostEscalation, ResolveObject) { + configuration::error_cnt err; configuration::applier::host hst_aply; configuration::host hst; ASSERT_TRUE(hst.parse("host_name", "test_host")); @@ -68,9 +70,9 @@ TEST_F(ApplierHostEscalation, ResolveObject) { configuration::hostescalation he; ASSERT_TRUE(he.parse("host_name", "test_host")); ASSERT_TRUE(he.parse("first_notification", "4")); - ASSERT_THROW(he_apply.resolve_object(he), std::exception); + ASSERT_THROW(he_apply.resolve_object(he, err), std::exception); he_apply.add_object(he); - ASSERT_NO_THROW(he_apply.resolve_object(he)); + ASSERT_NO_THROW(he_apply.resolve_object(he, err)); } TEST_F(ApplierHostEscalation, RemoveEscalation) { diff --git a/engine/tests/configuration/applier/applier-hostgroup.cc b/engine/tests/configuration/applier/applier-hostgroup.cc index 6c0c0da0299..3747fac883d 100644 --- a/engine/tests/configuration/applier/applier-hostgroup.cc +++ b/engine/tests/configuration/applier/applier-hostgroup.cc @@ -41,6 +41,7 @@ class ApplierHostGroup : public ::testing::Test { // Given host configuration without host_id // Then the applier add_object throws an exception. TEST_F(ApplierHostGroup, NewHostGroup) { + error_cnt err; configuration::applier::hostgroup hg_aply; configuration::applier::host hst_aply; configuration::hostgroup hg; @@ -72,10 +73,10 @@ TEST_F(ApplierHostGroup, NewHostGroup) { ASSERT_NO_THROW(hst_aply.expand_objects(*config)); ASSERT_NO_THROW(hg_aply.expand_objects(*config)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_a)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_b)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_c)); - ASSERT_NO_THROW(hg_aply.resolve_object(hg)); + ASSERT_NO_THROW(hst_aply.resolve_object(hst_a, err)); + ASSERT_NO_THROW(hst_aply.resolve_object(hst_b, err)); + ASSERT_NO_THROW(hst_aply.resolve_object(hst_c, err)); + ASSERT_NO_THROW(hg_aply.resolve_object(hg, err)); ASSERT_EQ(engine::hostgroup::hostgroups.size(), 1u); ASSERT_EQ(engine::hostgroup::hostgroups.begin()->second->members.size(), 3u); @@ -111,9 +112,10 @@ TEST_F(ApplierHostGroup, HostRenamed) { ASSERT_NO_THROW(hst_aply.expand_objects(*config)); ASSERT_NO_THROW(hg_aply.expand_objects(*config)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_a)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_c)); - ASSERT_NO_THROW(hg_aply.resolve_object(hg)); + error_cnt err; + ASSERT_NO_THROW(hst_aply.resolve_object(hst_a, err)); + ASSERT_NO_THROW(hst_aply.resolve_object(hst_c, err)); + ASSERT_NO_THROW(hg_aply.resolve_object(hg, err)); ASSERT_NO_THROW(hg_aply.remove_object(hg)); ASSERT_TRUE(hg.parse("hostgroup_name", "temp_hg")); @@ -155,9 +157,10 @@ TEST_F(ApplierHostGroup, HostRemoved) { ASSERT_NO_THROW(hst_aply.expand_objects(*config)); ASSERT_NO_THROW(hg_aply.expand_objects(*config)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_a)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_c)); - ASSERT_NO_THROW(hg_aply.resolve_object(hg)); + error_cnt err; + ASSERT_NO_THROW(hst_aply.resolve_object(hst_a, err)); + ASSERT_NO_THROW(hst_aply.resolve_object(hst_c, err)); + ASSERT_NO_THROW(hg_aply.resolve_object(hg, err)); engine::hostgroup* hg_obj{engine::hostgroup::hostgroups["temphg"].get()}; ASSERT_EQ(hg_obj->members.size(), 2u); diff --git a/engine/tests/configuration/applier/applier-log.cc b/engine/tests/configuration/applier/applier-log.cc index 9f6becac860..b3b0c707cd7 100644 --- a/engine/tests/configuration/applier/applier-log.cc +++ b/engine/tests/configuration/applier/applier-log.cc @@ -22,6 +22,7 @@ #include #include +#include "com/centreon/engine/configuration/state.hh" #include "helper.hh" using namespace com::centreon; @@ -39,6 +40,7 @@ class ApplierLog : public ::testing::Test { TEST_F(ApplierLog, logV2Enabled) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_v2_enabled(), true); @@ -48,7 +50,7 @@ TEST_F(ApplierLog, logV2Enabled) { ofs << "log_v2_enabled=0" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); std::remove("/tmp/test-config.cfg"); ASSERT_EQ(st.log_v2_enabled(), false); @@ -57,6 +59,7 @@ TEST_F(ApplierLog, logV2Enabled) { TEST_F(ApplierLog, logLegacyEnabled) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_legacy_enabled(), true); @@ -66,13 +69,14 @@ TEST_F(ApplierLog, logLegacyEnabled) { ofs << "log_legacy_enabled=0" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); std::remove("/tmp/test-config.cfg"); ASSERT_EQ(st.log_legacy_enabled(), false); } TEST_F(ApplierLog, logV2Logger) { + configuration::error_cnt err; configuration::parser parser; configuration::state st; @@ -84,13 +88,14 @@ TEST_F(ApplierLog, logV2Logger) { ofs << "log_v2_logger=syslog" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); std::remove("/tmp/test-config.cfg"); ASSERT_EQ(st.log_v2_logger(), "syslog"); } TEST_F(ApplierLog, logLevelFunctions) { + configuration::error_cnt err; configuration::parser parser; configuration::state st; @@ -102,7 +107,7 @@ TEST_F(ApplierLog, logLevelFunctions) { ofs << "log_level_functions=trace" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); ASSERT_EQ(st.log_level_functions(), "trace"); @@ -110,13 +115,14 @@ TEST_F(ApplierLog, logLevelFunctions) { ofs << "log_level_functions=tracerrrr" << std::endl; ofs.close(); - ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st, err), std::exception); std::remove("/tmp/test-config.cfg"); } TEST_F(ApplierLog, logLevelConfig) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_level_config(), "info"); @@ -126,7 +132,7 @@ TEST_F(ApplierLog, logLevelConfig) { ofs << "log_level_config=debug" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); ASSERT_EQ(st.log_level_config(), "debug"); @@ -134,7 +140,7 @@ TEST_F(ApplierLog, logLevelConfig) { ofs << "log_level_config=tracerrrr" << std::endl; ofs.close(); - ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st), std::exception); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st, err), std::exception); std::remove("/tmp/test-config.cfg"); // testing::internal::CaptureStdout(); @@ -151,6 +157,7 @@ TEST_F(ApplierLog, logLevelConfig) { } TEST_F(ApplierLog, logLevelEvents) { + configuration::error_cnt err; configuration::parser parser; configuration::state st; @@ -162,14 +169,14 @@ TEST_F(ApplierLog, logLevelEvents) { ofs << "log_level_events=warning" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); 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); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st, err), std::exception); std::remove("/tmp/test-config.cfg"); // testing::internal::CaptureStdout(); // parser.parse("/tmp/test-config.cfg", st); @@ -187,6 +194,7 @@ TEST_F(ApplierLog, logLevelEvents) { TEST_F(ApplierLog, logLevelChecks) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_level_checks(), "info"); @@ -196,14 +204,14 @@ TEST_F(ApplierLog, logLevelChecks) { ofs << "log_level_checks=error" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); 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); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st, err), std::exception); std::remove("/tmp/test-config.cfg"); // testing::internal::CaptureStdout(); // parser.parse("/tmp/test-config.cfg", st); @@ -221,6 +229,7 @@ TEST_F(ApplierLog, logLevelChecks) { TEST_F(ApplierLog, logLevelNotifications) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_level_notifications(), "error"); @@ -230,14 +239,14 @@ TEST_F(ApplierLog, logLevelNotifications) { ofs << "log_level_notifications=off" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); 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); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st, err), std::exception); std::remove("/tmp/test-config.cfg"); // testing::internal::CaptureStdout(); // parser.parse("/tmp/test-config.cfg", st); @@ -255,6 +264,7 @@ TEST_F(ApplierLog, logLevelNotifications) { TEST_F(ApplierLog, logLevelEventBroker) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_level_eventbroker(), "error"); @@ -264,14 +274,14 @@ TEST_F(ApplierLog, logLevelEventBroker) { ofs << "log_level_eventbroker=critical" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); 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); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st, err), std::exception); std::remove("/tmp/test-config.cfg"); // testing::internal::CaptureStdout(); // parser.parse("/tmp/test-config.cfg", st); @@ -289,6 +299,7 @@ TEST_F(ApplierLog, logLevelEventBroker) { TEST_F(ApplierLog, logLevelExternalCommand) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_level_external_command(), "error"); @@ -298,14 +309,14 @@ TEST_F(ApplierLog, logLevelExternalCommand) { ofs << "log_level_external_command=trace" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); 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); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st, err), std::exception); std::remove("/tmp/test-config.cfg"); // testing::internal::CaptureStdout(); // parser.parse("/tmp/test-config.cfg", st); @@ -323,6 +334,7 @@ TEST_F(ApplierLog, logLevelExternalCommand) { TEST_F(ApplierLog, logLevelCommands) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_level_commands(), "error"); @@ -332,14 +344,14 @@ TEST_F(ApplierLog, logLevelCommands) { ofs << "log_level_commands=debug" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); 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); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st, err), std::exception); std::remove("/tmp/test-config.cfg"); // testing::internal::CaptureStdout(); // parser.parse("/tmp/test-config.cfg", st); @@ -357,6 +369,7 @@ TEST_F(ApplierLog, logLevelCommands) { TEST_F(ApplierLog, logLevelDowntimes) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_level_downtimes(), "error"); @@ -366,14 +379,14 @@ TEST_F(ApplierLog, logLevelDowntimes) { ofs << "log_level_downtimes=warning" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); 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); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st, err), std::exception); std::remove("/tmp/test-config.cfg"); // testing::internal::CaptureStdout(); // parser.parse("/tmp/test-config.cfg", st); @@ -391,6 +404,7 @@ TEST_F(ApplierLog, logLevelDowntimes) { TEST_F(ApplierLog, logLevelComments) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_level_comments(), "error"); @@ -400,14 +414,14 @@ TEST_F(ApplierLog, logLevelComments) { ofs << "log_level_comments=error" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); 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); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st, err), std::exception); std::remove("/tmp/test-config.cfg"); // testing::internal::CaptureStdout(); // parser.parse("/tmp/test-config.cfg", st); @@ -425,6 +439,7 @@ TEST_F(ApplierLog, logLevelComments) { TEST_F(ApplierLog, logLevelMacros) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_level_macros(), "error"); @@ -434,14 +449,14 @@ TEST_F(ApplierLog, logLevelMacros) { ofs << "log_level_macros=critical" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); 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); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st, err), std::exception); std::remove("/tmp/test-config.cfg"); // testing::internal::CaptureStdout(); // parser.parse("/tmp/test-config.cfg", st); @@ -459,6 +474,7 @@ TEST_F(ApplierLog, logLevelMacros) { TEST_F(ApplierLog, logLevelProcess) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_level_process(), "info"); @@ -468,14 +484,14 @@ TEST_F(ApplierLog, logLevelProcess) { ofs << "log_level_process=off" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); 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); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st, err), std::exception); std::remove("/tmp/test-config.cfg"); // testing::internal::CaptureStdout(); // parser.parse("/tmp/test-config.cfg", st); @@ -493,6 +509,7 @@ TEST_F(ApplierLog, logLevelProcess) { TEST_F(ApplierLog, logLevelRuntime) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_level_runtime(), "error"); @@ -502,14 +519,14 @@ TEST_F(ApplierLog, logLevelRuntime) { ofs << "log_level_runtime=off" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); 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); + ASSERT_THROW(parser.parse("/tmp/test-config.cfg", st, err), std::exception); std::remove("/tmp/test-config.cfg"); // testing::internal::CaptureStdout(); // parser.parse("/tmp/test-config.cfg", st); @@ -527,6 +544,7 @@ TEST_F(ApplierLog, logLevelRuntime) { TEST_F(ApplierLog, logFile) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; ASSERT_EQ(st.log_file(), DEFAULT_LOG_FILE); @@ -536,7 +554,7 @@ TEST_F(ApplierLog, logFile) { ofs << "log_file=/tmp/centengine.log" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); + parser.parse("/tmp/test-config.cfg", st, err); std::remove("/tmp/test-config.cfg"); ASSERT_EQ(st.log_file(), "/tmp/centengine.log"); diff --git a/engine/tests/configuration/applier/applier-service.cc b/engine/tests/configuration/applier/applier-service.cc index 1f5b0d20a6f..abba80764f3 100644 --- a/engine/tests/configuration/applier/applier-service.cc +++ b/engine/tests/configuration/applier/applier-service.cc @@ -28,6 +28,7 @@ #include "com/centreon/engine/configuration/applier/service.hh" #include "com/centreon/engine/configuration/applier/tag.hh" #include "com/centreon/engine/configuration/host.hh" +#include "com/centreon/engine/configuration/object.hh" #include "com/centreon/engine/configuration/service.hh" #include "com/centreon/engine/contact.hh" #include "com/centreon/engine/exceptions/error.hh" @@ -259,29 +260,30 @@ TEST_F(ApplierService, ServicesEquality) { } // Given a service configuration applied to a service, -// When the check_validity() method is executed on the configuration, +// When the check_validity(err) method is executed on the configuration, // Then it throws an exception because: // 1. it does not provide a service description // 2. it is not attached to a host // 3. the service does not contain any check command. TEST_F(ApplierService, ServicesCheckValidity) { + error_cnt err; configuration::applier::host hst_aply; configuration::applier::service svc_aply; configuration::service csvc; // No service description - ASSERT_THROW(csvc.check_validity(), com::centreon::exceptions::msg_fmt); + ASSERT_THROW(csvc.check_validity(err), com::centreon::exceptions::msg_fmt); ASSERT_TRUE(csvc.parse("service_description", "check description")); ASSERT_TRUE(csvc.parse("service_id", "53")); // No host attached to - ASSERT_THROW(csvc.check_validity(), com::centreon::exceptions::msg_fmt); + ASSERT_THROW(csvc.check_validity(err), com::centreon::exceptions::msg_fmt); ASSERT_TRUE(csvc.parse("hosts", "test_host")); // No check command attached to - ASSERT_THROW(csvc.check_validity(), com::centreon::exceptions::msg_fmt); + ASSERT_THROW(csvc.check_validity(err), com::centreon::exceptions::msg_fmt); configuration::applier::command cmd_aply; configuration::command cmd("cmd"); @@ -302,8 +304,8 @@ TEST_F(ApplierService, ServicesCheckValidity) { ASSERT_TRUE(csvc.parse("service_description", "foo")); // No check command - ASSERT_NO_THROW(csvc.check_validity()); - svc_aply.resolve_object(csvc); + ASSERT_NO_THROW(csvc.check_validity(err)); + svc_aply.resolve_object(csvc, err); service_map const& sm(engine::service::services); ASSERT_EQ(sm.size(), 1u); @@ -372,6 +374,7 @@ TEST_F(ApplierService, ServicesStalkingOptions) { // Then after the service resolution, we can see the contactgroup stored in the // service with the contact inside it. TEST_F(ApplierService, ContactgroupResolution) { + error_cnt err; configuration::contact ctct{new_configuration_contact("admin", true)}; configuration::applier::contact ct_aply; ct_aply.add_object(ctct); @@ -380,7 +383,7 @@ TEST_F(ApplierService, ContactgroupResolution) { cg.parse("members", "admin"); configuration::applier::contactgroup cg_aply; cg_aply.add_object(cg); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::host hst_aply; configuration::applier::service svc_aply; configuration::service svc; @@ -404,7 +407,7 @@ TEST_F(ApplierService, ContactgroupResolution) { svc.set_host_id(1); svc_aply.add_object(svc); - svc_aply.resolve_object(svc); + svc_aply.resolve_object(svc, err); service_id_map const& sm(engine::service::services_by_id); ASSERT_EQ(sm.size(), 1u); ASSERT_EQ(sm.begin()->first.first, 1u); @@ -755,7 +758,7 @@ TEST_F(ApplierService, ServicesEqualityTags) { } // Given a service configuration applied to a service, -// When the check_validity() method is executed on the configuration, +// When the check_validity(err) method is executed on the configuration, // Then it throws an exception because: // 1. it does not provide a service description // 2. it is not attached to a host @@ -764,9 +767,10 @@ TEST_F(ApplierService, ServicesCheckValidityTags) { configuration::applier::host hst_aply; configuration::applier::service svc_aply; configuration::service csvc; + configuration::error_cnt err; // No service description - ASSERT_THROW(csvc.check_validity(), com::centreon::exceptions::msg_fmt); + ASSERT_THROW(csvc.check_validity(err), com::centreon::exceptions::msg_fmt); ASSERT_TRUE(csvc.parse("service_description", "check description")); ASSERT_TRUE(csvc.parse("service_id", "53")); @@ -774,12 +778,12 @@ TEST_F(ApplierService, ServicesCheckValidityTags) { ASSERT_TRUE(csvc.parse("category_tags", "3")); // No host attached to - ASSERT_THROW(csvc.check_validity(), com::centreon::exceptions::msg_fmt); + ASSERT_THROW(csvc.check_validity(err), com::centreon::exceptions::msg_fmt); ASSERT_TRUE(csvc.parse("hosts", "test_host")); // No check command attached to - ASSERT_THROW(csvc.check_validity(), com::centreon::exceptions::msg_fmt); + ASSERT_THROW(csvc.check_validity(err), com::centreon::exceptions::msg_fmt); configuration::applier::command cmd_aply; configuration::command cmd("cmd"); @@ -816,8 +820,8 @@ TEST_F(ApplierService, ServicesCheckValidityTags) { ASSERT_TRUE(csvc.parse("service_description", "foo")); // No check command - ASSERT_NO_THROW(csvc.check_validity()); - svc_aply.resolve_object(csvc); + ASSERT_NO_THROW(csvc.check_validity(err)); + svc_aply.resolve_object(csvc, err); service_map const& sm(engine::service::services); ASSERT_EQ(sm.size(), 1u); diff --git a/engine/tests/configuration/applier/applier-serviceescalation.cc b/engine/tests/configuration/applier/applier-serviceescalation.cc index 754e30da81a..f0598101452 100644 --- a/engine/tests/configuration/applier/applier-serviceescalation.cc +++ b/engine/tests/configuration/applier/applier-serviceescalation.cc @@ -75,6 +75,7 @@ TEST_F(ApplierServiceEscalation, AddEscalation) { } TEST_F(ApplierServiceEscalation, ResolveObject) { + configuration::error_cnt err; configuration::applier::host hst_aply; configuration::host hst; ASSERT_TRUE(hst.parse("host_name", "test_host")); @@ -104,9 +105,9 @@ TEST_F(ApplierServiceEscalation, ResolveObject) { ASSERT_TRUE(se.parse("host", "test_host")); ASSERT_TRUE(se.parse("service_description", "test_svc")); ASSERT_TRUE(se.parse("first_notification", "4")); - ASSERT_THROW(se_apply.resolve_object(se), std::exception); + ASSERT_THROW(se_apply.resolve_object(se, err), std::exception); se_apply.add_object(se); - ASSERT_NO_THROW(se_apply.resolve_object(se)); + ASSERT_NO_THROW(se_apply.resolve_object(se, err)); } TEST_F(ApplierServiceEscalation, RemoveEscalation) { diff --git a/engine/tests/configuration/applier/applier-servicegroup.cc b/engine/tests/configuration/applier/applier-servicegroup.cc index 273507f8084..50c117ac4f7 100644 --- a/engine/tests/configuration/applier/applier-servicegroup.cc +++ b/engine/tests/configuration/applier/applier-servicegroup.cc @@ -33,16 +33,9 @@ using namespace com::centreon::engine; using namespace com::centreon::engine::configuration; using namespace com::centreon::engine::configuration::applier; -extern int config_errors; -extern int config_warnings; - class ApplierServicegroup : public ::testing::Test { public: - void SetUp() override { - config_errors = 0; - config_warnings = 0; - init_config_state(); - } + void SetUp() override { init_config_state(); } void TearDown() override { deinit_config_state(); } }; @@ -94,13 +87,14 @@ TEST_F(ApplierServicegroup, ModifyServicegroupFromConfig) { // When the resolve_object() method is called // Then no warning, nor error are given TEST_F(ApplierServicegroup, ResolveEmptyservicegroup) { + error_cnt err; configuration::applier::servicegroup aplyr; configuration::servicegroup grp("test"); aplyr.add_object(grp); aplyr.expand_objects(*config); - aplyr.resolve_object(grp); - ASSERT_EQ(config_warnings, 0); - ASSERT_EQ(config_errors, 0); + aplyr.resolve_object(grp, err); + ASSERT_EQ(err.config_warnings, 0); + ASSERT_EQ(err.config_errors, 0); } // Given a servicegroup with a non-existing service @@ -108,20 +102,22 @@ TEST_F(ApplierServicegroup, ResolveEmptyservicegroup) { // Then an exception is thrown // And the method returns 1 error TEST_F(ApplierServicegroup, ResolveInexistentService) { + error_cnt err; configuration::applier::servicegroup aplyr; configuration::servicegroup grp("test"); grp.parse("members", "host1,non_existing_service"); aplyr.add_object(grp); aplyr.expand_objects(*config); - ASSERT_THROW(aplyr.resolve_object(grp), std::exception); - ASSERT_EQ(config_warnings, 0); - ASSERT_EQ(config_errors, 1); + ASSERT_THROW(aplyr.resolve_object(grp, err), std::exception); + ASSERT_EQ(err.config_warnings, 0); + ASSERT_EQ(err.config_errors, 1); } // Given a servicegroup with a service and a host // When the resolve_object() method is called // Then the service is really added to the service group. TEST_F(ApplierServicegroup, ResolveServicegroup) { + error_cnt err; configuration::applier::host aply_hst; configuration::applier::service aply_svc; configuration::applier::command aply_cmd; @@ -149,7 +145,7 @@ TEST_F(ApplierServicegroup, ResolveServicegroup) { grp.parse("members", "test_host,test"); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - ASSERT_NO_THROW(aply_grp.resolve_object(grp)); + ASSERT_NO_THROW(aply_grp.resolve_object(grp, err)); } // Given a servicegroup with a service already configured @@ -158,6 +154,7 @@ TEST_F(ApplierServicegroup, ResolveServicegroup) { // Then the parse method returns true and set the first one service // to the second one. TEST_F(ApplierServicegroup, SetServicegroupMembers) { + error_cnt err; configuration::applier::host aply_hst; configuration::applier::service aply_svc; configuration::applier::command aply_cmd; @@ -185,7 +182,7 @@ TEST_F(ApplierServicegroup, SetServicegroupMembers) { grp.parse("members", "test_host,test"); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - aply_grp.resolve_object(grp); + aply_grp.resolve_object(grp, err); ASSERT_TRUE(grp.members().size() == 1); configuration::servicegroup grp1("big_group"); @@ -202,6 +199,7 @@ TEST_F(ApplierServicegroup, SetServicegroupMembers) { // When we remove the configuration // Then it is really removed TEST_F(ApplierServicegroup, RemoveServicegroupFromConfig) { + error_cnt err; configuration::applier::host aply_hst; configuration::applier::service aply_svc; configuration::applier::command aply_cmd; @@ -229,7 +227,7 @@ TEST_F(ApplierServicegroup, RemoveServicegroupFromConfig) { grp.parse("members", "test_host,test"); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - aply_grp.resolve_object(grp); + aply_grp.resolve_object(grp, err); ASSERT_TRUE(grp.members().size() == 1); configuration::servicegroup grp1("big_group"); @@ -249,6 +247,7 @@ TEST_F(ApplierServicegroup, RemoveServicegroupFromConfig) { // When we remove the configuration // Then it is really removed TEST_F(ApplierServicegroup, RemoveServiceFromGroup) { + error_cnt err; configuration::applier::host aply_hst; configuration::applier::service aply_svc; configuration::applier::command aply_cmd; @@ -288,7 +287,7 @@ TEST_F(ApplierServicegroup, RemoveServiceFromGroup) { grp.parse("members", "test_host,test,test_host,test2"); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - aply_grp.resolve_object(grp); + aply_grp.resolve_object(grp, err); ASSERT_TRUE(grp.members().size() == 2); engine::servicegroup* sg{ diff --git a/engine/tests/configuration/applier/applier-state.cc b/engine/tests/configuration/applier/applier-state.cc index 3248dcf52d3..38177e7f6c6 100644 --- a/engine/tests/configuration/applier/applier-state.cc +++ b/engine/tests/configuration/applier/applier-state.cc @@ -22,16 +22,14 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/configuration/extended_conf.hh" #include "com/centreon/engine/configuration/parser.hh" +#include "com/centreon/engine/configuration/state.hh" #include "com/centreon/engine/globals.hh" using namespace com::centreon::engine; class ApplierState : public ::testing::Test { public: - void SetUp() override { - config_errors = 0; - config_warnings = 0; - } + void SetUp() override {} void TearDown() override {} }; @@ -702,8 +700,9 @@ constexpr size_t SERVICEGROUPS = 3u; TEST_F(ApplierState, StateLegacyParsing) { configuration::state config; configuration::parser p; + configuration::error_cnt err; CreateConf(); - p.parse("/tmp/centengine.cfg", config); + p.parse("/tmp/centengine.cfg", config, err); ASSERT_EQ(config.check_service_freshness(), true); ASSERT_EQ(config.enable_flap_detection(), false); ASSERT_EQ(config.instance_heartbeat_interval(), 30); @@ -969,61 +968,69 @@ TEST_F(ApplierState, StateLegacyParsing) { TEST_F(ApplierState, StateLegacyParsingServicegroupValidityFailed) { configuration::state config; configuration::parser p; + configuration::error_cnt err; CreateBadConf(ConfigurationObject::SERVICEGROUP); - ASSERT_THROW(p.parse("/tmp/centengine.cfg", config), std::exception); + ASSERT_THROW(p.parse("/tmp/centengine.cfg", config, err), std::exception); } TEST_F(ApplierState, StateLegacyParsingTagValidityFailed) { configuration::state config; configuration::parser p; + configuration::error_cnt err; CreateBadConf(ConfigurationObject::TAG); - ASSERT_THROW(p.parse("/tmp/centengine.cfg", config), std::exception); + ASSERT_THROW(p.parse("/tmp/centengine.cfg", config, err), std::exception); } TEST_F(ApplierState, StateLegacyParsingServicedependencyValidityFailed) { configuration::state config; configuration::parser p; + configuration::error_cnt err; CreateBadConf(ConfigurationObject::SERVICEDEPENDENCY); - ASSERT_THROW(p.parse("/tmp/centengine.cfg", config), std::exception); + ASSERT_THROW(p.parse("/tmp/centengine.cfg", config, err), std::exception); } TEST_F(ApplierState, StateLegacyParsingAnomalydetectionValidityFailed) { configuration::state config; configuration::parser p; + configuration::error_cnt err; CreateBadConf(ConfigurationObject::ANOMALYDETECTION); - ASSERT_THROW(p.parse("/tmp/centengine.cfg", config), std::exception); + ASSERT_THROW(p.parse("/tmp/centengine.cfg", config, err), std::exception); } TEST_F(ApplierState, StateLegacyParsingContactgroupWithoutName) { configuration::state config; configuration::parser p; + configuration::error_cnt err; CreateBadConf(ConfigurationObject::CONTACTGROUP); - ASSERT_THROW(p.parse("/tmp/centengine.cfg", config), std::exception); + ASSERT_THROW(p.parse("/tmp/centengine.cfg", config, err), std::exception); } TEST_F(ApplierState, StateLegacyParsingHostescalationWithoutHost) { configuration::state config; configuration::parser p; + configuration::error_cnt err; CreateBadConf(ConfigurationObject::HOSTESCALATION); - ASSERT_THROW(p.parse("/tmp/centengine.cfg", config), std::exception); + ASSERT_THROW(p.parse("/tmp/centengine.cfg", config, err), std::exception); } TEST_F(ApplierState, StateLegacyParsingHostdependencyWithoutHost) { configuration::state config; configuration::parser p; + configuration::error_cnt err; CreateBadConf(ConfigurationObject::HOSTDEPENDENCY); - ASSERT_THROW(p.parse("/tmp/centengine.cfg", config), std::exception); + ASSERT_THROW(p.parse("/tmp/centengine.cfg", config, err), std::exception); } TEST_F(ApplierState, extended_override_conf) { configuration::state config; configuration::parser p; + configuration::error_cnt err; CreateConf(); - p.parse("/tmp/centengine.cfg", config); + p.parse("/tmp/centengine.cfg", config, err); const char* file_paths[] = {"/tmp/extended_conf.json"}; CreateFile(file_paths[0], - R"({"instance_heartbeat_interval":120, + R"({"instance_heartbeat_interval":120, "log_level_functions":"debug", "log_level_checks":"trace", "enable_flap_detection": true, @@ -1042,8 +1049,9 @@ TEST_F(ApplierState, extended_override_conf) { TEST_F(ApplierState, extended_override_conf_overflow) { configuration::state config; configuration::parser p; + configuration::error_cnt err; CreateConf(); - p.parse("/tmp/centengine.cfg", config); + p.parse("/tmp/centengine.cfg", config, err); const char* file_paths[] = {"/tmp/extended_conf.json"}; CreateFile(file_paths[0], diff --git a/engine/tests/configuration/contact.cc b/engine/tests/configuration/contact.cc index 8a3bfea06cf..4d53553e0f7 100644 --- a/engine/tests/configuration/contact.cc +++ b/engine/tests/configuration/contact.cc @@ -38,5 +38,6 @@ class ConfigContact : public ::testing::Test { // Then an exception is thrown. TEST_F(ConfigContact, NewContactWithNoName) { configuration::contact ctct(""); - ASSERT_THROW(ctct.check_validity(), std::exception); + configuration::error_cnt err; + ASSERT_THROW(ctct.check_validity(err), std::exception); } diff --git a/engine/tests/configuration/severity.cc b/engine/tests/configuration/severity.cc index ab632869ea5..fce65fbab87 100644 --- a/engine/tests/configuration/severity.cc +++ b/engine/tests/configuration/severity.cc @@ -39,14 +39,16 @@ class ConfigSeverity : public ::testing::Test { // Then an exception is thrown. TEST_F(ConfigSeverity, NewSeverityWithNoKey) { configuration::severity sv({0, 0}); - ASSERT_THROW(sv.check_validity(), std::exception); + configuration::error_cnt err; + ASSERT_THROW(sv.check_validity(err), std::exception); } // When I create a configuration::severity with a null level // Then an exception is thrown. TEST_F(ConfigSeverity, NewSeverityWithNoLevel) { configuration::severity sv({1, 0}); - ASSERT_THROW(sv.check_validity(), std::exception); + configuration::error_cnt err; + ASSERT_THROW(sv.check_validity(err), std::exception); } // When I create a configuration::severity with an empty name @@ -54,7 +56,8 @@ TEST_F(ConfigSeverity, NewSeverityWithNoLevel) { TEST_F(ConfigSeverity, NewSeverityWithNoName) { configuration::severity sv({1, 0}); sv.parse("level", "2"); - ASSERT_THROW(sv.check_validity(), std::exception); + configuration::error_cnt err; + ASSERT_THROW(sv.check_validity(err), std::exception); } // When I create a configuration::severity with a non empty name, @@ -69,7 +72,8 @@ TEST_F(ConfigSeverity, NewSeverityWellFilled) { ASSERT_EQ(sv.level(), 2); ASSERT_EQ(sv.severity_name(), "foobar"); ASSERT_EQ(sv.type(), configuration::severity::service); - ASSERT_NO_THROW(sv.check_validity()); + configuration::error_cnt err; + ASSERT_NO_THROW(sv.check_validity(err)); } // When I create a configuration::severity with an icon id. @@ -81,5 +85,6 @@ TEST_F(ConfigSeverity, NewSeverityIconId) { sv.parse("severity_name", "foobar"); sv.parse("type", "host"); ASSERT_EQ(sv.icon_id(), 18); - ASSERT_NO_THROW(sv.check_validity()); + configuration::error_cnt err; + ASSERT_NO_THROW(sv.check_validity(err)); } diff --git a/engine/tests/configuration/tag.cc b/engine/tests/configuration/tag.cc index 32a1e3fcacc..db4b1c0f5f8 100644 --- a/engine/tests/configuration/tag.cc +++ b/engine/tests/configuration/tag.cc @@ -20,6 +20,7 @@ #include "com/centreon/engine/configuration/tag.hh" #include +#include "com/centreon/engine/configuration/object.hh" #include "helper.hh" using namespace com::centreon; @@ -38,45 +39,50 @@ class ConfigTag : public ::testing::Test { // When I create a configuration::tag with a null id // Then an exception is thrown. TEST_F(ConfigTag, NewTagWithNoKey) { + configuration::error_cnt err; configuration::tag tg({0, 0}); - ASSERT_THROW(tg.check_validity(), std::exception); + ASSERT_THROW(tg.check_validity(err), std::exception); } // When I create a configuration::tag with a null type // Then an exception is thrown. TEST_F(ConfigTag, NewTagWithNoLevel) { + configuration::error_cnt err; configuration::tag tg({1, 0}); - ASSERT_THROW(tg.check_validity(), std::exception); + ASSERT_THROW(tg.check_validity(err), std::exception); } // When I create a configuration::tag with an empty name // Then an exception is thrown. TEST_F(ConfigTag, NewTagWithNoName) { + configuration::error_cnt err; configuration::tag tg({1, 0}); tg.parse("type", "hostcategory"); - ASSERT_THROW(tg.check_validity(), std::exception); + ASSERT_THROW(tg.check_validity(err), std::exception); } // When I create a configuration::tag with a non empty name, // non null id and non null type // Then no exception is thrown. TEST_F(ConfigTag, NewTagWellFilled) { + configuration::error_cnt err; configuration::tag tg({1, 0}); tg.parse("type", "servicegroup"); tg.parse("tag_name", "foobar"); ASSERT_EQ(tg.key().first, 1); ASSERT_EQ(tg.key().second, engine::configuration::tag::servicegroup); ASSERT_EQ(tg.tag_name(), "foobar"); - ASSERT_NO_THROW(tg.check_validity()); + ASSERT_NO_THROW(tg.check_validity(err)); } // When I create a configuration::tag with a non empty name, // non null id and non null type. // Then we can get the type value. TEST_F(ConfigTag, NewTagIconId) { + configuration::error_cnt err; configuration::tag tg({1, 0}); tg.parse("type", "hostgroup"); tg.parse("tag_name", "foobar"); ASSERT_EQ(tg.key().second, engine::configuration::tag::hostgroup); - ASSERT_NO_THROW(tg.check_validity()); + ASSERT_NO_THROW(tg.check_validity(err)); } diff --git a/engine/tests/configuration/timeperiod-test.cc b/engine/tests/configuration/timeperiod-test.cc index 3cce0dc866e..838e84f00fd 100644 --- a/engine/tests/configuration/timeperiod-test.cc +++ b/engine/tests/configuration/timeperiod-test.cc @@ -20,15 +20,12 @@ #include +#include #include -#include "com/centreon/engine/timerange.hh" - #include "com/centreon/engine/common.hh" #include "com/centreon/engine/configuration/applier/timeperiod.hh" -#include "com/centreon/engine/configuration/timeperiod.hh" #include "com/centreon/engine/globals.hh" -#include "com/centreon/engine/string.hh" using namespace com::centreon::engine::configuration; using namespace com::centreon::engine; @@ -673,7 +670,9 @@ std::vector parse_timeperiods_cfg(const std::string& file_path) { current.clear(); continue; } - current.push_back(com::centreon::engine::string::trim(line)); + + absl::StripAsciiWhitespace(&line); + current.push_back(std::move(line)); } } @@ -714,4 +713,4 @@ TEST_P(timeperiod_config_parser_test, VerifyParserContent) { ASSERT_TRUE(comparator.is_equal()); ASSERT_TRUE(comparator.is_result_equal()); -} \ No newline at end of file +} diff --git a/engine/tests/configuration/timeperiods.cfg b/engine/tests/configuration/timeperiods.cfg index be670adf37b..970c610c90f 100644 --- a/engine/tests/configuration/timeperiods.cfg +++ b/engine/tests/configuration/timeperiods.cfg @@ -179,21 +179,21 @@ define timeperiod { define timeperiod { name 01h25-23h55 timeperiod_name 01h25-23h55 - alias 01h25-23h55 - sunday 01:25-23:55 - monday 01:25-23:55 + alias 01h25-23h55 + sunday 01:25-23:55 + monday 01:25-23:55 tuesday 01:25-23:55 wednesday 01:25-23:55 - thursday 01:25-23:55 + thursday 01:25-23:55 friday 01:25-23:55 - saturday 01:25-23:55 + saturday 01:25-23:55 } define timeperiod { - name 06h00-22h00 - timeperiod_name 06h00-22h00 - alias 06h00-22h00 - sunday 06:00-22:00 + name 06h00-22h00 + timeperiod_name 06h00-22h00 + alias 06h00-22h00 + sunday 06:00-22:00 monday 06:00-22:00 tuesday 06:00-22:00 wednesday 06:00-22:00 @@ -402,50 +402,77 @@ define timeperiod { name nonworkhours timeperiod_name nonworkhours alias Non-Work_Hours - sunday 00:00-24:00 ; Every Sunday of every week - monday 00:00-09:00,17:00-24:00 ; Every Monday of every week - tuesday 00:00-09:00,17:00-24:00 ; Every Tuesday of every week - wednesday 00:00-09:00,17:00-24:00 ; Every Wednesday of every week - thursday 00:00-09:00,17:00-24:00 ; Every Thursday of every week - friday 00:00-09:00,17:00-24:00 ; Every Friday of every week - saturday 00:00-24:00 ; Every Saturday of every week + # Every Sunday of every week + sunday 00:00-24:00 + # Every Monday of every week + monday 00:00-09:00,17:00-24:00 + # Every Tuesday of every week + tuesday 00:00-09:00,17:00-24:00 + # Every Wednesday of every week + wednesday 00:00-09:00,17:00-24:00 + # Every Thursday of every week + thursday 00:00-09:00,17:00-24:00 + # Every Friday of every week + friday 00:00-09:00,17:00-24:00 + # Every Saturday of every week + saturday 00:00-24:00 } define timeperiod { name misc-single-days timeperiod_name misc-single-days alias Misc Single Days - 1999-01-28 00:00-24:00 ; January 28th, 1999 - monday 3 00:00-24:00 ; 3rd Monday of every month - day 2 00:00-24:00 ; 2nd day of every month - february 10 00:00-24:00 ; February 10th of every year - february -1 00:00-24:00 ; Last day in February of every year - friday -2 00:00-24:00 ; 2nd to last Friday of every month - thursday -1 november 00:00-24:00 ; Last Thursday in November of every year + # January 28th, 1999 + 1999-01-28 00:00-24:00 + # 3rd Monday of every month + monday 3 00:00-24:00 + # 2nd day of every month + day 2 00:00-24:00 + # February 10th of every year + february 10 00:00-24:00 + # Last day in February of every year + february -1 00:00-24:00 + # 2nd to last Friday of every month + friday -2 00:00-24:00 + # Last Thursday in November of every year + thursday -1 november 00:00-24:00 } define timeperiod { name misc-date-ranges timeperiod_name misc-date-ranges alias Misc Date Ranges - 2007-01-01 - 2008-02-01 00:00-24:00 ; January 1st, 2007 to February 1st, 2008 - monday 3 - thursday 4 00:00-24:00 ; 3rd Monday to 4th Thursday of every month - day 1 - 15 00:00-24:00 ; 1st to 15th day of every month - day 20 - -1 00:00-24:00 ; 20th to the last day of every month - july 10 - 15 00:00-24:00 ; July 10th to July 15th of every year - april 10 - may 15 00:00-24:00 ; April 10th to May 15th of every year - tuesday 1 april - friday 2 may 00:00-24:00 ; 1st Tuesday in April to 2nd Friday in May of every year + # January 1st, 2007 to February 1st, 2008 + 2007-01-01 - 2008-02-01 00:00-24:00 + # 3rd Monday to 4th Thursday of every month + monday 3 - thursday 4 00:00-24:00 + # 1st to 15th day of every month + day 1 - 15 00:00-24:00 + # 20th to the last day of every month + day 20 - -1 00:00-24:00 + # July 10th to July 15th of every year + july 10 - 15 00:00-24:00 + # April 10th to May 15th of every year + april 10 - may 15 00:00-24:00 + # 1st Tuesday in April to 2nd Friday in May of every year + tuesday 1 april - friday 2 may 00:00-24:00 } define timeperiod { name misc-skip-ranges timeperiod_name misc-skip-ranges alias Misc Skip Ranges - 2007-01-01 - 2008-02-01 / 3 00:00-24:00 ; Every 3 days from January 1st, 2007 to February 1st, 2008 - 2008-04-01 / 7 00:00-24:00 ; Every 7 days from April 1st, 2008 (continuing forever) - monday 3 - thursday 4 / 2 00:00-24:00 ; Every other day from 3rd Monday to 4th Thursday of every month - day 1 - 15 / 5 00:00-24:00 ; Every 5 days from the 1st to the 15th day of every month - july 10 - 15 / 2 00:00-24:00 ; Every other day from July 10th to July 15th of every year - tuesday 1 april - friday 2 may / 6 00:00-24:00 ; Every 6 days from the 1st Tuesday in April to the 2nd Friday in May of every year + # Every 3 days from January 1st, 2007 to February 1st, 2008 + 2007-01-01 - 2008-02-01 / 3 00:00-24:00 + # Every 7 days from April 1st, 2008 (continuing forever) + 2008-04-01 / 7 00:00-24:00 + # Every other day from 3rd Monday to 4th Thursday of every month + monday 3 - thursday 4 / 2 00:00-24:00 + # Every 5 days from the 1st to the 15th day of every month + day 1 - 15 / 5 00:00-24:00 + # Every other day from July 10th to July 15th of every year + july 10 - 15 / 2 00:00-24:00 + # Every 6 days from the 1st Tuesday in April to the 2nd Friday in May of every year + tuesday 1 april - friday 2 may / 6 00:00-24:00 } diff --git a/engine/tests/custom_vars/extcmd.cc b/engine/tests/custom_vars/extcmd.cc index 0bde69f2481..5833fd7584e 100755 --- a/engine/tests/custom_vars/extcmd.cc +++ b/engine/tests/custom_vars/extcmd.cc @@ -45,6 +45,7 @@ class CustomVar : public ::testing::Test { // When the command is removed from the configuration, // Then the command is totally removed. TEST_F(CustomVar, UpdateHostCustomVar) { + configuration::error_cnt err; configuration::applier::command cmd_aply; configuration::applier::host hst_aply; configuration::applier::contact cnt_aply; @@ -84,7 +85,7 @@ TEST_F(CustomVar, UpdateHostCustomVar) { ASSERT_TRUE(config->hosts().size() == 1); hst_aply.expand_objects(*config); - hst_aply.resolve_object(hst); + hst_aply.resolve_object(hst, err); ASSERT_TRUE(hst_found->second->custom_variables.size() == 3); nagios_macros* macros(get_global_macros()); grab_host_macros_r(macros, hst_found->second.get()); diff --git a/engine/tests/downtimes/downtime_finder.cc b/engine/tests/downtimes/downtime_finder.cc index 94e01a6f996..423aeed7630 100644 --- a/engine/tests/downtimes/downtime_finder.cc +++ b/engine/tests/downtimes/downtime_finder.cc @@ -40,6 +40,7 @@ using namespace com::centreon::engine::downtimes; class DowntimeFinderFindMatchingAllTest : public TestEngine { public: void SetUp() override { + configuration::error_cnt err; init_config_state(); configuration::contact ctc{new_configuration_contact("admin", false, "a")}; configuration::applier::contact ctc_aply; @@ -55,8 +56,8 @@ class DowntimeFinderFindMatchingAllTest : public TestEngine { configuration::host hst2{new_configuration_host("other_host", "admin", 2)}; hst_aply.add_object(hst2); - hst_aply.resolve_object(hst); - hst_aply.resolve_object(hst1); + hst_aply.resolve_object(hst, err); + hst_aply.resolve_object(hst1, err); configuration::service svc{ new_configuration_service("first_host", "test_service", "admin", 8)}; @@ -79,11 +80,11 @@ class DowntimeFinderFindMatchingAllTest : public TestEngine { new_configuration_service("test_host", "new_svc2", "admin", 12)}; svc_aply.add_object(svc4); - svc_aply.resolve_object(svc); - svc_aply.resolve_object(svc1); - svc_aply.resolve_object(svc2); - svc_aply.resolve_object(svc3); - svc_aply.resolve_object(svc4); + svc_aply.resolve_object(svc, err); + svc_aply.resolve_object(svc1, err); + svc_aply.resolve_object(svc2, err); + svc_aply.resolve_object(svc3, err); + svc_aply.resolve_object(svc4, err); downtime_manager::instance().clear_scheduled_downtimes(); downtime_manager::instance().initialize_downtime_data(); diff --git a/engine/tests/enginerpc/enginerpc.cc b/engine/tests/enginerpc/enginerpc.cc index 2cc77c5d18e..c44963989b1 100644 --- a/engine/tests/enginerpc/enginerpc.cc +++ b/engine/tests/enginerpc/enginerpc.cc @@ -66,12 +66,13 @@ class EngineRpc : public TestEngine { config->execute_service_checks(true); + configuration::error_cnt err; /* contact */ configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); /* hosts */ configuration::host hst_child; @@ -87,8 +88,8 @@ class EngineRpc : public TestEngine { hst.parse("_HOST_ID", "12"); hst_aply.add_object(hst); - hst_aply.resolve_object(hst); - hst_aply2.resolve_object(hst_child); + hst_aply.resolve_object(hst, err); + hst_aply2.resolve_object(hst_child, err); ASSERT_EQ(engine::host::hosts.size(), 2u); @@ -105,7 +106,7 @@ class EngineRpc : public TestEngine { hg.parse("members", "test_host"); hg_aply.add_object(hg); hg_aply.expand_objects(*config); - hg_aply.resolve_object(hg); + hg_aply.resolve_object(hg, err); /* service */ configuration::service svc{ @@ -119,7 +120,7 @@ class EngineRpc : public TestEngine { svc_aply.add_object(svc); cmd_aply.add_object(cmd); - svc_aply.resolve_object(svc); + svc_aply.resolve_object(svc, err); configuration::anomalydetection ad{new_configuration_anomalydetection( "test_host", "test_ad", "admin", @@ -129,7 +130,7 @@ class EngineRpc : public TestEngine { configuration::applier::anomalydetection ad_aply; ad_aply.add_object(ad); - ad_aply.resolve_object(ad); + ad_aply.resolve_object(ad, err); host_map const& hm{engine::host::hosts}; _host = hm.begin()->second; @@ -161,7 +162,7 @@ class EngineRpc : public TestEngine { sg_aply.add_object(sg); sg_aply.expand_objects(*config); - sg_aply.resolve_object(sg); + sg_aply.resolve_object(sg, err); } void TearDown() override { diff --git a/engine/tests/external_commands/anomalydetection.cc b/engine/tests/external_commands/anomalydetection.cc index 09bae184388..96afd9e5d5d 100644 --- a/engine/tests/external_commands/anomalydetection.cc +++ b/engine/tests/external_commands/anomalydetection.cc @@ -30,6 +30,7 @@ #include "com/centreon/engine/configuration/applier/host.hh" #include "com/centreon/engine/configuration/applier/service.hh" #include "com/centreon/engine/configuration/contact.hh" +#include "com/centreon/engine/configuration/state.hh" #include "com/centreon/engine/events/loop.hh" #include "com/centreon/engine/timezone_manager.hh" #include "com/centreon/engine/version.hh" @@ -43,11 +44,12 @@ class ADExtCmd : public TestEngine { void SetUp() override { init_config_state(); + configuration::error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -58,8 +60,8 @@ class ADExtCmd : public TestEngine { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); configuration::anomalydetection ad{new_configuration_anomalydetection( "test_host", "test_ad", "admin", @@ -69,7 +71,7 @@ class ADExtCmd : public TestEngine { configuration::applier::anomalydetection ad_aply; ad_aply.add_object(ad); - ad_aply.resolve_object(ad); + ad_aply.resolve_object(ad, err); host_map const& hm{engine::host::hosts}; _host = hm.begin()->second; diff --git a/engine/tests/external_commands/service.cc b/engine/tests/external_commands/service.cc index be4b0bb1ab3..e9f55852974 100644 --- a/engine/tests/external_commands/service.cc +++ b/engine/tests/external_commands/service.cc @@ -24,6 +24,7 @@ #include "com/centreon/engine/commands/commands.hh" #include "com/centreon/engine/configuration/applier/command.hh" #include "com/centreon/engine/configuration/applier/host.hh" +#include "com/centreon/engine/configuration/state.hh" #include "com/centreon/engine/events/loop.hh" #include "com/centreon/process_manager.hh" #include "helper.hh" @@ -42,6 +43,7 @@ class ServiceExternalCommand : public ::testing::Test { }; TEST_F(ServiceExternalCommand, AddServiceDowntime) { + configuration::error_cnt err; configuration::applier::host hst_aply; configuration::applier::service svc_aply; configuration::applier::command cmd_aply; @@ -73,8 +75,8 @@ TEST_F(ServiceExternalCommand, AddServiceDowntime) { hst_aply.expand_objects(*config); svc_aply.expand_objects(*config); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); set_time(20000); time_t now = time(nullptr); @@ -123,8 +125,9 @@ TEST_F(ServiceExternalCommand, AddServiceDowntimeByHostIpAddress) { hst_aply.expand_objects(*config); svc_aply.expand_objects(*config); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + configuration::error_cnt err; + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); set_time(20000); time_t now = time(nullptr); @@ -173,8 +176,9 @@ TEST_F(ServiceExternalCommand, AddServiceComment) { hst_aply.expand_objects(*config); svc_aply.expand_objects(*config); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + configuration::error_cnt err; + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); std::string cmd_com1{ "test_host;test_description;1;user;this is a first comment"}; diff --git a/engine/tests/loop/loop.cc b/engine/tests/loop/loop.cc index 2a7a04d91c9..2d9988dbed8 100644 --- a/engine/tests/loop/loop.cc +++ b/engine/tests/loop/loop.cc @@ -40,13 +40,14 @@ using namespace com::centreon::engine::configuration; class LoopTest : public TestEngine { public: void SetUp() override { + error_cnt err; init_config_state(); configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -57,8 +58,8 @@ class LoopTest : public TestEngine { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); host_map const& hm{engine::host::hosts}; _host = hm.begin()->second; diff --git a/engine/tests/macros/macro.cc b/engine/tests/macros/macro.cc old mode 100755 new mode 100644 index 9a12b752e6d..fff4d22da81 --- a/engine/tests/macros/macro.cc +++ b/engine/tests/macros/macro.cc @@ -19,6 +19,7 @@ #include #include +#include "com/centreon/engine/configuration/state.hh" #include "com/centreon/engine/globals.hh" #include @@ -78,6 +79,7 @@ class Macro : public TestEngine { TEST_F(Macro, pollerName) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -86,8 +88,8 @@ TEST_F(Macro, pollerName) { ofs << "log_file=\"\"" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); std::string out; nagios_macros* mac(get_global_macros()); @@ -98,6 +100,7 @@ TEST_F(Macro, pollerName) { TEST_F(Macro, pollerId) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -106,8 +109,8 @@ TEST_F(Macro, pollerId) { ofs << "log_file=\"\"" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); std::string out; nagios_macros* mac(get_global_macros()); process_macros_r(mac, "$POLLERID$", out, 0); @@ -320,6 +323,7 @@ TEST_F(Macro, ContactPager) { TEST_F(Macro, FullCmd) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -329,14 +333,14 @@ TEST_F(Macro, FullCmd) { ofs << "admin_pager=\"pager\"" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); init_macros(); std::string out; nagios_macros* mac(get_global_macros()); - //process_macros_r(mac, "$ADMINEMAIL:test_host$", out, 1); + // process_macros_r(mac, "$ADMINEMAIL:test_host$", out, 1); process_macros_r(mac, "/bin/sh -c '/bin/echo \"LogFile: $LOGFILE$ - AdminEmail: " "$ADMINEMAIL$ - AdminPager: $ADMINPAGER$\"", @@ -349,6 +353,7 @@ TEST_F(Macro, FullCmd) { TEST_F(Macro, AdminEmail) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -357,14 +362,14 @@ TEST_F(Macro, AdminEmail) { ofs << "log_file=\"\"" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); init_macros(); std::string out; nagios_macros* mac(get_global_macros()); - //process_macros_r(mac, "$ADMINEMAIL:test_host$", out, 1); + // process_macros_r(mac, "$ADMINEMAIL:test_host$", out, 1); process_macros_r(mac, "$ADMINEMAIL$", out, 1); ASSERT_EQ(out, "contactadmin@centreon.com"); } @@ -372,6 +377,7 @@ TEST_F(Macro, AdminEmail) { TEST_F(Macro, AdminPager) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -380,8 +386,8 @@ TEST_F(Macro, AdminPager) { ofs << "log_file=\"\"" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); init_macros(); @@ -394,6 +400,7 @@ TEST_F(Macro, AdminPager) { TEST_F(Macro, MainConfigFile) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -401,8 +408,8 @@ TEST_F(Macro, MainConfigFile) { ofs << "log_file=\"\"" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); init_macros(); std::string out; @@ -414,6 +421,7 @@ TEST_F(Macro, MainConfigFile) { TEST_F(Macro, StatusDataFile) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -422,8 +430,8 @@ TEST_F(Macro, StatusDataFile) { ofs << "log_file=\"\"" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); init_macros(); std::string out; @@ -435,6 +443,7 @@ TEST_F(Macro, StatusDataFile) { TEST_F(Macro, RetentionDataFile) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -444,8 +453,8 @@ TEST_F(Macro, RetentionDataFile) { ofs << "log_file=\"\"" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); init_macros(); std::string out; @@ -457,6 +466,7 @@ TEST_F(Macro, RetentionDataFile) { TEST_F(Macro, TempFile) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -464,8 +474,8 @@ TEST_F(Macro, TempFile) { ofs << "log_file=\"\"" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); init_macros(); std::string out; @@ -477,6 +487,7 @@ TEST_F(Macro, TempFile) { TEST_F(Macro, LogFile) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -484,8 +495,8 @@ TEST_F(Macro, LogFile) { ofs << "log_file=/tmp/centengine.log" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); init_macros(); std::string out; @@ -497,6 +508,7 @@ TEST_F(Macro, LogFile) { TEST_F(Macro, CommandFile) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -505,8 +517,8 @@ TEST_F(Macro, CommandFile) { ofs << "log_file=\"\"" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); init_macros(); std::string out; @@ -518,6 +530,7 @@ TEST_F(Macro, CommandFile) { TEST_F(Macro, TempPath) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -525,8 +538,8 @@ TEST_F(Macro, TempPath) { ofs << "log_file=\"\"" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); init_macros(); std::string out; @@ -536,18 +549,19 @@ TEST_F(Macro, TempPath) { } TEST_F(Macro, ContactGroupName) { + configuration::error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("test_contact", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); init_macros(); int now{500000000}; @@ -560,18 +574,19 @@ TEST_F(Macro, ContactGroupName) { } TEST_F(Macro, ContactGroupAlias) { + configuration::error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("test_contact", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); init_macros(); int now{500000000}; set_time(now); @@ -587,14 +602,15 @@ TEST_F(Macro, ContactGroupMembers) { configuration::contact ctct{new_configuration_contact("test_contact", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + configuration::error_cnt err; + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); init_macros(); int now{500000000}; set_time(now); @@ -606,18 +622,19 @@ TEST_F(Macro, ContactGroupMembers) { } TEST_F(Macro, ContactGroupNames) { + configuration::error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("test_contact", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); init_macros(); int now{500000000}; set_time(now); @@ -637,13 +654,14 @@ TEST_F(Macro, NotificationRecipients) { new_configuration_contact("admin1", false, "c,r")}; ct_aply.add_object(ctct1); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); - ct_aply.resolve_object(ctct1); + configuration::error_cnt err; + ct_aply.resolve_object(ctct, err); + ct_aply.resolve_object(ctct1, err); configuration::contact ctct2{ new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct2); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct2); + ct_aply.resolve_object(ctct2, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -654,8 +672,8 @@ TEST_F(Macro, NotificationRecipients) { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); host_map const& hm{engine::host::hosts}; _host3 = hm.begin()->second; @@ -683,6 +701,7 @@ TEST_F(Macro, NotificationRecipients) { } TEST_F(Macro, NotificationAuthor) { + configuration::error_cnt err; init_macros(); configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; @@ -691,13 +710,13 @@ TEST_F(Macro, NotificationAuthor) { new_configuration_contact("admin1", false, "c,r")}; ct_aply.add_object(ctct1); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); - ct_aply.resolve_object(ctct1); + ct_aply.resolve_object(ctct, err); + ct_aply.resolve_object(ctct1, err); configuration::contact ctct2{ new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct2); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct2); + ct_aply.resolve_object(ctct2, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -708,8 +727,8 @@ TEST_F(Macro, NotificationAuthor) { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); host_map const& hm{engine::host::hosts}; _host3 = hm.begin()->second; @@ -737,6 +756,7 @@ TEST_F(Macro, NotificationAuthor) { } TEST_F(Macro, NotificationAuthorName) { + configuration::error_cnt err; init_macros(); configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; @@ -745,13 +765,13 @@ TEST_F(Macro, NotificationAuthorName) { new_configuration_contact("admin1", false, "c,r")}; ct_aply.add_object(ctct1); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); - ct_aply.resolve_object(ctct1); + ct_aply.resolve_object(ctct, err); + ct_aply.resolve_object(ctct1, err); configuration::contact ctct2{ new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct2); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct2); + ct_aply.resolve_object(ctct2, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -762,8 +782,8 @@ TEST_F(Macro, NotificationAuthorName) { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); host_map const& hm{engine::host::hosts}; _host3 = hm.begin()->second; @@ -790,6 +810,7 @@ TEST_F(Macro, NotificationAuthorName) { } TEST_F(Macro, NotificationAuthorAlias) { + configuration::error_cnt err; init_macros(); configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; @@ -798,13 +819,13 @@ TEST_F(Macro, NotificationAuthorAlias) { new_configuration_contact("admin1", false, "c,r")}; ct_aply.add_object(ctct1); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); - ct_aply.resolve_object(ctct1); + ct_aply.resolve_object(ctct, err); + ct_aply.resolve_object(ctct1, err); configuration::contact ctct2{ new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct2); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct2); + ct_aply.resolve_object(ctct2, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -815,8 +836,8 @@ TEST_F(Macro, NotificationAuthorAlias) { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); host_map const& hm{engine::host::hosts}; _host3 = hm.begin()->second; @@ -843,6 +864,7 @@ TEST_F(Macro, NotificationAuthorAlias) { } TEST_F(Macro, NotificationComment) { + configuration::error_cnt err; init_macros(); configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; @@ -851,13 +873,13 @@ TEST_F(Macro, NotificationComment) { new_configuration_contact("admin1", false, "c,r")}; ct_aply.add_object(ctct1); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); - ct_aply.resolve_object(ctct1); + ct_aply.resolve_object(ctct, err); + ct_aply.resolve_object(ctct1, err); configuration::contact ctct2{ new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct2); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct2); + ct_aply.resolve_object(ctct2, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -868,8 +890,8 @@ TEST_F(Macro, NotificationComment) { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); host_map const& hm{engine::host::hosts}; _host3 = hm.begin()->second; diff --git a/engine/tests/macros/macro_hostname.cc b/engine/tests/macros/macro_hostname.cc index 4d5010cb06c..4a57cec5449 100644 --- a/engine/tests/macros/macro_hostname.cc +++ b/engine/tests/macros/macro_hostname.cc @@ -19,6 +19,7 @@ #include #include +#include "com/centreon/engine/configuration/state.hh" #include "com/centreon/engine/globals.hh" #include @@ -518,6 +519,7 @@ TEST_F(MacroHostname, HostPercentChange) { } TEST_F(MacroHostname, HostGroupName) { + configuration::error_cnt err; configuration::applier::hostgroup hg_aply; configuration::applier::host hst_aply; configuration::hostgroup hg; @@ -543,9 +545,9 @@ TEST_F(MacroHostname, HostGroupName) { ASSERT_NO_THROW(hst_aply.expand_objects(*config)); ASSERT_NO_THROW(hg_aply.expand_objects(*config)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_a)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_c)); - ASSERT_NO_THROW(hg_aply.resolve_object(hg)); + ASSERT_NO_THROW(hst_aply.resolve_object(hst_a, err)); + ASSERT_NO_THROW(hst_aply.resolve_object(hst_c, err)); + ASSERT_NO_THROW(hg_aply.resolve_object(hg, err)); int now{500000000}; set_time(now); @@ -584,9 +586,10 @@ TEST_F(MacroHostname, HostGroupAlias) { ASSERT_NO_THROW(hst_aply.expand_objects(*config)); ASSERT_NO_THROW(hg_aply.expand_objects(*config)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_a)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_c)); - ASSERT_NO_THROW(hg_aply.resolve_object(hg)); + configuration::error_cnt err; + ASSERT_NO_THROW(hst_aply.resolve_object(hst_a, err)); + ASSERT_NO_THROW(hst_aply.resolve_object(hst_c, err)); + ASSERT_NO_THROW(hg_aply.resolve_object(hg, err)); int now{500000000}; set_time(now); @@ -693,6 +696,7 @@ TEST_F(MacroHostname, HostCheckCommand) { TEST_F(MacroHostname, HostPerDataFile) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -702,8 +706,8 @@ TEST_F(MacroHostname, HostPerDataFile) { ofs << "log_file=\"\"" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); init_macros(); std::string out; @@ -1095,9 +1099,10 @@ TEST_F(MacroHostname, HostGroupNames) { ASSERT_NO_THROW(hst_aply.expand_objects(*config)); ASSERT_NO_THROW(hg_aply.expand_objects(*config)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_a)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_c)); - ASSERT_NO_THROW(hg_aply.resolve_object(hg)); + configuration::error_cnt err; + ASSERT_NO_THROW(hst_aply.resolve_object(hst_a, err)); + ASSERT_NO_THROW(hst_aply.resolve_object(hst_c, err)); + ASSERT_NO_THROW(hg_aply.resolve_object(hg, err)); int now{500000000}; set_time(now); @@ -1256,9 +1261,10 @@ TEST_F(MacroHostname, HostGroupNotes) { ASSERT_NO_THROW(hst_aply.expand_objects(*config)); ASSERT_NO_THROW(hg_aply.expand_objects(*config)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_a)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_c)); - ASSERT_NO_THROW(hg_aply.resolve_object(hg)); + configuration::error_cnt err; + ASSERT_NO_THROW(hst_aply.resolve_object(hst_a, err)); + ASSERT_NO_THROW(hst_aply.resolve_object(hst_c, err)); + ASSERT_NO_THROW(hg_aply.resolve_object(hg, err)); int now{500000000}; set_time(now); @@ -1297,9 +1303,10 @@ TEST_F(MacroHostname, HostGroupNotesUrl) { ASSERT_NO_THROW(hst_aply.expand_objects(*config)); ASSERT_NO_THROW(hg_aply.expand_objects(*config)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_a)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_c)); - ASSERT_NO_THROW(hg_aply.resolve_object(hg)); + configuration::error_cnt err; + ASSERT_NO_THROW(hst_aply.resolve_object(hst_a, err)); + ASSERT_NO_THROW(hst_aply.resolve_object(hst_c, err)); + ASSERT_NO_THROW(hg_aply.resolve_object(hg, err)); int now{500000000}; set_time(now); @@ -1338,9 +1345,10 @@ TEST_F(MacroHostname, HostGroupActionUrl) { ASSERT_NO_THROW(hst_aply.expand_objects(*config)); ASSERT_NO_THROW(hg_aply.expand_objects(*config)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_a)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_c)); - ASSERT_NO_THROW(hg_aply.resolve_object(hg)); + configuration::error_cnt err; + ASSERT_NO_THROW(hst_aply.resolve_object(hst_a, err)); + ASSERT_NO_THROW(hst_aply.resolve_object(hst_c, err)); + ASSERT_NO_THROW(hg_aply.resolve_object(hg, err)); int now{500000000}; set_time(now); @@ -1379,9 +1387,10 @@ TEST_F(MacroHostname, HostGroupMembers) { ASSERT_NO_THROW(hst_aply.expand_objects(*config)); ASSERT_NO_THROW(hg_aply.expand_objects(*config)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_a)); - ASSERT_NO_THROW(hst_aply.resolve_object(hst_c)); - ASSERT_NO_THROW(hg_aply.resolve_object(hg)); + configuration::error_cnt err; + ASSERT_NO_THROW(hst_aply.resolve_object(hst_a, err)); + ASSERT_NO_THROW(hst_aply.resolve_object(hst_c, err)); + ASSERT_NO_THROW(hg_aply.resolve_object(hg, err)); int now{500000000}; set_time(now); @@ -1522,9 +1531,10 @@ TEST_F(MacroHostname, HostChildren) { ASSERT_EQ(engine::host::hosts.size(), 2u); + configuration::error_cnt err; hst_aply.expand_objects(*config); - hst_aply.resolve_object(hst_child); - hst_aply.resolve_object(hst_parent); + hst_aply.resolve_object(hst_child, err); + hst_aply.resolve_object(hst_parent, err); int now{500000000}; set_time(now); diff --git a/engine/tests/macros/macro_service.cc b/engine/tests/macros/macro_service.cc index f1b1df136f7..01be150cfc9 100644 --- a/engine/tests/macros/macro_service.cc +++ b/engine/tests/macros/macro_service.cc @@ -19,6 +19,7 @@ #include #include +#include "com/centreon/engine/configuration/state.hh" #include "com/centreon/engine/globals.hh" #include @@ -723,12 +724,13 @@ TEST_F(MacroService, ServiceGroupName) { // We fake here the expand_object on configuration::service svc.set_host_id(12); + configuration::error_cnt err; aply_svc.add_object(svc); ASSERT_TRUE(svc.parse("servicegroups", "test_group")); grp.parse("members", "test_host,test"); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - ASSERT_NO_THROW(aply_grp.resolve_object(grp)); + ASSERT_NO_THROW(aply_grp.resolve_object(grp, err)); init_macros(); int now{500000000}; @@ -763,13 +765,14 @@ TEST_F(MacroService, ServiceGroupAlias) { // We fake here the expand_object on configuration::service svc.set_host_id(12); + configuration::error_cnt err; aply_svc.add_object(svc); ASSERT_TRUE(svc.parse("servicegroups", "test_group")); grp.parse("members", "test_host,test"); grp.parse("alias", "test_group_alias"); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - ASSERT_NO_THROW(aply_grp.resolve_object(grp)); + ASSERT_NO_THROW(aply_grp.resolve_object(grp, err)); init_macros(); int now{500000000}; @@ -969,6 +972,7 @@ TEST_F(MacroService, ServiceCheckCommand) { TEST_F(MacroService, ServicePerfDataFile) { configuration::parser parser; configuration::state st; + configuration::error_cnt err; std::remove("/tmp/test-config.cfg"); @@ -978,8 +982,8 @@ TEST_F(MacroService, ServicePerfDataFile) { ofs << "log_file=\"\"" << std::endl; ofs.close(); - parser.parse("/tmp/test-config.cfg", st); - configuration::applier::state::instance().apply(st); + parser.parse("/tmp/test-config.cfg", st, err); + configuration::applier::state::instance().apply(st, err); init_macros(); std::string out; @@ -1636,12 +1640,13 @@ TEST_F(MacroService, ServiceGroupNames) { // We fake here the expand_object on configuration::service svc.set_host_id(12); + configuration::error_cnt err; aply_svc.add_object(svc); ASSERT_TRUE(svc.parse("servicegroups", "test_group")); grp.parse("members", "test_host,test"); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - ASSERT_NO_THROW(aply_grp.resolve_object(grp)); + ASSERT_NO_THROW(aply_grp.resolve_object(grp, err)); init_macros(); int now{500000000}; @@ -1716,13 +1721,14 @@ TEST_F(MacroService, ServiceGroupNotes) { // We fake here the expand_object on configuration::service svc.set_host_id(12); + configuration::error_cnt err; aply_svc.add_object(svc); ASSERT_TRUE(svc.parse("servicegroups", "test_group")); grp.parse("members", "test_host,test"); ASSERT_TRUE(grp.parse("notes", "test_notes")); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - ASSERT_NO_THROW(aply_grp.resolve_object(grp)); + ASSERT_NO_THROW(aply_grp.resolve_object(grp, err)); init_macros(); int now{500000000}; set_time(now); @@ -1758,13 +1764,14 @@ TEST_F(MacroService, ServiceGroupNotesUrl) { // We fake here the expand_object on configuration::service svc.set_host_id(12); + configuration::error_cnt err; aply_svc.add_object(svc); ASSERT_TRUE(svc.parse("servicegroups", "test_group")); grp.parse("members", "test_host,test"); ASSERT_TRUE(grp.parse("notes_url", "test_notes_url")); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - ASSERT_NO_THROW(aply_grp.resolve_object(grp)); + ASSERT_NO_THROW(aply_grp.resolve_object(grp, err)); init_macros(); int now{500000000}; set_time(now); @@ -1798,13 +1805,14 @@ TEST_F(MacroService, ServiceGroupActionUrl) { // We fake here the expand_object on configuration::service svc.set_host_id(12); + configuration::error_cnt err; aply_svc.add_object(svc); ASSERT_TRUE(svc.parse("servicegroups", "test_group")); grp.parse("members", "test_host,test"); ASSERT_TRUE(grp.parse("action_url", "test_notes_url")); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - ASSERT_NO_THROW(aply_grp.resolve_object(grp)); + ASSERT_NO_THROW(aply_grp.resolve_object(grp, err)); init_macros(); int now{500000000}; set_time(now); @@ -1838,13 +1846,14 @@ TEST_F(MacroService, ServiceGroupMembers) { // We fake here the expand_object on configuration::service svc.set_host_id(12); + configuration::error_cnt err; aply_svc.add_object(svc); ASSERT_TRUE(svc.parse("servicegroups", "test_group")); grp.parse("members", "test_host,test"); ASSERT_TRUE(grp.parse("action_url", "test_notes_url")); aply_grp.add_object(grp); aply_grp.expand_objects(*config); - ASSERT_NO_THROW(aply_grp.resolve_object(grp)); + ASSERT_NO_THROW(aply_grp.resolve_object(grp, err)); init_macros(); int now{500000000}; set_time(now); @@ -2010,6 +2019,7 @@ TEST_F(MacroService, LastServiceStateId) { TEST_F(MacroService, ServiceProblemID) { init_macros(); + configuration::error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); @@ -2017,8 +2027,8 @@ TEST_F(MacroService, ServiceProblemID) { new_configuration_contact("admin1", false, "c,r")}; ct_aply.add_object(ctct1); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); - ct_aply.resolve_object(ctct1); + ct_aply.resolve_object(ctct, err); + ct_aply.resolve_object(ctct1, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -2029,8 +2039,8 @@ TEST_F(MacroService, ServiceProblemID) { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); host_map const& hm{engine::host::hosts}; _host3 = hm.begin()->second; diff --git a/engine/tests/notifications/host_downtime_notification.cc b/engine/tests/notifications/host_downtime_notification.cc index 61f2003faa5..a4f2a32a4c9 100644 --- a/engine/tests/notifications/host_downtime_notification.cc +++ b/engine/tests/notifications/host_downtime_notification.cc @@ -42,18 +42,19 @@ using namespace com::centreon::engine::configuration::applier; class HostDowntimeNotification : public TestEngine { public: void SetUp() override { + error_cnt err; init_config_state(); configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host aply; aply.add_object(hst); - aply.resolve_object(hst); + aply.resolve_object(hst, err); host_map const& hm{engine::host::hosts}; _host = hm.begin()->second; diff --git a/engine/tests/notifications/host_flapping_notification.cc b/engine/tests/notifications/host_flapping_notification.cc index 0f9b7e6c3e3..f670d0bb46c 100644 --- a/engine/tests/notifications/host_flapping_notification.cc +++ b/engine/tests/notifications/host_flapping_notification.cc @@ -26,6 +26,7 @@ #include "com/centreon/engine/configuration/applier/contact.hh" #include "com/centreon/engine/configuration/applier/host.hh" #include "com/centreon/engine/configuration/host.hh" +#include "com/centreon/engine/configuration/state.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/host.hh" #include "com/centreon/engine/hostescalation.hh" @@ -40,13 +41,14 @@ using namespace com::centreon::engine::configuration::applier; class HostFlappingNotification : public TestEngine { public: void SetUp() override { + configuration::error_cnt err; init_config_state(); configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::host hst_aply; configuration::host hst; @@ -55,7 +57,7 @@ class HostFlappingNotification : public TestEngine { hst.parse("_HOST_ID", "12"); hst.parse("contacts", "admin"); hst_aply.add_object(hst); - hst_aply.resolve_object(hst); + hst_aply.resolve_object(hst, err); host_map const& hm{engine::host::hosts}; _host = hm.begin()->second; _host->set_current_state(engine::host::state_up); @@ -70,7 +72,7 @@ class HostFlappingNotification : public TestEngine { hst_child.parse("_HOST_ID", "13"); hst_child.parse("contacts", "admin"); hst_aply.add_object(hst_child); - hst_aply.resolve_object(hst_child); + hst_aply.resolve_object(hst_child, err); _host2 = hm.begin()->second; _host2->set_current_state(engine::host::state_up); diff --git a/engine/tests/notifications/host_normal_notification.cc b/engine/tests/notifications/host_normal_notification.cc index c53cbd34795..67b513bd6dc 100644 --- a/engine/tests/notifications/host_normal_notification.cc +++ b/engine/tests/notifications/host_normal_notification.cc @@ -56,16 +56,17 @@ class HostNotification : public TestEngine { events_logger->set_level(spdlog::level::off); + error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; hst_aply.add_object(hst); - hst_aply.resolve_object(hst); + hst_aply.resolve_object(hst, err); host_map const& hm{engine::host::hosts}; _host = hm.begin()->second; _host->set_current_state(engine::host::state_up); @@ -557,25 +558,26 @@ TEST_F(HostNotification, CheckFirstNotificationDelay) { // Then contacts from the escalation are notified when notification number // is in [2,6] and are separated by at less 4*60s. TEST_F(HostNotification, HostEscalation) { + error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::hostescalation he_aply; configuration::hostescalation he{ new_configuration_hostescalation("test_host", "test_cg")}; he_aply.add_object(he); he_aply.expand_objects(*config); - he_aply.resolve_object(he); + he_aply.resolve_object(he, err); int now{50000}; set_time(now); @@ -682,36 +684,37 @@ TEST_F(HostNotification, HostEscalation) { } TEST_F(HostNotification, HostDependency) { + error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::host h_aply; configuration::host h{new_configuration_host("dep_host", "admin", 15)}; h_aply.add_object(h); h_aply.expand_objects(*config); - h_aply.resolve_object(h); + h_aply.resolve_object(h, err); configuration::applier::hostdependency hd_aply; configuration::hostdependency hd{ new_configuration_hostdependency("test_host", "dep_host")}; hd_aply.expand_objects(*config); hd_aply.add_object(hd); - hd_aply.resolve_object(hd); + hd_aply.resolve_object(hd, err); int now{50000}; set_time(now); - int w{0}, e{0}; + uint32_t w = 0, e = 0; pre_flight_circular_check(&w, &e); ASSERT_EQ(w, 0); @@ -823,25 +826,26 @@ TEST_F(HostNotification, HostDependency) { // is sent 1 time // Then both are sent to contacts from the escalation. TEST_F(HostNotification, HostEscalationOneTime) { + error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::hostescalation he_aply; configuration::hostescalation he{ new_configuration_hostescalation("test_host", "test_cg", 1, 0)}; he_aply.add_object(he); he_aply.expand_objects(*config); - he_aply.resolve_object(he); + he_aply.resolve_object(he, err); int now{50000}; set_time(now); @@ -918,25 +922,26 @@ TEST_F(HostNotification, HostEscalationOneTime) { // is sent 1 time // Then both are sent to contacts from the escalation. TEST_F(HostNotification, HostEscalationOneTimeNotifInter0) { + error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::hostescalation he_aply; configuration::hostescalation he{ new_configuration_hostescalation("test_host", "test_cg", 1, 0, 0)}; he_aply.add_object(he); he_aply.expand_objects(*config); - he_aply.resolve_object(he); + he_aply.resolve_object(he, err); int now{50000}; set_time(now); @@ -1013,25 +1018,26 @@ TEST_F(HostNotification, HostEscalationOneTimeNotifInter0) { // is sent 1 time // Then both are sent to contacts from the escalation. TEST_F(HostNotification, HostEscalationRetention) { + error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::hostescalation he_aply; configuration::hostescalation he{ new_configuration_hostescalation("test_host", "test_cg", 1, 0, 0)}; he_aply.add_object(he); he_aply.expand_objects(*config); - he_aply.resolve_object(he); + he_aply.resolve_object(he, err); int now{50000}; set_time(now); diff --git a/engine/tests/notifications/service_downtime_notification_test.cc b/engine/tests/notifications/service_downtime_notification_test.cc index f0bd0266fd4..003b497d863 100644 --- a/engine/tests/notifications/service_downtime_notification_test.cc +++ b/engine/tests/notifications/service_downtime_notification_test.cc @@ -50,12 +50,13 @@ class ServiceDowntimeNotification : public TestEngine { public: void SetUp() override { init_config_state(); + error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -66,8 +67,8 @@ class ServiceDowntimeNotification : public TestEngine { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); host_map const& hm{engine::host::hosts}; _host = hm.begin()->second; diff --git a/engine/tests/notifications/service_flapping_notification.cc b/engine/tests/notifications/service_flapping_notification.cc index 140d4690273..3d3f5563af0 100644 --- a/engine/tests/notifications/service_flapping_notification.cc +++ b/engine/tests/notifications/service_flapping_notification.cc @@ -45,13 +45,14 @@ using namespace com::centreon::engine::retention; class ServiceFlappingNotification : public TestEngine { public: void SetUp() override { + error_cnt err; init_config_state(); configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::command cmd_aply; configuration::command cmd("cmd"); @@ -65,7 +66,7 @@ class ServiceFlappingNotification : public TestEngine { hst.parse("_HOST_ID", "12"); hst.parse("check_command", "cmd"); hst_aply.add_object(hst); - hst_aply.resolve_object(hst); + hst_aply.resolve_object(hst, err); configuration::applier::service svc_aply; configuration::service svc; @@ -79,7 +80,7 @@ class ServiceFlappingNotification : public TestEngine { svc.set_host_id(12); svc_aply.add_object(svc); - svc_aply.resolve_object(svc); + svc_aply.resolve_object(svc, err); service_map const& sv{engine::service::services}; diff --git a/engine/tests/notifications/service_normal_notification.cc b/engine/tests/notifications/service_normal_notification.cc index 2f1111e2f5e..d56a713cde6 100644 --- a/engine/tests/notifications/service_normal_notification.cc +++ b/engine/tests/notifications/service_normal_notification.cc @@ -50,6 +50,7 @@ class ServiceNotification : public TestEngine { public: void SetUp() override { init_config_state(); + error_cnt err; configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; @@ -58,8 +59,8 @@ class ServiceNotification : public TestEngine { new_configuration_contact("admin1", false, "c,r")}; ct_aply.add_object(ctct1); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); - ct_aply.resolve_object(ctct1); + ct_aply.resolve_object(ctct, err); + ct_aply.resolve_object(ctct1, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -70,8 +71,8 @@ class ServiceNotification : public TestEngine { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); host_map const& hm{engine::host::hosts}; _host = hm.begin()->second; @@ -759,21 +760,22 @@ TEST_F(ServiceNotification, ServiceEscalationCG) { configuration::contact ctct{new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + error_cnt err; + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::serviceescalation se_aply; configuration::serviceescalation se{ new_configuration_serviceescalation("test_host", "test_svc", "test_cg")}; se_aply.add_object(se); se_aply.expand_objects(*config); - se_aply.resolve_object(se); + se_aply.resolve_object(se, err); int now{50000}; set_time(now); diff --git a/engine/tests/notifications/service_timeperiod_notification.cc b/engine/tests/notifications/service_timeperiod_notification.cc index 4288dbda448..86b9a0376f3 100644 --- a/engine/tests/notifications/service_timeperiod_notification.cc +++ b/engine/tests/notifications/service_timeperiod_notification.cc @@ -38,6 +38,7 @@ #include "com/centreon/engine/configuration/applier/state.hh" #include "com/centreon/engine/configuration/host.hh" #include "com/centreon/engine/configuration/service.hh" +#include "com/centreon/engine/configuration/state.hh" #include "com/centreon/engine/exceptions/error.hh" #include "com/centreon/engine/serviceescalation.hh" #include "com/centreon/engine/timeperiod.hh" @@ -53,6 +54,7 @@ using namespace com::centreon::engine::configuration::applier; class ServiceTimePeriodNotification : public TestEngine { public: void SetUp() override { + error_cnt err; init_config_state(); configuration::applier::contact ct_aply; @@ -62,8 +64,8 @@ class ServiceTimePeriodNotification : public TestEngine { new_configuration_contact("admin1", false, "c,r")}; ct_aply.add_object(ctct1); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); - ct_aply.resolve_object(ctct1); + ct_aply.resolve_object(ctct, err); + ct_aply.resolve_object(ctct1, err); configuration::host hst{new_configuration_host("test_host", "admin")}; configuration::applier::host hst_aply; @@ -74,8 +76,8 @@ class ServiceTimePeriodNotification : public TestEngine { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); host_map const& hm{engine::host::hosts}; _host = hm.begin()->second; @@ -119,6 +121,7 @@ class ServiceTimePeriodNotification : public TestEngine { // Then contacts from the escalation are notified when notification number // is in [2,6] and are separated by at less 4*60s. TEST_F(ServiceTimePeriodNotification, NoTimePeriodOk) { + error_cnt err; init_macros(); std::unique_ptr tperiod{ new engine::timeperiod("tperiod", "alias")}; @@ -129,21 +132,21 @@ TEST_F(ServiceTimePeriodNotification, NoTimePeriodOk) { configuration::contact ctct{new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::serviceescalation se_aply; configuration::serviceescalation se{ new_configuration_serviceescalation("test_host", "test_svc", "test_cg")}; se_aply.add_object(se); se_aply.expand_objects(*config); - se_aply.resolve_object(se); + se_aply.resolve_object(se, err); // uint64_t id{_svc->get_next_notification_id()}; for (int i = 0; i < 7; ++i) { @@ -223,6 +226,7 @@ TEST_F(ServiceTimePeriodNotification, NoTimePeriodOk) { } TEST_F(ServiceTimePeriodNotification, NoTimePeriodKo) { + error_cnt err; init_macros(); std::unique_ptr tperiod{ new engine::timeperiod("tperiod", "alias")}; @@ -233,14 +237,14 @@ TEST_F(ServiceTimePeriodNotification, NoTimePeriodKo) { configuration::contact ctct{new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::serviceescalation se_aply; configuration::serviceescalation se; @@ -253,7 +257,7 @@ TEST_F(ServiceTimePeriodNotification, NoTimePeriodKo) { se.parse("contact_groups", "test_cg"); se_aply.add_object(se); se_aply.expand_objects(*config); - se_aply.resolve_object(se); + se_aply.resolve_object(se, err); for (int i = 0; i < 7; ++i) { timerange_list list_time; list_time.emplace_back(35000, 85000); @@ -338,6 +342,7 @@ TEST_F(ServiceTimePeriodNotification, NoTimePeriodKo) { } TEST_F(ServiceTimePeriodNotification, TimePeriodOut) { + error_cnt err; init_macros(); std::unique_ptr tperiod{ new engine::timeperiod("tperiod", "alias")}; @@ -348,21 +353,21 @@ TEST_F(ServiceTimePeriodNotification, TimePeriodOut) { configuration::contact ctct{new_configuration_contact("test_contact", false)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::serviceescalation se_aply; configuration::serviceescalation se{ new_configuration_serviceescalation("test_host", "test_svc", "test_cg")}; se_aply.add_object(se); se_aply.expand_objects(*config); - se_aply.resolve_object(se); + se_aply.resolve_object(se, err); // uint64_t id{_svc->get_next_notification_id()}; for (int i = 0; i < 7; ++i) { @@ -442,6 +447,7 @@ TEST_F(ServiceTimePeriodNotification, TimePeriodOut) { } TEST_F(ServiceTimePeriodNotification, TimePeriodUserOut) { + error_cnt err; init_macros(); std::unique_ptr tiperiod{ new engine::timeperiod("tperiod", "alias")}; @@ -473,21 +479,21 @@ TEST_F(ServiceTimePeriodNotification, TimePeriodUserOut) { ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::serviceescalation se_aply; configuration::serviceescalation se{ new_configuration_serviceescalation("test_host", "test_svc", "test_cg")}; se_aply.add_object(se); se_aply.expand_objects(*config); - se_aply.resolve_object(se); + se_aply.resolve_object(se, err); // uint64_t id{_svc->get_next_notification_id()}; for (int i = 0; i < 7; ++i) { @@ -566,6 +572,7 @@ TEST_F(ServiceTimePeriodNotification, TimePeriodUserOut) { } TEST_F(ServiceTimePeriodNotification, TimePeriodUserIn) { + error_cnt err; init_macros(); std::unique_ptr tiperiod{ new engine::timeperiod("tperiod", "alias")}; @@ -597,21 +604,21 @@ TEST_F(ServiceTimePeriodNotification, TimePeriodUserIn) { ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::serviceescalation se_aply; configuration::serviceescalation se{ new_configuration_serviceescalation("test_host", "test_svc", "test_cg")}; se_aply.add_object(se); se_aply.expand_objects(*config); - se_aply.resolve_object(se); + se_aply.resolve_object(se, err); // uint64_t id{_svc->get_next_notification_id()}; for (int i = 0; i < 7; ++i) { @@ -719,23 +726,24 @@ TEST_F(ServiceTimePeriodNotification, TimePeriodUserAll) { ctct.parse("host_notifications_enabled", "1"); ctct.parse("service_notifications_enabled", "1"); + error_cnt err; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::serviceescalation se_aply; configuration::serviceescalation se{ new_configuration_serviceescalation("test_host", "test_svc", "test_cg")}; se_aply.add_object(se); se_aply.expand_objects(*config); - se_aply.resolve_object(se); + se_aply.resolve_object(se, err); // uint64_t id{_svc->get_next_notification_id()}; for (int i = 0; i < 7; ++i) { @@ -836,23 +844,24 @@ TEST_F(ServiceTimePeriodNotification, TimePeriodUserNone) { ctct.parse("host_notifications_enabled", "1"); ctct.parse("service_notifications_enabled", "1"); + error_cnt err; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::serviceescalation se_aply; configuration::serviceescalation se{ new_configuration_serviceescalation("test_host", "test_svc", "test_cg")}; se_aply.add_object(se); se_aply.expand_objects(*config); - se_aply.resolve_object(se); + se_aply.resolve_object(se, err); // uint64_t id{_svc->get_next_notification_id()}; for (int i = 0; i < 7; ++i) { @@ -952,23 +961,24 @@ TEST_F(ServiceTimePeriodNotification, NoTimePeriodUser) { ctct.parse("host_notifications_enabled", "1"); ctct.parse("service_notifications_enabled", "1"); + error_cnt err; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::applier::contactgroup cg_aply; configuration::contactgroup cg{ new_configuration_contactgroup("test_cg", "test_contact")}; cg_aply.add_object(cg); cg_aply.expand_objects(*config); - cg_aply.resolve_object(cg); + cg_aply.resolve_object(cg, err); configuration::applier::serviceescalation se_aply; configuration::serviceescalation se{ new_configuration_serviceescalation("test_host", "test_svc", "test_cg")}; se_aply.add_object(se); se_aply.expand_objects(*config); - se_aply.resolve_object(se); + se_aply.resolve_object(se, err); // uint64_t id{_svc->get_next_notification_id()}; for (int i = 0; i < 7; ++i) { diff --git a/engine/tests/opentelemetry/open_telemetry_test.cc b/engine/tests/opentelemetry/open_telemetry_test.cc index 58603487909..14e2ec38470 100644 --- a/engine/tests/opentelemetry/open_telemetry_test.cc +++ b/engine/tests/opentelemetry/open_telemetry_test.cc @@ -114,13 +114,14 @@ void open_telemetry_test::SetUpTestSuite() { } void open_telemetry_test::SetUp() { + configuration::error_cnt err; init_config_state(); config->contacts().clear(); configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::host hst{new_configuration_host("localhost", "admin")}; configuration::applier::host hst_aply; @@ -131,8 +132,8 @@ void open_telemetry_test::SetUp() { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); data_point_fifo::update_fifo_limit(std::numeric_limits::max(), 10); } diff --git a/engine/tests/opentelemetry/otl_converter_test.cc b/engine/tests/opentelemetry/otl_converter_test.cc index 8ebc07f4282..558970ad7fe 100644 --- a/engine/tests/opentelemetry/otl_converter_test.cc +++ b/engine/tests/opentelemetry/otl_converter_test.cc @@ -53,13 +53,14 @@ class otl_converter_test : public TestEngine { }; void otl_converter_test::SetUp() { + configuration::error_cnt err; init_config_state(); config->contacts().clear(); configuration::applier::contact ct_aply; configuration::contact ctct{new_configuration_contact("admin", true)}; ct_aply.add_object(ctct); ct_aply.expand_objects(*config); - ct_aply.resolve_object(ctct); + ct_aply.resolve_object(ctct, err); configuration::host hst{new_configuration_host("localhost", "admin")}; configuration::applier::host hst_aply; @@ -70,8 +71,8 @@ void otl_converter_test::SetUp() { configuration::applier::service svc_aply; svc_aply.add_object(svc); - hst_aply.resolve_object(hst); - svc_aply.resolve_object(svc); + hst_aply.resolve_object(hst, err); + svc_aply.resolve_object(svc, err); data_point_fifo::update_fifo_limit(std::numeric_limits::max(), 10); }