Skip to content

Commit

Permalink
centreon_agent => centagent
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-christophe81 committed Jun 19, 2024
1 parent 8e2f51d commit 93afcbf
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/package-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ jobs:
"build/connectors/perl/centreon_connector_perl"
"build/connectors/ssh/centreon_connector_ssh"
"build/ccc/ccc"
"build/agent/centreon_agent")
"build/agent/centagent")
for file in ${exe[@]}; do
echo "Making a debug file of $file"
objcopy --only-keep-debug $file $file.debug
Expand Down
33 changes: 22 additions & 11 deletions agent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ foreach(name IN LISTS otl_protobuf_files)
endforeach()


#centreon_agent server and client
#centagent 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)"
COMMENT "Generating interface files of the conf centagent 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)"
COMMENT "Generating interface files of the conf centagent proto file (protobuf)"
OUTPUT ${SRC_DIR}/agent.pb.cc
COMMAND
${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${SRC_DIR}
Expand All @@ -97,7 +97,7 @@ add_custom_command(
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})


add_library(centreon_agent_lib STATIC
add_library(centagent_lib STATIC
${SRC_DIR}/agent.grpc.pb.cc
${SRC_DIR}/agent.pb.cc
${SRC_DIR}/bireactor.cc
Expand All @@ -120,33 +120,44 @@ include_directories(
${CMAKE_SOURCE_DIR}/common/grpc/inc
)

target_precompile_headers(centreon_agent_lib PRIVATE precomp_inc/precomp.hh)
target_precompile_headers(centagent_lib PRIVATE precomp_inc/precomp.hh)

add_executable(centreon_agent ${SRC_DIR}/main.cc)
SET(CENTREON_AGENT centagent)

add_executable(${CENTREON_AGENT} ${SRC_DIR}/main.cc)

target_link_libraries(
centreon_agent PRIVATE
${CENTREON_AGENT} PRIVATE
-L${PROTOBUF_LIB_DIR}
gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts
# cerpc
# berpc
centreon_agent_lib
centagent_lib
centreon_common
centreon_grpc
-L${Boost_LIBRARY_DIR_RELEASE}
boost_program_options
fmt::fmt)

target_precompile_headers(centreon_agent REUSE_FROM centreon_agent_lib)
target_precompile_headers(${CENTREON_AGENT} REUSE_FROM centagent_lib)

target_include_directories(centreon_agent PRIVATE
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}")
set(AGENT_VAR_LOG_DIR
"${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-agent")


install(TARGETS ${CENTREON_AGENT} RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")

if(WITH_TESTING)
add_subdirectory(test)
endif()

#if(WITH_CONF)
# add_subdirectory(conf)
#endif()

10 changes: 5 additions & 5 deletions agent/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ int main(int argc, char* argv[]) {
"max size of log file in Mo before rotate")(
"logger-max-files", po::value<unsigned>(), "max log files");

SPDLOG_INFO(
"centreon-agent start, you can decrease log level by kill -USR1 "
"{} or increase by kill -USR2 {}",
getpid(), getpid());

po::variables_map vm;

try {
Expand All @@ -143,6 +138,11 @@ int main(int argc, char* argv[]) {
return 2;
}

SPDLOG_INFO(
"centreon-agent start, you can decrease log level by kill -USR1 "
"{} or increase by kill -USR2 {}",
getpid(), getpid());

const std::string logger_name = "centreon-agent";

auto logger_file = [&]() {
Expand Down
4 changes: 2 additions & 2 deletions agent/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ set_target_properties(


target_link_libraries(ut_agent PRIVATE
centreon_agent_lib
centagent_lib
centreon_common
GTest::gtest
GTest::gtest_main
Expand All @@ -51,7 +51,7 @@ target_link_libraries(ut_agent PRIVATE
crypto ssl
)

add_dependencies(ut_agent centreon_common centreon_agent_lib)
add_dependencies(ut_agent centreon_common centagent_lib)

set_property(TARGET ut_agent PROPERTY POSITION_INDEPENDENT_CODE ON)

Expand Down
15 changes: 9 additions & 6 deletions agent/test/check_exec_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static const std::string cmd_name("command");
static std::string command_line;

TEST(check_exec_test, echo) {
command_line = "/usr/bin/echo hello toto";
command_line = "/bin/echo hello toto";
int status;
std::list<std::string> outputs;
std::condition_variable cond;
Expand All @@ -55,7 +55,7 @@ TEST(check_exec_test, echo) {
}

TEST(check_exec_test, timeout) {
command_line = "/usr/bin/sleep 5";
command_line = "/bin/sleep 5";
int status;
std::list<std::string> outputs;
std::condition_variable cond;
Expand All @@ -77,29 +77,32 @@ TEST(check_exec_test, timeout) {
cond.wait(l);
ASSERT_EQ(status, 3);
ASSERT_EQ(outputs.size(), 1);
ASSERT_EQ(*outputs.begin(), "Timeout at execution of /usr/bin/sleep 5");
ASSERT_EQ(*outputs.begin(), "Timeout at execution of /bin/sleep 5");
}

TEST(check_exec_test, bad_command) {
command_line = "/usr/bad_path/turlututu titi toto";
int status;
std::list<std::string> outputs;
std::condition_variable cond;
std::mutex mut;
std::shared_ptr<check_exec> check = check_exec::load(
g_io_context, spdlog::default_logger(), time_point(), serv, cmd_name,
command_line, engine_to_agent_request_ptr(),
[&](const std::shared_ptr<com::centreon::agent::check>& caller,
int statuss,
const std::list<com::centreon::common::perfdata>& perfdata,
const std::list<std::string>& output) {
status = statuss;
outputs = output;
{
std::lock_guard l(mut);
status = statuss;
outputs = output;
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
cond.notify_one();
});
check->start_check(std::chrono::seconds(1));

std::mutex mut;
std::unique_lock l(mut);
cond.wait(l);
ASSERT_EQ(status, 3);
Expand Down
15 changes: 9 additions & 6 deletions agent/test/scheduler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,15 @@ TEST_F(scheduler_test, time_out) {
std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
std::mutex m;
std::shared_ptr<scheduler> sched = scheduler::load(
g_io_context, spdlog::default_logger(), "my_host",
create_conf(1, 1, 1, 1, 1),
[&](const std::shared_ptr<MessageFromAgent>& req) {
exported_request = req;
{
std::lock_guard l(m);
exported_request = req;
}
export_cond.notify_all();
},
[](const std::shared_ptr<asio::io_context>& io_context,
Expand All @@ -243,7 +247,6 @@ TEST_F(scheduler_test, time_out) {
engine_to_agent_request, 0, std::chrono::milliseconds(1500),
std::move(handler));
});
std::mutex m;
std::unique_lock l(m);
export_cond.wait(l);

Expand All @@ -268,9 +271,9 @@ TEST_F(scheduler_test, time_out) {
ASSERT_EQ(metric.gauge().data_points_size(), 1);
const auto& data_point = metric.gauge().data_points()[0];
ASSERT_EQ(data_point.as_int(), 3);
// one second first check timer expire + timeout => 2s
ASSERT_GE(data_point.time_unix_nano(), expected_completion_time + 2000000000);
ASSERT_LE(data_point.time_unix_nano(), expected_completion_time + 2500000000);
// timeout 1s
ASSERT_GE(data_point.time_unix_nano(), expected_completion_time + 1000000000);
ASSERT_LE(data_point.time_unix_nano(), expected_completion_time + 1500000000);

sched->stop();
}
Expand Down Expand Up @@ -344,7 +347,7 @@ TEST_F(scheduler_test, correct_output_examplar) {
scope_metrics2.metrics()[0];
ASSERT_EQ(metric2.name(), "status");
ASSERT_EQ(metric2.description(), "Command OK: /usr/bin/ls");
ASSERT_EQ(metric2.gauge().data_points_size(), 1);
ASSERT_GE(metric2.gauge().data_points_size(), 1);
const auto& data_point_state2 = metric2.gauge().data_points()[0];
ASSERT_EQ(data_point_state2.as_int(), 0);

Expand Down
2 changes: 1 addition & 1 deletion engine/modules/opentelemetry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ foreach(name IN LISTS service_files)

endforeach()

#centreon_agent server and client
#centagent server and client
add_custom_command(
DEPENDS ${CMAKE_SOURCE_DIR}/agent/proto/agent.proto
COMMENT "Generating interface files of the conf centreon_agent proto file (grpc)"
Expand Down
2 changes: 1 addition & 1 deletion engine/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ if(WITH_TESTING)
cce_core
log_v2
opentelemetry
centreon_agent_lib
centagent_lib
"-Wl,-no-whole-archive"
pb_open_telemetry_lib
centreon_grpc
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "centreon-agent-debuginfo"
name: "centagent-debuginfo"
arch: "${ARCH}"
platform: "linux"
version_schema: "none"
Expand All @@ -8,34 +8,34 @@ section: "default"
priority: "optional"
maintainer: "Centreon <[email protected]>"
description: |
Debuginfo package for centreon-agent.
Debuginfo package for centagent.
Commit: @COMMIT_HASH@
vendor: "Centreon"
homepage: "https://www.centreon.com"
license: "Apache-2.0"

contents:
- src: "../build/agent/centreon_agent.debug"
dst: "/usr/lib/debug/usr/bin/centreon_agent.debug"
- src: "../build/agent/centagent.debug"
dst: "/usr/lib/debug/usr/bin/centagent.debug"
file_info:
mode: 0644

overrides:
rpm:
depends:
- centreon-agent = ${VERSION}-${RELEASE}${DIST}
- centagent = ${VERSION}-${RELEASE}${DIST}
deb:
depends:
- centreon-agent (= ${VERSION}-${RELEASE}${DIST})
- centagent (= ${VERSION}-${RELEASE}${DIST})
conflicts:
- centreon-agent-dbgsym
- centagent-dbgsym
replaces:
- centreon-agent-dbgsym
- centagent-dbgsym
provides:
- centreon-agent-dbgsym
- centagent-dbgsym

rpm:
summary: Debuginfo package for centreon-agent.
summary: Debuginfo package for centagent.
compression: zstd
signature:
key_file: ${RPM_SIGNING_KEY_FILE}
Expand Down
6 changes: 3 additions & 3 deletions packaging/centreon-agent.yaml → packaging/centagent.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "centreon-agent"
name: "centagent"
arch: "${ARCH}"
platform: "linux"
version_schema: "none"
Expand All @@ -15,8 +15,8 @@ homepage: "https://www.centreon.com"
license: "Apache-2.0"

contents:
- src: "../build/agent/centreon_agent"
dst: "/usr/bin/centreon_agent"
- src: "../build/agent/centagent"
dst: "/usr/bin/centagent"

rpm:
summary: Centreon Collect Agent. It can be used to execute remotely plugins
Expand Down
4 changes: 2 additions & 2 deletions tests/resources/Agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def ctn_config_centreon_agent(key_path:str = None, cert_path:str = None, ca_path
Creates a default centreon agent config without encryption nor reverse connection
"""
makedirs(CONF_DIR, mode=0o777, exist_ok=True)
with open(f"{CONF_DIR}/centreon_agent.conf", "w") as ff:
with open(f"{CONF_DIR}/centagent.conf", "w") as ff:
ff.write(agent_config)
if key_path is not None or cert_path is not None or ca_path is not None:
ff.write("encryption=true\n")
Expand All @@ -56,7 +56,7 @@ def ctn_config_reverse_centreon_agent(key_path:str = None, cert_path:str = None,
Creates a default reversed centreon agent config without encryption listening on 0.0.0.0:4317
"""
makedirs(CONF_DIR, mode=0o777, exist_ok=True)
with open(f"{CONF_DIR}/centreon_agent.conf", "w") as ff:
with open(f"{CONF_DIR}/centagent.conf", "w") as ff:
ff.write(agent_config)
ff.write("reversed-grpc-streaming=1\n")
if key_path is not None or cert_path is not None or ca_path is not None:
Expand Down
6 changes: 3 additions & 3 deletions tests/resources/resources.resource
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ Ctn Wait For Engine To Be Ready


Ctn Start Agent
Start Process /usr/sbin/centreon_agent --config-file ${EtcRoot}/centreon-engine/centreon_agent.conf alias=centreon_agent
Start Process /usr/bin/centagent --config-file ${EtcRoot}/centreon-engine/centagent.conf alias=centreon_agent

Ctn Kindly Stop Agent
#in most case centreon_agent is not started
Expand All @@ -408,13 +408,13 @@ Ctn Kindly Stop Agent
IF "${result}" == "${None}"
Log To Console "fail to stop centreon_agent"
Ctn Save Logs
Ctn Dump Process centreon_agent /usr/sbin/centreon_agent centreon_agent
Ctn Dump Process centreon_agent /usr/bin/centagent centreon_agent
Send Signal To Process SIGKILL centreon_agent
Fail centreon_agent not correctly stopped (coredump generated)
ELSE
IF ${result.rc} != 0
Ctn Save Logs
Ctn Coredump Info centreon_agent /usr/sbin/centreon_agent centreon_agent
Ctn Coredump Info centreon_agent /usr/bin/centagent centreon_agent
Should Be Equal As Integers ${result.rc} 0 centreon_agent not correctly stopped
END
END

0 comments on commit 93afcbf

Please sign in to comment.