From f611324343a7afac2516ccfa8417ddb381f1cef2 Mon Sep 17 00:00:00 2001 From: jean-christophe81 <98889244+jean-christophe81@users.noreply.github.com> Date: Wed, 12 Jun 2024 17:14:33 +0200 Subject: [PATCH] add prebuild and robot test workflows (#1537) * compile agent on windows runner fix fmt windows compile issue --- .github/scripts/windows-agent-compile.ps1 | 78 +++++++ .github/workflows/centreon-collect.yml | 4 +- .../workflows/windows-agent-robot-test.yml | 15 ++ .github/workflows/windows-agent.yml | 66 +++++- CMakeLists.txt | 198 +++--------------- CMakeListsLinux.txt | 194 +++++++++++++++++ CMakeListsWindows.txt | 93 ++++++++ CMakePresets.json | 27 +++ README.md | 9 + agent/CMakeLists.txt | 91 +++++--- agent/conf/centagent.reg | Bin 0 -> 1712 bytes agent/src/config_win.cc | 109 ++++++++++ agent/src/main_win.cc | 172 +++++++++++++++ agent/src/streaming_client.cc | 10 +- agent/src/streaming_server.cc | 10 +- agent/test/CMakeLists.txt | 49 +++-- agent/test/check_exec_test.cc | 26 ++- agent/test/scheduler_test.cc | 31 +-- agent/test/scripts/sleep.bat | 2 + agent/test/test_main.cc | 3 +- centreon_cmake.bat | 61 ++++++ common/CMakeLists.txt | 37 ++-- common/grpc/CMakeLists.txt | 3 +- common/precomp_inc/precomp.hh | 2 + common/process/src/process.cc | 6 + common/tests/CMakeLists.txt | 104 ++++++--- common/tests/scripts/bad_script.bat | 3 + common/tests/scripts/echo.bat | 1 + common/tests/test_main_win.cc | 54 +++++ custom-triplets/x64-windows.cmake | 6 + .../opentelemetry/doc/opentelemetry.md | 2 +- packaging/centreon-monitoring-agent.yaml | 1 - vcpkg.json | 57 +++-- 33 files changed, 1210 insertions(+), 314 deletions(-) create mode 100644 .github/scripts/windows-agent-compile.ps1 create mode 100644 .github/workflows/windows-agent-robot-test.yml create mode 100644 CMakeListsLinux.txt create mode 100644 CMakeListsWindows.txt create mode 100644 CMakePresets.json create mode 100644 agent/conf/centagent.reg create mode 100644 agent/src/config_win.cc create mode 100644 agent/src/main_win.cc create mode 100644 agent/test/scripts/sleep.bat create mode 100644 centreon_cmake.bat create mode 100644 common/tests/scripts/bad_script.bat create mode 100644 common/tests/scripts/echo.bat create mode 100644 common/tests/test_main_win.cc create mode 100644 custom-triplets/x64-windows.cmake diff --git a/.github/scripts/windows-agent-compile.ps1 b/.github/scripts/windows-agent-compile.ps1 new file mode 100644 index 00000000000..9118532affc --- /dev/null +++ b/.github/scripts/windows-agent-compile.ps1 @@ -0,0 +1,78 @@ +# +# Copyright 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 +# + +Write-Host "Work in" $pwd.ToString() + +[System.Environment]::SetEnvironmentVariable("AWS_EC2_METADATA_DISABLED","true") + +Write-Host $env:VCPKG_BINARY_SOURCES + +$current_dir = $pwd.ToString() + +#get cache from s3 +$files_to_hash = "vcpkg.json", "custom-triplets\x64-windows.cmake", "CMakeLists.txt", "CMakeListsWindows.txt" +$files_content = Get-Content -Path $files_to_hash -Raw +$stringAsStream = [System.IO.MemoryStream]::new() +$writer = [System.IO.StreamWriter]::new($stringAsStream) +$writer.write($files_content -join " ") +$writer.Flush() +$stringAsStream.Position = 0 +$vcpkg_hash = Get-FileHash -InputStream $stringAsStream -Algorithm SHA256 | Select-Object Hash +$file_name = "windows-agent-vcpkg-dependencies-cache-" + $vcpkg_hash.Hash +$file_name_extension = "${file_name}.7z" + +#try to get compiled dependenciesfrom s3 +Write-Host "try to download compiled dependencies from s3" +aws --quiet s3 cp s3://centreon-collect-robot-report/$file_name_extension $file_name_extension +if ( $? -ne $true ) { + #no => generate + Write-Host "#######################################################################################################################" + Write-Host "compiled dependencies unavailable for this version we will need to build it, it will take a long time" + Write-Host "#######################################################################################################################" + + Write-Host "install vcpkg" + git clone --depth 1 --single-branch --no-tags https://github.com/microsoft/vcpkg vcpkg + cd vcpkg + bootstrap-vcpkg.bat + cd $current_dir + + [System.Environment]::SetEnvironmentVariable("VCPKG_ROOT",$pwd.ToString()+"\vcpkg") + [System.Environment]::SetEnvironmentVariable("PATH",$pwd.ToString()+"\vcpkg;" + $env:PATH) + + Write-Host "compile vcpkg dependencies" + vcpkg install --vcpkg-root $env:VCPKG_ROOT --x-install-root build_windows\vcpkg_installed --x-manifest-root . --overlay-triplets custom-triplets --triplet x64-windows + + Write-Host "Compress binary archive" + 7z a $file_name_extension build_windows\vcpkg_installed + Write-Host "Upload binary archive" + aws s3 cp $file_name_extension s3://centreon-collect-robot-report/$file_name_extension + Write-Host "create CMake files" +} +else { + 7z x $file_name_extension + Write-Host "Create cmake files from binary-cache downloaded without use vcpkg" +} + + + +cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTING=On -DWINDOWS=On -DBUILD_FROM_CACHE=On -S. -DVCPKG_CRT_LINKAGE=dynamic -DBUILD_SHARED_LIBS=OFF -Bbuild_windows + +Write-Host "build agent and tests" + +cmake --build build_windows --config Release + diff --git a/.github/workflows/centreon-collect.yml b/.github/workflows/centreon-collect.yml index ccaa4ad3825..d12a78d31c7 100644 --- a/.github/workflows/centreon-collect.yml +++ b/.github/workflows/centreon-collect.yml @@ -21,10 +21,10 @@ on: - cmake.sh - cmake-vcpkg.sh - CMakeLists.txt + - CMakeListsLinux.txt - vcpkg.json - overlays/** - selinux/** - - vcpkg/** - "!.veracode-exclusions" - "!veracode.json" - "!**/test/**" @@ -48,10 +48,10 @@ on: - cmake.sh - cmake-vcpkg.sh - CMakeLists.txt + - CMakeListsLinux.txt - vcpkg.json - overlays/** - selinux/** - - vcpkg/** - "!.veracode-exclusions" - "!veracode.json" - "!**/test/**" diff --git a/.github/workflows/windows-agent-robot-test.yml b/.github/workflows/windows-agent-robot-test.yml new file mode 100644 index 00000000000..8d52099a14e --- /dev/null +++ b/.github/workflows/windows-agent-robot-test.yml @@ -0,0 +1,15 @@ +name: Centreon Monitoring Agent Windows robot test + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +on: + workflow_dispatch: + +jobs: + build-agent: + runs-on: windows-latest + steps: + - name: Checkout sources + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 diff --git a/.github/workflows/windows-agent.yml b/.github/workflows/windows-agent.yml index c1bbf3bb7e4..20bec7eb300 100644 --- a/.github/workflows/windows-agent.yml +++ b/.github/workflows/windows-agent.yml @@ -1,4 +1,4 @@ -name: Centreon Monitoring Agent Windows packaging +name: Centreon Monitoring Agent Windows build and packaging concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -6,16 +6,66 @@ concurrency: on: workflow_dispatch: + pull_request: + paths: + - agent/** + - custom-triplets/** + - CMakeLists.txt + - CMakeListsWindows.txt + - vcpkg.json + push: + branches: + - develop + - dev-[2-9][0-9].[0-9][0-9].x + - master + - "[2-9][0-9].[0-9][0-9].x" + paths: + - agent/** + - custom-triplets/** + - CMakeLists.txt + - CMakeListsWindows.txt + - vcpkg.json jobs: - build: + build-and-test-agent: runs-on: windows-latest + env: + AWS_ACCESS_KEY_ID: ${{ secrets.COLLECT_S3_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.COLLECT_S3_SECRET_KEY }} + steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - uses: ilammy/msvc-dev-cmd@v1.4.1 + - name: Checkout sources + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Compile Agent + run: .github/scripts/windows-agent-compile.ps1 + shell: powershell + + - name: Common test + run: | + cd build_windows + tests/ut_common - - name: install vcpkg + - name: Agent test run: | - git clone --depth 1 https://github.com/microsoft/vcpkg $HOME/vcpkg - cd $HOME/vcpkg - bootstrap-vcpkg.bat + cd build_windows + tests/ut_agent + + - name: Zip agent + run: | + $files_to_compress = "agent\conf\centagent.reg", "build_windows\agent\Release\centagent.exe" + Compress-Archive -Path $files_to_compress -DestinationPath centreon-monitoring-agent.zip + + - name: Save agent package in cache + uses: actions/cache/save@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0 + with: + path: centreon-monitoring-agent.zip + key: ${{ github.run_id }}-${{ github.sha }}-CMA-${{ github.head_ref || github.ref_name }} + + - name: Upload package artifacts + if: ${{ false }} + uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 + with: + name: packages-centreon-monitoring-agent-windows + path: centreon-monitoring-agent.zip + retention-days: 1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 74bcb7aa4b0..5bc04dfa178 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,71 +27,45 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_CXX_STANDARD 17) -if(DEFINED ENV{VCPKG_ROOT}) - set(VCPKG_ROOT "$ENV{VCPKG_ROOT}") - message(STATUS "TOOLCHAIN set to ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake") - set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" - CACHE STRING "Vcpkg toolchain file") -else() - message(STATUS "TOOLCHAIN set to ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake") - set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" - CACHE STRING "Vcpkg toolchain file") -endif() - -set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" - CACHE STRING "Vcpkg toolchain file") - -project("Centreon Collect" C CXX) +string(TIMESTAMP CENTREON_CURRENT_YEAR "%Y") +add_definitions(-DCENTREON_CURRENT_YEAR="${CENTREON_CURRENT_YEAR}") + +#when we build from cache(CI), we don't use vcpkg because it recompiles often everything +if (NOT BUILD_FROM_CACHE) + if(DEFINED ENV{VCPKG_ROOT}) + set(VCPKG_ROOT "$ENV{VCPKG_ROOT}") + message( + STATUS "TOOLCHAIN set to ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake") + set(CMAKE_TOOLCHAIN_FILE + "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + CACHE STRING "Vcpkg toolchain file") + else() + message( + STATUS + "TOOLCHAIN set to ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" + ) + set(CMAKE_TOOLCHAIN_FILE + "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" + CACHE STRING "Vcpkg toolchain file") + endif() -option(WITH_ASAN - "Add the libasan to check memory leaks and other memory issues." OFF) + set(CMAKE_TOOLCHAIN_FILE + "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" + CACHE STRING "Vcpkg toolchain file") -option(WITH_TSAN - "Add the libtsan to check threads and other multithreading issues." OFF) -if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_ID - STREQUAL "Clang") - message( - FATAL_ERROR "You can build broker with g++ or clang++. CMake will exit.") endif() -option(WITH_MALLOC_TRACE "compile centreon-malloc-trace library." OFF) +project("Centreon Collect" C CXX) # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -stdlib=libc++") # set(CMAKE_CXX_COMPILER "clang++") add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1") -add_definitions("-DBOOST_PROCESS_USE_STD_FS=1") -option(DEBUG_ROBOT OFF) +add_definitions("-DBOOST_PROCESS_USE_STD_FS=1") set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -if(WITH_TSAN) - set(CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") - set(CMAKE_LINKER_FLAGS_DEBUG - "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") -endif() - -if(WITH_ASAN) - set(CMAKE_BUILD_TYPE Debug) - if(WITH_CLANG) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address") - set(CMAKE_LINKER_FLAGS_DEBUG - "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=address") - else() - set(CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") - set(CMAKE_LINKER_FLAGS_DEBUG - "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address" - ) - endif() -endif() - -set(ALLOW_DUPLICATE_EXECUTABLE TRUE) - -set(BUILD_ARGS "-w" "dupbuild=warn") - # # Get distributions name # @@ -138,122 +112,10 @@ set(COLLECT_MAJOR 24) set(COLLECT_MINOR 04) set(COLLECT_PATCH 5) set(COLLECT_VERSION "${COLLECT_MAJOR}.${COLLECT_MINOR}.${COLLECT_PATCH}") -add_definitions(-DCENTREON_CONNECTOR_VERSION=\"${COLLECT_VERSION}\") - -if (DEBUG_ROBOT) - add_definitions(-DDEBUG_ROBOT) -endif() -# ########### CONSTANTS ########### -set(USER_BROKER centreon-broker) -set(USER_ENGINE centreon-engine) - -find_package(fmt CONFIG REQUIRED) -find_package(spdlog CONFIG REQUIRED) -find_package(gRPC CONFIG REQUIRED) -find_package(Protobuf REQUIRED) -find_package(nlohmann_json CONFIG REQUIRED) -find_package(GTest CONFIG REQUIRED) -find_package(CURL REQUIRED) -find_package(Boost REQUIRED COMPONENTS url) -find_package(ryml CONFIG REQUIRED) -add_definitions("-DSPDLOG_FMT_EXTERNAL") - -include(FindPkgConfig) -pkg_check_modules(MARIADB REQUIRED libmariadb) -pkg_check_modules(LIBSSH2 REQUIRED libssh2) - -# There is a bug with grpc. It is not put in the triplet directory. So we have -# to search for its plugin. -file(GLOB_RECURSE GRPC_CPP_PLUGIN_EXE - RELATIVE ${CMAKE_BINARY_DIR} grpc_cpp_plugin) -find_program(GRPC_CPP_PLUGIN - NAMES ${GRPC_CPP_PLUGIN_EXE} - PATHS ${CMAKE_BINARY_DIR} - REQUIRED - NO_DEFAULT_PATH) - -set(PROTOBUF_LIB_DIR ${Protobuf_DIR}/../../lib) -set(OTLP_LIB_DIR ${opentelemetry-cpp_DIR}/../../lib) -set(VCPKG_INCLUDE_DIR ${Protobuf_INCLUDE_DIR}) -include(GNUInstallDirs) - -#import opentelemetry-proto -add_custom_command( - OUTPUT ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto - ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/metrics/v1/metrics.proto - ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/common/v1/common.proto - ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto - COMMENT "get opentelemetry proto files from git repository" - COMMAND /bin/rm -rf ${CMAKE_SOURCE_DIR}/opentelemetry-proto - COMMAND git ARGS clone --depth=1 --single-branch https://github.com/open-telemetry/opentelemetry-proto.git ${CMAKE_SOURCE_DIR}/opentelemetry-proto - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) - -add_custom_target(opentelemetry-proto-files DEPENDS ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto - ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/metrics/v1/metrics.proto - ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/common/v1/common.proto - ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto -) - -# var directories. -set(BROKER_VAR_LOG_DIR - "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-broker") -set(BROKER_VAR_LIB_DIR - "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/centreon-broker") -set(ENGINE_VAR_LOG_DIR - "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-engine") -set(ENGINE_VAR_LOG_ARCHIVE_DIR - "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-engine/archives") -set(ENGINE_VAR_LIB_DIR - "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/centreon-engine") - -set(CMAKE_INSTALL_PREFIX "/usr") -option(WITH_TESTING "Build unit tests." OFF) - -option(WITH_CONF "Install configuration files." ON) - -# Code coverage on unit tests -option(WITH_COVERAGE "Add code coverage on unit tests." OFF) - -if(WITH_TESTING AND WITH_COVERAGE) - set(CMAKE_BUILD_TYPE "Debug") - include(cmake/CodeCoverage.cmake) - append_coverage_compiler_flags() -endif() - -set(protobuf_MODULE_COMPATIBLE True) - -include_directories(${CMAKE_SOURCE_DIR} - ${VCPKG_INCLUDE_DIR} - fmt::fmt - spdlog::spdlog - ${CMAKE_SOURCE_DIR}/clib/inc) - -add_subdirectory(clib) -add_subdirectory(common) -add_subdirectory(broker) -add_subdirectory(bbdo) -add_subdirectory(engine) -add_subdirectory(connectors) -add_subdirectory(ccc) -add_subdirectory(agent) - -if (WITH_MALLOC_TRACE) - add_subdirectory(malloc-trace) +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + include(CMakeListsLinux.txt) +else() + include(CMakeListsWindows.txt) endif() - - -add_custom_target(test-broker COMMAND tests/ut_broker) -add_custom_target(test-engine COMMAND tests/ut_engine) -add_custom_target(test-clib COMMAND tests/ut_clib) -add_custom_target(test-connector COMMAND tests/ut_connector) -add_custom_target(test-common COMMAND tests/ut_common) -add_custom_target(test-agent COMMAND tests/ut_agent) - -add_custom_target(test DEPENDS test-broker test-engine test-clib test-connector - test-common test-agent) - -add_custom_target(test-coverage DEPENDS broker-test-coverage - engine-test-coverage clib-test-coverage) diff --git a/CMakeListsLinux.txt b/CMakeListsLinux.txt new file mode 100644 index 00000000000..a7b4120a02b --- /dev/null +++ b/CMakeListsLinux.txt @@ -0,0 +1,194 @@ +# +# Copyright 2009-2023 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 +# + +# +# Global settings. +# + + +option(WITH_ASAN + "Add the libasan to check memory leaks and other memory issues." OFF) + +option(WITH_TSAN + "Add the libtsan to check threads and other multithreading issues." OFF) +if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_ID + STREQUAL "Clang") + message( + FATAL_ERROR "You can build broker with g++ or clang++. CMake will exit.") +endif() + +option(WITH_MALLOC_TRACE "compile centreon-malloc-trace library." OFF) + +option(DEBUG_ROBOT OFF) + + +if(WITH_TSAN) + set(CMAKE_CXX_FLAGS_DEBUG + "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") + set(CMAKE_LINKER_FLAGS_DEBUG + "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") +endif() + +if(WITH_ASAN) + set(CMAKE_BUILD_TYPE Debug) + if(WITH_CLANG) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address") + set(CMAKE_LINKER_FLAGS_DEBUG + "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=address") + else() + set(CMAKE_CXX_FLAGS_DEBUG + "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") + set(CMAKE_LINKER_FLAGS_DEBUG + "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address" + ) + endif() +endif() + +set(ALLOW_DUPLICATE_EXECUTABLE TRUE) + +set(BUILD_ARGS "-w" "dupbuild=warn") + + +# Version. +add_definitions(-DCENTREON_CONNECTOR_VERSION=\"${COLLECT_VERSION}\") + +if (DEBUG_ROBOT) + add_definitions(-DDEBUG_ROBOT) +endif() + +# ########### CONSTANTS ########### +set(USER_BROKER centreon-broker) +set(USER_ENGINE centreon-engine) + +find_package(fmt CONFIG REQUIRED) +find_package(spdlog CONFIG REQUIRED) +find_package(gRPC CONFIG REQUIRED) +find_package(Protobuf REQUIRED) +find_package(nlohmann_json CONFIG REQUIRED) +find_package(GTest CONFIG REQUIRED) +find_package(CURL REQUIRED) +find_package(Boost REQUIRED COMPONENTS url) +find_package(ryml CONFIG REQUIRED) +add_definitions("-DSPDLOG_FMT_EXTERNAL") + +add_definitions("-DCOLLECT_MAJOR=${COLLECT_MAJOR}") +add_definitions("-DCOLLECT_MINOR=${COLLECT_MINOR}") +add_definitions("-DCOLLECT_PATCH=${COLLECT_PATCH}") + +include(FindPkgConfig) +pkg_check_modules(MARIADB REQUIRED libmariadb) +pkg_check_modules(LIBSSH2 REQUIRED libssh2) + +# There is a bug with grpc. It is not put in the triplet directory. So we have +# to search for its plugin. +file(GLOB_RECURSE GRPC_CPP_PLUGIN_EXE + RELATIVE ${CMAKE_BINARY_DIR} grpc_cpp_plugin) +find_program(GRPC_CPP_PLUGIN + NAMES ${GRPC_CPP_PLUGIN_EXE} + PATHS ${CMAKE_BINARY_DIR} + REQUIRED + NO_DEFAULT_PATH) + +set(PROTOBUF_LIB_DIR ${Protobuf_DIR}/../../lib) +set(OTLP_LIB_DIR ${opentelemetry-cpp_DIR}/../../lib) +set(VCPKG_INCLUDE_DIR ${Protobuf_INCLUDE_DIR}) +include(GNUInstallDirs) + +#import opentelemetry-proto +add_custom_command( + OUTPUT ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/metrics/v1/metrics.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/common/v1/common.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto + COMMENT "get opentelemetry proto files from git repository" + COMMAND /bin/rm -rf ${CMAKE_SOURCE_DIR}/opentelemetry-proto + COMMAND git ARGS clone --depth=1 --single-branch https://github.com/open-telemetry/opentelemetry-proto.git ${CMAKE_SOURCE_DIR}/opentelemetry-proto + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +) + +add_custom_target(opentelemetry-proto-files DEPENDS ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/metrics/v1/metrics.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/common/v1/common.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto +) + +# var directories. +set(BROKER_VAR_LOG_DIR + "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-broker") +set(BROKER_VAR_LIB_DIR + "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/centreon-broker") +set(ENGINE_VAR_LOG_DIR + "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-engine") +set(ENGINE_VAR_LOG_ARCHIVE_DIR + "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-engine/archives") +set(ENGINE_VAR_LIB_DIR + "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/centreon-engine") +add_definitions(-DDEFAULT_COMMAND_FILE="${ENGINE_VAR_LIB_DIR}/rw/centengine.cmd" + -DDEFAULT_DEBUG_FILE="${ENGINE_VAR_LOG_DIR}/centengine.debug" + -DDEFAULT_LOG_FILE="${ENGINE_VAR_LOG_DIR}/centengine.log" + -DDEFAULT_RETENTION_FILE="${ENGINE_VAR_LOG_DIR}/retention.dat" + -DDEFAULT_STATUS_FILE="${ENGINE_VAR_LOG_DIR}/status.dat") + +set(CMAKE_INSTALL_PREFIX "/usr") +option(WITH_TESTING "Build unit tests." OFF) + +option(WITH_CONF "Install configuration files." ON) + +# Code coverage on unit tests +option(WITH_COVERAGE "Add code coverage on unit tests." OFF) + +if(WITH_TESTING AND WITH_COVERAGE) + set(CMAKE_BUILD_TYPE "Debug") + include(cmake/CodeCoverage.cmake) + append_coverage_compiler_flags() +endif() + +set(protobuf_MODULE_COMPATIBLE True) + +include_directories(${CMAKE_SOURCE_DIR} + ${VCPKG_INCLUDE_DIR} + fmt::fmt + spdlog::spdlog + ${CMAKE_SOURCE_DIR}/clib/inc) + +add_subdirectory(clib) +add_subdirectory(common) +add_subdirectory(broker) +add_subdirectory(bbdo) +add_subdirectory(engine) +add_subdirectory(connectors) +add_subdirectory(ccc) +add_subdirectory(agent) + +if (WITH_MALLOC_TRACE) + add_subdirectory(malloc-trace) +endif() + + +add_custom_target(test-broker COMMAND tests/ut_broker) +add_custom_target(test-engine COMMAND tests/ut_engine) +add_custom_target(test-clib COMMAND tests/ut_clib) +add_custom_target(test-connector COMMAND tests/ut_connector) +add_custom_target(test-common COMMAND tests/ut_common) +add_custom_target(test-agent COMMAND tests/ut_agent) + +add_custom_target(test DEPENDS test-broker test-engine test-clib test-connector + test-common test-agent) + +add_custom_target(test-coverage DEPENDS broker-test-coverage + engine-test-coverage clib-test-coverage) diff --git a/CMakeListsWindows.txt b/CMakeListsWindows.txt new file mode 100644 index 00000000000..86a3f82d221 --- /dev/null +++ b/CMakeListsWindows.txt @@ -0,0 +1,93 @@ +# +# Copyright 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 +# + +# When we build from cache (CI), we don't use vcpkg cmaketool, so we tell to cmake where to find packages info +if (BUILD_FROM_CACHE) + LIST(APPEND CMAKE_PREFIX_PATH "build_windows/vcpkg_installed/x64-windows") +endif() + +#in order to make fmt compile +add_definitions("/utf-8") + + +find_package(fmt CONFIG REQUIRED) +find_package(spdlog CONFIG REQUIRED) +find_package(gRPC CONFIG REQUIRED) +find_package(Protobuf REQUIRED) +find_package(GTest CONFIG REQUIRED) +find_package(boost_asio CONFIG REQUIRED) +find_package(boost_process CONFIG REQUIRED) +find_package(boost_multi_index CONFIG REQUIRED) +find_package(boost_program_options CONFIG REQUIRED) +find_package(boost_multi_index CONFIG REQUIRED) +add_definitions("-DSPDLOG_FMT_EXTERNAL") + +add_definitions("-DCOLLECT_MAJOR=${COLLECT_MAJOR}") +add_definitions("-DCOLLECT_MINOR=${COLLECT_MINOR}") +add_definitions("-DCOLLECT_PATCH=${COLLECT_PATCH}") + + +# There is a bug with grpc. It is not put in the triplet directory. So we have +# to search for its plugin. +file(GLOB_RECURSE GRPC_CPP_PLUGIN_EXE + RELATIVE ${CMAKE_BINARY_DIR} grpc_cpp_plugin.exe) +find_program(GRPC_CPP_PLUGIN + NAMES ${GRPC_CPP_PLUGIN_EXE} + PATHS ${CMAKE_BINARY_DIR} + REQUIRED + NO_DEFAULT_PATH) + +set(PROTOBUF_LIB_DIR ${Protobuf_DIR}/../../lib) +set(VCPKG_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}) +include(GNUInstallDirs) + +option(WITH_TESTING "Build unit tests." OFF) + +set(protobuf_MODULE_COMPATIBLE True) + +include_directories(${CMAKE_SOURCE_DIR} + ${VCPKG_INCLUDE_DIR} + ${CMAKE_SOURCE_DIR}/clib/inc) + +#import opentelemetry-proto +add_custom_command( + OUTPUT ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/metrics/v1/metrics.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/common/v1/common.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto + COMMENT "get opentelemetry proto files from git repository" + COMMAND RMDIR /S /Q \"${CMAKE_SOURCE_DIR}/opentelemetry-proto\" + COMMAND git ARGS clone --depth=1 --single-branch https://github.com/open-telemetry/opentelemetry-proto.git ${CMAKE_SOURCE_DIR}/opentelemetry-proto + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +) + +add_custom_target(opentelemetry-proto-files DEPENDS ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/metrics/v1/metrics.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/common/v1/common.proto + ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto +) + +add_subdirectory(common) +add_subdirectory(agent) + + +add_custom_target(test-common COMMAND tests/ut_common) +add_custom_target(test-agent COMMAND tests/ut_agent) + +add_custom_target(test DEPENDS test-common test-agent) + diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 00000000000..e94d5ad68b9 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,27 @@ +{ + "version": 2, + "configurePresets": [ + { + "name": "debug", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build_windows", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "WITH_TESTING": "On", + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + } + }, + { + "name": "release", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build_windows", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "WITH_TESTING": "On", + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "VCPKG_OVERLAY_TRIPLETS": "custom-triplets", + "VCPKG_TARGET_TRIPLET": "x64-windows" + } + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index b22f7400d3a..83970d026d9 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,15 @@ make -Cbuild install These two variables are very important if you want to recompile the project later. +#### Windows compilation +A small part of the project (centreon-monitoring-agent in agent folder) is Windows compatible. +In order to compile it, you need at least msbuild tools and git. +Then you have to: +* Start a x64 command tool console +* Execute centreon_cmake.bat. It first installs vcpkg in your home directory and then tells you to set two environment variables VCPKG_ROOT and PATH. Be careful, the next time you will start x64 command tool console, it will set VCPKG_ROOT to wrong value and you will need to set it again. +* Then install agent\conf\agent.reg in the registry and modify parameters such as server, certificates or logging. + + ### Other distributions If you are on another distribution, then follow the steps below. diff --git a/agent/CMakeLists.txt b/agent/CMakeLists.txt index c64801646c4..09eb1737271 100644 --- a/agent/CMakeLists.txt +++ b/agent/CMakeLists.txt @@ -98,21 +98,39 @@ add_custom_command( WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +set( SRC_COMMON + ${SRC_DIR}/agent.grpc.pb.cc + ${SRC_DIR}/agent.pb.cc + ${SRC_DIR}/bireactor.cc + ${SRC_DIR}/check.cc + ${SRC_DIR}/check_exec.cc + ${SRC_DIR}/opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.cc + ${SRC_DIR}/opentelemetry/proto/collector/metrics/v1/metrics_service.pb.cc + ${SRC_DIR}/opentelemetry/proto/metrics/v1/metrics.pb.cc + ${SRC_DIR}/opentelemetry/proto/common/v1/common.pb.cc + ${SRC_DIR}/opentelemetry/proto/resource/v1/resource.pb.cc + ${SRC_DIR}/scheduler.cc + ${SRC_DIR}/streaming_client.cc + ${SRC_DIR}/streaming_server.cc +) + +set( SRC_WINDOWS + ${SRC_DIR}/config_win.cc +) + +set( SRC_LINUX + ${SRC_DIR}/config.cc +) + +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(SRC ${SRC_COMMON} ${SRC_LINUX}) +else() + set(SRC ${SRC_COMMON} ${SRC_WINDOWS}) +endif() + + add_library(centagent_lib STATIC - ${SRC_DIR}/agent.grpc.pb.cc - ${SRC_DIR}/agent.pb.cc - ${SRC_DIR}/bireactor.cc - ${SRC_DIR}/check.cc - ${SRC_DIR}/check_exec.cc - ${SRC_DIR}/opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.cc - ${SRC_DIR}/opentelemetry/proto/collector/metrics/v1/metrics_service.pb.cc - ${SRC_DIR}/opentelemetry/proto/metrics/v1/metrics.pb.cc - ${SRC_DIR}/opentelemetry/proto/common/v1/common.pb.cc - ${SRC_DIR}/opentelemetry/proto/resource/v1/resource.pb.cc - ${SRC_DIR}/config.cc - ${SRC_DIR}/scheduler.cc - ${SRC_DIR}/streaming_client.cc - ${SRC_DIR}/streaming_server.cc + ${SRC} ) include_directories( @@ -127,21 +145,36 @@ target_precompile_headers(centagent_lib PRIVATE precomp_inc/precomp.hh) SET(CENTREON_AGENT centagent) -add_executable(${CENTREON_AGENT} ${SRC_DIR}/main.cc) - -target_link_libraries( - ${CENTREON_AGENT} PRIVATE - -L${PROTOBUF_LIB_DIR} - gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts - centagent_lib - centreon_common - centreon_grpc - centreon_process - -L${Boost_LIBRARY_DIR_RELEASE} - boost_program_options - fmt::fmt - stdc++fs - ) +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + add_executable(${CENTREON_AGENT} ${SRC_DIR}/main.cc) + + target_link_libraries( + ${CENTREON_AGENT} PRIVATE + -L${PROTOBUF_LIB_DIR} + gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts + centagent_lib + centreon_common + centreon_grpc + centreon_process + -L${Boost_LIBRARY_DIR_RELEASE} + boost_program_options + fmt::fmt + stdc++fs) +else() + add_executable(${CENTREON_AGENT} ${SRC_DIR}/main_win.cc) + + target_link_libraries( + ${CENTREON_AGENT} PRIVATE + centagent_lib + centreon_common + centreon_grpc + centreon_process + gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts + absl::any absl::log absl::base absl::bits + Boost::program_options + fmt::fmt) +endif() + target_precompile_headers(${CENTREON_AGENT} REUSE_FROM centagent_lib) diff --git a/agent/conf/centagent.reg b/agent/conf/centagent.reg new file mode 100644 index 0000000000000000000000000000000000000000..ba43c5406a93f129db9fe747c0c76d7374607ab1 GIT binary patch literal 1712 zcmb`IYi|-!5Qg8+CjJMqpELn4P?l)av{`LyENw!GO(SMQfKnp20IjV*UVY}AUG{(> zHpXl=d(K?nd1nTG{k+gfQ}s2|cP&*?O9Ks&Ew$1@_eegV9dVm+FX=P-1=^YYJ#z0C9qSW5mr8Y_GbK9Uo2tn-LHALoXgfMbcc`{5khh#9A@bB^9k|#X>^CJ% zC(p4M?jhd8%<8MlA8Cx$kc?Mg9HWc$mUkb^Bl4V*Go=d4>Jc9CeGje{HqUvJ%*s%m zVV?$``&8@WM_bt}(=G2f%V+4WK(cMOg46jLmG`l#D?8#&)YTmr@@i7Y{f{g{pRQS7 z`g-lUV4d(!cMIQkoTbCL+rO6iTL=0ep24Q!^lZLylCk60reehX9T@gh(@QnhRhxIu z&CwiRKQk6#cV0h95neWD=3|xjU}3dpE$4KO#R%5DF4Z?I?lXkBjd`XIismh+*iZh* zbWQ!X5x)8fSt>4OIIk5IR<;ch=zM=|Uk22iGM5XO>T&Y>HE`MdBuDV~H(o66!#C`b zEo(EyP4+F(4Y>`GVNR&WW1rE(bEGS`lg9b2<9h(Y4!$xrW=#bLaS&y*k|N?JHwDL4*w3@ZLFI8!ZFu$^75MC)|GWGKRY3Xc literal 0 HcmV?d00001 diff --git a/agent/src/config_win.cc b/agent/src/config_win.cc new file mode 100644 index 00000000000..faa95415ea3 --- /dev/null +++ b/agent/src/config_win.cc @@ -0,0 +1,109 @@ +/** + * Copyright 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 + */ + +#include + +#include + +#include "com/centreon/exceptions/msg_fmt.hh" +#include "config.hh" + +using namespace com::centreon::agent; + +/** + * @brief Construct a new config::config object + * + * @param registry_key registry path as + * HKEY_LOCAL_MACHINE\SOFTWARE\Centreon\CentreonMonitoringAgent + */ +config::config(const std::string& registry_key) { + HKEY h_key; + LSTATUS res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, registry_key.c_str(), 0, + KEY_READ, &h_key); + if (res != ERROR_SUCCESS) { + if (res == ERROR_FILE_NOT_FOUND) { + throw exceptions::msg_fmt("{} not found", registry_key); + } else { + throw exceptions::msg_fmt("unable to read {}", registry_key); + } + } + + char str_buffer[4096]; + + auto get_sz_reg_or_default = [&](const char* value_name, + const char* default_value) { + DWORD size = sizeof(str_buffer); + LSTATUS result = RegGetValueA(h_key, nullptr, value_name, RRF_RT_REG_SZ, + nullptr, str_buffer, &size); + return (result == ERROR_SUCCESS) ? str_buffer : default_value; + }; + + auto get_bool = [&](const char* value_name) -> bool { + int32_t value; + DWORD size = sizeof(value); + LSTATUS result = RegGetValueA(h_key, nullptr, value_name, RRF_RT_DWORD, + nullptr, &value, &size); + return result == ERROR_SUCCESS && value; + }; + + auto get_unsigned = [&](const char* value_name) -> uint32_t { + uint32_t value; + DWORD size = sizeof(value); + LSTATUS result = RegGetValueA(h_key, nullptr, value_name, RRF_RT_DWORD, + nullptr, &value, &size); + return result == ERROR_SUCCESS ? value : 0; + }; + + _endpoint = get_sz_reg_or_default("endpoint", ""); + + // pattern schema doesn't work so we do it ourselves + if (!RE2::FullMatch(_endpoint, "[\\w\\.:]+:\\w+")) { + RegCloseKey(h_key); + throw exceptions::msg_fmt( + "bad format for endpoint {}, it must match to the regex: " + "[\\w\\.:]+:\\w+", + _endpoint); + } + _log_level = + spdlog::level::from_str(get_sz_reg_or_default("log_level", "info")); + + const char* log_type = get_sz_reg_or_default("log_type", "event-log"); + if (!strcmp(log_type, "file")) { + _log_type = to_file; + } else if (!strcmp(log_type, "stdout")) { + _log_type = to_stdout; + } else { + _log_type = to_event_log; + } + + _log_file = get_sz_reg_or_default("log_file", ""); + _log_files_max_size = get_unsigned("log_files_max_size"); + _log_files_max_number = get_unsigned("log_files_max_number"); + _encryption = get_bool("encryption"); + _public_cert_file = get_sz_reg_or_default("public_cert", ""); + _private_key_file = get_sz_reg_or_default("private_key", ""); + _ca_certificate_file = get_sz_reg_or_default("ca_certificate", ""); + _ca_name = get_sz_reg_or_default("ca_name", ""); + _host = get_sz_reg_or_default("host", ""); + if (_host.empty()) { + _host = boost::asio::ip::host_name(); + } + _reverse_connection = get_bool("reverse_connection"); + + RegCloseKey(h_key); +} diff --git a/agent/src/main_win.cc b/agent/src/main_win.cc new file mode 100644 index 00000000000..05ba6276b17 --- /dev/null +++ b/agent/src/main_win.cc @@ -0,0 +1,172 @@ +/** + * Copyright 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 + */ + +#include +#include +#include +#include + +#include "config.hh" +#include "streaming_client.hh" +#include "streaming_server.hh" + +using namespace com::centreon::agent; + +std::shared_ptr g_io_context = + std::make_shared(); + +std::shared_ptr g_logger; +static std::shared_ptr _streaming_client; + +static std::shared_ptr _streaming_server; + +static asio::signal_set _signals(*g_io_context, SIGTERM, SIGINT); + +static void signal_handler(const boost::system::error_code& error, + int signal_number) { + if (!error) { + switch (signal_number) { + case SIGINT: + case SIGTERM: + SPDLOG_LOGGER_INFO(g_logger, "SIGTERM or SIGINT received"); + if (_streaming_client) { + _streaming_client->shutdown(); + } + if (_streaming_server) { + _streaming_server->shutdown(); + } + g_io_context->post([]() { g_io_context->stop(); }); + return; + } + _signals.async_wait(signal_handler); + } +} + +static std::string read_file(const std::string& file_path) { + if (file_path.empty()) { + return {}; + } + try { + std::ifstream file(file_path); + if (file.is_open()) { + std::stringstream ss; + ss << file.rdbuf(); + file.close(); + return ss.str(); + } + } catch (const std::exception& e) { + SPDLOG_LOGGER_ERROR(g_logger, "fail to read {}: {}", file_path, e.what()); + } + return ""; +} + +int main(int argc, char* argv[]) { + const char* registry_path = "SOFTWARE\\Centreon\\CentreonMonitoringAgent"; + + std::unique_ptr conf; + try { + conf = std::make_unique(registry_path); + } catch (const std::exception& e) { + SPDLOG_ERROR("fail to read conf from registry {}: {}", registry_path, + e.what()); + return 1; + } + + SPDLOG_INFO("centreon-monitoring-agent start"); + + const std::string logger_name = "centreon-monitoring-agent"; + + auto create_event_logger = []() { + auto sink = std::make_shared( + "CentreonMonitoringAgent"); + g_logger = std::make_shared("", sink); + }; + + try { + if (conf->get_log_type() == config::to_file) { + if (!conf->get_log_file().empty()) { + if (conf->get_log_files_max_size() > 0 && + conf->get_log_files_max_number() > 0) { + g_logger = spdlog::rotating_logger_mt( + logger_name, conf->get_log_file(), + conf->get_log_files_max_size() * 0x100000, + conf->get_log_files_max_number()); + } else { + SPDLOG_INFO( + "no log-max-file-size option or no log-max-files option provided " + "=> logs will not be rotated by centagent"); + g_logger = spdlog::basic_logger_mt(logger_name, conf->get_log_file()); + } + } else { + SPDLOG_ERROR( + "log-type=file needs the option log-file => log to event log"); + create_event_logger(); + } + } else if (conf->get_log_type() == config::to_stdout) { + g_logger = spdlog::stdout_color_mt(logger_name); + } else { + create_event_logger(); + } + } catch (const std::exception& e) { + SPDLOG_CRITICAL("Can't log to {}: {}", conf->get_log_file(), e.what()); + return 2; + } + + g_logger->set_level(conf->get_log_level()); + + g_logger->flush_on(spdlog::level::warn); + + spdlog::flush_every(std::chrono::seconds(1)); + + SPDLOG_LOGGER_INFO(g_logger, "centreon-monitoring-agent start"); + std::shared_ptr grpc_conf; + + try { + _signals.async_wait(signal_handler); + + grpc_conf = std::make_shared( + conf->get_endpoint(), conf->use_encryption(), + read_file(conf->get_public_cert_file()), + read_file(conf->get_private_key_file()), + read_file(conf->get_ca_certificate_file()), conf->get_ca_name(), true, + 30); + + } catch (const std::exception& e) { + SPDLOG_CRITICAL("fail to parse input params: {}", e.what()); + return -1; + } + + if (conf->use_reverse_connection()) { + _streaming_server = streaming_server::load(g_io_context, g_logger, + grpc_conf, conf->get_host()); + } else { + _streaming_client = streaming_client::load(g_io_context, g_logger, + grpc_conf, conf->get_host()); + } + + try { + g_io_context->run(); + } catch (const std::exception& e) { + SPDLOG_LOGGER_CRITICAL(g_logger, "unhandled exception: {}", e.what()); + return -1; + } + + SPDLOG_LOGGER_INFO(g_logger, "centreon-monitoring-agent end"); + + return 0; +} diff --git a/agent/src/streaming_client.cc b/agent/src/streaming_client.cc index 5fa122c83cd..424d384b1c9 100644 --- a/agent/src/streaming_client.cc +++ b/agent/src/streaming_client.cc @@ -18,7 +18,6 @@ #include "streaming_client.hh" #include "check_exec.hh" -#include "com/centreon/clib/version.hh" #include "com/centreon/common/defer.hh" using namespace com::centreon::agent; @@ -146,12 +145,9 @@ void streaming_client::_create_reactor() { std::make_shared(); auto infos = who_i_am->mutable_init(); - infos->mutable_centreon_version()->set_major( - com::centreon::clib::version::major); - infos->mutable_centreon_version()->set_minor( - com::centreon::clib::version::minor); - infos->mutable_centreon_version()->set_patch( - com::centreon::clib::version::patch); + infos->mutable_centreon_version()->set_major(COLLECT_MAJOR); + infos->mutable_centreon_version()->set_minor(COLLECT_MINOR); + infos->mutable_centreon_version()->set_patch(COLLECT_PATCH); infos->set_host(_supervised_host); diff --git a/agent/src/streaming_server.cc b/agent/src/streaming_server.cc index cfc23fabb11..215c1d2457b 100644 --- a/agent/src/streaming_server.cc +++ b/agent/src/streaming_server.cc @@ -18,7 +18,6 @@ #include "streaming_server.hh" #include "check_exec.hh" -#include "com/centreon/clib/version.hh" #include "scheduler.hh" using namespace com::centreon::agent; @@ -90,12 +89,9 @@ void server_reactor::_start() { std::make_shared(); auto infos = who_i_am->mutable_init(); - infos->mutable_centreon_version()->set_major( - com::centreon::clib::version::major); - infos->mutable_centreon_version()->set_minor( - com::centreon::clib::version::minor); - infos->mutable_centreon_version()->set_patch( - com::centreon::clib::version::patch); + infos->mutable_centreon_version()->set_major(COLLECT_MAJOR); + infos->mutable_centreon_version()->set_minor(COLLECT_MINOR); + infos->mutable_centreon_version()->set_patch(COLLECT_PATCH); infos->set_host(_supervised_host); write(who_i_am); diff --git a/agent/test/CMakeLists.txt b/agent/test/CMakeLists.txt index c677ecc9c93..897aea3b643 100644 --- a/agent/test/CMakeLists.txt +++ b/agent/test/CMakeLists.txt @@ -16,15 +16,21 @@ # For more information : contact@centreon.com # - - -add_executable(ut_agent - config_test.cc +set( SRC_COMMON check_test.cc check_exec_test.cc scheduler_test.cc test_main.cc - ${TESTS_SOURCES}) +) + +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(SRC ${SRC_COMMON} config_test.cc) +else() + set(SRC ${SRC_COMMON}) +endif() + + +add_executable(ut_agent ${SRC}) add_test(NAME tests COMMAND ut_agent) @@ -36,8 +42,25 @@ set_target_properties( RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/tests RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/tests) - -target_link_libraries(ut_agent PRIVATE +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + target_link_libraries(ut_agent PRIVATE + centagent_lib + centreon_common + centreon_process + GTest::gtest + GTest::gtest_main + GTest::gmock + GTest::gmock_main + -L${Boost_LIBRARY_DIR_RELEASE} + boost_program_options + stdc++fs + -L${PROTOBUF_LIB_DIR} + gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts + fmt::fmt pthread + crypto ssl + ) +else() + target_link_libraries(ut_agent PRIVATE centagent_lib centreon_common centreon_process @@ -45,14 +68,11 @@ target_link_libraries(ut_agent PRIVATE GTest::gtest_main GTest::gmock GTest::gmock_main - -L${Boost_LIBRARY_DIR_RELEASE} - boost_program_options - stdc++fs - -L${PROTOBUF_LIB_DIR} + Boost::program_options gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts - fmt::fmt pthread - crypto ssl + fmt::fmt ) +endif() add_dependencies(ut_agent centreon_common centagent_lib) @@ -60,3 +80,6 @@ set_property(TARGET ut_agent PROPERTY POSITION_INDEPENDENT_CODE ON) target_precompile_headers(ut_agent PRIVATE ${PROJECT_SOURCE_DIR}/precomp_inc/precomp.hh) +file(COPY ${PROJECT_SOURCE_DIR}/test/scripts/sleep.bat + DESTINATION ${CMAKE_BINARY_DIR}/tests) + diff --git a/agent/test/check_exec_test.cc b/agent/test/check_exec_test.cc index c0a6ef1278c..c5cf3b15bbc 100644 --- a/agent/test/check_exec_test.cc +++ b/agent/test/check_exec_test.cc @@ -22,6 +22,16 @@ using namespace com::centreon::agent; +#ifdef _WINDOWS +#define ECHO_PATH "tests\\echo.bat" +#define SLEEP_PATH "tests\\sleep.bat" +#define END_OF_LINE "\r\n" +#else +#define ECHO_PATH "/bin/echo" +#define SLEEP_PATH "/bin/sleep" +#define END_OF_LINE "\n" +#endif + extern std::shared_ptr g_io_context; static const std::string serv("serv"); @@ -29,7 +39,7 @@ static const std::string cmd_name("command"); static std::string command_line; TEST(check_exec_test, echo) { - command_line = "/bin/echo hello toto"; + command_line = ECHO_PATH " hello toto"; int status; std::list outputs; std::mutex mut; @@ -54,11 +64,11 @@ TEST(check_exec_test, echo) { cond.wait(l); ASSERT_EQ(status, 0); ASSERT_EQ(outputs.size(), 1); - ASSERT_EQ(*outputs.begin(), "hello toto"); + ASSERT_EQ(outputs.begin()->substr(0, 10), "hello toto"); } TEST(check_exec_test, timeout) { - command_line = "/bin/sleep 5"; + command_line = SLEEP_PATH " 5"; int status; std::list outputs; std::condition_variable cond; @@ -78,9 +88,10 @@ TEST(check_exec_test, timeout) { std::mutex mut; std::unique_lock l(mut); cond.wait(l); - ASSERT_EQ(status, 3); + ASSERT_NE(status, 0); ASSERT_EQ(outputs.size(), 1); - ASSERT_EQ(*outputs.begin(), "Timeout at execution of /bin/sleep 5"); + + ASSERT_EQ(*outputs.begin(), "Timeout at execution of " SLEEP_PATH " 5"); } TEST(check_exec_test, bad_command) { @@ -111,7 +122,12 @@ TEST(check_exec_test, bad_command) { cond.wait(l); ASSERT_EQ(status, 3); ASSERT_EQ(outputs.size(), 1); +#ifdef _WINDOWS + // message is language dependant + ASSERT_GE(outputs.begin()->size(), 20); +#else ASSERT_EQ(*outputs.begin(), "Fail to execute /usr/bad_path/turlututu titi toto : No such file " "or directory"); +#endif } diff --git a/agent/test/scheduler_test.cc b/agent/test/scheduler_test.cc index a7ac335382e..5af1a86f4dd 100644 --- a/agent/test/scheduler_test.cc +++ b/agent/test/scheduler_test.cc @@ -94,6 +94,11 @@ class scheduler_test : public ::testing::Test { spdlog::default_logger()->set_level(spdlog::level::trace); } + void TearDown() override { + // let time to async check to end + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } + std::shared_ptr create_conf( unsigned nb_serv, unsigned second_check_period, @@ -151,11 +156,11 @@ TEST_F(scheduler_test, no_config) { static bool tempo_check_assert_pred(const time_point& after, const time_point& before) { - if ((after - before) <= std::chrono::milliseconds(40)) { + if ((after - before) <= std::chrono::milliseconds(400)) { SPDLOG_ERROR("after={}, before={}", after, before); return false; } - if ((after - before) >= std::chrono::milliseconds(60)) { + if ((after - before) >= std::chrono::milliseconds(600)) { SPDLOG_ERROR("after={}, before={}", after, before); return false; } @@ -165,7 +170,7 @@ static bool tempo_check_assert_pred(const time_point& after, TEST_F(scheduler_test, correct_schedule) { std::shared_ptr sched = scheduler::load( g_io_context, spdlog::default_logger(), "my_host", - create_conf(20, 1, 1, 50, 1), + create_conf(20, 10, 1, 50, 1), [](const std::shared_ptr&) {}, [](const std::shared_ptr& io_context, const std::shared_ptr& logger, @@ -184,10 +189,10 @@ TEST_F(scheduler_test, correct_schedule) { tempo_check::check_starts.clear(); } - std::this_thread::sleep_for(std::chrono::milliseconds(1100)); + std::this_thread::sleep_for(std::chrono::milliseconds(10100)); - // we have 2 * 10 = 20 checks spread over 1 second - duration expected_interval = std::chrono::milliseconds(50); + // we have 2 * 10 = 20 checks spread over 10 second + duration expected_interval = std::chrono::milliseconds(1000); { std::lock_guard l(tempo_check::check_starts_m); @@ -206,7 +211,7 @@ TEST_F(scheduler_test, correct_schedule) { } } - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + std::this_thread::sleep_for(std::chrono::milliseconds(10000)); { std::lock_guard l(tempo_check::check_starts_m); @@ -432,7 +437,7 @@ unsigned concurent_check::max_active_check; TEST_F(scheduler_test, max_concurent) { std::shared_ptr sched = scheduler::load( g_io_context, spdlog::default_logger(), "my_host", - create_conf(200, 1, 1, 10, 1), + create_conf(200, 10, 1, 10, 1), [&](const std::shared_ptr& req) {}, [](const std::shared_ptr& io_context, const std::shared_ptr& logger, @@ -442,17 +447,17 @@ TEST_F(scheduler_test, max_concurent) { check::completion_handler&& handler) { return std::make_shared( io_context, logger, start_expected, service, cmd_name, cmd_line, - engine_to_agent_request, 0, std::chrono::milliseconds(75), + engine_to_agent_request, 0, std::chrono::milliseconds(750), std::move(handler)); }); - // to many tests to be completed in one second - std::this_thread::sleep_for(std::chrono::milliseconds(1100)); + // to many tests to be completed in eleven second + std::this_thread::sleep_for(std::chrono::milliseconds(11000)); ASSERT_LT(concurent_check::checked.size(), 200); ASSERT_EQ(concurent_check::max_active_check, 10); - // all tests must be completed in 1.5s - std::this_thread::sleep_for(std::chrono::milliseconds(500)); + // all tests must be completed in 16s + std::this_thread::sleep_for(std::chrono::milliseconds(5000)); ASSERT_EQ(concurent_check::max_active_check, 10); ASSERT_EQ(concurent_check::checked.size(), 200); diff --git a/agent/test/scripts/sleep.bat b/agent/test/scripts/sleep.bat new file mode 100644 index 00000000000..9b178637c61 --- /dev/null +++ b/agent/test/scripts/sleep.bat @@ -0,0 +1,2 @@ +@echo off +ping 127.0.0.1 -n1 %~1 \ No newline at end of file diff --git a/agent/test/test_main.cc b/agent/test/test_main.cc index 919a087af50..21d63bb5a22 100644 --- a/agent/test/test_main.cc +++ b/agent/test/test_main.cc @@ -23,12 +23,13 @@ std::shared_ptr g_io_context( class CentreonEngineEnvironment : public testing::Environment { public: +#ifndef _WINDOWS void SetUp() override { setenv("TZ", ":Europe/Paris", 1); return; } +#endif - void TearDown() override { return; } }; /** diff --git a/centreon_cmake.bat b/centreon_cmake.bat new file mode 100644 index 00000000000..07bb3e28e38 --- /dev/null +++ b/centreon_cmake.bat @@ -0,0 +1,61 @@ +echo off + +set "build_type=debug" + +if "%~1" == "--help" ( + call :show_help + goto :eof +) else if "%~1" == "--release" ( + set "build_type=release" +) + +where /q cl.exe +IF ERRORLEVEL 1 ( + echo unable to find cl.exe, please run vcvarsall.bat or compile from x64 Native Tools Command Prompt for VS20xx + exit /B +) + +where /q cmake.exe +IF ERRORLEVEL 1 ( + echo unable to find cmake.exe, please install cmake.exe + exit /B +) + +where /q ninja.exe +IF ERRORLEVEL 1 ( + echo unable to find ninja.exe, please install ninja.exe + exit /B +) + +if not defined VCPKG_ROOT ( + echo "install vcpkg" + set "current_dir=%cd%" + cd /D %USERPROFILE% + git clone https://github.com/microsoft/vcpkg.git + cd vcpkg && bootstrap-vcpkg.bat + cd /D %current_dir% + set "VCPKG_ROOT=%USERPROFILE%\vcpkg" + set "PATH=%VCPKG_ROOT%;%PATH%" + echo "Please add this variables to environment for future compile:" + echo "VCPKG_ROOT=%USERPROFILE%\vcpkg" + echo "PATH=%VCPKG_ROOT%;%PATH%" +) + + +cmake.exe --preset=%build_type% + +cmake.exe --build build_windows + +goto :eof + + +:show_help +echo This program build Centreon-Monitoring-Agent +echo --release : Build on release mode +echo --help : help +goto :eof + + + + + diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 6142a2fa804..fbe4f620f5b 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -19,7 +19,9 @@ # Global options. project("Centreon common" C CXX) -add_subdirectory(log_v2) +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + add_subdirectory(log_v2) +endif() # Set directories. set(INCLUDE_DIR "${PROJECT_SOURCE_DIR}/inc/com/centreon/common") @@ -44,16 +46,24 @@ add_custom_command( WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) # Set sources. -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 -) +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 + ) +else() +#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}" @@ -68,7 +78,10 @@ set_property(TARGET centreon_common PROPERTY POSITION_INDEPENDENT_CODE ON) target_precompile_headers(centreon_common PRIVATE precomp_inc/precomp.hh) -add_subdirectory(http) +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + add_subdirectory(http) +endif() + add_subdirectory(grpc) add_subdirectory(process) diff --git a/common/grpc/CMakeLists.txt b/common/grpc/CMakeLists.txt index ac154d422f4..e2371114e20 100644 --- a/common/grpc/CMakeLists.txt +++ b/common/grpc/CMakeLists.txt @@ -33,5 +33,4 @@ target_include_directories(centreon_grpc PRIVATE ${INC_DIR}) target_precompile_headers(centreon_grpc REUSE_FROM centreon_common) -set_target_properties(centreon_grpc PROPERTIES COMPILE_FLAGS "-fPIC") - +set_target_properties(centreon_grpc PROPERTIES POSITION_INDEPENDENT_CODE ON) diff --git a/common/precomp_inc/precomp.hh b/common/precomp_inc/precomp.hh index 0b20d35411a..d05e44049b5 100644 --- a/common/precomp_inc/precomp.hh +++ b/common/precomp_inc/precomp.hh @@ -46,8 +46,10 @@ #include #include +#ifndef _WINDOWS #include #include +#endif #include #include "com/centreon/exceptions/msg_fmt.hh" diff --git a/common/process/src/process.cc b/common/process/src/process.cc index 615d16da564..f8e982c9a71 100644 --- a/common/process/src/process.cc +++ b/common/process/src/process.cc @@ -21,7 +21,9 @@ #include "com/centreon/common/process/process.hh" +#if !defined(BOOST_PROCESS_V2_WINDOWS) #include "com/centreon/common/process/detail/centreon_posix_process_launcher.hh" +#endif #include @@ -146,7 +148,11 @@ process::process(const std::shared_ptr& io_context, const std::shared_ptr& logger, const std::string_view& cmd_line) : _io_context(io_context), _logger(logger) { +#ifdef _WINDOWS + auto split_res = boost::program_options::split_winmain(std::string(cmd_line)); +#else auto split_res = boost::program_options::split_unix(std::string(cmd_line)); +#endif if (split_res.begin() == split_res.end()) { SPDLOG_LOGGER_ERROR(_logger, "empty command line:\"{}\"", cmd_line); throw exceptions::msg_fmt("empty command line:\"{}\"", cmd_line); diff --git a/common/tests/CMakeLists.txt b/common/tests/CMakeLists.txt index afd6c972eb8..d44100b1313 100644 --- a/common/tests/CMakeLists.txt +++ b/common/tests/CMakeLists.txt @@ -16,17 +16,27 @@ # For more information : contact@centreon.com # -add_executable(ut_common - process_stat_test.cc - hex_dump_test.cc - log_v2/log_v2.cc - node_allocator_test.cc - perfdata_test.cc - process_test.cc - rapidjson_helper_test.cc - test_main.cc - utf8_test.cc - ${TESTS_SOURCES}) + +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + add_executable(ut_common + process_stat_test.cc + hex_dump_test.cc + log_v2/log_v2.cc + node_allocator_test.cc + perfdata_test.cc + process_test.cc + rapidjson_helper_test.cc + test_main.cc + utf8_test.cc + ${TESTS_SOURCES}) +else() + add_executable(ut_common + perfdata_test.cc + process_test.cc + test_main_win.cc + utf8_test.cc + ${TESTS_SOURCES}) +endif() set_target_properties( ut_common @@ -43,32 +53,60 @@ if(WITH_COVERAGE) set(GCOV gcov) endif() + +file(COPY ${PROJECT_SOURCE_DIR}/tests/scripts/echo.bat + DESTINATION ${CMAKE_BINARY_DIR}/tests) +file(COPY ${PROJECT_SOURCE_DIR}/tests/scripts/bad_script.bat + DESTINATION ${CMAKE_BINARY_DIR}/tests) + add_test(NAME tests COMMAND ut_common) +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + target_link_libraries( + ut_common + PRIVATE centreon_common + centreon_http + centreon_process + -L${Boost_LIBRARY_DIR_RELEASE} + boost_program_options + re2::re2 + log_v2 + crypto + ssl + GTest::gtest + GTest::gtest_main + GTest::gmock + GTest::gmock_main + absl::any + absl::log + absl::base + absl::bits + fmt::fmt pthread) + + add_dependencies(ut_common centreon_common centreon_http) + +else() + target_link_libraries( + ut_common + PRIVATE centreon_common + centreon_process + Boost::program_options + re2::re2 + GTest::gtest + GTest::gtest_main + GTest::gmock + GTest::gmock_main + absl::any + absl::log + absl::base + absl::bits + fmt::fmt) + + add_dependencies(ut_common centreon_common) + +endif() -target_link_libraries( - ut_common - PRIVATE centreon_common - centreon_http - centreon_process - -L${Boost_LIBRARY_DIR_RELEASE} - boost_program_options - re2::re2 - log_v2 - crypto - ssl - GTest::gtest - GTest::gtest_main - GTest::gmock - GTest::gmock_main - absl::any - absl::log - absl::base - absl::bits - fmt::fmt pthread) - -add_dependencies(ut_common centreon_common centreon_http) set_property(TARGET ut_common PROPERTY POSITION_INDEPENDENT_CODE ON) diff --git a/common/tests/scripts/bad_script.bat b/common/tests/scripts/bad_script.bat new file mode 100644 index 00000000000..41297daaf43 --- /dev/null +++ b/common/tests/scripts/bad_script.bat @@ -0,0 +1,3 @@ +@echo off + +fzeurnezirfrf diff --git a/common/tests/scripts/echo.bat b/common/tests/scripts/echo.bat new file mode 100644 index 00000000000..8efa2965191 --- /dev/null +++ b/common/tests/scripts/echo.bat @@ -0,0 +1 @@ +@echo %* \ No newline at end of file diff --git a/common/tests/test_main_win.cc b/common/tests/test_main_win.cc new file mode 100644 index 00000000000..936fbda07b0 --- /dev/null +++ b/common/tests/test_main_win.cc @@ -0,0 +1,54 @@ +/** + * Copyright 2024 Centreon (https://www.centreon.com/) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * For more information : contact@centreon.com + * + */ + +#include + +std::shared_ptr g_io_context( + std::make_shared()); + +class CentreonEngineEnvironment : public testing::Environment { + public: + void TearDown() override { return; } +}; + +/** + * Tester entry point. + * + * @param[in] argc Argument count. + * @param[in] argv Argument values. + * + * @return 0 on success, any other value on failure. + */ +int main(int argc, char* argv[]) { + // GTest initialization. + testing::InitGoogleTest(&argc, argv); + + auto _worker{asio::make_work_guard(*g_io_context)}; + + // Set specific environment. + testing::AddGlobalTestEnvironment(new CentreonEngineEnvironment()); + + std::thread asio_thread([] { g_io_context->run(); }); + // Run all tests. + int ret = RUN_ALL_TESTS(); + g_io_context->stop(); + asio_thread.join(); + spdlog::shutdown(); + return ret; +} diff --git a/custom-triplets/x64-windows.cmake b/custom-triplets/x64-windows.cmake new file mode 100644 index 00000000000..17a9406b348 --- /dev/null +++ b/custom-triplets/x64-windows.cmake @@ -0,0 +1,6 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) + +#set(VCPKG_CMAKE_SYSTEM_NAME windows) +set(VCPKG_BUILD_TYPE release) diff --git a/engine/modules/opentelemetry/doc/opentelemetry.md b/engine/modules/opentelemetry/doc/opentelemetry.md index 379643f2889..c2839528431 100644 --- a/engine/modules/opentelemetry/doc/opentelemetry.md +++ b/engine/modules/opentelemetry/doc/opentelemetry.md @@ -390,4 +390,4 @@ An example: From this configuration an agent_reverse_client object maintains a list of endpoints engine has to connect to. It manages also agent list updates. It contains a map of to_agent_connector indexed by config. The role to_agent_connector is to maintain an alive connection to agent (agent_connection class). It owns an agent_connection class and recreates it in case of network failure. -Agent_connection holds a weak_ptr to agent_connection to warn it about connection failure. \ No newline at end of file +Agent_connection holds a weak_ptr to agent_connection to warn it about connection failure. diff --git a/packaging/centreon-monitoring-agent.yaml b/packaging/centreon-monitoring-agent.yaml index c452432cf47..a784e7ccdb7 100644 --- a/packaging/centreon-monitoring-agent.yaml +++ b/packaging/centreon-monitoring-agent.yaml @@ -67,7 +67,6 @@ scripts: preremove: ./scripts/centreon-monitoring-agent-preremove.sh postremove: ./scripts/centreon-monitoring-agent-postremove.sh - rpm: summary: Centreon Collect Agent. It can be used to execute plugins remotely compression: zstd diff --git a/vcpkg.json b/vcpkg.json index 8e2b18a4af3..408c71efe59 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -6,25 +6,58 @@ "cxx17" ] }, - "libssh2", - "curl", "fmt", "grpc", - "ryml", "spdlog", "boost-asio", - "boost-beast", - "boost-container", - "boost-circular-buffer", "boost-multi-index", - "boost-interprocess", - "boost-exception", "boost-process", "boost-program-options", - "boost-serialization", - "boost-url", - "nlohmann-json", "rapidjson", - "gtest" + "gtest", + { + "name": "libssh2", + "platform": "linux" + }, + { + "name": "curl", + "platform": "linux" + }, + { + "name": "ryml", + "platform": "linux" + }, + { + "name": "boost-beast", + "platform": "linux" + }, + { + "name": "boost-container", + "platform": "linux" + }, + { + "name": "boost-circular-buffer", + "platform": "linux" + }, + { + "name": "boost-interprocess", + "platform": "linux" + }, + { + "name": "boost-exception", + "platform": "linux" + }, + { + "name": "boost-serialization", + "platform": "linux" + }, + { + "name": "boost-url", + "platform": "linux" + }, + { + "name": "nlohmann-json", + "platform": "linux" + } ] } \ No newline at end of file