Skip to content

Commit

Permalink
copy agent from develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-christophe81 committed Dec 20, 2024
1 parent e505ca3 commit 79a27ea
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 28 deletions.
4 changes: 2 additions & 2 deletions agent/inc/com/centreon/agent/scheduler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ scheduler::scheduler(
const std::shared_ptr<com::centreon::agent::MessageToAgent>& config,
sender&& met_sender,
chck_builder&& builder)
: _metric_sender(met_sender),
_io_context(io_context),
: _io_context(io_context),
_logger(logger),
_supervised_host(supervised_host),
_metric_sender(met_sender),
_send_timer(*io_context),
_check_timer(*io_context),
_check_builder(builder),
Expand Down
6 changes: 3 additions & 3 deletions agent/src/bireactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ bireactor<bireactor_class>::bireactor(
const std::string_view& class_name,
const std::string& peer)
: _write_pending(false),
_alive(true),
_class_name(class_name),
_peer(peer),
_io_context(io_context),
_logger(logger) {
_logger(logger),
_alive(true) {
SPDLOG_LOGGER_DEBUG(_logger, "create {} this={:p} peer:{}", _class_name,
static_cast<const void*>(this), _peer);
}
Expand Down Expand Up @@ -204,4 +204,4 @@ template class bireactor<
template class bireactor<
::grpc::ServerBidiReactor<MessageToAgent, MessageFromAgent>>;

} // namespace com::centreon::agent
} // namespace com::centreon::agent
8 changes: 4 additions & 4 deletions agent/src/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ void scheduler::stop() {
* @param outputs
*/
void scheduler::_store_result_in_metrics(
const check::pointer& check,
unsigned status,
const std::list<com::centreon::common::perfdata>& perfdata,
const std::list<std::string>& outputs) {
[[maybe_unused]] const check::pointer& check,
[[maybe_unused]] unsigned status,
[[maybe_unused]] const std::list<com::centreon::common::perfdata>& perfdata,
[[maybe_unused]] const std::list<std::string>& outputs) {
// auto scope_metrics =
// get_scope_metrics(check->get_host(), check->get_service());
// unsigned now = std::chrono::duration_cast<std::chrono::nanoseconds>(
Expand Down
2 changes: 1 addition & 1 deletion agent/src/streaming_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void streaming_client::_send(const std::shared_ptr<MessageFromAgent>& request) {
* @param request
*/
void streaming_client::on_incomming_request(
const std::shared_ptr<client_reactor>& caller,
const std::shared_ptr<client_reactor>& caller [[maybe_unused]],
const std::shared_ptr<MessageToAgent>& request) {
// incoming request is used in main thread
_io_context->post([request, sched = _sched]() { sched->update(request); });
Expand Down
23 changes: 15 additions & 8 deletions agent/test/check_exec_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ TEST(check_exec_test, echo) {
std::shared_ptr<check_exec> check = check_exec::load(
g_io_context, spdlog::default_logger(), {}, {}, serv, cmd_name,
command_line, engine_to_agent_request_ptr(),
[&](const std::shared_ptr<com::centreon::agent::check>& caller,
[&]([[maybe_unused]] const std::shared_ptr<com::centreon::agent::check>&
caller,
int statuss,
const std::list<com::centreon::common::perfdata>& perfdata,
[[maybe_unused]] const std::list<com::centreon::common::perfdata>&
perfdata,
const std::list<std::string>& output) {
{
std::lock_guard l(mut);
Expand All @@ -78,9 +80,11 @@ TEST(check_exec_test, timeout) {
std::shared_ptr<check_exec> check = check_exec::load(
g_io_context, spdlog::default_logger(), {}, {}, serv, cmd_name,
command_line, engine_to_agent_request_ptr(),
[&](const std::shared_ptr<com::centreon::agent::check>& caller,
[&]([[maybe_unused]] const std::shared_ptr<com::centreon::agent::check>&
caller,
int statuss,
const std::list<com::centreon::common::perfdata>& perfdata,
[[maybe_unused]] const std::list<com::centreon::common::perfdata>&
perfdata,
const std::list<std::string>& output) {
status = statuss;
outputs = output;
Expand Down Expand Up @@ -123,9 +127,11 @@ TEST(check_exec_test, bad_command) {
std::shared_ptr<check_exec> check = check_exec::load(
g_io_context, spdlog::default_logger(), {}, {}, serv, cmd_name,
command_line, engine_to_agent_request_ptr(),
[&](const std::shared_ptr<com::centreon::agent::check>& caller,
[&]([[maybe_unused]] const std::shared_ptr<com::centreon::agent::check>&
caller,
int statuss,
const std::list<com::centreon::common::perfdata>& perfdata,
[[maybe_unused]] const std::list<com::centreon::common::perfdata>&
perfdata,
const std::list<std::string>& output) {
{
std::lock_guard l(mut);
Expand Down Expand Up @@ -161,8 +167,9 @@ TEST(check_exec_test, recurse_not_lock) {
g_io_context, spdlog::default_logger(), {}, {}, serv, cmd_name,
command_line, engine_to_agent_request_ptr(),
[&](const std::shared_ptr<com::centreon::agent::check>& caller, int,
const std::list<com::centreon::common::perfdata>& perfdata,
const std::list<std::string>& output) {
[[maybe_unused]] const std::list<com::centreon::common::perfdata>&
perfdata,
[[maybe_unused]] const std::list<std::string>& output) {
if (!cpt) {
++cpt;
caller->start_check(std::chrono::seconds(1));
Expand Down
4 changes: 0 additions & 4 deletions agent/test/check_linux_cpu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ TEST(proc_stat_file_test, no_threshold) {

ASSERT_EQ(perfs.size(), 5);

constexpr float nan_to_cmp = NAN;

for (const auto& perf : perfs) {
ASSERT_TRUE(std::isnan(perf.critical_low()));
ASSERT_TRUE(std::isnan(perf.critical()));
Expand Down Expand Up @@ -223,8 +221,6 @@ TEST(proc_stat_file_test, no_threshold_detailed) {
std::string output;
std::list<com::centreon::common::perfdata> perfs;

static const char* conf_doc = R"({"cpu-detailed":true})";

using namespace com::centreon::common::literals;
rapidjson::Document check_args = R"({"cpu-detailed":"true"})"_json;

Expand Down
6 changes: 4 additions & 2 deletions agent/test/check_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ TEST(check_test, timeout) {
serv, cmd_name, cmd_line, std::chrono::milliseconds(500),
[&status, &output, &handler_call_cpt, &cond](
const std::shared_ptr<check>&, unsigned statuss,
const std::list<com::centreon::common::perfdata>& perfdata,
[[maybe_unused]] const std::list<com::centreon::common::perfdata>&
perfdata,
const std::list<std::string>& outputs) {
status = statuss;
if (outputs.size() == 1) {
Expand Down Expand Up @@ -118,7 +119,8 @@ TEST(check_test, no_timeout) {
serv, cmd_name, cmd_line, std::chrono::milliseconds(100),
[&status, &output, &handler_call_cpt, &cond](
const std::shared_ptr<check>&, unsigned statuss,
const std::list<com::centreon::common::perfdata>& perfdata,
[[maybe_unused]] const std::list<com::centreon::common::perfdata>&
perfdata,
const std::list<std::string>& outputs) {
status = statuss;
if (outputs.size() == 1) {
Expand Down
9 changes: 5 additions & 4 deletions agent/test/scheduler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class tempo_check : public check {
_completion_timer.async_wait([me = shared_from_this(), this,
check_running_index =
_get_running_check_index()](
const boost::system::error_code& err) {
[[maybe_unused]] const boost::system::
error_code& err) {
SPDLOG_TRACE("end of completion timer for serv {}", get_service());
me->on_completion(
check_running_index, _command_exit_status,
Expand Down Expand Up @@ -307,7 +308,6 @@ TEST_F(scheduler_test, time_out) {
TEST_F(scheduler_test, correct_output_examplar) {
std::shared_ptr<MessageFromAgent> exported_request;
std::condition_variable export_cond;
time_point now = std::chrono::system_clock::now();
std::shared_ptr<scheduler> sched = scheduler::load(
g_io_context, spdlog::default_logger(), "my_host",
create_conf(2, 1, 2, 10, 1),
Expand Down Expand Up @@ -433,7 +433,8 @@ class concurent_check : public check {
_completion_timer.async_wait([me = shared_from_this(), this,
check_running_index =
_get_running_check_index()](
const boost::system::error_code& err) {
[[maybe_unused]] const boost::system::
error_code& err) {
active_checks.erase(this);
checked.insert(this);
SPDLOG_TRACE("end of completion timer for serv {}", get_service());
Expand All @@ -457,7 +458,7 @@ TEST_F(scheduler_test, max_concurent) {
std::shared_ptr<scheduler> sched = scheduler::load(
g_io_context, spdlog::default_logger(), "my_host",
create_conf(200, 10, 1, 10, 1),
[&](const std::shared_ptr<MessageFromAgent>& req) {},
[&]([[maybe_unused]] const std::shared_ptr<MessageFromAgent>& req) {},
[](const std::shared_ptr<asio::io_context>& io_context,
const std::shared_ptr<spdlog::logger>& logger,
time_point start_expected, duration check_interval,
Expand Down

0 comments on commit 79a27ea

Please sign in to comment.