Skip to content

Commit

Permalink
fix(common/engine_conf): multiple inheritence broken because of a mis… (
Browse files Browse the repository at this point in the history
#1680)

* fix(common/engine_conf): multiple inheritence broken because of a missing flag enabled
* fix(common/log_v2): segfault in centengine fixed
* fix(engine/config/applier): bad use of std::equal
* fix(tests/engine): new test
* fix(broker/neb): cbmod was linked with not needed libraries
*  fix(broker/lua): a memory leak introduced with the new openssl md5 fixed
* fix(tests/engine): a new test to validate the good behavior of inheritance
* enh(cmake): new option LEGACY_ENGINE to compile the legacy engine instead of the new one
* fix(gh/alma8): maxscale repo is disabled on alma8
* fix(cmake): issues with dependencies
* enh(gha): new possibility to save packages as artifacts

REFS: MON-147499
  • Loading branch information
bouda1 authored Sep 12, 2024
1 parent 45a726c commit 2810e5a
Show file tree
Hide file tree
Showing 33 changed files with 808 additions and 649 deletions.
3 changes: 2 additions & 1 deletion .github/docker/Dockerfile.centreon-collect-alma8
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ baseurl=https://repo.goreleaser.com/yum/
enabled=1
gpgcheck=0' | tee /etc/yum.repos.d/goreleaser.repo

curl -LsS "https://r.mariadb.com/downloads/mariadb_repo_setup" | bash -s -- --os-type=rhel --os-version=8 --mariadb-server-version="mariadb-10.5"
curl -LsS "https://r.mariadb.com/downloads/mariadb_repo_setup" | bash -s -- --skip-maxscale --os-type=rhel --os-version=8 --mariadb-server-version="mariadb-10.5"

dnf install -y cmake \
gcc \
gcc-c++ \
Expand Down
22 changes: 21 additions & 1 deletion .github/workflows/centreon-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ on:
required: true
default: false
type: boolean
legacy_engine:
description: 'Compile Engine with legacy configuration library'
required: true
default: false
type: boolean
packages_in_artifact:
description: 'Save packages in artifacts'
required: true
default: false
type: boolean
unit_tests:
description: 'Execute the unit tests'
required: true
default: true
type: boolean

schedule:
- cron: '30 0 * * 1-5'
pull_request:
Expand Down Expand Up @@ -110,7 +126,7 @@ jobs:

unit-test:
needs: [get-version]
if: ${{ ! contains(fromJson('["stable"]'), needs.get-version.outputs.stability) }}
if: ${{ github.event.inputs.unit_tests == 'true' && ! contains(fromJson('["stable"]'), needs.get-version.outputs.stability) }}

strategy:
fail-fast: false
Expand All @@ -125,6 +141,7 @@ jobs:
SCCACHE_REGION: "eu-west-1"
AWS_ACCESS_KEY_ID: ${{ secrets.COLLECT_S3_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.COLLECT_S3_SECRET_KEY }}
LEGACY_ENGINE: ${{ github.event.inputs.legacy_engine == 'true' && 'ON' || 'OFF' }}

container:
image: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/centreon-collect-${{ matrix.distrib }}:${{ needs.get-version.outputs.img_version }}
Expand Down Expand Up @@ -195,6 +212,7 @@ jobs:
-DWITH_MODULE_SIMU=On \
-DCMAKE_C_COMPILER_LAUNCHER=${SCCACHE_PATH} \
-DCMAKE_CXX_COMPILER_LAUNCHER=${SCCACHE_PATH} \
-DLEGACY_ENGINE=${LEGACY_ENGINE} \
-S .
ninja -Cbuild
Expand Down Expand Up @@ -231,6 +249,8 @@ jobs:
release: ${{ needs.get-version.outputs.release }}
commit_hash: ${{ github.sha }}
stability: ${{ needs.get-version.outputs.stability }}
legacy_engine: ${{ github.event.inputs.legacy_engine == 'true' }}
packages_in_artifact: ${{ github.event.inputs.packages_in_artifact == 'true' }}
secrets: inherit

robot-test:
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/package-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ on:
stability:
required: true
type: string
legacy_engine:
required: true
type: boolean
packages_in_artifact:
required: true
type: boolean

jobs:
package:
Expand Down Expand Up @@ -135,6 +141,11 @@ jobs:
export TRIPLET=x64-linux-release
fi
if [ "${{ inputs.legacy_engine }}" == true ]; then
export LEGACY_ENGINE=ON
else
export LEGACY_ENGINE=OFF
fi
mv /root/.cache /github/home/
export VCPKG_ROOT="/vcpkg"
export PATH="$VCPKG_ROOT:$PATH"
Expand Down Expand Up @@ -162,6 +173,7 @@ jobs:
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_C_COMPILER_LAUNCHER=${SCCACHE_PATH} \
-DCMAKE_CXX_COMPILER_LAUNCHER=${SCCACHE_PATH} \
-DLEGACY_ENGINE=$LEGACY_ENGINE \
-S .
ninja -Cbuild
Expand Down Expand Up @@ -221,7 +233,7 @@ jobs:
run: rm -rf *-debuginfo*.${{ matrix.package_extension }}

# set condition to true if artifacts are needed
- if: ${{ false }}
- if: inputs.packages_in_artifact == true
name: Upload package artifacts
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
with:
Expand Down
6 changes: 6 additions & 0 deletions CMakeListsLinux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
# Global settings.
#

option(LEGACY_ENGINE
"Enable this option to compile the old Engine version." OFF)

option(WITH_ASAN
"Add the libasan to check memory leaks and other memory issues." OFF)

Expand All @@ -35,6 +38,9 @@ option(WITH_MALLOC_TRACE "compile centreon-malloc-trace library." OFF)

option(DEBUG_ROBOT OFF)

if(LEGACY_ENGINE)
add_definitions(-DLEGACY_CONF)
endif()

if(WITH_TSAN)
set(CMAKE_CXX_FLAGS_DEBUG
Expand Down
16 changes: 7 additions & 9 deletions broker/lua/src/broker_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -815,25 +815,22 @@ static void md5_message(const unsigned char* message,
unsigned char** digest,
unsigned int* digest_len) {
EVP_MD_CTX* mdctx;
auto handle_error = [](const std::string& msg) {
auto logger = log_v2::instance().get(log_v2::LUA);
logger->error(msg);
};
auto logger = log_v2::instance().get(log_v2::LUA);
if ((mdctx = EVP_MD_CTX_new()) == nullptr) {
handle_error("lua: fail to call MD5 (EVP_MD_CTX_new call)");
logger->error("lua: fail to call MD5 (EVP_MD_CTX_new call)");
}
if (1 != EVP_DigestInit_ex(mdctx, EVP_md5(), nullptr)) {
handle_error("lua: fail to call MD5 (EVP_DigestInit_ex call)");
logger->error("lua: fail to call MD5 (EVP_DigestInit_ex call)");
}
if (1 != EVP_DigestUpdate(mdctx, message, message_len)) {
handle_error("lua: fail to call MD5 (EVP_DigestUpdate call)");
logger->error("lua: fail to call MD5 (EVP_DigestUpdate call)");
}
if ((*digest = (unsigned char*)OPENSSL_malloc(EVP_MD_size(EVP_md5()))) ==
nullptr) {
handle_error("lua: fail to call MD5 (OPENSSL_malloc call)");
logger->error("lua: fail to call MD5 (OPENSSL_malloc call)");
}
if (1 != EVP_DigestFinal_ex(mdctx, *digest, digest_len)) {
handle_error("lua: fail to call MD5 (EVP_DigestFinal_ex call)");
logger->error("lua: fail to call MD5 (EVP_DigestFinal_ex call)");
}
EVP_MD_CTX_free(mdctx);
}
Expand Down Expand Up @@ -861,6 +858,7 @@ static int l_broker_md5(lua_State* L) {
}
*tmp = 0;
lua_pushstring(L, result);
OPENSSL_free(md5);
return 1;
}

Expand Down
7 changes: 2 additions & 5 deletions broker/neb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,9 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
"-Wl,--whole-archive"
rokerbase
multiplexing
"-Wl,--no-whole-archive"
nlohmann_json::nlohmann_json
spdlog::spdlog)
"-Wl,--no-whole-archive")
else()
target_link_libraries("${CBMOD}" -L${PROTOBUF_LIB_DIR} "rokerbase"
nlohmann_json::nlohmann_json spdlog::spdlog)
target_link_libraries("${CBMOD}" -L${PROTOBUF_LIB_DIR} "rokerbase")
endif()

set_target_properties("${CBMOD}" PROPERTIES PREFIX "")
Expand Down
7 changes: 4 additions & 3 deletions broker/neb/src/callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,10 @@ int neb::callback_pb_custom_variable(int, void* data) {
std::string value(common::check_string_utf8(cvar->var_value));
obj.set_value(value);
obj.set_default_value(value);
SPDLOG_LOGGER_DEBUG(
neb_logger, "callbacks: new custom variable '{}' on host {}",
name, host_id);
SPDLOG_LOGGER_DEBUG(neb_logger,
"callbacks: new custom variable '{}' with "
"value '{}' on host {}",
name, value, host_id);
} else {
SPDLOG_LOGGER_DEBUG(
neb_logger,
Expand Down
41 changes: 19 additions & 22 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ project("Centreon common" C CXX)

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
add_subdirectory(log_v2)
add_subdirectory(engine_conf)
add_subdirectory(engine_legacy_conf)
if(LEGACY_ENGINE)
add_subdirectory(engine_legacy_conf)
else()
add_subdirectory(engine_conf)
endif()
endif()

# Set directories.
Expand All @@ -49,30 +52,24 @@ add_custom_command(

# Set sources.
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(SOURCES
${SRC_DIR}/hex_dump.cc
${SRC_DIR}/perfdata.cc
${SRC_DIR}/pool.cc
${SRC_DIR}/process_stat.cc
${SRC_DIR}/process_stat.pb.cc
${SRC_DIR}/process_stat.grpc.pb.cc
${SRC_DIR}/rapidjson_helper.cc
${SRC_DIR}/utf8.cc
)
set(SOURCES
${SRC_DIR}/hex_dump.cc
${SRC_DIR}/perfdata.cc
${SRC_DIR}/pool.cc
${SRC_DIR}/process_stat.cc
${SRC_DIR}/process_stat.pb.cc
${SRC_DIR}/process_stat.grpc.pb.cc
${SRC_DIR}/rapidjson_helper.cc
${SRC_DIR}/utf8.cc)
else()
#we need not many things to just compile centreon-monitoring-agent (centagent)
set(SOURCES
${SRC_DIR}/perfdata.cc
${SRC_DIR}/utf8.cc
)
# we need not many things to just compile centreon-monitoring-agent
# (centagent)
set(SOURCES ${SRC_DIR}/perfdata.cc ${SRC_DIR}/utf8.cc)
endif()

# Include directories.
include_directories("${INCLUDE_DIR}"
${HTTP_INCLUDE_DIR}
${VCPKG_INCLUDE_DIR}
${PROCESS_INCLUDE_DIR}
)
include_directories("${INCLUDE_DIR}" ${HTTP_INCLUDE_DIR} ${VCPKG_INCLUDE_DIR}
${PROCESS_INCLUDE_DIR})

add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)
add_library(centreon_common STATIC ${SOURCES})
Expand Down
1 change: 1 addition & 0 deletions common/engine_conf/anomalydetection_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ bool anomalydetection_helper::insert_customvariable(std::string_view key,
return false;

key.remove_prefix(1);

Anomalydetection* obj = static_cast<Anomalydetection*>(mut_obj());
auto* cvs = obj->mutable_customvariables();
for (auto& c : *cvs) {
Expand Down
1 change: 1 addition & 0 deletions common/engine_conf/contact_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ bool contact_helper::insert_customvariable(std::string_view key,
return false;

key.remove_prefix(1);

Contact* obj = static_cast<Contact*>(mut_obj());
auto* cvs = obj->mutable_customvariables();
for (auto& c : *cvs) {
Expand Down
1 change: 1 addition & 0 deletions common/engine_conf/host_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ bool host_helper::insert_customvariable(std::string_view key,
return false;

key.remove_prefix(1);

Host* obj = static_cast<Host*>(mut_obj());
auto* cvs = obj->mutable_customvariables();
for (auto& c : *cvs) {
Expand Down
16 changes: 8 additions & 8 deletions common/engine_conf/message_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ bool message_helper::set(const std::string_view& key,
bool val;
if (absl::SimpleAtob(value, &val)) {
refl->SetBool(static_cast<Message*>(msg), f, val);
set_changed(f->number());
set_changed(f->index());
return true;
} else
return false;
Expand All @@ -371,7 +371,7 @@ bool message_helper::set(const std::string_view& key,
int32_t val;
if (absl::SimpleAtoi(value, &val)) {
refl->SetInt32(static_cast<Message*>(msg), f, val);
set_changed(f->number());
set_changed(f->index());
return true;
} else
return false;
Expand All @@ -380,7 +380,7 @@ bool message_helper::set(const std::string_view& key,
uint32_t val;
if (absl::SimpleAtoi(value, &val)) {
refl->SetUInt32(static_cast<Message*>(msg), f, val);
set_changed(f->number());
set_changed(f->index());
return true;
} else
return false;
Expand All @@ -389,7 +389,7 @@ bool message_helper::set(const std::string_view& key,
uint64_t val;
if (absl::SimpleAtoi(value, &val)) {
refl->SetUInt64(static_cast<Message*>(msg), f, val);
set_changed(f->number());
set_changed(f->index());
return true;
} else
return false;
Expand All @@ -398,7 +398,7 @@ bool message_helper::set(const std::string_view& key,
double val;
if (absl::SimpleAtod(value, &val)) {
refl->SetDouble(static_cast<Message*>(msg), f, val);
set_changed(f->number());
set_changed(f->index());
return true;
} else
return false;
Expand All @@ -411,7 +411,7 @@ bool message_helper::set(const std::string_view& key,
refl->SetString(static_cast<Message*>(msg), f,
std::string(value.data(), value.size()));
}
set_changed(f->number());
set_changed(f->index());
return true;
case FieldDescriptor::TYPE_MESSAGE:
if (!f->is_repeated()) {
Expand All @@ -422,13 +422,13 @@ bool message_helper::set(const std::string_view& key,
StringSet* set =
static_cast<StringSet*>(refl->MutableMessage(msg, f));
fill_string_group(set, value);
set_changed(f->number());
set_changed(f->index());
return true;
} else if (d && d->name() == "StringList") {
StringList* lst =
static_cast<StringList*>(refl->MutableMessage(msg, f));
fill_string_group(lst, value);
set_changed(f->number());
set_changed(f->index());
return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions common/engine_conf/message_helper.hh
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class message_helper {
* 5. We can replace unchanged fields with the parent values if needed.
*/
std::vector<bool> _modified_field;

/* When a configuration object is resolved, this flag is set to true. */
bool _resolved = false;

Expand Down
Loading

0 comments on commit 2810e5a

Please sign in to comment.