Skip to content

Commit

Permalink
add windows-agent.yaml
Browse files Browse the repository at this point in the history
try zip all
  • Loading branch information
jean-christophe81 committed Jul 17, 2024
1 parent 465e265 commit 89d703d
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 95 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/windows-agent-build-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: install msvc command prompt
uses: ilammy/msvc-dev-cmd@v1.4.1

Expand Down Expand Up @@ -51,3 +51,4 @@ jobs:
Write-Host "aws s3 cp $file_name_extension s3://centreon-collect-robot-report/$file_name_extension"
[System.Environment]::SetEnvironmentVariable("AWS_EC2_METADATA_DISABLED","true")
aws s3 cp $file_name_extension s3://centreon-collect-robot-report/$file_name_extension
1 change: 0 additions & 1 deletion .github/workflows/windows-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: install msvc command prompt
uses: ilammy/msvc-dev-cmd@v1.4.1

Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ set(COLLECT_MINOR 07)
set(COLLECT_PATCH 0)
set(COLLECT_VERSION "${COLLECT_MAJOR}.${COLLECT_MINOR}.${COLLECT_PATCH}")

add_definitions("-DCOLLECT_MAJOR=${COLLECT_MAJOR}")
add_definitions("-DCOLLECT_MINOR=${COLLECT_MINOR}")
add_definitions("-DCOLLECT_PATCH=${COLLECT_PATCH}")


if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
include(CMakeListsLinux.txt)
Expand Down
5 changes: 4 additions & 1 deletion CMakeListsWindows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ 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 REQUIRED COMPONENTS beast)
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.
Expand Down
17 changes: 15 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build_$env{OS}",
"binaryDir": "${sourceDir}/build_windows",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"WITH_TESTING": "On",
Expand All @@ -14,14 +14,27 @@
{
"name": "release",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build_$env{OS}",
"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"
}
},
{
"name": "release-ci",
"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",
"VCPKG_INSTALL_OPTIONS": "--no-downloads"
}
}
]
}
14 changes: 6 additions & 8 deletions agent/src/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,12 @@ scheduler::default_config() {
*
*/
void scheduler::_start_check_timer() {
time_point next_time_expire =
(_check_queue.empty() ||
_active_check >= _conf->config().max_concurrent_checks())
? (std::chrono::system_clock::now() + std::chrono::milliseconds(100))
: (*_check_queue.begin())->get_start_expected();
SPDLOG_LOGGER_TRACE(_logger, "check timer will expire at {}",
next_time_expire);
_check_timer.expires_at(next_time_expire);
if (_check_queue.empty() ||
_active_check >= _conf->config().max_concurrent_checks()) {
_check_timer.expires_from_now(std::chrono::milliseconds(100));
} else {
_check_timer.expires_at((*_check_queue.begin())->get_start_expected());
}
_check_timer.async_wait(
[me = shared_from_this()](const boost::system::error_code& err) {
me->_check_timer_handler(err);
Expand Down
10 changes: 3 additions & 7 deletions agent/src/streaming_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,12 +145,9 @@ void streaming_client::_create_reactor() {
std::make_shared<MessageFromAgent>();
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);

Expand Down
10 changes: 3 additions & 7 deletions agent/src/streaming_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,12 +89,9 @@ void server_reactor::_start() {
std::make_shared<MessageFromAgent>();
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);
Expand Down
31 changes: 18 additions & 13 deletions agent/test/scheduler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<com::centreon::agent::MessageToAgent> create_conf(
unsigned nb_serv,
unsigned second_check_period,
Expand Down Expand Up @@ -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;
}
Expand All @@ -165,7 +170,7 @@ static bool tempo_check_assert_pred(const time_point& after,
TEST_F(scheduler_test, correct_schedule) {
std::shared_ptr<scheduler> 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<MessageFromAgent>&) {},
[](const std::shared_ptr<asio::io_context>& io_context,
const std::shared_ptr<spdlog::logger>& logger,
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -432,7 +437,7 @@ unsigned concurent_check::max_active_check;
TEST_F(scheduler_test, max_concurent) {
std::shared_ptr<scheduler> 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<MessageFromAgent>& req) {},
[](const std::shared_ptr<asio::io_context>& io_context,
const std::shared_ptr<spdlog::logger>& logger,
Expand All @@ -442,17 +447,17 @@ TEST_F(scheduler_test, max_concurent) {
check::completion_handler&& handler) {
return std::make_shared<concurent_check>(
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);

Expand Down
2 changes: 1 addition & 1 deletion agent/test/scripts/sleep.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@echo off
timeout %~1
ping 127.0.0.1 -n1 %~1
3 changes: 0 additions & 3 deletions agent/test/test_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class CentreonEngineEnvironment : public testing::Environment {
}
#endif

void TearDown() override {
return;
}
};

/**
Expand Down
32 changes: 16 additions & 16 deletions broker/core/src/misc/string.cc
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
* Copyright 2011-2013 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
*/
* Copyright 2011-2013 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 "com/centreon/broker/misc/string.hh"
#include "com/centreon/common/utf8.hh"
Expand Down
2 changes: 1 addition & 1 deletion centreon_cmake.bat
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if not defined VCPKG_ROOT (

cmake.exe --preset=%build_type%

cmake.exe --build build_%os%
cmake.exe --build build_windows

goto :eof

Expand Down
32 changes: 16 additions & 16 deletions clib/src/process.cc
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
* Copyright 2012-2013,2020-2021 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
*/
* Copyright 2012-2013,2020-2021 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 <sstream>

Expand Down
6 changes: 1 addition & 5 deletions common/http/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ target_include_directories(centreon_http PRIVATE ${INC_DIR})

target_precompile_headers(centreon_http REUSE_FROM centreon_common)

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set_target_properties(centreon_http PROPERTIES COMPILE_FLAGS "-fPIC")
else()
set_target_properties(centreon_http PROPERTIES COMPILE_FLAGS "/bigobj")
endif()
set_target_properties(centreon_http PROPERTIES COMPILE_FLAGS "-fPIC")

# Testing.
if(WITH_TESTING)
Expand Down
5 changes: 0 additions & 5 deletions common/http/src/https_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ std::shared_ptr<std::string> certificate_cache::get_certificate(
throw msg_fmt("stat fail of certificate: {} : {}", path,
strerror(errno));
}
#ifdef _WINDOWS
if (file_stat.st_mtime >
exist->second.last_access) { // modified on disk => reload}
#else
if (file_stat.st_mtim.tv_sec >
exist->second.last_access) { // modified on disk => reload}
#endif
_certs.erase(exist);
} else { // not modified => return cache content
exist->second.last_access = now;
Expand Down
1 change: 0 additions & 1 deletion common/tests/test_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

#include <gtest/gtest.h>

#include "pool.hh"

std::shared_ptr<asio::io_context> g_io_context(
Expand Down
1 change: 1 addition & 0 deletions packaging/centreon-monitoring-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ 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
Expand Down
Loading

0 comments on commit 89d703d

Please sign in to comment.