Skip to content

Commit

Permalink
enh(broker): new bbdo/protobuf service and lua stream simplified (#133)
Browse files Browse the repository at this point in the history
* cmake files more modern.
* neb headers are no more needed in broker.
* bbdo messages move to the bbdo directory
* global_lock in broker removed since no more used.
* concurrent accesses in muxer fixed.
* centreon-tests refactorization of variables

REFS: MON-11869 MON-12006
  • Loading branch information
bouda1 committed Jan 28, 2022
1 parent 01fab30 commit 7356efb
Show file tree
Hide file tree
Showing 259 changed files with 3,126 additions and 16,732 deletions.
51 changes: 10 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,49 +58,22 @@ set(USER_BROKER centreon-broker)
set(USER_ENGINE centreon-engine)
##################################

include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

include(GNUInstallDirs)

set(CMAKE_INSTALL_PREFIX "/usr")
option(WITH_TESTING "Build unit tests." OFF)
if (WITH_TESTING)
find_package(GTest REQUIRED)
endif ()

set(protobuf_MODULE_COMPATIBLE True)
option(WITH_CONF "Install configuration files." ON)

find_package(asio REQUIRED)
find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(c-ares REQUIRED)
find_package(ZLIB REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(Protobuf REQUIRED)
find_package(gRPC REQUIRED)
set(protobuf_MODULE_COMPATIBLE True)

add_definitions(${spdlog_DEFINITIONS})

include_directories(${nlohmann_json_INCLUDE_DIRS})
include_directories(${fmt_INCLUDE_DIRS})
include_directories(${spdlog_INCLUDE_DIRS})
include_directories(${asio_INCLUDE_DIRS})
include_directories(${protobuf_INCLUDE_DIRS})
include_directories(${absl_INCLUDE_DIRS})
include_directories(${gRPC_INCLUDE_DIRS})
include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(${CMAKE_SOURCE_DIR})

link_directories(${nlohmann_json_LIB_DIRS})
link_directories(${fmt_LIB_DIRS})
link_directories(${spdlog_LIB_DIRS})
link_directories(${protobuf_LIB_DIRS})
link_directories(${gRPC_LIB_DIRS})
link_directories(${c-ares_LIB_DIRS})
link_directories(${OpenSSL_LIB_DIRS})
link_directories(${ZLIB_LIB_DIRS})

set(PROTOBUF_PREFIX "${protobuf_LIB_DIRS}/..")
include_directories(${CMAKE_SOURCE_DIR}
${CONAN_INCLUDE_DIRS})

add_subdirectory(bbdo)
add_subdirectory(centreon-broker)
Expand All @@ -109,20 +82,16 @@ add_subdirectory(centreon-engine)
add_subdirectory(centreon-connector)

add_custom_target(test-broker
WORKING_DIRECTORY centreon-broker
COMMAND test/ut
COMMAND tests/ut_broker
)
add_custom_target(test-engine
WORKING_DIRECTORY centreon-engine
COMMAND tests/ut_engine
)
add_custom_target(test-clib
WORKING_DIRECTORY centreon-clib
COMMAND test/ut-clib
COMMAND tests/ut_clib
)
add_custom_target(test-connector
WORKING_DIRECTORY centreon-connector
COMMAND ut_connector
COMMAND tests/ut_connector
)

add_custom_target(test
Expand Down
23 changes: 21 additions & 2 deletions bbdo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
set(protobuf_files
rebuild_message
remove_graph_message
service
)

foreach(name IN LISTS protobuf_files)
Expand All @@ -28,13 +27,33 @@ foreach(name IN LISTS protobuf_files)
add_custom_command(OUTPUT "${CMAKE_SOURCE_DIR}/bbdo/${name}.pb.cc" "${CMAKE_SOURCE_DIR}/bbdo/${name}.pb.h"
DEPENDS ${full_proto_file}
COMMENT "Generating interface files of the bbdo file ${proto_file}"
COMMAND ${PROTOBUF_PREFIX}/bin/protoc
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
ARGS --cpp_out=${CMAKE_SOURCE_DIR}/bbdo --proto_path=${CMAKE_SOURCE_DIR}/bbdo ${proto_file}
VERBATIM
)

add_custom_target(${name} DEPENDS "${CMAKE_SOURCE_DIR}/bbdo/${name}.pb.cc" "${CMAKE_SOURCE_DIR}/bbdo/${name}.pb.h")
endforeach()

add_custom_command(OUTPUT "${CMAKE_SOURCE_DIR}/bbdo/service.pb.cc" "${CMAKE_SOURCE_DIR}/bbdo/service.pb.h"
DEPENDS ${CMAKE_SOURCE_DIR}/bbdo/service.proto
COMMENT "Generating interface files of the bbdo file service.proto"
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
ARGS --cpp_out=${CMAKE_SOURCE_DIR}/bbdo --proto_path=${CMAKE_SOURCE_DIR}/bbdo service.proto
VERBATIM
)
add_custom_target(target_service DEPENDS "${CMAKE_SOURCE_DIR}/bbdo/service.pb.cc" "${CMAKE_SOURCE_DIR}/bbdo/service.pb.h")

#set_source_files_properties("${CMAKE_SOURCE_DIR}/bbdo/service.pb.cc" PROPERTIES GENERATED TRUE)
#set_source_files_properties("${CMAKE_SOURCE_DIR}/bbdo/service.pb.h" PROPERTIES GENERATED TRUE)
add_library(
pb_service_lib STATIC
"service.pb.cc"
"service.pb.h"
)
add_dependencies(pb_service_lib target_service)
set_target_properties(pb_service_lib PROPERTIES COMPILE_FLAGS "-fPIC")

macro(get_protobuf_files name)
set_source_files_properties("${CMAKE_SOURCE_DIR}/bbdo/${name}.pb.cc" PROPERTIES GENERATED TRUE)
set_source_files_properties("${CMAKE_SOURCE_DIR}/bbdo/${name}.pb.h" PROPERTIES GENERATED TRUE)
Expand Down
32 changes: 32 additions & 0 deletions bbdo/events.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,38 @@ enum data_element {
de_remove_graphs = 5,
};
}
namespace neb {
// Data elements.
enum data_element {
de_acknowledgement = 1,
de_comment,
de_custom_variable,
de_custom_variable_status,
de_downtime,
de_event_handler,
de_flapping_status,
de_host_check,
de_host_dependency,
de_host_group,
de_host_group_member,
de_host,
de_host_parent,
de_host_status,
de_instance,
de_instance_status,
de_log_entry,
de_module,
de_service_check,
de_service_dependency,
de_service_group,
de_service_group_member,
de_service,
de_service_status,
de_instance_configuration,
de_responsive_instance,
de_pb_service = 27,
};
}
namespace storage {
enum data_element {
de_metric = 1,
Expand Down
58 changes: 53 additions & 5 deletions bbdo/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,64 @@ message Service {
}
bool acknowledged = 3;
AckType acknowledgement_type = 4;

bool active_checks_enabled = 5;
string check_command = 6;
int32 check_interval = 7;
string check_period = 8;
int32 downtime_depth = 6;
string check_command = 7;
int32 check_interval = 8;
string check_period = 9;

enum CheckType {
CHECK_ACTIVE = 0;
CHECK_PASSIVE = 1;
}
CheckType check_type = 9;
int32 current_check_attempt = 10;
CheckType check_type = 10;
int32 current_check_attempt = 11;
enum State {
OK = 0;
WARNING = 1;
CRITICAL = 2;
UNKNOWN = 3;
PENDING = 4;
}
State current_state = 12;
bool event_handler_enabled = 13;
string event_handler = 14;
double execution_time = 15;
bool flap_detection_enabled = 16;
bool has_been_checked = 17;
bool is_flapping = 18;
int64 last_check = 19;
State last_hard_state = 20;
int64 last_hard_state_change = 21;
int64 last_notification = 22;
int32 notification_number = 23;
int64 last_state_change = 24;
int64 last_time_ok = 25;
int64 last_time_warning = 26;
int64 last_time_critical = 27;
int64 last_time_unknown = 28;
int64 last_update = 29;
double latency = 30;
int32 max_check_attempts = 31;
int64 next_check = 32;
int64 next_notification = 33;
bool no_more_notifications = 34;
bool notifications_enabled = 35;
string output = 37;
string long_output = 38;
bool passive_checks_enabled = 39;
double percent_state_change = 40;
string perf_data = 41;
double retry_interval = 42;
string host_name = 43;
string service_description = 44;
bool should_be_scheduled = 45;

enum StateType {
SOFT = 0;
HARD = 1;
}

StateType state_type = 46;
}
29 changes: 11 additions & 18 deletions centreon-broker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ endif ()

include_directories("${PROJECT_SOURCE_DIR}/core/inc")
include_directories("${PROJECT_SOURCE_DIR}/neb/inc")
include_directories("${CMAKE_SOURCE_DIR}/centreon-engine/inc")
set(INC_DIR "${PROJECT_SOURCE_DIR}/core/inc/com/centreon/broker")
set(SRC_DIR "${PROJECT_SOURCE_DIR}/core/src")
set(TEST_DIR "${PROJECT_SOURCE_DIR}/core/test")
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)

add_custom_command(
DEPENDS ${SRC_DIR}/database/table_max_size.py "${PROJECT_SOURCE_DIR}/simu/docker/installBroker.sql" "${PROJECT_SOURCE_DIR}/simu/docker/partitioning-logs.xml" "${PROJECT_SOURCE_DIR}/simu/docker/bam.sql" "${PROJECT_SOURCE_DIR}/simu/docker/createTablesCentstorage.sql"
Expand All @@ -71,28 +71,23 @@ add_custom_target(table_max_size DEPENDS ${INC_DIR}/database/table_max_size.hh)

set_source_files_properties(${INC_DIR}/database/table_max_size.hh PROPERTIES GENERATED TRUE)

find_package(mariadb-connector-c REQUIRED)

add_definitions(${spdlog_DEFINITIONS} ${mariadb-connector-c_DEFINITIONS})

include_directories(${mariadb-connector-c_INCLUDE_DIRS})

link_directories(${mariadb-connector-c_LIB_DIRS})
include_directories(${CONAN_INCLUDE_DIRS_MARIADB-CONNECTOR-C})

message(STATUS "${PROTOBUF_PREFIX}/bin/protoc")
set(GRPC_PREFIX "${gRPC_LIB_DIRS}/..")
#link_directories(${mariadb-connector-c_LIB_DIRS})

add_custom_command(
DEPENDS ${SRC_DIR}/broker.proto
COMMENT "Generating interface files of the proto file (grpc)"
OUTPUT ${SRC_DIR}/broker.grpc.pb.cc ${SRC_DIR}/broker.grpc.pb.h
COMMAND ${PROTOBUF_PREFIX}/bin/protoc
ARGS --plugin=protoc-gen-grpc=${GRPC_PREFIX}/bin/grpc_cpp_plugin --proto_path=${SRC_DIR} --grpc_out="${SRC_DIR}" ${SRC_DIR}/broker.proto
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
ARGS --plugin=protoc-gen-grpc=${CONAN_BIN_DIRS_GRPC}/grpc_cpp_plugin --proto_path=${SRC_DIR} --grpc_out="${SRC_DIR}" ${SRC_DIR}/broker.proto

DEPENDS ${SRC_DIR}/broker.proto
COMMENT "Generating interface files of the proto file (protobuf)"
OUTPUT ${SRC_DIR}/broker.pb.cc ${SRC_DIR}/broker.pb.h
COMMAND ${PROTOBUF_PREFIX}/bin/protoc
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
ARGS --cpp_out="${SRC_DIR}" --proto_path=${SRC_DIR} ${SRC_DIR}/broker.proto
)

Expand All @@ -106,7 +101,7 @@ add_library(
${SRC_DIR}/broker.pb.cc
${SRC_DIR}/broker.grpc.pb.h
${SRC_DIR}/broker.pb.h)
target_link_libraries(berpc ${protobuf_LIBS})
target_link_libraries(berpc CONAN_PKG::protobuf)
set_target_properties(berpc PROPERTIES COMPILE_FLAGS "-fPIC")

# Version.
Expand All @@ -131,8 +126,6 @@ include(cmake/tool.cmake)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
add_definitions("-DASIO_STANDALONE")

find_package(PkgConfig REQUIRED)

#
# Get distributions name
#
Expand Down Expand Up @@ -477,19 +470,20 @@ set(LIBROKER_SOURCES
add_library(rokerbase STATIC ${LIBROKER_SOURCES})
set_target_properties(rokerbase PROPERTIES COMPILE_FLAGS "-fPIC")
add_dependencies(rokerbase berpc)
target_link_libraries(rokerbase ${ZLIB_LIBRARIES} ${OpenSSL_LIBS} ${mariadb-connector-c_LIBS} pthread dl berpc bbdo_bbdo)
target_link_libraries(rokerbase CONAN_PKG::zlib CONAN_PKG::spdlog CONAN_PKG::openssl CONAN_PKG::mariadb-connector-c pthread dl berpc bbdo_bbdo)

add_library(roker STATIC
${SRC_DIR}/config/applier/init.cc)
target_link_libraries(roker rokerbase dl ${c-ares_LIBS} ${OpenSSL_LIBS} ${gRPC_LIBS} ${absl_LIBS} pthread)
target_link_libraries(roker rokerbase dl CONAN_PKG::openssl CONAN_PKG::grpc pthread)
#target_link_libraries(roker rokerbase dl ${c-ares_LIBS} CONAN_PKG::openssl CONAN_PKG::grpc ${absl_LIBS} pthread)


# Standalone binary.
add_executable(cbd ${SRC_DIR}/main.cc)

#Flags needed to include all symbols in binary.
target_link_libraries(cbd
"-Wl,--whole-archive" rokerbase roker "-Wl,--no-whole-archive" ${nlohmann_json_LIBS} ${fmt_LIBS} ${spdlog_LIBS} ${gRPC_LIBS} ${absl_LIBS} )
"-Wl,--whole-archive" rokerbase roker "-Wl,--no-whole-archive" CONAN_PKG::nlohmann_json CONAN_PKG::fmt CONAN_PKG::spdlog CONAN_PKG::grpc )

# Centreon Broker Watchdog
option(WITH_CBWD "Build centreon broker watchdog." ON)
Expand Down Expand Up @@ -608,7 +602,6 @@ include(cmake/package.cmake)
# Unit tests.
#
# Enable testing.
option(WITH_TESTING "Generate unit tests." OFF)
if (WITH_TESTING)
add_subdirectory(test)
endif ()
Expand Down
2 changes: 1 addition & 1 deletion centreon-broker/bam/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ add_library("${BAM}" SHARED
"${INC_DIR}/service_listener.hh"
"${INC_DIR}/timeperiod_map.hh"
)
target_link_libraries("${BAM}" bbdo_storage bbdo_bam)
target_link_libraries("${BAM}" bbdo_storage bbdo_bam CONAN_PKG::spdlog)
set_target_properties("${BAM}" PROPERTIES
PREFIX "")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** Copyright 2018 Centreon
** Copyright 2018, 2021 Centreon
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,8 +42,9 @@ class mysql_bind {
uint32_t value_as_u32(int range) const;
void set_value_as_u32(int range, uint32_t value);
int64_t value_as_i64(int range) const;
void set_value_as_i64(int range, int64_t value);
uint64_t value_as_u64(int range) const;
void set_value_as_u64(int range, unsigned long long value);
void set_value_as_u64(int range, uint64_t value);
bool value_as_bool(int range) const;
void set_value_as_bool(int range, bool value);
float value_as_f32(int range) const;
Expand Down
Loading

0 comments on commit 7356efb

Please sign in to comment.