Skip to content

Commit

Permalink
enh(collect): engine and broker share the same logger library.
Browse files Browse the repository at this point in the history
* enh(common): new log library in common/log_v2.
* enh(common/tests): tests directory renamed to 'tests'
* doc(broke): update on muxer/processing
* fix(broker): stop event is handled by the sql streams now.
* fix(broker): engine simplified
* doc(broker): engine doc is growing up
* fix(broker/muxer)
* enh(broker/muxer_filter): filter improved in muxers. There are two filters now, one mandatory and one forbidden.
* fix(broker): stats center is embedded by its users now
* enh(tests): two new benchs with reversed connections
* fix(broker/tests): if hostname fqdn fails, we replace hostname by localhost

REFS: MON-21266
  • Loading branch information
bouda1 authored May 28, 2024
1 parent 24b8d16 commit 974ca8b
Show file tree
Hide file tree
Showing 554 changed files with 14,047 additions and 13,093 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,6 @@ test/python/*.crt
test/python/*.key
tests/logs/*
tests/bench.unqlite
tests/resources/process_stat_pb2.py
tests/resources/process_stat_pb2_grpc.py
tests/resources/*_pb2.py
tests/resources/*_pb2_grpc.py
tests/resources/grpc_stream.proto
3 changes: 2 additions & 1 deletion bbdo/bbdo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ message Ack {

/*io::bbdo, bbdo::de_pb_stop*/
message Stop {
}
uint64 poller_id = 1;
}
21 changes: 14 additions & 7 deletions bbdo/events.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
#include <cstdint>
#include <cstring>

namespace com {
namespace centreon {
namespace broker {
namespace com::centreon::broker {
namespace io {
enum data_category {
none = 0,
Expand All @@ -35,7 +33,8 @@ enum data_category {
bam = 6,
extcmd = 7,
generator = 8,
max_data_category = 9,
local = 9,
max_data_category = 10,
internal = 65535
};
constexpr uint16_t category_id(const char* name) {
Expand All @@ -55,6 +54,8 @@ constexpr uint16_t category_id(const char* name) {
return dumper;
if (std::string_view("generator", 9) == name)
return generator;
if (std::string_view("local", 5) == name)
return local;
return none;
}
constexpr const char* category_name(data_category cat) {
Expand All @@ -75,6 +76,8 @@ constexpr const char* category_name(data_category cat) {
return "generator";
case internal:
return "internal";
case local:
return "local";
default:
return "unknown category";
}
Expand Down Expand Up @@ -208,6 +211,12 @@ namespace extcmd {
enum data_element { de_pb_bench = 1, de_ba_info = 2 };
}

namespace local {
enum data_element {
de_pb_stop = 1,
};
}

constexpr uint32_t make_type(io::data_category cat, uint32_t elem) {
return (cat << 16) | elem;
}
Expand All @@ -217,8 +226,6 @@ constexpr uint16_t category_of_type(uint32_t type) {
constexpr uint16_t element_of_type(uint32_t type) {
return static_cast<uint16_t>(type);
}
} // namespace broker
} // namespace centreon
} // namespace com
} // namespace com::centreon::broker

#endif /* !CC_BROKER_EVENTS_HH */
41 changes: 24 additions & 17 deletions broker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ add_custom_command(
OUTPUT ${SRC_DIR}/broker.grpc.pb.cc ${SRC_DIR}/broker.grpc.pb.h
COMMAND
${Protobuf_PROTOC_EXECUTABLE} ARGS
--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN}
--proto_path=${SRC_DIR} --proto_path=${CMAKE_SOURCE_DIR}/common/src
--grpc_out="${SRC_DIR}" ${SRC_DIR}/broker.proto
--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN} --proto_path=${SRC_DIR}
--proto_path=${CMAKE_SOURCE_DIR}/common/src --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_PROTOC_EXECUTABLE} ARGS --cpp_out="${SRC_DIR}"
--proto_path=${SRC_DIR} --proto_path=${CMAKE_SOURCE_DIR}/common/src
${SRC_DIR}/broker.proto
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

add_custom_target("target_broker_message" DEPENDS "${SRC_DIR}/broker.pb.cc"
"${SRC_DIR}/broker.pb.h")
Expand Down Expand Up @@ -436,15 +436,10 @@ set(LIBROKER_SOURCES
${INC_DIR}/version.hh)

# Static libraries.
add_library(rokerlog STATIC ${SRC_DIR}/log_v2.cc)
set_target_properties(rokerlog PROPERTIES COMPILE_FLAGS "-fPIC")
target_precompile_headers(rokerlog REUSE_FROM multiplexing)
target_link_libraries(rokerlog spdlog::spdlog)

add_library(rokerbase STATIC ${LIBROKER_SOURCES})
set_target_properties(rokerbase PROPERTIES COMPILE_FLAGS "-fPIC")
target_precompile_headers(rokerbase REUSE_FROM multiplexing)
add_dependencies(rokerbase berpc target_bbdo)
add_dependencies(rokerbase berpc target_bbdo target_extcmd)
target_link_libraries(
rokerbase
sql
Expand All @@ -454,14 +449,23 @@ target_link_libraries(
berpc
z
spdlog::spdlog
crypto ssl
crypto
ssl
pthread
dl)

add_library(roker STATIC ${SRC_DIR}/config/applier/init.cc)
target_link_libraries(roker rokerbase crypto ssl
gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts
pthread dl)
target_link_libraries(
roker
rokerbase
crypto
ssl
gRPC::gpr
gRPC::grpc
gRPC::grpc++
gRPC::grpc++_alts
pthread
dl)

# Standalone binary.
add_executable(cbd ${SRC_DIR}/main.cc)
Expand All @@ -471,8 +475,8 @@ add_dependencies(cbd multiplexing centreon_common)
target_link_libraries(
cbd
"-rdynamic"
rokerlog
"-Wl,--whole-archive"
log_v2
sql
rokerbase
roker
Expand All @@ -487,8 +491,11 @@ target_link_libraries(
protobuf
"-Wl,--no-whole-archive"
stdc++fs
spdlog::spdlog
gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts)
# spdlog::spdlog
gRPC::gpr
gRPC::grpc
gRPC::grpc++
gRPC::grpc++_alts)

# Centreon Broker Watchdog
option(WITH_CBWD "Build centreon broker watchdog." ON)
Expand Down
45 changes: 21 additions & 24 deletions broker/bam/inc/com/centreon/broker/bam/availability_builder.hh
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
/*
** Copyright 2014 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 : contact@centreon.com
*/
/**
* Copyright 2014, 2022-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 : contact@centreon.com
*/

#ifndef CCB_BAM_AVAILABILITY_BUILDER_HH
#define CCB_BAM_AVAILABILITY_BUILDER_HH

#include "com/centreon/broker/time/timeperiod.hh"
#include "com/centreon/broker/timestamp.hh"

namespace com::centreon::broker {

namespace bam {
namespace com::centreon::broker::bam {
/**
* @class availability_builder availability_builder.hh
* "com/centreon/broker/bam/availability_builder.hh"
Expand Down Expand Up @@ -56,7 +54,8 @@ class availability_builder {
time_t start,
time_t end,
bool was_in_downtime,
time::timeperiod::ptr const& tp);
time::timeperiod::ptr const& tp,
const std::shared_ptr<spdlog::logger>& logger);

int get_available() const;
int get_unavailable() const;
Expand Down Expand Up @@ -86,8 +85,6 @@ class availability_builder {

bool _timeperiods_is_default;
};
} // namespace bam

}
} // namespace com::centreon::broker::bam

#endif // !CCB_BAM_AVAILABILITY_BUILDER_HH
47 changes: 25 additions & 22 deletions broker/bam/inc/com/centreon/broker/bam/availability_thread.hh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
** Copyright 2014 - 2021 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 : contact@centreon.com
*/
/**
* Copyright 2014 - 2021-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 : contact@centreon.com
*/

#ifndef CCB_BAM_AVAILABILITY_THREAD_HH
#define CCB_BAM_AVAILABILITY_THREAD_HH
Expand All @@ -41,11 +41,11 @@ namespace bam {
class availability_thread final {
public:
availability_thread(database_config const& db_cfg,
timeperiod_map& shared_map);
timeperiod_map& shared_map,
const std::shared_ptr<spdlog::logger>& logger);
~availability_thread();
availability_thread(availability_thread const& other) = delete;
availability_thread& operator=(availability_thread const& other) const =
delete;
availability_thread(availability_thread const&) = delete;
availability_thread& operator=(availability_thread const&) const = delete;

virtual void run();
void terminate();
Expand Down Expand Up @@ -87,9 +87,12 @@ class availability_thread final {
bool _should_rebuild_all;
std::string _bas_to_rebuild;
std::condition_variable _wait;

/* Logger */
std::shared_ptr<spdlog::logger> _logger;
};
} // namespace bam

}
} // namespace com::centreon::broker

#endif // !CCB_BAM_AVAILABILITY_THREAD_HH
13 changes: 5 additions & 8 deletions broker/bam/inc/com/centreon/broker/bam/ba.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2014-2015, 2021-2023 Centreon
* Copyright 2014-2015, 2021-2024 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 @@ -30,9 +30,7 @@
#include "com/centreon/broker/io/stream.hh"
#include "com/centreon/broker/persistent_cache.hh"

namespace com::centreon::broker {

namespace bam {
namespace com::centreon::broker::bam {
// Forward declaration.
class kpi;

Expand Down Expand Up @@ -112,7 +110,8 @@ class ba : public computable, public service_listener {
uint32_t host_id,
uint32_t service_id,
configuration::ba::state_source source,
bool generate_virtual_status = true);
bool generate_virtual_status,
const std::shared_ptr<spdlog::logger>& logger);
ba(const ba&) = delete;
virtual ~ba() noexcept = default;
ba& operator=(ba const& other) = delete;
Expand Down Expand Up @@ -154,8 +153,6 @@ class ba : public computable, public service_listener {
void dump(const std::string& filename) const;
void dump(std::ofstream& output) const override;
};
} // namespace bam

} // namespace com::centreon::broker
} // namespace com::centreon::broker::bam

#endif // !CCB_BAM_BA_HH
3 changes: 2 additions & 1 deletion broker/bam/inc/com/centreon/broker/bam/ba_best.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class ba_best : public ba {
ba_best(uint32_t id,
uint32_t host_id,
uint32_t service_id,
bool generate_virtual_status = true);
bool generate_virtual_status,
const std::shared_ptr<spdlog::logger>& logger);
state get_state_hard() const override;
state get_state_soft() const override;
std::string get_output() const override;
Expand Down
3 changes: 2 additions & 1 deletion broker/bam/inc/com/centreon/broker/bam/ba_impact.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class ba_impact : public ba {
ba_impact(uint32_t id,
uint32_t host_id,
uint32_t service_id,
bool generate_virtual_status = true);
bool generate_virtual_status,
const std::shared_ptr<spdlog::logger>& logger);
state get_state_hard() const override;
state get_state_soft() const override;
double get_ack_impact_hard() override;
Expand Down
3 changes: 2 additions & 1 deletion broker/bam/inc/com/centreon/broker/bam/ba_ratio_number.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class ba_ratio_number : public ba {
ba_ratio_number(uint32_t id,
uint32_t host_id,
uint32_t service_id,
bool generate_virtual_status = true);
bool generate_virtual_status,
const std::shared_ptr<spdlog::logger>& logger);
state get_state_hard() const override;
state get_state_soft() const override;
std::string get_output() const override;
Expand Down
3 changes: 2 additions & 1 deletion broker/bam/inc/com/centreon/broker/bam/ba_ratio_percent.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class ba_ratio_percent : public ba {
ba_ratio_percent(uint32_t id,
uint32_t host_id,
uint32_t service_id,
bool generate_virtual_status = true);
bool generate_virtual_status,
const std::shared_ptr<spdlog::logger>& logger);
state get_state_hard() const override;
state get_state_soft() const override;
std::string get_output() const override;
Expand Down
Loading

0 comments on commit 974ca8b

Please sign in to comment.