-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ef2a2f
commit f764bb0
Showing
52 changed files
with
3,168 additions
and
756 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
# | ||
# 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] | ||
# | ||
|
||
# Global options. | ||
project("Centreon agent" C CXX) | ||
|
||
# Set directories. | ||
set(INCLUDE_DIR "${PROJECT_SOURCE_DIR}/inc/com/centreon/agent") | ||
set(SRC_DIR "${PROJECT_SOURCE_DIR}/src") | ||
|
||
|
||
add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1") | ||
add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE) | ||
|
||
option(WITH_LIBCXX "compiles and link cbd with clang++/libc++") | ||
|
||
if(WITH_LIBCXX) | ||
set(CMAKE_CXX_COMPILER "clang++") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") | ||
|
||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -Werror -O1 | ||
# -fno-omit-frame-pointer") | ||
endif() | ||
|
||
#otel service | ||
set(service_files | ||
opentelemetry/proto/collector/metrics/v1/metrics_service | ||
) | ||
|
||
foreach(name IN LISTS service_files) | ||
set(proto_file "${name}.proto") | ||
add_custom_command( | ||
OUTPUT "${SRC_DIR}/${name}.grpc.pb.cc" | ||
COMMENT "Generating grpc files of the otl service file ${proto_file}" | ||
DEPENDS opentelemetry-proto-files | ||
COMMAND | ||
${Protobuf_PROTOC_EXECUTABLE} ARGS | ||
--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN} | ||
--proto_path=${CMAKE_SOURCE_DIR}/opentelemetry-proto | ||
--grpc_out=${SRC_DIR} ${proto_file} | ||
VERBATIM | ||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) | ||
|
||
endforeach() | ||
|
||
set(otl_protobuf_files | ||
opentelemetry/proto/collector/metrics/v1/metrics_service | ||
opentelemetry/proto/metrics/v1/metrics | ||
opentelemetry/proto/common/v1/common | ||
opentelemetry/proto/resource/v1/resource | ||
) | ||
foreach(name IN LISTS otl_protobuf_files) | ||
set(proto_file "${name}.proto") | ||
add_custom_command( | ||
OUTPUT "${SRC_DIR}/${name}.pb.cc" | ||
COMMENT "Generating interface files of the otl file ${proto_file}" | ||
DEPENDS opentelemetry-proto-files | ||
COMMAND | ||
${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${SRC_DIR} | ||
--proto_path=${CMAKE_SOURCE_DIR}/opentelemetry-proto ${proto_file} | ||
VERBATIM) | ||
endforeach() | ||
|
||
|
||
#centreon_agent server and client | ||
add_custom_command( | ||
DEPENDS ${PROJECT_SOURCE_DIR}/proto/agent.proto | ||
COMMENT "Generating interface files of the conf centreon_agent proto file (grpc)" | ||
OUTPUT ${SRC_DIR}/agent.grpc.pb.cc | ||
COMMAND | ||
${Protobuf_PROTOC_EXECUTABLE} ARGS | ||
--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN} | ||
--proto_path=${PROJECT_SOURCE_DIR}/proto --proto_path=${CMAKE_SOURCE_DIR}/opentelemetry-proto | ||
--grpc_out=${SRC_DIR} ${PROJECT_SOURCE_DIR}/proto/agent.proto | ||
DEPENDS ${PROJECT_SOURCE_DIR}/proto/agent.proto | ||
COMMENT "Generating interface files of the conf centreon_agent proto file (protobuf)" | ||
OUTPUT ${SRC_DIR}/agent.pb.cc | ||
COMMAND | ||
${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${SRC_DIR} | ||
--proto_path=${PROJECT_SOURCE_DIR}/proto --proto_path=${CMAKE_SOURCE_DIR}/opentelemetry-proto | ||
${PROJECT_SOURCE_DIR}/proto/agent.proto | ||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) | ||
|
||
|
||
add_library(centreon_agent_lib STATIC | ||
${SRC_DIR}/agent.grpc.pb.cc | ||
${SRC_DIR}/agent.pb.cc | ||
${SRC_DIR}/check.cc | ||
${SRC_DIR}/check_exec.cc | ||
${SRC_DIR}/opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.cc | ||
${SRC_DIR}/opentelemetry/proto/collector/metrics/v1/metrics_service.pb.cc | ||
${SRC_DIR}/opentelemetry/proto/metrics/v1/metrics.pb.cc | ||
${SRC_DIR}/opentelemetry/proto/common/v1/common.pb.cc | ||
${SRC_DIR}/opentelemetry/proto/resource/v1/resource.pb.cc | ||
${SRC_DIR}/scheduler.cc | ||
) | ||
|
||
include_directories( | ||
${INCLUDE_DIR} | ||
${SRC_DIR} | ||
${CMAKE_SOURCE_DIR}/common/inc | ||
) | ||
|
||
target_precompile_headers(centreon_agent_lib PRIVATE precomp_inc/precomp.hh) | ||
|
||
add_executable(centreon_agent ${SRC_DIR}/main.cc) | ||
|
||
target_link_libraries( | ||
centreon_agent PRIVATE | ||
-L${PROTOBUF_LIB_DIR} | ||
gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts | ||
# cerpc | ||
# berpc | ||
centreon_agent_lib | ||
centreon_common | ||
-L${Boost_LIBRARY_DIR_RELEASE} | ||
boost_program_options | ||
fmt::fmt) | ||
|
||
target_precompile_headers(centreon_agent REUSE_FROM centreon_agent_lib) | ||
|
||
target_include_directories(centreon_agent PRIVATE | ||
${INCLUDE_DIR} | ||
${SRC_DIR} | ||
${CMAKE_SOURCE_DIR}/common/inc | ||
) | ||
|
||
install(TARGETS centreon_agent RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") | ||
|
||
if(WITH_TESTING) | ||
add_subdirectory(test) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Centreon Agent documentation {#mainpage} | ||
|
||
## Introduction | ||
|
||
The goal of this program is to execute checks in both windows and linux OS | ||
It's full asynchronous, excepted grpc layers, it's single threaded and you won't find mutex in code. | ||
|
||
## Configuration | ||
configuration is given by Engine by a AgentConfiguration sent over grpc | ||
|
||
## Scheduler | ||
|
||
We trie to spread checks over check_period. | ||
Example: We have 10 checks to execute during one second. check1 will start at now + 0.1s, second at now + 0.2s.. | ||
In case of check duration is too long, we might exceed maximum of concurrent checks. In that case checks will b executed as soon one will be ended. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/** | ||
* 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_CHECK_HH | ||
#define CENTREON_AGENT_CHECK_HH | ||
|
||
#include "agent.pb.h" | ||
#include "com/centreon/common/perfdata.hh" | ||
|
||
namespace com::centreon::agent { | ||
|
||
using engine_to_agent_request_ptr = | ||
std::shared_ptr<com::centreon::agent::EngineToAgent>; | ||
|
||
using time_point = std::chrono::system_clock::time_point; | ||
using duration = std::chrono::system_clock::duration; | ||
|
||
/** | ||
* @brief base class for check | ||
* start_expected is set by scheduler and increased by check_period on each | ||
* check | ||
* | ||
*/ | ||
class check : public std::enable_shared_from_this<check> { | ||
public: | ||
using completion_handler = std::function<void( | ||
const std::shared_ptr<check>& caller, | ||
int status, | ||
const std::list<com::centreon::common::perfdata>& perfdata, | ||
const std::list<std::string>& outputs)>; | ||
|
||
private: | ||
time_point _start_expected; | ||
const std::string& _host; | ||
const std::string& _service; | ||
const std::string& _command_name; | ||
const std::string& _command_line; | ||
// by owning a reference to the original request, we can get only reference to | ||
// host, service and command_line | ||
engine_to_agent_request_ptr _conf; | ||
|
||
asio::system_timer _time_out_timer; | ||
|
||
void _start_timeout_timer(const duration& timeout); | ||
|
||
bool _running_check = false; | ||
unsigned _running_check_index = 0; | ||
completion_handler _completion_handler; | ||
|
||
protected: | ||
std::shared_ptr<asio::io_context> _io_context; | ||
std::shared_ptr<spdlog::logger> _logger; | ||
|
||
unsigned _get_running_check_index() const { return _running_check_index; } | ||
const completion_handler& _get_completion_handler() const { | ||
return _completion_handler; | ||
} | ||
|
||
virtual void _timeout_timer_handler(const boost::system::error_code& err, | ||
unsigned start_check_index); | ||
|
||
public: | ||
using pointer = std::shared_ptr<check>; | ||
|
||
template <typename handler_type> | ||
check(const std::shared_ptr<asio::io_context>& io_context, | ||
const std::shared_ptr<spdlog::logger>& logger, | ||
time_point exp, | ||
const std::string& hst, | ||
const std::string& serv, | ||
const std::string& command_name, | ||
const std::string& cmd_line, | ||
const engine_to_agent_request_ptr& cnf, | ||
handler_type&& handler) | ||
: _start_expected(exp), | ||
_host(hst), | ||
_service(serv), | ||
_command_name(command_name), | ||
_command_line(cmd_line), | ||
_conf(cnf), | ||
_io_context(io_context), | ||
_logger(logger), | ||
_time_out_timer(*io_context), | ||
_completion_handler(handler) {} | ||
|
||
virtual ~check() = default; | ||
|
||
struct pointer_compare { | ||
bool operator()(const check::pointer& left, | ||
const check::pointer& right) const { | ||
return left->_start_expected < right->_start_expected; | ||
} | ||
}; | ||
|
||
void add_duration_to_start_expected(const duration& to_add); | ||
|
||
time_point get_start_expected() const { return _start_expected; } | ||
|
||
const std::string& get_host() const { return _host; } | ||
|
||
const std::string& get_service() const { return _service; } | ||
|
||
const std::string& get_command_name() const { return _command_name; } | ||
|
||
const std::string& get_command_line() const { return _command_line; } | ||
|
||
const engine_to_agent_request_ptr& get_conf() const { return _conf; } | ||
|
||
void on_completion(unsigned start_check_index, | ||
unsigned status, | ||
const std::list<com::centreon::common::perfdata>& perfdata, | ||
const std::list<std::string>& outputs); | ||
|
||
virtual void start_check(const duration& timeout); | ||
}; | ||
|
||
} // namespace com::centreon::agent | ||
|
||
#endif |
Oops, something went wrong.