Skip to content

Commit bdc89af

Browse files
* centreon-agent => centreon-monitoring-agent
* 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
1 parent b4b14a7 commit bdc89af

File tree

93 files changed

+6268
-977
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+6268
-977
lines changed

.github/workflows/windows-agent.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Centreon Monitoring Agent Windows packaging
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
5+
cancel-in-progress: true
6+
7+
on:
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
runs-on: windows-latest
13+
steps:
14+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
15+
- uses: ilammy/[email protected]
16+
17+
- name: install vcpkg
18+
run: |
19+
git clone --depth 1 https://github.com/microsoft/vcpkg $HOME/vcpkg
20+
cd $HOME/vcpkg
21+
bootstrap-vcpkg.bat

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ option(WITH_MALLOC_TRACE "compile centreon-malloc-trace library." OFF)
5959
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -stdlib=libc++")
6060
# set(CMAKE_CXX_COMPILER "clang++")
6161
add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1")
62+
add_definitions("-DBOOST_PROCESS_USE_STD_FS=1")
6263

6364
option(DEBUG_ROBOT OFF)
6465

agent/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ add_custom_command(
101101
add_library(centagent_lib STATIC
102102
${SRC_DIR}/agent.grpc.pb.cc
103103
${SRC_DIR}/agent.pb.cc
104+
${SRC_DIR}/bireactor.cc
104105
${SRC_DIR}/check.cc
105106
${SRC_DIR}/check_exec.cc
106107
${SRC_DIR}/opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.cc
@@ -110,13 +111,16 @@ add_library(centagent_lib STATIC
110111
${SRC_DIR}/opentelemetry/proto/resource/v1/resource.pb.cc
111112
${SRC_DIR}/config.cc
112113
${SRC_DIR}/scheduler.cc
114+
${SRC_DIR}/streaming_client.cc
115+
${SRC_DIR}/streaming_server.cc
113116
)
114117

115118
include_directories(
116119
${INCLUDE_DIR}
117120
${SRC_DIR}
118121
${CMAKE_SOURCE_DIR}/common/inc
119122
${CMAKE_SOURCE_DIR}/common/grpc/inc
123+
${CMAKE_SOURCE_DIR}/common/process/inc
120124
)
121125

122126
target_precompile_headers(centagent_lib PRIVATE precomp_inc/precomp.hh)
@@ -135,16 +139,12 @@ target_link_libraries(
135139
centreon_process
136140
-L${Boost_LIBRARY_DIR_RELEASE}
137141
boost_program_options
138-
fmt::fmt)
142+
fmt::fmt
143+
stdc++fs
144+
)
139145

140146
target_precompile_headers(${CENTREON_AGENT} REUSE_FROM centagent_lib)
141147

142-
target_include_directories(${CENTREON_AGENT} PRIVATE
143-
${INCLUDE_DIR}
144-
${SRC_DIR}
145-
${CMAKE_SOURCE_DIR}/common/inc
146-
)
147-
148148
set(AGENT_VAR_LOG_DIR
149149
"${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-monitoring-agent")
150150

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* Copyright 2024 Centreon
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* For more information : [email protected]
17+
*/
18+
19+
#ifndef CENTREON_AGENT_BIREACTOR_HH
20+
#define CENTREON_AGENT_BIREACTOR_HH
21+
22+
#include "agent.grpc.pb.h"
23+
24+
namespace com::centreon::agent {
25+
26+
template <class bireactor_class>
27+
class bireactor
28+
: public bireactor_class,
29+
public std::enable_shared_from_this<bireactor<bireactor_class>> {
30+
private:
31+
static std::set<std::shared_ptr<bireactor>> _instances;
32+
static std::mutex _instances_m;
33+
34+
bool _write_pending;
35+
std::deque<std::shared_ptr<MessageFromAgent>> _write_queue;
36+
std::shared_ptr<MessageToAgent> _read_current;
37+
38+
const std::string_view _class_name;
39+
40+
const std::string _peer;
41+
42+
protected:
43+
std::shared_ptr<boost::asio::io_context> _io_context;
44+
std::shared_ptr<spdlog::logger> _logger;
45+
46+
bool _alive;
47+
/**
48+
* @brief All attributes of this object are protected by this mutex
49+
*
50+
*/
51+
mutable std::mutex _protect;
52+
53+
public:
54+
bireactor(const std::shared_ptr<boost::asio::io_context>& io_context,
55+
const std::shared_ptr<spdlog::logger>& logger,
56+
const std::string_view& class_name,
57+
const std::string& peer);
58+
59+
virtual ~bireactor();
60+
61+
static void register_stream(const std::shared_ptr<bireactor>& strm);
62+
63+
void start_read();
64+
65+
void start_write();
66+
void write(const std::shared_ptr<MessageFromAgent>& request);
67+
68+
// bireactor part
69+
void OnReadDone(bool ok) override;
70+
71+
virtual void on_incomming_request(
72+
const std::shared_ptr<MessageToAgent>& request) = 0;
73+
74+
virtual void on_error() = 0;
75+
76+
void OnWriteDone(bool ok) override;
77+
78+
// server version
79+
void OnDone();
80+
// client version
81+
void OnDone(const ::grpc::Status& /*s*/);
82+
83+
virtual void shutdown();
84+
};
85+
86+
} // namespace com::centreon::agent
87+
88+
#endif

agent/inc/com/centreon/agent/check_exec.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#define CENTREON_AGENT_CHECK_EXEC_HH
2121

2222
#include "check.hh"
23-
#include "com/centreon/common/process.hh"
23+
#include "com/centreon/common/process/process.hh"
2424

2525
namespace com::centreon::agent {
2626

agent/inc/com/centreon/agent/config.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* Copyright 2024 Centreon
43
* Licensed under the Apache License, Version 2.0(the "License");
@@ -15,6 +14,7 @@
1514
*
1615
* For more information : [email protected]
1716
*/
17+
1818
#ifndef CENTREON_AGENT_CONFIG_HH
1919
#define CENTREON_AGENT_CONFIG_HH
2020

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

2525
class config {
2626
public:
27-
enum log_type { to_stdout, to_file };
27+
enum log_type { to_stdout, to_file, to_event_log };
2828

2929
static const std::string_view config_schema;
3030

agent/inc/com/centreon/agent/scheduler.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ class scheduler : public std::enable_shared_from_this<scheduler> {
5757
// pointers in this struct point to _current_request
5858
struct scope_metric_request {
5959
::opentelemetry::proto::metrics::v1::ScopeMetrics* scope_metric;
60-
absl::flat_hash_map<std::string /*metric name*/,
61-
::opentelemetry::proto::metrics::v1::Metric*>
60+
std::unordered_map<std::string /*metric name*/,
61+
::opentelemetry::proto::metrics::v1::Metric*>
6262
metrics;
6363
};
6464

6565
// one serv => one scope_metric => several metrics
66-
absl::flat_hash_map<std::string, scope_metric_request> _serv_to_scope_metrics;
66+
std::unordered_map<std::string, scope_metric_request> _serv_to_scope_metrics;
6767

6868
std::shared_ptr<asio::io_context> _io_context;
6969
std::shared_ptr<spdlog::logger> _logger;
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**
2+
* Copyright 2024 Centreon
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* For more information : [email protected]
17+
*/
18+
19+
#ifndef CENTREON_AGENT_STREAMING_CLIENT_HH
20+
#define CENTREON_AGENT_STREAMING_CLIENT_HH
21+
22+
#include "com/centreon/common/grpc/grpc_client.hh"
23+
24+
#include "bireactor.hh"
25+
#include "scheduler.hh"
26+
27+
namespace com::centreon::agent {
28+
29+
class streaming_client;
30+
31+
class client_reactor
32+
: public bireactor<
33+
::grpc::ClientBidiReactor<MessageFromAgent, MessageToAgent>> {
34+
std::weak_ptr<streaming_client> _parent;
35+
::grpc::ClientContext _context;
36+
37+
public:
38+
client_reactor(const std::shared_ptr<boost::asio::io_context>& io_context,
39+
const std::shared_ptr<spdlog::logger>& logger,
40+
const std::shared_ptr<streaming_client>& parent,
41+
const std::string& peer);
42+
43+
std::shared_ptr<client_reactor> shared_from_this() {
44+
return std::static_pointer_cast<client_reactor>(
45+
bireactor<::grpc::ClientBidiReactor<MessageFromAgent, MessageToAgent>>::
46+
shared_from_this());
47+
}
48+
49+
::grpc::ClientContext& get_context() { return _context; }
50+
51+
void on_incomming_request(
52+
const std::shared_ptr<MessageToAgent>& request) override;
53+
54+
void on_error() override;
55+
56+
void shutdown() override;
57+
};
58+
59+
/**
60+
* @brief this object not only manages connection to engine, but also embed
61+
* check scheduler
62+
*
63+
*/
64+
class streaming_client : public common::grpc::grpc_client_base,
65+
public std::enable_shared_from_this<streaming_client> {
66+
std::shared_ptr<boost::asio::io_context> _io_context;
67+
std::shared_ptr<spdlog::logger> _logger;
68+
std::string _supervised_host;
69+
70+
std::unique_ptr<AgentService::Stub> _stub;
71+
72+
std::shared_ptr<client_reactor> _reactor;
73+
std::shared_ptr<scheduler> _sched;
74+
75+
/**
76+
* @brief All attributes of this object are protected by this mutex
77+
*
78+
*/
79+
std::mutex _protect;
80+
81+
void _create_reactor();
82+
83+
void _start();
84+
85+
void _send(const std::shared_ptr<MessageFromAgent>& request);
86+
87+
public:
88+
streaming_client(const std::shared_ptr<boost::asio::io_context>& io_context,
89+
const std::shared_ptr<spdlog::logger>& logger,
90+
const std::shared_ptr<common::grpc::grpc_config>& conf,
91+
const std::string& supervised_host);
92+
93+
static std::shared_ptr<streaming_client> load(
94+
const std::shared_ptr<boost::asio::io_context>& io_context,
95+
const std::shared_ptr<spdlog::logger>& logger,
96+
const std::shared_ptr<common::grpc::grpc_config>& conf,
97+
const std::string& supervised_host);
98+
99+
void on_incomming_request(const std::shared_ptr<client_reactor>& caller,
100+
const std::shared_ptr<MessageToAgent>& request);
101+
void on_error(const std::shared_ptr<client_reactor>& caller);
102+
103+
void shutdown();
104+
105+
// use only for tests
106+
engine_to_agent_request_ptr get_last_message_to_agent() const {
107+
return _sched->get_last_message_to_agent();
108+
}
109+
};
110+
111+
} // namespace com::centreon::agent
112+
113+
#endif

0 commit comments

Comments
 (0)