From 4a8cb6506b5b3a7e395f0ad8dd1d12f2b068ae61 Mon Sep 17 00:00:00 2001 From: David Boucher Date: Wed, 5 Jun 2024 08:34:50 +0200 Subject: [PATCH] enh(engine): customvariables have their own configuration class --- broker/neb/src/initial.cc | 4 +- .../centreon/engine/configuration/service.hh | 2 +- .../centreon/engine/configuration/state.hh | 2 +- .../inc/com/centreon/engine/customvariable.hh | 4 +- engine/src/commands/raw.cc | 15 +++--- engine/src/configuration/CMakeLists.txt | 1 + .../configuration/applier/anomalydetection.cc | 41 ++++++++-------- engine/src/configuration/applier/contact.cc | 22 +++++---- engine/src/configuration/applier/host.cc | 16 +++--- engine/src/configuration/applier/service.cc | 49 +++++++++---------- engine/src/configuration/applier/state.cc | 2 +- engine/src/configuration/parser.cc | 2 +- engine/src/configuration/service.cc | 2 +- engine/src/configuration/state.cc | 2 +- engine/src/customvariable.cc | 2 +- engine/src/macros.cc | 2 +- engine/src/retention/applier/contact.cc | 36 +++++++------- engine/src/retention/applier/host.cc | 36 +++++++------- engine/src/retention/applier/service.cc | 2 +- engine/src/retention/dump.cc | 2 +- engine/src/xsddefault.cc | 6 +-- .../configuration/applier/applier-contact.cc | 7 ++- .../configuration/applier/applier-state.cc | 2 +- engine/tests/enginerpc/enginerpc.cc | 7 ++- 24 files changed, 132 insertions(+), 134 deletions(-) diff --git a/broker/neb/src/initial.cc b/broker/neb/src/initial.cc index 71829c4e99d..a8fad65920e 100644 --- a/broker/neb/src/initial.cc +++ b/broker/neb/src/initial.cc @@ -76,7 +76,7 @@ static void send_custom_variables_list( nscvd.type = NEBTYPE_HOSTCUSTOMVARIABLE_ADD; nscvd.timestamp.tv_sec = time(nullptr); nscvd.var_name = const_cast(name.c_str()); - nscvd.var_value = const_cast(cit->second.get_value().c_str()); + nscvd.var_value = const_cast(cit->second.value().c_str()); nscvd.object_ptr = it->second.get(); // Callback. @@ -103,7 +103,7 @@ static void send_custom_variables_list( nscvd.type = NEBTYPE_SERVICECUSTOMVARIABLE_ADD; nscvd.timestamp.tv_sec = time(nullptr); nscvd.var_name = const_cast(name.c_str()); - nscvd.var_value = const_cast(cit->second.get_value().c_str()); + nscvd.var_value = const_cast(cit->second.value().c_str()); nscvd.object_ptr = it->second.get(); // Callback. diff --git a/engine/inc/com/centreon/engine/configuration/service.hh b/engine/inc/com/centreon/engine/configuration/service.hh index 49fc7bd5853..d72dc1fb52d 100644 --- a/engine/inc/com/centreon/engine/configuration/service.hh +++ b/engine/inc/com/centreon/engine/configuration/service.hh @@ -69,7 +69,7 @@ class service : public object { set_string const& contacts() const noexcept; bool contacts_defined() const noexcept; map_customvar const& customvariables() const noexcept; - map_customvar& customvariables() noexcept; + map_customvar& mut_customvariables() noexcept; std::string const& display_name() const noexcept; std::string const& event_handler() const noexcept; bool event_handler_enabled() const noexcept; diff --git a/engine/inc/com/centreon/engine/configuration/state.hh b/engine/inc/com/centreon/engine/configuration/state.hh index e0b3cc2d9ab..76f167f8bb0 100644 --- a/engine/inc/com/centreon/engine/configuration/state.hh +++ b/engine/inc/com/centreon/engine/configuration/state.hh @@ -346,7 +346,7 @@ class state { // const set_anomalydetection& anomalydetections() const noexcept; set_anomalydetection& anomalydetections() noexcept; set_service const& services() const noexcept; - set_service& services() noexcept; + set_service& mut_services() noexcept; set_anomalydetection::iterator anomalydetections_find( anomalydetection::key_type const& k); set_service::iterator services_find(service::key_type const& k); diff --git a/engine/inc/com/centreon/engine/customvariable.hh b/engine/inc/com/centreon/engine/customvariable.hh index cf1ad73e40a..3b2e7fefc2e 100644 --- a/engine/inc/com/centreon/engine/customvariable.hh +++ b/engine/inc/com/centreon/engine/customvariable.hh @@ -43,7 +43,7 @@ class customvariable { void set_sent(bool sent); bool is_sent() const; void set_value(std::string const& value); - std::string const& get_value() const; + const std::string& value() const; bool has_been_modified() const; void update(std::string const& value); @@ -55,6 +55,6 @@ class customvariable { typedef std::unordered_map map_customvar; -} +} // namespace com::centreon::engine #endif // !CCE_OBJECTS_CUSTOMVARIABLE_HH diff --git a/engine/src/commands/raw.cc b/engine/src/commands/raw.cc index 50e195545a1..21774f804d9 100644 --- a/engine/src/commands/raw.cc +++ b/engine/src/commands/raw.cc @@ -394,9 +394,8 @@ void raw::_build_custom_contact_macro_environment(nagios_macros& macros, // Set custom contact variable into the environement for (auto const& cv : macros.custom_contact_vars) { if (!cv.first.empty()) { - std::string value( - clean_macro_chars(cv.second.get_value(), - STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS)); + std::string value(clean_macro_chars( + cv.second.value(), STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS)); std::string line; line.append(MACRO_ENV_VAR_PREFIX); line.append(cv.first); @@ -429,9 +428,8 @@ void raw::_build_custom_host_macro_environment(nagios_macros& macros, // Set custom host variable into the environement for (auto const& cv : macros.custom_host_vars) { if (!cv.first.empty()) { - std::string value( - clean_macro_chars(cv.second.get_value(), - STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS)); + std::string value(clean_macro_chars( + cv.second.value(), STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS)); std::string line; line.append(MACRO_ENV_VAR_PREFIX); line.append(cv.first); @@ -464,9 +462,8 @@ void raw::_build_custom_service_macro_environment(nagios_macros& macros, // Set custom service variable into the environement for (auto const& cv : macros.custom_service_vars) { if (!cv.first.empty()) { - std::string value( - clean_macro_chars(cv.second.get_value(), - STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS)); + std::string value(clean_macro_chars( + cv.second.value(), STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS)); std::string line; line.append(MACRO_ENV_VAR_PREFIX); line.append(cv.first); diff --git a/engine/src/configuration/CMakeLists.txt b/engine/src/configuration/CMakeLists.txt index b0bd8910f26..ff0c4fcd7a0 100644 --- a/engine/src/configuration/CMakeLists.txt +++ b/engine/src/configuration/CMakeLists.txt @@ -32,6 +32,7 @@ set(FILES "${SRC_DIR}/connector.cc" "${SRC_DIR}/contact.cc" "${SRC_DIR}/contactgroup.cc" + "${SRC_DIR}/customvariable.cc" "${SRC_DIR}/extended_conf.cc" "${SRC_DIR}/group.cc" "${SRC_DIR}/host.cc" diff --git a/engine/src/configuration/applier/anomalydetection.cc b/engine/src/configuration/applier/anomalydetection.cc index a4cc5ef1d14..ccbd1325b63 100644 --- a/engine/src/configuration/applier/anomalydetection.cc +++ b/engine/src/configuration/applier/anomalydetection.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020-2024 Centreon + * Copyright 2020,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. @@ -141,21 +141,22 @@ void applier::anomalydetection::add_object( ad->mut_contacts().insert({*it, nullptr}); // Add contactgroups. - for (set_string::const_iterator it(obj.contactgroups().begin()), - end(obj.contactgroups().end()); + for (set_string::const_iterator it = obj.contactgroups().begin(), + end = obj.contactgroups().end(); it != end; ++it) ad->get_contactgroups().insert({*it, nullptr}); // Add custom variables. - for (map_customvar::const_iterator it(obj.customvariables().begin()), - end(obj.customvariables().end()); + for (auto it = obj.customvariables().begin(), + end = obj.customvariables().end(); it != end; ++it) { - ad->custom_variables[it->first] = it->second; + ad->custom_variables[it->first] = + engine::customvariable(it->second.value(), it->second.is_sent()); if (it->second.is_sent()) { timeval tv(get_broker_timestamp(nullptr)); broker_custom_variable(NEBTYPE_SERVICECUSTOMVARIABLE_ADD, ad, - it->first.c_str(), it->second.get_value().c_str(), + it->first.c_str(), it->second.value().c_str(), &tv); } } @@ -172,21 +173,22 @@ void applier::anomalydetection::add_object( */ void applier::anomalydetection::expand_objects(configuration::state& s) { // Browse all anomalydetections. - for (configuration::set_anomalydetection::iterator - it_ad = s.anomalydetections().begin(), - end_ad = s.anomalydetections().end(); - it_ad != end_ad; ++it_ad) { + configuration::set_anomalydetection new_ads; + // In a set, we cannot change items as it would change their order. So we + // create a new set and replace the old one with the new one at the end. + for (auto ad : s.anomalydetections()) { // Should custom variables be sent to broker ? - for (map_customvar::iterator - it = const_cast(it_ad->customvariables()).begin(), - end = const_cast(it_ad->customvariables()).end(); + for (auto it = ad.customvariables().begin(), + end = ad.customvariables().end(); it != end; ++it) { if (!s.enable_macros_filter() || s.macros_filter().find(it->first) != s.macros_filter().end()) { it->second.set_sent(true); } } + new_ads.insert(std::move(ad)); } + s.anomalydetections() = new_ads; } /** @@ -373,20 +375,19 @@ void applier::anomalydetection::modify_object( if (c.second.is_sent()) { timeval tv(get_broker_timestamp(nullptr)); broker_custom_variable(NEBTYPE_SERVICECUSTOMVARIABLE_DELETE, s.get(), - c.first.c_str(), c.second.get_value().c_str(), - &tv); + c.first.c_str(), c.second.value().c_str(), &tv); } } s->custom_variables.clear(); for (auto& c : obj.customvariables()) { - s->custom_variables[c.first] = c.second; + s->custom_variables[c.first] = + engine::customvariable(c.second.value(), c.second.is_sent()); if (c.second.is_sent()) { timeval tv(get_broker_timestamp(nullptr)); broker_custom_variable(NEBTYPE_SERVICECUSTOMVARIABLE_ADD, s.get(), - c.first.c_str(), c.second.get_value().c_str(), - &tv); + c.first.c_str(), c.second.value().c_str(), &tv); } } } @@ -524,8 +525,6 @@ void applier::anomalydetection::_expand_service_memberships( // Reinsert anomalydetection group. s.servicegroups().insert(backup); } - - return; } /** diff --git a/engine/src/configuration/applier/contact.cc b/engine/src/configuration/applier/contact.cc index 022737ac760..c3bb3025aff 100644 --- a/engine/src/configuration/applier/contact.cc +++ b/engine/src/configuration/applier/contact.cc @@ -98,15 +98,17 @@ void applier::contact::add_object(configuration::contact const& obj) { engine::contact::contacts.insert({c->get_name(), c}); // Add all custom variables. - for (map_customvar::const_iterator it(obj.customvariables().begin()), - end(obj.customvariables().end()); + for (auto it = obj.customvariables().begin(), + end = obj.customvariables().end(); it != end; ++it) { - c->get_custom_variables()[it->first] = it->second; + auto& cv = c->get_custom_variables()[it->first]; + cv.set_value(it->second.value()); + cv.set_sent(it->second.is_sent()); if (it->second.is_sent()) { timeval tv(get_broker_timestamp(nullptr)); broker_custom_variable(NEBTYPE_CONTACTCUSTOMVARIABLE_ADD, c.get(), - it->first.c_str(), it->second.get_value().c_str(), + it->first.c_str(), it->second.value().c_str(), &tv); } } @@ -298,20 +300,22 @@ void applier::contact::modify_object(configuration::contact const& obj) { if (cus.second.is_sent()) { timeval tv(get_broker_timestamp(nullptr)); broker_custom_variable(NEBTYPE_CONTACTCUSTOMVARIABLE_DELETE, c, - cus.first.c_str(), - cus.second.get_value().c_str(), &tv); + cus.first.c_str(), cus.second.value().c_str(), + &tv); } } c->get_custom_variables().clear(); for (auto& cus : obj.customvariables()) { - c->get_custom_variables()[cus.first] = cus.second; + auto& cv = c->get_custom_variables()[cus.first]; + cv.set_value(cus.second.value()); + cv.set_sent(cus.second.is_sent()); if (cus.second.is_sent()) { timeval tv(get_broker_timestamp(nullptr)); broker_custom_variable(NEBTYPE_CONTACTCUSTOMVARIABLE_ADD, c, - cus.first.c_str(), - cus.second.get_value().c_str(), &tv); + cus.first.c_str(), cus.second.value().c_str(), + &tv); } } } diff --git a/engine/src/configuration/applier/host.cc b/engine/src/configuration/applier/host.cc index 6ca6239e0a8..c21486618e1 100644 --- a/engine/src/configuration/applier/host.cc +++ b/engine/src/configuration/applier/host.cc @@ -119,15 +119,16 @@ void applier::host::add_object(configuration::host const& obj) { h->get_contactgroups().insert({*it, nullptr}); // Custom variables. - for (map_customvar::const_iterator it(obj.customvariables().begin()), - end(obj.customvariables().end()); + for (auto it = obj.customvariables().begin(), + end = obj.customvariables().end(); it != end; ++it) { - h->custom_variables[it->first] = it->second; + h->custom_variables[it->first] = + engine::customvariable(it->second.value(), it->second.is_sent()); if (it->second.is_sent()) { timeval tv(get_broker_timestamp(nullptr)); broker_custom_variable(NEBTYPE_HOSTCUSTOMVARIABLE_ADD, h.get(), - it->first.c_str(), it->second.get_value().c_str(), + it->first.c_str(), it->second.value().c_str(), &tv); } } @@ -381,19 +382,20 @@ void applier::host::modify_object(configuration::host const& obj) { timeval tv(get_broker_timestamp(nullptr)); broker_custom_variable(NEBTYPE_HOSTCUSTOMVARIABLE_DELETE, it_obj->second.get(), c.first.c_str(), - c.second.get_value().c_str(), &tv); + c.second.value().c_str(), &tv); } } it_obj->second->custom_variables.clear(); for (auto& c : obj.customvariables()) { - it_obj->second->custom_variables[c.first] = c.second; + it_obj->second->custom_variables[c.first] = + engine::customvariable(c.second.value(), c.second.is_sent()); if (c.second.is_sent()) { timeval tv(get_broker_timestamp(nullptr)); broker_custom_variable(NEBTYPE_HOSTCUSTOMVARIABLE_ADD, it_obj->second.get(), c.first.c_str(), - c.second.get_value().c_str(), &tv); + c.second.value().c_str(), &tv); } } } diff --git a/engine/src/configuration/applier/service.cc b/engine/src/configuration/applier/service.cc index e26d4f3d955..3d83fb17eb5 100644 --- a/engine/src/configuration/applier/service.cc +++ b/engine/src/configuration/applier/service.cc @@ -113,7 +113,7 @@ void applier::service::add_object(configuration::service const& obj) { obj.service_description(), *obj.hosts().begin()); // Add service to the global configuration set. - config->services().insert(obj); + config->mut_services().insert(obj); // Create service. engine::service* svc{add_service( @@ -185,15 +185,16 @@ void applier::service::add_object(configuration::service const& obj) { svc->get_contactgroups().insert({*it, nullptr}); // Add custom variables. - for (map_customvar::const_iterator it(obj.customvariables().begin()), - end(obj.customvariables().end()); + for (auto it = obj.customvariables().begin(), + end = obj.customvariables().end(); it != end; ++it) { - svc->custom_variables[it->first] = it->second; + svc->custom_variables[it->first] = + engine::customvariable(it->second.value(), it->second.is_sent()); if (it->second.is_sent()) { timeval tv(get_broker_timestamp(nullptr)); broker_custom_variable(NEBTYPE_SERVICECUSTOMVARIABLE_ADD, svc, - it->first.c_str(), it->second.get_value().c_str(), + it->first.c_str(), it->second.value().c_str(), &tv); } } @@ -238,13 +239,10 @@ void applier::service::add_object(configuration::service const& obj) { void applier::service::expand_objects(configuration::state& s) { // Browse all services. configuration::set_service expanded; - for (configuration::set_service::iterator it_svc(s.services().begin()), - end_svc(s.services().end()); - it_svc != end_svc; ++it_svc) { + for (auto svc_cfg : s.services()) { // Should custom variables be sent to broker ? - for (map_customvar::iterator - it(const_cast(it_svc->customvariables()).begin()), - end(const_cast(it_svc->customvariables()).end()); + for (auto it = svc_cfg.mut_customvariables().begin(), + end = svc_cfg.mut_customvariables().end(); it != end; ++it) { if (!s.enable_macros_filter() || s.macros_filter().find(it->first) != s.macros_filter().end()) { @@ -256,24 +254,24 @@ void applier::service::expand_objects(configuration::state& s) { std::set target_hosts; // Hosts members. - target_hosts = it_svc->hosts(); + target_hosts = svc_cfg.hosts(); // Host group members. - for (set_string::const_iterator it(it_svc->hostgroups().begin()), - end(it_svc->hostgroups().end()); + for (set_string::const_iterator it(svc_cfg.hostgroups().begin()), + end(svc_cfg.hostgroups().end()); it != end; ++it) { // Find host group. set_hostgroup::iterator it2(s.hostgroups_find(*it)); if (it2 == s.hostgroups().end()) throw(engine_error() << "Could not find host group '" << *it << "' on which to apply service '" - << it_svc->service_description() << "'"); + << svc_cfg.service_description() << "'"); // Check host group and user configuration. if (it2->members().empty() && !s.allow_empty_hostgroup_assignment()) throw(engine_error() << "Could not expand host group '" << *it << "' specified in service '" - << it_svc->service_description() << "'"); + << svc_cfg.service_description() << "'"); // Add host group members. target_hosts.insert(it2->members().begin(), it2->members().end()); @@ -284,7 +282,7 @@ void applier::service::expand_objects(configuration::state& s) { end(target_hosts.end()); it != end; ++it) { // Create service instance. - configuration::service svc(*it_svc); + configuration::service svc(svc_cfg); svc.hostgroups().clear(); svc.hosts().clear(); svc.hosts().insert(*it); @@ -301,7 +299,7 @@ void applier::service::expand_objects(configuration::state& s) { } // Set expanded services in configuration state. - s.services().swap(expanded); + s.mut_services().swap(expanded); } /** @@ -340,8 +338,8 @@ void applier::service::modify_object(configuration::service const& obj) { // Update the global configuration set. configuration::service obj_old(*it_cfg); - config->services().erase(it_cfg); - config->services().insert(obj); + config->mut_services().erase(it_cfg); + config->mut_services().insert(obj); // Modify properties. if (it_obj->second->get_hostname() != *obj.hosts().begin() || @@ -482,20 +480,19 @@ void applier::service::modify_object(configuration::service const& obj) { if (c.second.is_sent()) { timeval tv(get_broker_timestamp(nullptr)); broker_custom_variable(NEBTYPE_SERVICECUSTOMVARIABLE_DELETE, s.get(), - c.first.c_str(), c.second.get_value().c_str(), - &tv); + c.first.c_str(), c.second.value().c_str(), &tv); } } s->custom_variables.clear(); for (auto& c : obj.customvariables()) { - s->custom_variables[c.first] = c.second; + s->custom_variables[c.first] = + engine::customvariable(c.second.value(), c.second.is_sent()); if (c.second.is_sent()) { timeval tv(get_broker_timestamp(nullptr)); broker_custom_variable(NEBTYPE_SERVICECUSTOMVARIABLE_ADD, s.get(), - c.first.c_str(), c.second.get_value().c_str(), - &tv); + c.first.c_str(), c.second.value().c_str(), &tv); } } } @@ -591,7 +588,7 @@ void applier::service::remove_object(configuration::service const& obj) { } // Remove service from the global configuration set. - config->services().erase(obj); + config->mut_services().erase(obj); } /** diff --git a/engine/src/configuration/applier/state.cc b/engine/src/configuration/applier/state.cc index dcf62c66ff0..e697f92bdca 100644 --- a/engine/src/configuration/applier/state.cc +++ b/engine/src/configuration/applier/state.cc @@ -1468,7 +1468,7 @@ void applier::state::_processing(configuration::state& new_cfg, config->hostgroups()); // Resolve services. - _resolve(config->services()); + _resolve(config->mut_services()); // Resolve anomalydetections. _resolve( diff --git a/engine/src/configuration/parser.cc b/engine/src/configuration/parser.cc index 5c017842d1f..112ef90061c 100644 --- a/engine/src/configuration/parser.cc +++ b/engine/src/configuration/parser.cc @@ -96,7 +96,7 @@ void parser::parse(std::string const& path, state& config) { config.servicedependencies()); _insert(_lst_objects[object::serviceescalation], config.serviceescalations()); _insert(_map_objects[object::servicegroup], config.servicegroups()); - _insert(_lst_objects[object::service], config.services()); + _insert(_lst_objects[object::service], config.mut_services()); _insert(_lst_objects[object::anomalydetection], config.anomalydetections()); _insert(_map_objects[object::timeperiod], config.timeperiods()); _insert(_lst_objects[object::severity], config.mut_severities()); diff --git a/engine/src/configuration/service.cc b/engine/src/configuration/service.cc index fdeb2d1d982..28951a26cf6 100644 --- a/engine/src/configuration/service.cc +++ b/engine/src/configuration/service.cc @@ -1052,7 +1052,7 @@ com::centreon::engine::map_customvar const& service::customvariables() * * @return The customvariables. */ -com::centreon::engine::map_customvar& service::customvariables() noexcept { +com::centreon::engine::map_customvar& service::mut_customvariables() noexcept { return _customvariables; } diff --git a/engine/src/configuration/state.cc b/engine/src/configuration/state.cc index dc4b3ee4e82..cf70aed70db 100644 --- a/engine/src/configuration/state.cc +++ b/engine/src/configuration/state.cc @@ -3213,7 +3213,7 @@ set_service const& state::services() const noexcept { * * @return All engine services. */ -set_service& state::services() noexcept { +set_service& state::mut_services() noexcept { return _services; } diff --git a/engine/src/customvariable.cc b/engine/src/customvariable.cc index 99be377b54f..077a437048d 100644 --- a/engine/src/customvariable.cc +++ b/engine/src/customvariable.cc @@ -83,7 +83,7 @@ bool customvariable::is_sent() const { * * @return The value of the customvariable */ -std::string const& customvariable::get_value() const { +const std::string& customvariable::value() const { return _value; } diff --git a/engine/src/macros.cc b/engine/src/macros.cc index 451c3756464..673b76b8856 100644 --- a/engine/src/macros.cc +++ b/engine/src/macros.cc @@ -644,7 +644,7 @@ int grab_custom_object_macro_r(nagios_macros* mac, /* get the custom variable */ for (auto const& cv : vars) { if (macro_name == cv.first) { - output = cv.second.get_value(); + output = cv.second.value(); result = OK; break; } diff --git a/engine/src/retention/applier/contact.cc b/engine/src/retention/applier/contact.cc index 69f9c1fbca3..5ffce899e14 100644 --- a/engine/src/retention/applier/contact.cc +++ b/engine/src/retention/applier/contact.cc @@ -1,21 +1,21 @@ /** -* Copyright 2011-2013,2016 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,2016 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 + * . + */ #include "com/centreon/engine/retention/applier/contact.hh" #include "com/centreon/engine/configuration/applier/state.hh" @@ -129,7 +129,7 @@ void applier::contact::_update(configuration::state const& config, if (!state.customvariables().empty() && (obj->get_modified_attributes() & MODATTR_CUSTOM_VARIABLE)) { for (auto const& cv : state.customvariables()) { - obj->get_custom_variables()[cv.first].update(cv.second.get_value()); + obj->get_custom_variables()[cv.first].update(cv.second.value()); } } } diff --git a/engine/src/retention/applier/host.cc b/engine/src/retention/applier/host.cc index c4c3057d216..c1f6e94f6a9 100644 --- a/engine/src/retention/applier/host.cc +++ b/engine/src/retention/applier/host.cc @@ -1,21 +1,21 @@ /** -* Copyright 2011-2013,2015-2016,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 2011-2013,2015-2016,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 + * . + */ #include "com/centreon/engine/retention/applier/host.hh" #include "com/centreon/engine/configuration/applier/state.hh" @@ -255,7 +255,7 @@ void applier::host::_update(configuration::state const& config, for (map_customvar::const_iterator it(state.customvariables().begin()), end(state.customvariables().end()); it != end; ++it) - obj.custom_variables[it->first].update(it->second.get_value()); + obj.custom_variables[it->first].update(it->second.value()); } } // Adjust modified attributes if necessary. diff --git a/engine/src/retention/applier/service.cc b/engine/src/retention/applier/service.cc index d8e060eec3b..13783948e2d 100644 --- a/engine/src/retention/applier/service.cc +++ b/engine/src/retention/applier/service.cc @@ -264,7 +264,7 @@ void applier::service::update(configuration::state const& config, for (map_customvar::const_iterator it(state.customvariables().begin()), end(state.customvariables().end()); it != end; ++it) - obj.custom_variables[it->first].update(it->second.get_value()); + obj.custom_variables[it->first].update(it->second.value()); } } // Adjust modified attributes if necessary. diff --git a/engine/src/retention/dump.cc b/engine/src/retention/dump.cc index 37a345833be..5e8962e3917 100644 --- a/engine/src/retention/dump.cc +++ b/engine/src/retention/dump.cc @@ -191,7 +191,7 @@ std::ostream& dump::customvariables(std::ostream& os, map_customvar const& obj) { for (auto const& cv : obj) os << "_" << cv.first << "=" << cv.second.has_been_modified() << "," - << cv.second.get_value() << "\n"; + << cv.second.value() << "\n"; return os; } diff --git a/engine/src/xsddefault.cc b/engine/src/xsddefault.cc index 9ae791a047d..93a219b608d 100644 --- a/engine/src/xsddefault.cc +++ b/engine/src/xsddefault.cc @@ -449,7 +449,7 @@ int xsddefault_save_status_data() { for (auto const& cv : it->second->custom_variables) { if (!cv.first.empty()) stream << "\t_" << cv.first << "=" << cv.second.has_been_modified() - << ";" << cv.second.get_value() << "\n"; + << ";" << cv.second.value() << "\n"; } stream << "\t}\n\n"; } @@ -625,7 +625,7 @@ int xsddefault_save_status_data() { for (auto const& cv : it->second->custom_variables) { if (!cv.first.empty()) stream << "\t_" << cv.first << "=" << cv.second.has_been_modified() - << ";" << cv.second.get_value() << "\n"; + << ";" << cv.second.value() << "\n"; } stream << "\t}\n\n"; } @@ -669,7 +669,7 @@ int xsddefault_save_status_data() { for (auto const& cv : cntct->get_custom_variables()) { if (!cv.first.empty()) stream << "\t_" << cv.first << "=" << cv.second.has_been_modified() - << ";" << cv.second.get_value() << "\n"; + << ";" << cv.second.value() << "\n"; } stream << "\t}\n\n"; } diff --git a/engine/tests/configuration/applier/applier-contact.cc b/engine/tests/configuration/applier/applier-contact.cc index d55dc5ab9ad..cf7752674be 100644 --- a/engine/tests/configuration/applier/applier-contact.cc +++ b/engine/tests/configuration/applier/applier-contact.cc @@ -133,8 +133,7 @@ TEST_F(ApplierContact, ModifyContactFromConfig) { ASSERT_TRUE(ctct.parse("service_notification_commands", "svc1,svc2")); ASSERT_TRUE(ctct.parse("_superVar", "superValue")); ASSERT_TRUE(ctct.customvariables().size() == 1); - ASSERT_TRUE(ctct.customvariables().at("superVar").get_value() == - "superValue"); + ASSERT_TRUE(ctct.customvariables().at("superVar").value() == "superValue"); configuration::applier::command cmd_aply; configuration::applier::connector cnn_aply; @@ -159,9 +158,9 @@ TEST_F(ApplierContact, ModifyContactFromConfig) { contact_map::const_iterator ct_it{engine::contact::contacts.find("test")}; ASSERT_TRUE(ct_it != engine::contact::contacts.end()); ASSERT_EQ(ct_it->second->get_custom_variables().size(), 2u); - ASSERT_TRUE(ct_it->second->get_custom_variables()["superVar"].get_value() == + ASSERT_TRUE(ct_it->second->get_custom_variables()["superVar"].value() == "Super"); - ASSERT_TRUE(ct_it->second->get_custom_variables()["superVar1"].get_value() == + ASSERT_TRUE(ct_it->second->get_custom_variables()["superVar1"].value() == "Super1"); ASSERT_TRUE(ct_it->second->get_alias() == "newAlias"); ASSERT_FALSE(ct_it->second->notify_on(notifier::service_notification, diff --git a/engine/tests/configuration/applier/applier-state.cc b/engine/tests/configuration/applier/applier-state.cc index cd6feb66e0a..cf5251b391a 100644 --- a/engine/tests/configuration/applier/applier-state.cc +++ b/engine/tests/configuration/applier/applier-state.cc @@ -891,7 +891,7 @@ TEST_F(ApplierState, StateLegacyParsing) { ASSERT_EQ(adit->dependent_service_id(), 1); ASSERT_TRUE(adit->metric_name() == "metric2"); ASSERT_EQ(adit->customvariables().size(), 1); - ASSERT_EQ(adit->customvariables().at("ad_cv").get_value(), + ASSERT_EQ(adit->customvariables().at("ad_cv").value(), std::string("this_is_a_test")); ASSERT_EQ(adit->contactgroups().size(), 2); ASSERT_EQ(adit->contacts().size(), 1); diff --git a/engine/tests/enginerpc/enginerpc.cc b/engine/tests/enginerpc/enginerpc.cc index 762e1886436..2cc77c5d18e 100644 --- a/engine/tests/enginerpc/enginerpc.cc +++ b/engine/tests/enginerpc/enginerpc.cc @@ -1688,7 +1688,7 @@ TEST_F(EngineRpc, ChangeHostObjectCustomVar) { th->join(); ASSERT_EQ(_host->custom_variables.size(), 1u); - ASSERT_EQ(_host->custom_variables["TEST_VAR"].get_value(), "test_val"); + ASSERT_EQ(_host->custom_variables["TEST_VAR"].value(), "test_val"); _host->custom_variables.clear(); ASSERT_EQ(_host->custom_variables.size(), 0u); erpc.shutdown(); @@ -1715,7 +1715,7 @@ TEST_F(EngineRpc, ChangeServiceObjectCustomVar) { th->join(); ASSERT_EQ(_svc->custom_variables.size(), 1u); - ASSERT_EQ(_svc->custom_variables["TEST_VAR"].get_value(), "test_val"); + ASSERT_EQ(_svc->custom_variables["TEST_VAR"].value(), "test_val"); _svc->custom_variables.clear(); ASSERT_EQ(_svc->custom_variables.size(), 0u); erpc.shutdown(); @@ -1740,8 +1740,7 @@ TEST_F(EngineRpc, ChangeContactObjectCustomVar) { condvar.notify_one(); th->join(); ASSERT_EQ(_contact->get_custom_variables().size(), 1u); - ASSERT_EQ(_contact->get_custom_variables()["TEST_VAR"].get_value(), - "test_val"); + ASSERT_EQ(_contact->get_custom_variables()["TEST_VAR"].value(), "test_val"); erpc.shutdown(); }