Skip to content

Commit

Permalink
first centagent executable
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-christophe81 committed Jun 20, 2024
1 parent 490f16a commit 2655b43
Show file tree
Hide file tree
Showing 34 changed files with 1,319 additions and 20 deletions.
1 change: 1 addition & 0 deletions .github/scripts/collect-unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ tests/ut_engine --gtest_output=xml:ut_engine.xml
tests/ut_clib --gtest_output=xml:ut_clib.xml
tests/ut_connector --gtest_output=xml:ut_connector.xml
tests/ut_common --gtest_output=xml:ut_common.xml
tests/ut_agent --gtest_output=xml:ut_agent.xml
echo "---------------------------------------------------------- end of ut tests ------------------------------------------------"
2 changes: 2 additions & 0 deletions .github/workflows/centreon-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
workflow_dispatch:
pull_request:
paths:
- agent/**
- bbdo/**
- broker/**
- ccc/**
Expand All @@ -33,6 +34,7 @@ on:
- master
- "[2-9][0-9].[0-9][0-9].x"
paths:
- agent/**
- bbdo/**
- broker/**
- ccc/**
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/package-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
if: ${{ matrix.package_extension == 'rpm' }}
run: |
cd selinux
for MODULE in "centreon-engine" "centreon-broker"; do
for MODULE in "centreon-engine" "centreon-broker" "centreon-agent"; do
cd $MODULE
sed -i "s/@VERSION@/${{ inputs.version }}/g" $MODULE.te
make -f /usr/share/selinux/devel/Makefile
Expand Down Expand Up @@ -187,7 +187,8 @@ jobs:
"build/engine/modules/bench/centengine_bench_passive"
"build/connectors/perl/centreon_connector_perl"
"build/connectors/ssh/centreon_connector_ssh"
"build/ccc/ccc")
"build/ccc/ccc"
"build/agent/centagent")
for file in ${exe[@]}; do
echo "Making a debug file of $file"
objcopy --only-keep-debug $file $file.debug
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ log.html
output.xml
report.html

# agent
agent/scripts/centagent.service
opentelemetry-proto

# bbdo
bbdo/*_accessor.hh

Expand Down Expand Up @@ -140,3 +144,4 @@ tests/bench.unqlite
tests/resources/*_pb2.py
tests/resources/*_pb2_grpc.py
tests/resources/grpc_stream.proto
tests/resources/opentelemetry
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ endif()
set(USER_BROKER centreon-broker)
set(USER_ENGINE centreon-engine)


find_package(fmt CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)
Expand Down Expand Up @@ -236,6 +237,7 @@ add_subdirectory(bbdo)
add_subdirectory(engine)
add_subdirectory(connectors)
add_subdirectory(ccc)
add_subdirectory(agent)

if (WITH_MALLOC_TRACE)
add_subdirectory(malloc-trace)
Expand All @@ -247,9 +249,10 @@ add_custom_target(test-engine COMMAND tests/ut_engine)
add_custom_target(test-clib COMMAND tests/ut_clib)
add_custom_target(test-connector COMMAND tests/ut_connector)
add_custom_target(test-common COMMAND tests/ut_common)
add_custom_target(test-agent COMMAND tests/ut_agent)

add_custom_target(test DEPENDS test-broker test-engine test-clib test-connector
test-common)
test-common test-agent)

add_custom_target(test-coverage DEPENDS broker-test-coverage
engine-test-coverage clib-test-coverage)
176 changes: 176 additions & 0 deletions agent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#
# 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")
set(SCRIPT_DIR "${PROJECT_SOURCE_DIR}/scripts")


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()


#centagent server and client
add_custom_command(
DEPENDS ${PROJECT_SOURCE_DIR}/proto/agent.proto
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 centagent 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(centagent_lib STATIC
${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
)

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

target_precompile_headers(centagent_lib PRIVATE precomp_inc/precomp.hh)

SET(CENTREON_AGENT centagent)

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
centagent_lib
centreon_common
centreon_grpc
-L${Boost_LIBRARY_DIR_RELEASE}
boost_program_options
fmt::fmt)

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-agent")


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

if(WITH_TESTING)
add_subdirectory(test)
endif()


set(PREFIX_AGENT_CONF "${CMAKE_INSTALL_FULL_SYSCONFDIR}/centreon-agent")
set(USER_AGENT centreon-agent)


if(WITH_CONF)
add_subdirectory(conf)
endif()

# Generate Systemd script.
message(STATUS "Generating systemd startup script.")
configure_file("${SCRIPT_DIR}/centagent.service.in"
"${SCRIPT_DIR}/centagent.service")

# Startup dir.
if(WITH_STARTUP_DIR)
set(STARTUP_DIR "${WITH_STARTUP_DIR}")
else()
set(STARTUP_DIR "/etc/systemd/system")
endif()

# Script install rule.
install(
PROGRAMS "${SCRIPT_DIR}/centagent.service"
DESTINATION "${STARTUP_DIR}"
COMPONENT "runtime")
43 changes: 43 additions & 0 deletions agent/conf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# 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]
#

# Set directories.
set(SRC_DIR "${PROJECT_SOURCE_DIR}/conf")

# Configure files.
configure_file("${SRC_DIR}/centagent.cfg.in"
"${SRC_DIR}/centagent.cfg")

# Install files if necessary.
option(WITH_SAMPLE_CONFIG "Install sample configuration files." ON)
if (WITH_SAMPLE_CONFIG)
install(DIRECTORY "${SRC_DIR}/"
DESTINATION "${PREFIX_AGENT_CONF}"
COMPONENT "runtime"
FILES_MATCHING PATTERN "*.cfg")

install(CODE "
function(my_chown user group file)
if (APPLE OR (UNIX AND NOT CYGWIN))
execute_process(COMMAND \"chown\" \"\${user}:\${group}\" \"\${file}\")
endif ()
endfunction()
my_chown(\"${USER_AGENT}\" \"${USER_AGENT}\" \"${PREFIX_AGENT_CONF}/centagent.cfg\")
")
endif ()
Loading

0 comments on commit 2655b43

Please sign in to comment.