Skip to content

Commit

Permalink
* centreon-agent => centreon-monitoring-agent
Browse files Browse the repository at this point in the history
* telegraf conf accepts only one host
add scheduler, check and check_exec class to agent

* otel tests checks resources table

* engine accept connections from centreon monitoring agent

add reverse client in opentelemetry module

* no overlays, provide our own launcher

move utf8 to common and some fixes (#1502)

add windows-agent.yaml (#1525)

* add windows-agent.yaml

* fix muxer issue
  • Loading branch information
jean-christophe81 committed Aug 27, 2024
1 parent 5b51013 commit df2b0db
Show file tree
Hide file tree
Showing 93 changed files with 6,268 additions and 977 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/windows-agent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Centreon Monitoring Agent Windows packaging

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

on:
workflow_dispatch:

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: ilammy/[email protected]

- name: install vcpkg
run: |
git clone --depth 1 https://github.com/microsoft/vcpkg $HOME/vcpkg
cd $HOME/vcpkg
bootstrap-vcpkg.bat
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ option(WITH_MALLOC_TRACE "compile centreon-malloc-trace library." OFF)
# 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)

Expand Down
14 changes: 7 additions & 7 deletions agent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ add_custom_command(
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
Expand All @@ -110,13 +111,16 @@ add_library(centagent_lib STATIC
${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
)

include_directories(
${INCLUDE_DIR}
${SRC_DIR}
${CMAKE_SOURCE_DIR}/common/inc
${CMAKE_SOURCE_DIR}/common/grpc/inc
${CMAKE_SOURCE_DIR}/common/process/inc
)

target_precompile_headers(centagent_lib PRIVATE precomp_inc/precomp.hh)
Expand All @@ -135,16 +139,12 @@ target_link_libraries(
centreon_process
-L${Boost_LIBRARY_DIR_RELEASE}
boost_program_options
fmt::fmt)
fmt::fmt
stdc++fs
)

target_precompile_headers(${CENTREON_AGENT} REUSE_FROM centagent_lib)

target_include_directories(${CENTREON_AGENT} PRIVATE
${INCLUDE_DIR}
${SRC_DIR}
${CMAKE_SOURCE_DIR}/common/inc
)

set(AGENT_VAR_LOG_DIR
"${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-monitoring-agent")

Expand Down
88 changes: 88 additions & 0 deletions agent/inc/com/centreon/agent/bireactor.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* 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 : [email protected]
*/

#ifndef CENTREON_AGENT_BIREACTOR_HH
#define CENTREON_AGENT_BIREACTOR_HH

#include "agent.grpc.pb.h"

namespace com::centreon::agent {

template <class bireactor_class>
class bireactor
: public bireactor_class,
public std::enable_shared_from_this<bireactor<bireactor_class>> {
private:
static std::set<std::shared_ptr<bireactor>> _instances;
static std::mutex _instances_m;

bool _write_pending;
std::deque<std::shared_ptr<MessageFromAgent>> _write_queue;
std::shared_ptr<MessageToAgent> _read_current;

const std::string_view _class_name;

const std::string _peer;

protected:
std::shared_ptr<boost::asio::io_context> _io_context;
std::shared_ptr<spdlog::logger> _logger;

bool _alive;
/**
* @brief All attributes of this object are protected by this mutex
*
*/
mutable std::mutex _protect;

public:
bireactor(const std::shared_ptr<boost::asio::io_context>& io_context,
const std::shared_ptr<spdlog::logger>& logger,
const std::string_view& class_name,
const std::string& peer);

virtual ~bireactor();

static void register_stream(const std::shared_ptr<bireactor>& strm);

void start_read();

void start_write();
void write(const std::shared_ptr<MessageFromAgent>& request);

// bireactor part
void OnReadDone(bool ok) override;

virtual void on_incomming_request(
const std::shared_ptr<MessageToAgent>& request) = 0;

virtual void on_error() = 0;

void OnWriteDone(bool ok) override;

// server version
void OnDone();
// client version
void OnDone(const ::grpc::Status& /*s*/);

virtual void shutdown();
};

} // namespace com::centreon::agent

#endif
2 changes: 1 addition & 1 deletion agent/inc/com/centreon/agent/check_exec.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define CENTREON_AGENT_CHECK_EXEC_HH

#include "check.hh"
#include "com/centreon/common/process.hh"
#include "com/centreon/common/process/process.hh"

namespace com::centreon::agent {

Expand Down
4 changes: 2 additions & 2 deletions agent/inc/com/centreon/agent/config.hh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Copyright 2024 Centreon
* Licensed under the Apache License, Version 2.0(the "License");
Expand All @@ -15,6 +14,7 @@
*
* For more information : [email protected]
*/

#ifndef CENTREON_AGENT_CONFIG_HH
#define CENTREON_AGENT_CONFIG_HH

Expand All @@ -24,7 +24,7 @@ namespace com::centreon::agent {

class config {
public:
enum log_type { to_stdout, to_file };
enum log_type { to_stdout, to_file, to_event_log };

static const std::string_view config_schema;

Expand Down
6 changes: 3 additions & 3 deletions agent/inc/com/centreon/agent/scheduler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class scheduler : public std::enable_shared_from_this<scheduler> {
// pointers in this struct point to _current_request
struct scope_metric_request {
::opentelemetry::proto::metrics::v1::ScopeMetrics* scope_metric;
absl::flat_hash_map<std::string /*metric name*/,
::opentelemetry::proto::metrics::v1::Metric*>
std::unordered_map<std::string /*metric name*/,
::opentelemetry::proto::metrics::v1::Metric*>
metrics;
};

// one serv => one scope_metric => several metrics
absl::flat_hash_map<std::string, scope_metric_request> _serv_to_scope_metrics;
std::unordered_map<std::string, scope_metric_request> _serv_to_scope_metrics;

std::shared_ptr<asio::io_context> _io_context;
std::shared_ptr<spdlog::logger> _logger;
Expand Down
113 changes: 113 additions & 0 deletions agent/inc/com/centreon/agent/streaming_client.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* 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 : [email protected]
*/

#ifndef CENTREON_AGENT_STREAMING_CLIENT_HH
#define CENTREON_AGENT_STREAMING_CLIENT_HH

#include "com/centreon/common/grpc/grpc_client.hh"

#include "bireactor.hh"
#include "scheduler.hh"

namespace com::centreon::agent {

class streaming_client;

class client_reactor
: public bireactor<
::grpc::ClientBidiReactor<MessageFromAgent, MessageToAgent>> {
std::weak_ptr<streaming_client> _parent;
::grpc::ClientContext _context;

public:
client_reactor(const std::shared_ptr<boost::asio::io_context>& io_context,
const std::shared_ptr<spdlog::logger>& logger,
const std::shared_ptr<streaming_client>& parent,
const std::string& peer);

std::shared_ptr<client_reactor> shared_from_this() {
return std::static_pointer_cast<client_reactor>(
bireactor<::grpc::ClientBidiReactor<MessageFromAgent, MessageToAgent>>::
shared_from_this());
}

::grpc::ClientContext& get_context() { return _context; }

void on_incomming_request(
const std::shared_ptr<MessageToAgent>& request) override;

void on_error() override;

void shutdown() override;
};

/**
* @brief this object not only manages connection to engine, but also embed
* check scheduler
*
*/
class streaming_client : public common::grpc::grpc_client_base,
public std::enable_shared_from_this<streaming_client> {
std::shared_ptr<boost::asio::io_context> _io_context;
std::shared_ptr<spdlog::logger> _logger;
std::string _supervised_host;

std::unique_ptr<AgentService::Stub> _stub;

std::shared_ptr<client_reactor> _reactor;
std::shared_ptr<scheduler> _sched;

/**
* @brief All attributes of this object are protected by this mutex
*
*/
std::mutex _protect;

void _create_reactor();

void _start();

void _send(const std::shared_ptr<MessageFromAgent>& request);

public:
streaming_client(const std::shared_ptr<boost::asio::io_context>& io_context,
const std::shared_ptr<spdlog::logger>& logger,
const std::shared_ptr<common::grpc::grpc_config>& conf,
const std::string& supervised_host);

static std::shared_ptr<streaming_client> load(
const std::shared_ptr<boost::asio::io_context>& io_context,
const std::shared_ptr<spdlog::logger>& logger,
const std::shared_ptr<common::grpc::grpc_config>& conf,
const std::string& supervised_host);

void on_incomming_request(const std::shared_ptr<client_reactor>& caller,
const std::shared_ptr<MessageToAgent>& request);
void on_error(const std::shared_ptr<client_reactor>& caller);

void shutdown();

// use only for tests
engine_to_agent_request_ptr get_last_message_to_agent() const {
return _sched->get_last_message_to_agent();
}
};

} // namespace com::centreon::agent

#endif
Loading

0 comments on commit df2b0db

Please sign in to comment.