Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-christophe81 committed Nov 18, 2024
1 parent 827fcd9 commit 25de6e8
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 62 deletions.
3 changes: 3 additions & 0 deletions .github/scripts/agent_installer_test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ function test_args_to_registry {
exit 1
}

#let time to windows to flush registry
Start-Sleep -Seconds 2

foreach ($value_name in $expected_registry_values.Keys) {
$expected_value = $($expected_registry_values[$value_name])
$real_value = (Get-ItemProperty -Path HKLM:\Software\Centreon\CentreonMonitoringAgent -Name $value_name).$value_name
Expand Down
2 changes: 1 addition & 1 deletion agent/doc/agent-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ The second one relies on performance data counters (pdh API), it gives us percen
The choice between the two methods is done by 'use-nt-query-system-information' boolean parameter.
### check_drive_size
we have to get free space on server drives. In case of network drives, this call can block in case of network failure. Unfortunately, there is no asynchronous API to do that. So a dedicated thread (drive_size_thread) computes these statistics. In order to be os independent and to test it, drive_size_thread relies on a functor that do the job: drive_size_thread::os_fs_stats.
we have to get free space on server drives. In case of network drives, this call can block in case of network failure. Unfortunately, there is no asynchronous API to do that. So a dedicated thread (drive_size_thread) computes these statistics. In order to be os independent and to test it, drive_size_thread relies on a functor that do the job: drive_size_thread::os_fs_stats. This functor is initialized in main function. drive_size thread is stopped at the end of main function.
So it works like that:
* check_drive_size post query in drive_size_thread queue
Expand Down
5 changes: 5 additions & 0 deletions agent/inc/com/centreon/agent/drive_size.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
namespace com::centreon::agent {
namespace check_drive_size_detail {

/**
* @brief these flags are passed in check parameter:filter-storage-type and
* filter-type
*
*/
enum e_drive_fs_type : uint64_t {
hr_unknown = 0,
hr_storage_ram = 1 << 0,
Expand Down
103 changes: 52 additions & 51 deletions agent/native_windows/src/check_cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,59 +468,60 @@ check_cpu::check_cpu(const std::shared_ptr<asio::io_context>& io_context,
}
}
}
catch (const std::exception& e) {
SPDLOG_LOGGER_ERROR(_logger, "check_cpu fail to parse check params: {}",
e.what());
throw;
}
} catch (const std::exception& e) {
SPDLOG_LOGGER_ERROR(_logger, "check_cpu fail to parse check params: {}",
e.what());
throw;
}

if (_use_nt_query_system_information) {
_ntdll_init();
} else {
_pdh_counters = std::make_unique<pdh_counters>();
}
if (_use_nt_query_system_information) {
_ntdll_init();
} else {
_pdh_counters = std::make_unique<pdh_counters>();
}
}

check_cpu::~check_cpu() {}

std::unique_ptr<
check_cpu_detail::cpu_time_snapshot<e_proc_stat_index::nb_field>>
check_cpu::get_cpu_time_snapshot(bool first_measure) {
if (_use_nt_query_system_information) {
return std::make_unique<check_cpu_detail::kernel_cpu_time_snapshot>(
_nb_core);
} else {
return std::make_unique<check_cpu_detail::pdh_cpu_time_snapshot>(
_nb_core, *_pdh_counters, first_measure);
}
check_cpu::~check_cpu() {}

std::unique_ptr<
check_cpu_detail::cpu_time_snapshot<e_proc_stat_index::nb_field>>
check_cpu::get_cpu_time_snapshot(bool first_measure) {
if (_use_nt_query_system_information) {
return std::make_unique<check_cpu_detail::kernel_cpu_time_snapshot>(
_nb_core);
} else {
return std::make_unique<check_cpu_detail::pdh_cpu_time_snapshot>(
_nb_core, *_pdh_counters, first_measure);
}
}

constexpr std::array<std::string_view, e_proc_stat_index::nb_field>
_sz_summary_labels = {", User ", ", System ", ", Idle ", ", Interrupt ",
", Dpc Interrupt "};

constexpr std::array<std::string_view, e_proc_stat_index::nb_field>
_sz_perfdata_name = {"user", "system", "idle", "interrupt",
"dpc_interrupt"};

/**
* @brief compute the difference between second_measure and first_measure and
* generate status, output and perfdatas
*
* @param first_measure first snapshot of /proc/stat
* @param second_measure second snapshot of /proc/stat
* @param output out plugin output
* @param perfs perfdatas
* @return e_status plugin out status
*/
e_status check_cpu::compute(
const check_cpu_detail::cpu_time_snapshot<
check_cpu_detail::e_proc_stat_index::nb_field>& first_measure,
const check_cpu_detail::cpu_time_snapshot<
check_cpu_detail::e_proc_stat_index::nb_field>& second_measure,
std::string* output, std::list<common::perfdata>* perfs) {
output->reserve(256 * _nb_core);

return _compute(first_measure, second_measure, _sz_summary_labels.data(),
_sz_perfdata_name.data(), output, perfs);
}
constexpr std::array<std::string_view, e_proc_stat_index::nb_field>
_sz_summary_labels = {", User ", ", System ", ", Idle ", ", Interrupt ",
", Dpc Interrupt "};

constexpr std::array<std::string_view, e_proc_stat_index::nb_field>
_sz_perfdata_name = {"user", "system", "idle", "interrupt",
"dpc_interrupt"};

/**
* @brief compute the difference between second_measure and first_measure and
* generate status, output and perfdatas
*
* @param first_measure first snapshot of /proc/stat
* @param second_measure second snapshot of /proc/stat
* @param output out plugin output
* @param perfs perfdatas
* @return e_status plugin out status
*/
e_status check_cpu::compute(
const check_cpu_detail::cpu_time_snapshot<
check_cpu_detail::e_proc_stat_index::nb_field>& first_measure,
const check_cpu_detail::cpu_time_snapshot<
check_cpu_detail::e_proc_stat_index::nb_field>& second_measure,
std::string* output,
std::list<common::perfdata>* perfs) {
output->reserve(256 * _nb_core);

return _compute(first_measure, second_measure, _sz_summary_labels.data(),
_sz_perfdata_name.data(), output, perfs);
}
1 change: 0 additions & 1 deletion agent/native_windows/src/check_uptime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include <windows.h>
#include <chrono>
#include <exception>

#include "absl/container/flat_hash_map.h"
#include "check_uptime.hh"
Expand Down
2 changes: 1 addition & 1 deletion broker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ target_link_libraries(roker rokerbase crypto ssl pthread dl)

# Standalone binary.
add_executable(cbd ${SRC_DIR}/main.cc)
add_dependencies(cbd multiplexing centreon_common)
add_dependencies(cbd multiplexing centreon_common pb_neb_lib)

# Flags needed to include all symbols in binary.
target_link_libraries(
Expand Down
16 changes: 8 additions & 8 deletions tests/broker-engine/cma.robot
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ BEOTEL_CENTREON_AGENT_CHECK_NATIVE_CPU
#a small threshold to make service_1 warning
Ctn Engine Config Replace Value In Services ${0} service_1 check_command otel_check2

Ctn Engine Config Add Command ${0} otel_check2 {"check": "cpu_percentage", "args": {"warning-average" : "0.1"}} OTEL connector
Ctn Engine Config Add Command ${0} otel_check2 {"check": "cpu_percentage", "args": {"warning-average" : "0.01"}} OTEL connector

Ctn Reload Engine
${result} Ctn Check Service Resource Status With Timeout host_1 service_1 1 60 ANY
Expand All @@ -405,7 +405,7 @@ BEOTEL_CENTREON_AGENT_CHECK_NATIVE_CPU
#a small threshold to make service_1 critical
Ctn Engine Config Replace Value In Services ${0} service_1 check_command otel_check3

Ctn Engine Config Add Command ${0} otel_check3 {"check": "cpu_percentage", "args": {"critical-average" : "0.2", "warning-average" : "0.1"}} OTEL connector
Ctn Engine Config Add Command ${0} otel_check3 {"check": "cpu_percentage", "args": {"critical-average" : "0.02", "warning-average" : "0.01"}} OTEL connector

Ctn Reload Engine
${result} Ctn Check Service Resource Status With Timeout host_1 service_1 2 60 ANY
Expand Down Expand Up @@ -557,11 +557,11 @@ Ctn Create Cert And Init
[Documentation] create key and certificates used by agent and engine on linux side
${host_name} Ctn Get Hostname
${run_env} Ctn Run Env
# IF "${run_env}" == "WSL"
# Copy File ../server_grpc.key /tmp/server_grpc.key
# Copy File ../server_grpc.crt /tmp/server_grpc.crt
# ELSE
# Ctn Create Key And Certificate ${host_name} /tmp/server_grpc.key /tmp/server_grpc.crt
# END
IF "${run_env}" == "WSL"
Copy File ../server_grpc.key /tmp/server_grpc.key
Copy File ../server_grpc.crt /tmp/server_grpc.crt
ELSE
Ctn Create Key And Certificate ${host_name} /tmp/server_grpc.key /tmp/server_grpc.crt
END

Ctn Clean Before Suite

0 comments on commit 25de6e8

Please sign in to comment.