From 420cd93ea37f6ed3dedbef18e0ef8df3ea9f7788 Mon Sep 17 00:00:00 2001 From: David Boucher Date: Wed, 24 Jul 2024 18:14:41 +0200 Subject: [PATCH] enh(broker): HostDependencies and ServiceDependencies are not used by broker. --- CMakeListsLinux.txt | 4 +- .../com/centreon/broker/sql/mysql_error.hh | 162 ++++---- broker/neb/CMakeLists.txt | 8 - .../inc/com/centreon/broker/neb/callbacks.hh | 2 - .../inc/com/centreon/broker/neb/dependency.hh | 59 --- .../neb/inc/com/centreon/broker/neb/events.hh | 2 - .../centreon/broker/neb/host_dependency.hh | 55 --- .../inc/com/centreon/broker/neb/initial.hh | 10 +- .../inc/com/centreon/broker/neb/internal.hh | 8 - .../centreon/broker/neb/service_dependency.hh | 61 --- broker/neb/src/broker.cc | 15 - broker/neb/src/callbacks.cc | 313 --------------- broker/neb/src/dependency.cc | 88 ---- broker/neb/src/host_dependency.cc | 101 ----- broker/neb/src/initial.cc | 91 ----- broker/neb/src/service_dependency.cc | 125 ------ broker/neb/test/host_dependency.cc | 97 ----- broker/neb/test/randomize.cc | 8 +- broker/neb/test/service_dependency.cc | 100 ----- .../broker/storage/conflict_manager.hh | 36 +- broker/storage/src/conflict_manager.cc | 7 +- broker/storage/src/conflict_manager_sql.cc | 182 +-------- .../com/centreon/broker/unified_sql/stream.hh | 42 +- broker/unified_sql/src/stream.cc | 27 +- broker/unified_sql/src/stream_sql.cc | 375 ++---------------- broker/unified_sql/src/stream_storage.cc | 9 +- common/inc/com/centreon/common/utf8.hh | 4 +- common/src/utf8.cc | 6 +- engine/inc/com/centreon/engine/nebstructs.hh | 2 +- tests/broker-engine/bbdo-protobuf.robot | 72 ---- tests/resources/Common.py | 50 --- 31 files changed, 171 insertions(+), 1950 deletions(-) delete mode 100644 broker/neb/inc/com/centreon/broker/neb/dependency.hh delete mode 100644 broker/neb/inc/com/centreon/broker/neb/host_dependency.hh delete mode 100644 broker/neb/inc/com/centreon/broker/neb/service_dependency.hh delete mode 100644 broker/neb/src/dependency.cc delete mode 100644 broker/neb/src/host_dependency.cc delete mode 100644 broker/neb/src/service_dependency.cc delete mode 100644 broker/neb/test/host_dependency.cc delete mode 100644 broker/neb/test/service_dependency.cc diff --git a/CMakeListsLinux.txt b/CMakeListsLinux.txt index a7b4120a02b..a3a47dcd080 100644 --- a/CMakeListsLinux.txt +++ b/CMakeListsLinux.txt @@ -20,7 +20,6 @@ # Global settings. # - option(WITH_ASAN "Add the libasan to check memory leaks and other memory issues." OFF) @@ -164,7 +163,8 @@ include_directories(${CMAKE_SOURCE_DIR} ${VCPKG_INCLUDE_DIR} fmt::fmt spdlog::spdlog - ${CMAKE_SOURCE_DIR}/clib/inc) + ${CMAKE_SOURCE_DIR}/clib/inc + ${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(clib) add_subdirectory(common) diff --git a/broker/core/sql/inc/com/centreon/broker/sql/mysql_error.hh b/broker/core/sql/inc/com/centreon/broker/sql/mysql_error.hh index 0afb7938210..d7af4120bc1 100644 --- a/broker/core/sql/inc/com/centreon/broker/sql/mysql_error.hh +++ b/broker/core/sql/inc/com/centreon/broker/sql/mysql_error.hh @@ -33,87 +33,83 @@ namespace database { class mysql_error { public: enum code { - empty, - clean_hosts_services, - clean_hostgroup_members, - clean_servicegroup_members, - clean_empty_hostgroups, - clean_empty_servicegroups, - clean_host_dependencies, - clean_service_dependencies, - clean_host_parents, - clean_modules, - clean_downtimes, - clean_comments, - clean_customvariables, - restore_instances, - update_customvariables, - update_logs, - update_metrics, - insert_data, - delete_metric, - delete_index, - flag_index_data, - delete_hosts, - delete_modules, - update_index_state, - delete_availabilities, - insert_availability, - rebuild_ba, - close_event, - close_ba_events, - close_kpi_events, - delete_ba_durations, - store_host_state, - store_acknowledgement, - store_comment, - remove_customvariable, - store_customvariable, - store_downtime, - store_eventhandler, - store_flapping, - store_host_check, - store_host_dependency, - store_host_group, - store_host_group_member, - delete_host_group_member, - store_host, - store_host_parentship, - store_host_status, - store_poller, - update_poller, - store_module, - store_service_check_command, - store_service_dependency, - store_service_group, - store_service_group_member, - delete_service_group_member, - store_service, - store_service_status, - update_ba, - update_kpi, - update_kpi_event, - insert_kpi_event, - insert_ba, - insert_bv, - insert_dimension_ba_bv, - truncate_dimension_table, - insert_dimension_kpi, - insert_timeperiod, - insert_timeperiod_exception, - insert_exclusion_timeperiod, - insert_relation_ba_timeperiod, - store_severity, - clean_severities, - store_tag, - clean_resources_tags, - update_index_data, - update_resources, - store_host_resources, - store_tags_resources_tags, - delete_resources_tags, - clean_resources, - delete_poller, + empty = 0, + clean_hosts_services = 1, + clean_hostgroup_members = 2, + clean_servicegroup_members = 3, + clean_empty_hostgroups = 4, + clean_empty_servicegroups = 5, + clean_host_parents = 6, + clean_modules = 7, + clean_downtimes = 8, + clean_comments = 9, + clean_customvariables = 10, + restore_instances = 11, + update_customvariables = 12, + update_logs = 13, + update_metrics = 14, + insert_data = 15, + delete_metric = 16, + delete_index = 17, + flag_index_data = 18, + delete_hosts = 19, + delete_modules = 20, + update_index_state = 21, + delete_availabilities = 22, + insert_availability = 23, + rebuild_ba = 24, + close_event = 25, + close_ba_events = 26, + close_kpi_events = 27, + delete_ba_durations = 28, + store_host_state = 29, + store_acknowledgement = 30, + store_comment = 31, + remove_customvariable = 32, + store_customvariable = 33, + store_downtime = 34, + store_eventhandler = 35, + store_flapping = 36, + store_host_check = 37, + store_host_group = 38, + store_host_group_member = 39, + delete_host_group_member = 40, + store_host = 41, + store_host_parentship = 42, + store_host_status = 43, + store_poller = 44, + update_poller = 45, + store_module = 46, + store_service_check_command = 47, + store_service_group = 48, + store_service_group_member = 49, + delete_service_group_member = 50, + store_service = 51, + store_service_status = 52, + update_ba = 53, + update_kpi = 54, + update_kpi_event = 55, + insert_kpi_event = 56, + insert_ba = 57, + insert_bv = 58, + insert_dimension_ba_bv = 59, + truncate_dimension_table = 60, + insert_dimension_kpi = 61, + insert_timeperiod = 62, + insert_timeperiod_exception = 63, + insert_exclusion_timeperiod = 64, + insert_relation_ba_timeperiod = 65, + store_severity = 66, + clean_severities = 67, + store_tag = 68, + clean_resources_tags = 69, + update_index_data = 70, + update_resources = 71, + store_host_resources = 72, + store_tags_resources_tags = 73, + delete_resources_tags = 74, + clean_resources = 75, + delete_poller = 76, }; static constexpr const char* msg[]{ @@ -123,8 +119,6 @@ class mysql_error { "could not clean service groups memberships table: ", "could not remove empty host groups: ", "could not remove empty service groups: ", - "could not clean host dependencies table: ", - "could not clean service dependencies table: ", "could not clean host parents table: ", "could not clean modules table: ", "could not clean downtimes table: ", @@ -158,7 +152,6 @@ class mysql_error { "could not store event handler: ", "could not store flapping status: ", "could not store host check: ", - "could not store host dependency: ", "could not store host group: ", "could not store host group membership: ", "could not delete membership of host to host group: ", @@ -169,7 +162,6 @@ class mysql_error { "could not update poller: ", "could not store module: ", "could not store service check command: ", - "could not store service dependency: ", "could not store service group: ", "could not store service group membership: ", "could not delete membersjip of service to service group: ", diff --git a/broker/neb/CMakeLists.txt b/broker/neb/CMakeLists.txt index 50fa3d67cca..ccc9e004133 100644 --- a/broker/neb/CMakeLists.txt +++ b/broker/neb/CMakeLists.txt @@ -31,13 +31,11 @@ set(NEB_SOURCES ${SRC_DIR}/comment.cc ${SRC_DIR}/custom_variable.cc ${SRC_DIR}/custom_variable_status.cc - ${SRC_DIR}/dependency.cc ${SRC_DIR}/downtime.cc ${SRC_DIR}/group.cc ${SRC_DIR}/group_member.cc ${SRC_DIR}/host.cc ${SRC_DIR}/host_check.cc - ${SRC_DIR}/host_dependency.cc ${SRC_DIR}/host_group.cc ${SRC_DIR}/host_group_member.cc ${SRC_DIR}/host_parent.cc @@ -51,7 +49,6 @@ set(NEB_SOURCES ${SRC_DIR}/responsive_instance.cc ${SRC_DIR}/service.cc ${SRC_DIR}/service_check.cc - ${SRC_DIR}/service_dependency.cc ${SRC_DIR}/service_group.cc ${SRC_DIR}/service_group_member.cc ${SRC_DIR}/service_status.cc @@ -61,14 +58,12 @@ set(NEB_SOURCES ${INC_DIR}/com/centreon/broker/neb/comment.hh ${INC_DIR}/com/centreon/broker/neb/custom_variable.hh ${INC_DIR}/com/centreon/broker/neb/custom_variable_status.hh - ${INC_DIR}/com/centreon/broker/neb/dependency.hh ${INC_DIR}/com/centreon/broker/neb/downtime.hh ${INC_DIR}/com/centreon/broker/neb/events.hh ${INC_DIR}/com/centreon/broker/neb/group.hh ${INC_DIR}/com/centreon/broker/neb/group_member.hh ${INC_DIR}/com/centreon/broker/neb/host.hh ${INC_DIR}/com/centreon/broker/neb/host_check.hh - ${INC_DIR}/com/centreon/broker/neb/host_dependency.hh ${INC_DIR}/com/centreon/broker/neb/host_group.hh ${INC_DIR}/com/centreon/broker/neb/host_group_member.hh ${INC_DIR}/com/centreon/broker/neb/host_parent.hh @@ -83,7 +78,6 @@ set(NEB_SOURCES ${INC_DIR}/com/centreon/broker/neb/responsive_instance.hh ${INC_DIR}/com/centreon/broker/neb/service.hh ${INC_DIR}/com/centreon/broker/neb/service_check.hh - ${INC_DIR}/com/centreon/broker/neb/service_dependency.hh ${INC_DIR}/com/centreon/broker/neb/service_group.hh ${INC_DIR}/com/centreon/broker/neb/service_group_member.hh ${INC_DIR}/com/centreon/broker/neb/service_status.hh @@ -183,7 +177,6 @@ if(WITH_TESTING) ${TEST_DIR}/custom_variable_status.cc ${TEST_DIR}/host.cc ${TEST_DIR}/host_check.cc - ${TEST_DIR}/host_dependency.cc ${TEST_DIR}/host_parent.cc ${TEST_DIR}/host_status.cc ${TEST_DIR}/instance.cc @@ -193,7 +186,6 @@ if(WITH_TESTING) ${TEST_DIR}/randomize.hh ${TEST_DIR}/service.cc ${TEST_DIR}/service_check.cc - ${TEST_DIR}/service_dependency.cc ${TEST_DIR}/service_status.cc ${TEST_DIR}/set_log_data.cc PARENT_SCOPE) diff --git a/broker/neb/inc/com/centreon/broker/neb/callbacks.hh b/broker/neb/inc/com/centreon/broker/neb/callbacks.hh index 4b226171c5b..f9ee10a1cb1 100644 --- a/broker/neb/inc/com/centreon/broker/neb/callbacks.hh +++ b/broker/neb/inc/com/centreon/broker/neb/callbacks.hh @@ -34,8 +34,6 @@ int callback_comment(int callback_type, void* data); int callback_pb_comment(int callback_type, void* data); int callback_custom_variable(int callback_type, void* data); int callback_pb_custom_variable(int callback_type, void* data); -int callback_dependency(int callback_type, void* data); -int callback_pb_dependency(int callback_type, void* data); int callback_downtime(int callback_type, void* data); int callback_pb_downtime(int callback_type, void* data); int callback_external_command(int callback_type, void* data); diff --git a/broker/neb/inc/com/centreon/broker/neb/dependency.hh b/broker/neb/inc/com/centreon/broker/neb/dependency.hh deleted file mode 100644 index 8b165e7a3ee..00000000000 --- a/broker/neb/inc/com/centreon/broker/neb/dependency.hh +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2009-2013,2015 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_NEB_DEPENDENCY_HH -#define CCB_NEB_DEPENDENCY_HH - -#include "com/centreon/broker/io/data.hh" - -namespace com::centreon::broker { - -namespace neb { -/** - * @class dependency dependency.hh "com/centreon/broker/neb/dependency.hh" - * @brief Dependency relationship. - * - * Defines a dependency between two objects. - * - * @see host_dependency - * @see service_dependency - */ -class dependency : public io::data { - public: - dependency() = delete; - dependency(uint32_t type); - dependency(dependency const& dep); - virtual ~dependency(); - dependency& operator=(dependency const& dep); - - std::string dependency_period; - uint32_t dependent_host_id; - bool enabled; - std::string execution_failure_options; - uint32_t host_id; - bool inherits_parent; - std::string notification_failure_options; - - private: - void _internal_copy(dependency const& dep); -}; -} // namespace neb - -} - -#endif // !CCB_NEB_DEPENDENCY_HH diff --git a/broker/neb/inc/com/centreon/broker/neb/events.hh b/broker/neb/inc/com/centreon/broker/neb/events.hh index 25b292c5e75..d364d16fc23 100644 --- a/broker/neb/inc/com/centreon/broker/neb/events.hh +++ b/broker/neb/inc/com/centreon/broker/neb/events.hh @@ -26,7 +26,6 @@ #include "com/centreon/broker/neb/downtime.hh" #include "com/centreon/broker/neb/host.hh" #include "com/centreon/broker/neb/host_check.hh" -#include "com/centreon/broker/neb/host_dependency.hh" #include "com/centreon/broker/neb/host_group.hh" #include "com/centreon/broker/neb/host_group_member.hh" #include "com/centreon/broker/neb/host_parent.hh" @@ -38,7 +37,6 @@ #include "com/centreon/broker/neb/responsive_instance.hh" #include "com/centreon/broker/neb/service.hh" #include "com/centreon/broker/neb/service_check.hh" -#include "com/centreon/broker/neb/service_dependency.hh" #include "com/centreon/broker/neb/service_group.hh" #include "com/centreon/broker/neb/service_group_member.hh" #include "com/centreon/broker/neb/service_status.hh" diff --git a/broker/neb/inc/com/centreon/broker/neb/host_dependency.hh b/broker/neb/inc/com/centreon/broker/neb/host_dependency.hh deleted file mode 100644 index 5ab87f8131c..00000000000 --- a/broker/neb/inc/com/centreon/broker/neb/host_dependency.hh +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright 2009-2012 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_NEB_HOST_DEPENDENCY_HH -#define CCB_NEB_HOST_DEPENDENCY_HH - -#include "com/centreon/broker/io/event_info.hh" -#include "com/centreon/broker/io/events.hh" -#include "com/centreon/broker/mapping/entry.hh" -#include "com/centreon/broker/neb/dependency.hh" -#include "com/centreon/broker/neb/internal.hh" - -namespace com::centreon::broker { - -namespace neb { -/** - * @class host_dependency host_dependency.hh - * "com/centreon/broker/neb/host_dependency.hh" - * @brief Host dependency relationship. - * - * Defines a dependency between two hosts. - */ -class host_dependency : public dependency { - public: - host_dependency(); - host_dependency(host_dependency const& other); - ~host_dependency(); - host_dependency& operator=(host_dependency const& other); - constexpr static uint32_t static_type() { - return io::events::data_type::value; - } - - static mapping::entry const entries[]; - static io::event_info::event_operations const operations; -}; -} // namespace neb - -} - -#endif // !CCB_NEB_HOST_DEPENDENCY_HH diff --git a/broker/neb/inc/com/centreon/broker/neb/initial.hh b/broker/neb/inc/com/centreon/broker/neb/initial.hh index 4556e4b699a..730beaff290 100644 --- a/broker/neb/inc/com/centreon/broker/neb/initial.hh +++ b/broker/neb/inc/com/centreon/broker/neb/initial.hh @@ -19,15 +19,9 @@ #ifndef CCB_NEB_INITIAL_HH_ #define CCB_NEB_INITIAL_HH_ -namespace com { -namespace centreon { -namespace broker { -namespace neb { +namespace com::centreon::broker::neb { void send_initial_configuration(); void send_initial_pb_configuration(); -} // namespace neb -} // namespace broker -} // namespace centreon -} // namespace com +} // namespace com::centreon::broker::neb #endif /* !CCB_NEB_INITIAL_HH_ */ diff --git a/broker/neb/inc/com/centreon/broker/neb/internal.hh b/broker/neb/inc/com/centreon/broker/neb/internal.hh index b3fba5da256..c12f0b660d3 100644 --- a/broker/neb/inc/com/centreon/broker/neb/internal.hh +++ b/broker/neb/inc/com/centreon/broker/neb/internal.hh @@ -99,14 +99,6 @@ using pb_acknowledgement = io::protobuf; -using pb_host_dependency = - io::protobuf; - -using pb_service_dependency = - io::protobuf; - using pb_host_group = io::protobuf; diff --git a/broker/neb/inc/com/centreon/broker/neb/service_dependency.hh b/broker/neb/inc/com/centreon/broker/neb/service_dependency.hh deleted file mode 100644 index adf3e7665ae..00000000000 --- a/broker/neb/inc/com/centreon/broker/neb/service_dependency.hh +++ /dev/null @@ -1,61 +0,0 @@ -/* -** Copyright 2009-2012 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_NEB_SERVICE_DEPENDENCY_HH -#define CCB_NEB_SERVICE_DEPENDENCY_HH - -#include "com/centreon/broker/io/event_info.hh" -#include "com/centreon/broker/io/events.hh" -#include "com/centreon/broker/mapping/entry.hh" -#include "com/centreon/broker/neb/dependency.hh" -#include "com/centreon/broker/neb/internal.hh" - -namespace com::centreon::broker { - -namespace neb { -/** - * @class service_dependency service_dependency.hh - * "com/centreon/broker/neb/service_dependency.hh" - * @brief Service dependency relationship. - * - * Defines a dependency between two services. - */ -class service_dependency : public dependency { - public: - service_dependency(); - service_dependency(service_dependency const& other); - ~service_dependency(); - service_dependency& operator=(service_dependency const& other); - constexpr static uint32_t static_type() { - return io::events::data_type::value; - } - - uint32_t dependent_service_id; - uint32_t service_id; - - static mapping::entry const entries[]; - static io::event_info::event_operations const operations; - - private: - void _internal_copy(service_dependency const& other); -}; -} // namespace neb - -} - -#endif // !CCB_NEB_SERVICE_DEPENDENCY_HH diff --git a/broker/neb/src/broker.cc b/broker/neb/src/broker.cc index d8645e48670..3a7c8e2f291 100644 --- a/broker/neb/src/broker.cc +++ b/broker/neb/src/broker.cc @@ -94,10 +94,6 @@ void broker_module_init(void const* arg) { e.register_event(make_type(io::neb, neb::de_host_check), "host_check", &neb::host_check::operations, neb::host_check::entries, "hosts"); - e.register_event(make_type(io::neb, neb::de_host_dependency), - "host_dependency", &neb::host_dependency::operations, - neb::host_dependency::entries, - "hosts_hosts_dependencies"); e.register_event(make_type(io::neb, neb::de_host), "host", &neb::host::operations, neb::host::entries, "hosts"); e.register_event(make_type(io::neb, neb::de_host_group), "host_group", @@ -124,10 +120,6 @@ void broker_module_init(void const* arg) { e.register_event(make_type(io::neb, neb::de_service_check), "service_check", &neb::service_check::operations, neb::service_check::entries, "services"); - e.register_event( - make_type(io::neb, neb::de_service_dependency), "service_dependency", - &neb::service_dependency::operations, - neb::service_dependency::entries, "services_services_dependencies"); e.register_event(make_type(io::neb, neb::de_service), "service", &neb::service::operations, neb::service::entries, "services"); @@ -211,13 +203,6 @@ void broker_module_init(void const* arg) { e.register_event(make_type(io::neb, neb::de_pb_acknowledgement), "Acknowledgement", &neb::pb_acknowledgement::operations, "acknowledgements"); - e.register_event(neb::pb_host_dependency::static_type(), "HostDependency", - &neb::pb_host_dependency::operations, - "hosts_hosts_dependencies"); - e.register_event(neb::pb_service_dependency::static_type(), - "ServiceDependency", - &neb::pb_service_dependency::operations, - "services_services_dependencies"); e.register_event(neb::pb_host_group::static_type(), "HostGroup", &neb::pb_host_group::operations, "hostgroups"); e.register_event( diff --git a/broker/neb/src/callbacks.cc b/broker/neb/src/callbacks.cc index 8ab21de522b..cac8b424458 100644 --- a/broker/neb/src/callbacks.cc +++ b/broker/neb/src/callbacks.cc @@ -40,11 +40,9 @@ #include "com/centreon/engine/comment.hh" #include "com/centreon/engine/events/loop.hh" #include "com/centreon/engine/globals.hh" -#include "com/centreon/engine/hostdependency.hh" #include "com/centreon/engine/hostgroup.hh" #include "com/centreon/engine/nebcallbacks.hh" #include "com/centreon/engine/nebstructs.hh" -#include "com/centreon/engine/servicedependency.hh" #include "com/centreon/engine/servicegroup.hh" #include "com/centreon/engine/severity.hh" #include "com/centreon/engine/tag.hh" @@ -119,7 +117,6 @@ static struct { uint32_t macro; int (*callback)(int, void*); } const gl_engine_callbacks[] = { - {NEBCALLBACK_ADAPTIVE_DEPENDENCY_DATA, &neb::callback_dependency}, {NEBCALLBACK_ADAPTIVE_HOST_DATA, &neb::callback_host}, {NEBCALLBACK_ADAPTIVE_SERVICE_DATA, &neb::callback_service}, {NEBCALLBACK_CUSTOM_VARIABLE_DATA, &neb::callback_custom_variable}, @@ -132,7 +129,6 @@ static struct { uint32_t macro; int (*callback)(int, void*); } const gl_pb_engine_callbacks[] = { - {NEBCALLBACK_ADAPTIVE_DEPENDENCY_DATA, &neb::callback_pb_dependency}, {NEBCALLBACK_ADAPTIVE_HOST_DATA, &neb::callback_pb_host}, {NEBCALLBACK_ADAPTIVE_SERVICE_DATA, &neb::callback_pb_service}, {NEBCALLBACK_CUSTOM_VARIABLE_DATA, &neb::callback_pb_custom_variable}, @@ -675,315 +671,6 @@ int neb::callback_custom_variable(int callback_type, void* data) { return 0; } -/** - * @brief Function that process dependency data. - * - * This function is called by Centreon Engine when some dependency data - * is available. - * - * @param[in] callback_type Type of the callback - * (NEBCALLBACK_ADAPTIVE_DEPENDENCY_DATA). - * @param[in] data A pointer to a - * nebstruct_adaptive_dependency_data - * containing the dependency data. - * - * @return 0 on success. - */ -int neb::callback_dependency(int callback_type, void* data) { - // Log message. - SPDLOG_LOGGER_DEBUG(neb_logger, "callbacks: generating dependency event"); - (void)callback_type; - - try { - // Input variables. - nebstruct_adaptive_dependency_data* nsadd( - static_cast(data)); - - // Host dependency. - if ((NEBTYPE_HOSTDEPENDENCY_ADD == nsadd->type) || - (NEBTYPE_HOSTDEPENDENCY_UPDATE == nsadd->type) || - (NEBTYPE_HOSTDEPENDENCY_DELETE == nsadd->type)) { - // Find IDs. - uint64_t host_id; - uint64_t dep_host_id; - engine::hostdependency* dep( - static_cast(nsadd->object_ptr)); - if (!dep->get_hostname().empty()) { - host_id = engine::get_host_id(dep->get_hostname()); - } else { - SPDLOG_LOGGER_ERROR( - neb_logger, - "callbacks: dependency callback called without valid host"); - host_id = 0; - } - if (!dep->get_dependent_hostname().empty()) { - dep_host_id = engine::get_host_id(dep->get_dependent_hostname()); - } else { - SPDLOG_LOGGER_DEBUG( - neb_logger, - "callbacks: dependency callback called without valid dependent " - "host"); - dep_host_id = 0; - } - - // Generate service dependency event. - auto hst_dep{std::make_shared()}; - hst_dep->host_id = host_id; - hst_dep->dependent_host_id = dep_host_id; - hst_dep->enabled = (nsadd->type != NEBTYPE_HOSTDEPENDENCY_DELETE); - if (!dep->get_dependency_period().empty()) - hst_dep->dependency_period = dep->get_dependency_period(); - { - std::string options; - if (dep->get_fail_on_down()) - options.append("d"); - if (dep->get_fail_on_up()) - options.append("o"); - if (dep->get_fail_on_pending()) - options.append("p"); - if (dep->get_fail_on_unreachable()) - options.append("u"); - if (dep->get_dependency_type() == engine::dependency::notification) - hst_dep->notification_failure_options = options; - else if (dep->get_dependency_type() == engine::dependency::execution) - hst_dep->execution_failure_options = options; - } - hst_dep->inherits_parent = dep->get_inherits_parent(); - SPDLOG_LOGGER_DEBUG(neb_logger, "callbacks: host {} depends on host {}", - dep_host_id, host_id); - - // Publish dependency event. - neb::gl_publisher.write(hst_dep); - } - // Service dependency. - else if ((NEBTYPE_SERVICEDEPENDENCY_ADD == nsadd->type) || - (NEBTYPE_SERVICEDEPENDENCY_UPDATE == nsadd->type) || - (NEBTYPE_SERVICEDEPENDENCY_DELETE == nsadd->type)) { - // Find IDs. - std::pair ids; - std::pair dep_ids; - engine::servicedependency* dep( - static_cast(nsadd->object_ptr)); - if (!dep->get_hostname().empty() && - !dep->get_service_description().empty()) { - ids = engine::get_host_and_service_id(dep->get_hostname(), - dep->get_service_description()); - } else { - SPDLOG_LOGGER_ERROR( - neb_logger, - "callbacks: dependency callback called without valid service"); - ids.first = 0; - ids.second = 0; - } - if (!dep->get_dependent_hostname().empty() && - !dep->get_dependent_service_description().empty()) { - dep_ids = engine::get_host_and_service_id( - dep->get_dependent_hostname(), - dep->get_dependent_service_description()); - } else { - SPDLOG_LOGGER_ERROR( - neb_logger, - "callbacks: dependency callback called without valid dependent " - "service"); - dep_ids.first = 0; - dep_ids.second = 0; - } - - // Generate service dependency event. - auto svc_dep{std::make_shared()}; - svc_dep->host_id = ids.first; - svc_dep->service_id = ids.second; - svc_dep->dependent_host_id = dep_ids.first; - svc_dep->dependent_service_id = dep_ids.second; - svc_dep->enabled = (nsadd->type != NEBTYPE_SERVICEDEPENDENCY_DELETE); - if (!dep->get_dependency_period().empty()) - svc_dep->dependency_period = dep->get_dependency_period(); - { - std::string options; - if (dep->get_fail_on_critical()) - options.append("c"); - if (dep->get_fail_on_ok()) - options.append("o"); - if (dep->get_fail_on_pending()) - options.append("p"); - if (dep->get_fail_on_unknown()) - options.append("u"); - if (dep->get_fail_on_warning()) - options.append("w"); - if (dep->get_dependency_type() == engine::dependency::notification) - svc_dep->notification_failure_options = options; - else if (dep->get_dependency_type() == engine::dependency::execution) - svc_dep->execution_failure_options = options; - } - svc_dep->inherits_parent = dep->get_inherits_parent(); - SPDLOG_LOGGER_DEBUG( - neb_logger, "callbacks: service ({}, {}) depends on service ({}, {})", - dep_ids.first, dep_ids.second, ids.first, ids.second); - - // Publish dependency event. - neb::gl_publisher.write(svc_dep); - } - } - // Avoid exception propagation to C code. - catch (...) { - } - - return 0; -} - -/** - * @brief Function that process dependency data. - * - * This function is called by Centreon Engine when some dependency data - * is available. - * - * @param[in] callback_type Type of the callback - * (NEBCALLBACK_ADAPTIVE_DEPENDENCY_DATA). - * @param[in] data A pointer to a - * nebstruct_adaptive_dependency_data - * containing the dependency data. - * - * @return 0 on success. - */ -int neb::callback_pb_dependency(int, void* data) { - // Log message. - SPDLOG_LOGGER_DEBUG(neb_logger, "callbacks: generating dependency event"); - - // Input variables. - nebstruct_adaptive_dependency_data* nsadd( - static_cast(data)); - - // Host dependency. - if ((NEBTYPE_HOSTDEPENDENCY_ADD == nsadd->type) || - (NEBTYPE_HOSTDEPENDENCY_UPDATE == nsadd->type) || - (NEBTYPE_HOSTDEPENDENCY_DELETE == nsadd->type)) { - // Find IDs. - uint64_t host_id; - uint64_t dep_host_id; - - engine::hostdependency* dep( - static_cast(nsadd->object_ptr)); - if (!dep->get_hostname().empty()) { - host_id = engine::get_host_id(dep->get_hostname()); - } else { - SPDLOG_LOGGER_ERROR( - neb_logger, - "callbacks: dependency callback called without valid host"); - host_id = 0; - } - if (!dep->get_dependent_hostname().empty()) { - dep_host_id = engine::get_host_id(dep->get_dependent_hostname()); - } else { - SPDLOG_LOGGER_DEBUG( - neb_logger, - "callbacks: dependency callback called without valid dependent " - "host"); - dep_host_id = 0; - } - - // Generate service dependency event. - auto hd{std::make_shared()}; - HostDependency& hst_dep = hd->mut_obj(); - hst_dep.set_host_id(host_id); - hst_dep.set_dependent_host_id(dep_host_id); - hst_dep.set_enabled(nsadd->type != NEBTYPE_HOSTDEPENDENCY_DELETE); - if (!dep->get_dependency_period().empty()) - hst_dep.set_dependency_period(dep->get_dependency_period()); - { - std::string options; - if (dep->get_fail_on_down()) - options.append("d"); - if (dep->get_fail_on_up()) - options.append("o"); - if (dep->get_fail_on_pending()) - options.append("p"); - if (dep->get_fail_on_unreachable()) - options.append("u"); - if (dep->get_dependency_type() == engine::dependency::notification) - hst_dep.set_notification_failure_options(options); - else if (dep->get_dependency_type() == engine::dependency::execution) - hst_dep.set_execution_failure_options(options); - } - hst_dep.set_inherits_parent(dep->get_inherits_parent()); - SPDLOG_LOGGER_DEBUG(neb_logger, "callbacks: host {} depends on host {}", - dep_host_id, host_id); - - // Publish dependency event. - neb::gl_publisher.write(hd); - } - // Service dependency. - else if ((NEBTYPE_SERVICEDEPENDENCY_ADD == nsadd->type) || - (NEBTYPE_SERVICEDEPENDENCY_UPDATE == nsadd->type) || - (NEBTYPE_SERVICEDEPENDENCY_DELETE == nsadd->type)) { - // Find IDs. - std::pair ids; - std::pair dep_ids; - engine::servicedependency* dep( - static_cast(nsadd->object_ptr)); - if (!dep->get_hostname().empty() && - !dep->get_service_description().empty()) { - ids = engine::get_host_and_service_id(dep->get_hostname(), - dep->get_service_description()); - } else { - SPDLOG_LOGGER_ERROR( - neb_logger, - "callbacks: dependency callback called without valid service"); - ids.first = 0; - ids.second = 0; - } - if (!dep->get_dependent_hostname().empty() && - !dep->get_dependent_service_description().empty()) { - dep_ids = engine::get_host_and_service_id( - dep->get_dependent_hostname(), - dep->get_dependent_service_description()); - } else { - SPDLOG_LOGGER_ERROR( - neb_logger, - "callbacks: dependency callback called without valid dependent " - "service"); - dep_ids.first = 0; - dep_ids.second = 0; - } - - // Generate service dependency event. - auto sd{std::make_shared()}; - ServiceDependency& svc_dep = sd->mut_obj(); - svc_dep.set_host_id(ids.first); - svc_dep.set_service_id(ids.second); - svc_dep.set_dependent_host_id(dep_ids.first); - svc_dep.set_dependent_service_id(dep_ids.second); - svc_dep.set_enabled(nsadd->type != NEBTYPE_SERVICEDEPENDENCY_DELETE); - if (!dep->get_dependency_period().empty()) - svc_dep.set_dependency_period(dep->get_dependency_period()); - { - std::string options; - if (dep->get_fail_on_critical()) - options.append("c"); - if (dep->get_fail_on_ok()) - options.append("o"); - if (dep->get_fail_on_pending()) - options.append("p"); - if (dep->get_fail_on_unknown()) - options.append("u"); - if (dep->get_fail_on_warning()) - options.append("w"); - if (dep->get_dependency_type() == engine::dependency::notification) - svc_dep.set_notification_failure_options(options); - else if (dep->get_dependency_type() == engine::dependency::execution) - svc_dep.set_execution_failure_options(options); - } - svc_dep.set_inherits_parent(dep->get_inherits_parent()); - SPDLOG_LOGGER_DEBUG( - neb_logger, "callbacks: service ({}, {}) depends on service ({}, {})", - dep_ids.first, dep_ids.second, ids.first, ids.second); - - // Publish dependency event. - neb::gl_publisher.write(sd); - } - - return 0; -} - /** * @brief Function that process downtime data. * diff --git a/broker/neb/src/dependency.cc b/broker/neb/src/dependency.cc deleted file mode 100644 index 9af51cdfc1c..00000000000 --- a/broker/neb/src/dependency.cc +++ /dev/null @@ -1,88 +0,0 @@ -/** -* Copyright 2009-2012,2015 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 -*/ - -#include "com/centreon/broker/neb/dependency.hh" - -using namespace com::centreon::broker::neb; - -/************************************** - * * - * Public Methods * - * * - **************************************/ - -/** - * Default constructor. - */ -dependency::dependency(uint32_t type) - : io::data(type), - dependent_host_id(0), - enabled(true), - host_id(0), - inherits_parent(false) {} - -/** - * Copy constructor. - * - * @param[in] dep Object to copy. - */ -dependency::dependency(dependency const& dep) : io::data(dep) { - _internal_copy(dep); -} - -/** - * Destructor. - */ -dependency::~dependency() {} - -/** - * Assignment operator. - * - * @param[in] dep Object to copy from. - * - * @return This object. - */ -dependency& dependency::operator=(dependency const& dep) { - io::data::operator=(dep); - _internal_copy(dep); - return (*this); -} - -/************************************** - * * - * Private Methods * - * * - **************************************/ - -/** - * @brief Copy internal data members. - * - * This method is used by the copy constructor and the assignment operator. - * - * @param[in] dep Object to copy. - */ -void dependency::_internal_copy(dependency const& dep) { - dependency_period = dep.dependency_period; - dependent_host_id = dep.dependent_host_id; - enabled = dep.enabled; - execution_failure_options = dep.execution_failure_options; - host_id = dep.host_id; - inherits_parent = dep.inherits_parent; - notification_failure_options = dep.notification_failure_options; - return; -} diff --git a/broker/neb/src/host_dependency.cc b/broker/neb/src/host_dependency.cc deleted file mode 100644 index 352c4e345ca..00000000000 --- a/broker/neb/src/host_dependency.cc +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Copyright 2009-2013,2015 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 - */ - -#include "com/centreon/broker/neb/host_dependency.hh" - -#include "com/centreon/broker/sql/table_max_size.hh" - -using namespace com::centreon::broker; -using namespace com::centreon::broker::neb; - -/************************************** - * * - * Public Methods * - * * - **************************************/ - -/** - * Default constructor. - */ -host_dependency::host_dependency() - : dependency(host_dependency::static_type()) {} - -/** - * Copy constructor. - * - * @param[in] other Object to copy. - */ -host_dependency::host_dependency(host_dependency const& other) - : dependency(other) {} - -/** - * Destructor. - */ -host_dependency::~host_dependency() {} - -/** - * Assignment operator. - * - * @param[in] other Object to copy. - * - * @return This object. - */ -host_dependency& host_dependency::operator=(host_dependency const& other) { - dependency::operator=(other); - return *this; -} - -/************************************** - * * - * Static Objects * - * * - **************************************/ - -// Mapping. -mapping::entry const host_dependency::entries[] = { - mapping::entry( - &host_dependency::dependency_period, - "dependency_period", - get_centreon_storage_hosts_hosts_dependencies_col_size( - centreon_storage_hosts_hosts_dependencies_dependency_period)), - mapping::entry(&host_dependency::dependent_host_id, - "dependent_host_id", - mapping::entry::invalid_on_zero), - mapping::entry(&host_dependency::enabled, ""), - mapping::entry( - &host_dependency::execution_failure_options, - "execution_failure_options", - get_centreon_storage_hosts_hosts_dependencies_col_size( - centreon_storage_hosts_hosts_dependencies_execution_failure_options)), - mapping::entry(&host_dependency::inherits_parent, "inherits_parent"), - mapping::entry(&host_dependency::host_id, - "host_id", - mapping::entry::invalid_on_zero), - mapping::entry( - &host_dependency::notification_failure_options, - "notification_failure_options", - get_centreon_storage_hosts_hosts_dependencies_col_size( - centreon_storage_hosts_hosts_dependencies_notification_failure_options)), - mapping::entry()}; - -// Operations. -static io::data* new_host_dep() { - return (new host_dependency); -} -io::event_info::event_operations const host_dependency::operations = { - &new_host_dep, nullptr, nullptr}; diff --git a/broker/neb/src/initial.cc b/broker/neb/src/initial.cc index a8fad65920e..183e26e1567 100644 --- a/broker/neb/src/initial.cc +++ b/broker/neb/src/initial.cc @@ -27,7 +27,6 @@ #include "com/centreon/engine/downtimes/service_downtime.hh" #include "com/centreon/engine/globals.hh" #include "com/centreon/engine/host.hh" -#include "com/centreon/engine/hostdependency.hh" #include "com/centreon/engine/nebcallbacks.hh" #include "com/centreon/engine/nebstructs.hh" #include "com/centreon/engine/objects.hh" @@ -72,7 +71,6 @@ static void send_custom_variables_list( if (cit->second.is_sent()) { // Fill callback struct. nebstruct_custom_variable_data nscvd; - memset(&nscvd, 0, sizeof(nscvd)); nscvd.type = NEBTYPE_HOSTCUSTOMVARIABLE_ADD; nscvd.timestamp.tv_sec = time(nullptr); nscvd.var_name = const_cast(name.c_str()); @@ -173,48 +171,6 @@ static void send_pb_downtimes_list() { send_downtimes_list(neb::callback_pb_downtime); } -/** - * Send to the global publisher the list of host dependencies within Nagios. - */ -static void send_host_dependencies_list( - neb_sender callbackfct = neb::callback_dependency) { - // Start log message. - neb_logger->info("init: beginning host dependencies dump"); - - try { - // Loop through all dependencies. - for (hostdependency_mmap::const_iterator - it{com::centreon::engine::hostdependency::hostdependencies - .begin()}, - end{com::centreon::engine::hostdependency::hostdependencies.end()}; - it != end; ++it) { - // Fill callback struct. - nebstruct_adaptive_dependency_data nsadd; - memset(&nsadd, 0, sizeof(nsadd)); - nsadd.type = NEBTYPE_HOSTDEPENDENCY_ADD; - nsadd.object_ptr = it->second.get(); - - // Callback. - callbackfct(NEBCALLBACK_ADAPTIVE_DEPENDENCY_DATA, &nsadd); - } - } catch (std::exception const& e) { - neb_logger->info("init: error occurred while dumping host dependencies: {}", - e.what()); - } catch (...) { - neb_logger->error( - "init: unknown error occurred while dumping host dependencies"); - } - - // End log message. - neb_logger->info("init: end of host dependencies dump"); - - return; -} - -static void send_pb_host_dependencies_list() { - send_host_dependencies_list(neb::callback_pb_dependency); -} - /** * Send to the global publisher the list of host groups within Engine. */ @@ -369,49 +325,6 @@ static void send_pb_host_parents_list() { send_host_parents_list(neb::callback_pb_relation); } -/** - * Send to the global publisher the list of service dependencies within - * Nagios. - */ -static void send_service_dependencies_list( - neb_sender sender_fct = neb::callback_dependency) { - // Start log message. - neb_logger->info("init: beginning service dependencies dump"); - - try { - // Loop through all dependencies. - for (servicedependency_mmap::const_iterator - it{com::centreon::engine::servicedependency::servicedependencies - .begin()}, - end{com::centreon::engine::servicedependency::servicedependencies - .end()}; - it != end; ++it) { - // Fill callback struct. - nebstruct_adaptive_dependency_data nsadd; - memset(&nsadd, 0, sizeof(nsadd)); - nsadd.type = NEBTYPE_SERVICEDEPENDENCY_ADD; - nsadd.object_ptr = it->second.get(); - - // Callback. - sender_fct(NEBCALLBACK_ADAPTIVE_DEPENDENCY_DATA, &nsadd); - } - } catch (std::exception const& e) { - neb_logger->error( - "init: error occurred while dumping service dependencies: {}", - e.what()); - } catch (...) { - neb_logger->error( - "init: unknown error occurred while dumping service dependencies"); - } - - // End log message. - neb_logger->info("init: end of service dependencies dump"); -} - -static void send_pb_service_dependencies_list() { - send_service_dependencies_list(neb::callback_pb_dependency); -} - /** * Send to the global publisher the list of service groups within Engine. */ @@ -541,8 +454,6 @@ void neb::send_initial_configuration() { send_host_parents_list(); send_host_group_list(); send_service_group_list(); - send_host_dependencies_list(); - send_service_dependencies_list(); send_instance_configuration(); } @@ -566,7 +477,5 @@ void neb::send_initial_pb_configuration() { send_pb_host_parents_list(); send_pb_host_group_list(); send_pb_service_group_list(); - send_pb_host_dependencies_list(); - send_pb_service_dependencies_list(); send_pb_instance_configuration(); } diff --git a/broker/neb/src/service_dependency.cc b/broker/neb/src/service_dependency.cc deleted file mode 100644 index 8357aa1df2a..00000000000 --- a/broker/neb/src/service_dependency.cc +++ /dev/null @@ -1,125 +0,0 @@ -/** - * Copyright 2009-2013,2015 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 - */ - -#include "com/centreon/broker/neb/service_dependency.hh" - -#include "com/centreon/broker/sql/table_max_size.hh" - -using namespace com::centreon::broker; -using namespace com::centreon::broker::neb; - -/** - * Default constructor. - */ -service_dependency::service_dependency() - : dependency(service_dependency::static_type()), - dependent_service_id(0), - service_id(0) {} - -/** - * Copy constructor. - * - * @param[in] sd Object to copy. - */ -service_dependency::service_dependency(service_dependency const& sd) - : dependency(sd) { - _internal_copy(sd); -} - -/** - * Destructor. - */ -service_dependency::~service_dependency() {} - -/** - * Assignment operator. - * - * @param[in] sd Object to copy. - * - * @return This object. - */ -service_dependency& service_dependency::operator=( - service_dependency const& sd) { - if (this != &sd) { - dependency::operator=(sd); - _internal_copy(sd); - } - return *this; -} - -/************************************** - * * - * Private Methods * - * * - **************************************/ - -/** - * Copy internal members from the given object. - * - * @param[in] sd Object to copy. - */ -void service_dependency::_internal_copy(service_dependency const& sd) { - dependent_service_id = sd.dependent_service_id; - service_id = sd.service_id; -} - -/************************************** - * * - * Static Objects * - * * - **************************************/ - -// Mapping. -mapping::entry const service_dependency::entries[] = { - mapping::entry( - &service_dependency::dependency_period, - "dependency_period", - get_centreon_storage_services_services_dependencies_col_size( - centreon_storage_services_services_dependencies_dependency_period)), - mapping::entry(&service_dependency::dependent_host_id, - "dependent_host_id", - mapping::entry::invalid_on_zero), - mapping::entry(&service_dependency::dependent_service_id, - "dependent_service_id", - mapping::entry::invalid_on_zero), - mapping::entry(&service_dependency::enabled, ""), - mapping::entry( - &service_dependency::execution_failure_options, - "execution_failure_options", - get_centreon_storage_services_services_dependencies_col_size( - centreon_storage_services_services_dependencies_execution_failure_options)), - mapping::entry(&service_dependency::host_id, - "host_id", - mapping::entry::invalid_on_zero), - mapping::entry(&service_dependency::inherits_parent, "inherits_parent"), - mapping::entry( - &service_dependency::notification_failure_options, - "notification_failure_options", - get_centreon_storage_services_services_dependencies_col_size( - centreon_storage_services_services_dependencies_notification_failure_options)), - mapping::entry(&service_dependency::service_id, - "service_id", - mapping::entry::invalid_on_zero), - mapping::entry()}; - -// Operations. -static io::data* new_service_dependency() { - return new service_dependency; -} -io::event_info::event_operations const service_dependency::operations = { - &new_service_dependency, nullptr, nullptr}; diff --git a/broker/neb/test/host_dependency.cc b/broker/neb/test/host_dependency.cc deleted file mode 100644 index 21a3d76e709..00000000000 --- a/broker/neb/test/host_dependency.cc +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Copyright 2011 - 2019 Centreon (https://www.centreon.com/) - * - * 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 - * - */ - -#include -#include -#include "com/centreon/broker/neb/host.hh" -#include "randomize.hh" - -using namespace com::centreon::broker; - -class HostDependencyTest : public ::testing::Test { - public: - void SetUp() override { - // Initialization. - randomize_init(); - } - - void TearDown() override { - // Cleanup. - randomize_cleanup(); - } -}; - -TEST_F(HostDependencyTest, Assignment) { - // Object #1. - neb::host_dependency hdep1; - std::vector randvals1; - randomize(hdep1, &randvals1); - - // Object #2. - neb::host_dependency hdep2; - randomize(hdep2); - - // Assignment. - hdep2 = hdep1; - - // Reset object #1. - std::vector randvals2; - randomize(hdep1, &randvals2); - - // Compare objects with expected results. - ASSERT_TRUE(hdep1 == randvals2); - ASSERT_TRUE(hdep2 == randvals1); -} - -TEST_F(HostDependencyTest, CopyConstructor) { - // Object #1. - neb::host_dependency hdep1; - std::vector randvals1; - randomize(hdep1, &randvals1); - - // Object #2. - neb::host_dependency hdep2(hdep1); - - // Reset object #1. - std::vector randvals2; - randomize(hdep1, &randvals2); - - // Compare objects with expected results. - ASSERT_TRUE(hdep1 == randvals2); - ASSERT_TRUE(hdep2 == randvals1); -} - -TEST_F(HostDependencyTest, DefaultConstructor) { - // Object. - neb::host_dependency hdep; - - // Check. - ASSERT_EQ(hdep.source_id, 0u); - ASSERT_EQ(hdep.destination_id, 0u); - ASSERT_TRUE(hdep.dependency_period == ""); - ASSERT_EQ(hdep.dependent_host_id, 0u); - ASSERT_TRUE(hdep.enabled); - ASSERT_TRUE(hdep.execution_failure_options.empty()); - ASSERT_EQ(hdep.host_id, 0u); - ASSERT_FALSE(hdep.inherits_parent); - ASSERT_TRUE(hdep.notification_failure_options.empty()); - ASSERT_FALSE( - hdep.type() != - (io::events::data_type::value)); -} diff --git a/broker/neb/test/randomize.cc b/broker/neb/test/randomize.cc index a87050945ac..c7787c46b9a 100644 --- a/broker/neb/test/randomize.cc +++ b/broker/neb/test/randomize.cc @@ -108,9 +108,6 @@ void randomize_init() { &neb::downtime::operations, neb::downtime::entries); e.register_event(make_type(io::neb, neb::de_host_check), "host_check", &neb::host_check::operations, neb::host_check::entries); - e.register_event(make_type(io::neb, neb::de_host_dependency), - "host_dependency", &neb::host_dependency::operations, - neb::host_dependency::entries); e.register_event(make_type(io::neb, neb::de_host), "host", &neb::host::operations, neb::host::entries); e.register_event(make_type(io::neb, neb::de_host_parent), "host_parent", @@ -127,9 +124,6 @@ void randomize_init() { e.register_event(make_type(io::neb, neb::de_service_check), "service_check", &neb::service_check::operations, neb::service_check::entries); - e.register_event(make_type(io::neb, neb::de_service_dependency), - "service_dependency", &neb::service_dependency::operations, - neb::service_dependency::entries); e.register_event(make_type(io::neb, neb::de_service), "service", &neb::service::operations, neb::service::entries); e.register_event(make_type(io::neb, neb::de_service_status), "service_status", @@ -143,7 +137,7 @@ void randomize_init() { void randomize_cleanup() { for (std::list::iterator it(generated.begin()), end(generated.end()); it != end; ++it) - delete[] * it; + delete[] *it; generated.clear(); io::events::unload(); io::protocols::unload(); diff --git a/broker/neb/test/service_dependency.cc b/broker/neb/test/service_dependency.cc deleted file mode 100644 index 66ad6dc4418..00000000000 --- a/broker/neb/test/service_dependency.cc +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright 2011 - 2019 Centreon (https://www.centreon.com/) - * - * 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 - * - */ - -#include "com/centreon/broker/neb/service_dependency.hh" -#include -#include "com/centreon/broker/io/events.hh" -#include "com/centreon/broker/neb/internal.hh" -#include "randomize.hh" - -using namespace com::centreon::broker; - -class ServiceDependencyTest : public ::testing::Test { - void SetUp() override { randomize_init(); }; - - void TearDown() override { randomize_cleanup(); }; -}; - -/** - * Check service_dependency's assignment operator. - */ -TEST_F(ServiceDependencyTest, Assign) { - // Object #1. - neb::service_dependency sdep1; - std::vector randvals1; - randomize(sdep1, &randvals1); - - // Object #2. - neb::service_dependency sdep2; - randomize(sdep2); - - // Assignment. - sdep2 = sdep1; - - // Reset object #1. - std::vector randvals2; - randomize(sdep1, &randvals2); - - // Compare objects with expected results. - ASSERT_FALSE(sdep1 != randvals2); - ASSERT_FALSE(sdep2 != randvals1); -} - -/** - * Check service_dependency's copy constructor. - */ -TEST_F(ServiceDependencyTest, CopyCtor) { - // Object #1. - neb::service_dependency sdep1; - std::vector randvals1; - randomize(sdep1, &randvals1); - - // Object #2. - neb::service_dependency sdep2(sdep1); - - // Reset object #1. - std::vector randvals2; - randomize(sdep1, &randvals2); - - // Compare objects with expected results. - ASSERT_FALSE(sdep1 != randvals2); - ASSERT_FALSE(sdep2 != randvals1); -} - -/** - * Check service_dependency's default constructor. - */ -TEST_F(ServiceDependencyTest, DefaultCtor) { - // Object. - neb::service_dependency sdep; - - // Check. - ASSERT_FALSE(sdep.source_id != 0); - ASSERT_FALSE(sdep.destination_id != 0); - ASSERT_FALSE(sdep.dependency_period != ""); - ASSERT_FALSE(sdep.dependent_host_id != 0); - ASSERT_FALSE(sdep.enabled != true); - ASSERT_FALSE(!sdep.execution_failure_options.empty()); - ASSERT_FALSE(sdep.host_id != 0); - ASSERT_FALSE(sdep.inherits_parent != false); - ASSERT_FALSE(!sdep.notification_failure_options.empty()); - ASSERT_FALSE(sdep.service_id != 0); - auto val(io::events::data_type::value); - ASSERT_FALSE(sdep.type() != val); -} diff --git a/broker/storage/inc/com/centreon/broker/storage/conflict_manager.hh b/broker/storage/inc/com/centreon/broker/storage/conflict_manager.hh index b7815b6e5be..19abaa710ad 100644 --- a/broker/storage/inc/com/centreon/broker/storage/conflict_manager.hh +++ b/broker/storage/inc/com/centreon/broker/storage/conflict_manager.hh @@ -78,11 +78,9 @@ class conflict_manager { enum special_conn { custom_variable, downtime, - host_dependency, host_group, host_parent, log, - service_dependency, service_group, severity, tag, @@ -94,21 +92,19 @@ class conflict_manager { comments = 1 << 1, custom_variables = 1 << 2, downtimes = 1 << 3, - host_dependencies = 1 << 4, - host_hostgroups = 1 << 5, - host_parents = 1 << 6, - hostgroups = 1 << 7, - hosts = 1 << 8, - instances = 1 << 9, - modules = 1 << 10, - service_dependencies = 1 << 11, - service_servicegroups = 1 << 12, - servicegroups = 1 << 13, - services = 1 << 14, - index_data = 1 << 15, - metrics = 1 << 16, - severities = 1 << 17, - tags = 1 << 18, + host_hostgroups = 1 << 4, + host_parents = 1 << 5, + hostgroups = 1 << 6, + hosts = 1 << 7, + instances = 1 << 8, + modules = 1 << 9, + service_servicegroups = 1 << 10, + servicegroups = 1 << 11, + services = 1 << 12, + index_data = 1 << 13, + metrics = 1 << 14, + severities = 1 << 15, + tags = 1 << 16, }; struct index_info { @@ -247,7 +243,6 @@ class conflict_manager { database::mysql_stmt _event_handler_insupdate; database::mysql_stmt _flapping_status_insupdate; database::mysql_stmt _host_check_update; - database::mysql_stmt _host_dependency_insupdate; database::mysql_stmt _host_group_insupdate; database::mysql_stmt _host_group_member_delete; database::mysql_stmt _host_group_member_insert; @@ -259,7 +254,6 @@ class conflict_manager { database::mysql_stmt _instance_status_insupdate; database::mysql_stmt _module_insert; database::mysql_stmt _service_check_update; - database::mysql_stmt _service_dependency_insupdate; database::mysql_stmt _service_group_insupdate; database::mysql_stmt _service_group_member_delete; database::mysql_stmt _service_group_member_insert; @@ -304,8 +298,6 @@ class conflict_manager { std::tuple, uint32_t, bool*>& t); void _process_host_check( std::tuple, uint32_t, bool*>& t); - void _process_host_dependency( - std::tuple, uint32_t, bool*>& t); void _process_host_group( std::tuple, uint32_t, bool*>& t); void _process_host_group_member( @@ -322,8 +314,6 @@ class conflict_manager { void _process_log(std::tuple, uint32_t, bool*>& t); void _process_service_check( std::tuple, uint32_t, bool*>& t); - void _process_service_dependency( - std::tuple, uint32_t, bool*>& t); void _process_service_group( std::tuple, uint32_t, bool*>& t); void _process_service_group_member( diff --git a/broker/storage/src/conflict_manager.cc b/broker/storage/src/conflict_manager.cc index 2978cbc1cb7..c19669f9db6 100644 --- a/broker/storage/src/conflict_manager.cc +++ b/broker/storage/src/conflict_manager.cc @@ -56,7 +56,7 @@ void (conflict_manager::*const conflict_manager::_neb_processing_table[])( nullptr, nullptr, &conflict_manager::_process_host_check, - &conflict_manager::_process_host_dependency, + nullptr, &conflict_manager::_process_host_group, &conflict_manager::_process_host_group_member, &conflict_manager::_process_host, @@ -67,7 +67,7 @@ void (conflict_manager::*const conflict_manager::_neb_processing_table[])( &conflict_manager::_process_log, nullptr, &conflict_manager::_process_service_check, - &conflict_manager::_process_service_dependency, + nullptr, &conflict_manager::_process_service_group, &conflict_manager::_process_service_group_member, &conflict_manager::_process_service, @@ -955,8 +955,7 @@ void conflict_manager::process_stop(const std::shared_ptr& d) { _finish_action(-1, actions::hosts | actions::acknowledgements | actions::modules | actions::downtimes | actions::comments | actions::servicegroups | - actions::hostgroups | actions::service_dependencies | - actions::host_dependencies); + actions::hostgroups); // Log message. _logger_sql->info("SQL: Disabling poller (id: {}, running: no)", diff --git a/broker/storage/src/conflict_manager_sql.cc b/broker/storage/src/conflict_manager_sql.cc index 3192190688f..0f02ec0a519 100644 --- a/broker/storage/src/conflict_manager_sql.cc +++ b/broker/storage/src/conflict_manager_sql.cc @@ -84,18 +84,6 @@ void conflict_manager::_clean_tables(uint32_t instance_id) { conn); _add_action(conn, actions::servicegroups); - /* Remove host dependencies. */ - _logger_sql->debug( - "conflict_manager: remove host dependencies (instance_id: {})", - instance_id); - query = fmt::format( - "DELETE hhd FROM hosts_hosts_dependencies AS hhd INNER JOIN hosts as " - "h ON hhd.host_id=h.host_id OR hhd.dependent_host_id=h.host_id WHERE " - "h.instance_id={}", - instance_id); - _mysql.run_query(query, database::mysql_error::clean_host_dependencies, conn); - _add_action(conn, actions::host_dependencies); - /* Remove host parents. */ _logger_sql->debug("conflict_manager: remove host parents (instance_id: {})", instance_id); @@ -107,23 +95,6 @@ void conflict_manager::_clean_tables(uint32_t instance_id) { _mysql.run_query(query, database::mysql_error::clean_host_parents, conn); _add_action(conn, actions::host_parents); - /* Remove service dependencies. */ - _logger_sql->debug( - "conflict_manager: remove service dependencies (instance_id: {})", - instance_id); - query = fmt::format( - "DELETE ssd FROM services_services_dependencies AS ssd" - " INNER JOIN services as s" - " ON ssd.service_id=s.service_id OR " - "ssd.dependent_service_id=s.service_id" - " INNER JOIN hosts as h" - " ON s.host_id=h.host_id" - " WHERE h.instance_id={}", - instance_id); - _mysql.run_query(query, database::mysql_error::clean_service_dependencies, - conn); - _add_action(conn, actions::service_dependencies); - /* Remove list of modules. */ _logger_sql->debug("SQL: remove list of modules (instance_id: {})", instance_id); @@ -400,8 +371,7 @@ void conflict_manager::_process_comment( std::tuple, uint32_t, bool*>& t) { auto& d = std::get<0>(t); _finish_action(-1, actions::hosts | actions::instances | - actions::host_parents | actions::host_dependencies | - actions::service_dependencies | actions::comments); + actions::host_parents | actions::comments); // Cast object. neb::comment const& cmmnt{*static_cast(d.get())}; @@ -592,8 +562,7 @@ void conflict_manager::_process_host_check( std::tuple, uint32_t, bool*>& t) { auto& d = std::get<0>(t); _finish_action(-1, actions::instances | actions::downtimes | - actions::comments | actions::host_dependencies | - actions::host_parents | actions::service_dependencies); + actions::comments | actions::host_parents); // Cast object. neb::host_check const& hc = *static_cast(d.get()); @@ -645,60 +614,6 @@ void conflict_manager::_process_host_check( *std::get<2>(t) = true; } -/** - * Process a host dependency event. - * - * @param[in] e Uncasted host dependency. - * - * @return The number of events that can be acknowledged. - */ -void conflict_manager::_process_host_dependency( - std::tuple, uint32_t, bool*>& t) { - auto& d = std::get<0>(t); - int32_t conn = special_conn::host_dependency % _mysql.connections_count(); - _finish_action(-1, actions::hosts | actions::host_parents | - actions::comments | actions::downtimes | - actions::host_dependencies | - actions::service_dependencies); - - // Cast object. - neb::host_dependency const& hd = - *static_cast(d.get()); - - // Insert/Update. - if (hd.enabled) { - _logger_sql->info("SQL: enabling host dependency of {} on {}", - hd.dependent_host_id, hd.host_id); - - // Prepare queries. - if (!_host_dependency_insupdate.prepared()) { - query_preparator::event_unique unique; - unique.insert("host_id"); - unique.insert("dependent_host_id"); - query_preparator qp(neb::host_dependency::static_type(), unique); - _host_dependency_insupdate = qp.prepare_insert_or_update(_mysql); - } - - // Process object. - _host_dependency_insupdate << hd; - _mysql.run_statement(_host_dependency_insupdate, - database::mysql_error::store_host_dependency, conn); - _add_action(conn, actions::host_dependencies); - } - // Delete. - else { - _logger_sql->info("SQL: removing host dependency of {} on {}", - hd.dependent_host_id, hd.host_id); - std::string query(fmt::format( - "DELETE FROM hosts_hosts_dependencies WHERE dependent_host_id={}" - " AND host_id={}", - hd.dependent_host_id, hd.host_id)); - _mysql.run_query(query, database::mysql_error::empty, conn); - _add_action(conn, actions::host_dependencies); - } - *std::get<2>(t) = true; -} - /** * Process a host group event. * @@ -843,9 +758,8 @@ void conflict_manager::_process_host( std::tuple, uint32_t, bool*>& t) { auto& d = std::get<0>(t); _finish_action(-1, actions::instances | actions::hostgroups | - actions::host_dependencies | actions::host_parents | - actions::custom_variables | actions::downtimes | - actions::comments | actions::service_dependencies); + actions::host_parents | actions::custom_variables | + actions::downtimes | actions::comments); neb::host& h = *static_cast(d.get()); // Log message. @@ -900,8 +814,7 @@ void conflict_manager::_process_host_parent( std::tuple, uint32_t, bool*>& t) { auto& d = std::get<0>(t); int32_t conn = special_conn::host_parent % _mysql.connections_count(); - _finish_action(-1, actions::hosts | actions::host_dependencies | - actions::comments | actions::downtimes); + _finish_action(-1, actions::hosts | actions::comments | actions::downtimes); neb::host_parent const& hp(*static_cast(d.get())); @@ -958,8 +871,7 @@ void conflict_manager::_process_host_status( auto& d = std::get<0>(t); _finish_action(-1, actions::instances | actions::downtimes | actions::comments | actions::custom_variables | - actions::hostgroups | actions::host_dependencies | - actions::host_parents); + actions::hostgroups | actions::host_parents); // Processed object. neb::host_status const& hs(*static_cast(d.get())); @@ -1017,8 +929,7 @@ void conflict_manager::_process_instance( _finish_action(-1, actions::hosts | actions::acknowledgements | actions::modules | actions::downtimes | actions::comments | actions::servicegroups | - actions::hostgroups | actions::service_dependencies | - actions::host_dependencies); + actions::hostgroups); // Log message. _logger_sql->info( @@ -1147,9 +1058,8 @@ void conflict_manager::_process_log( void conflict_manager::_process_service_check( std::tuple, uint32_t, bool*>& t) { auto& d = std::get<0>(t); - _finish_action(-1, actions::downtimes | actions::comments | - actions::host_dependencies | actions::host_parents | - actions::service_dependencies); + _finish_action( + -1, actions::downtimes | actions::comments | actions::host_parents); // Cast object. neb::service_check const& sc( @@ -1211,67 +1121,6 @@ void conflict_manager::_process_service_check( *std::get<2>(t) = true; } -/** - * Process a service dependency event. - * - * @param[in] e Uncasted service dependency. - * - * @return The number of events that can be acknowledged. - */ -void conflict_manager::_process_service_dependency( - std::tuple, uint32_t, bool*>& t) { - auto& d = std::get<0>(t); - int32_t conn = special_conn::service_dependency % _mysql.connections_count(); - _finish_action(-1, actions::hosts | actions::host_parents | - actions::downtimes | actions::comments | - actions::host_dependencies | - actions::service_dependencies); - - // Cast object. - neb::service_dependency const& sd( - *static_cast(d.get())); - - // Insert/Update. - if (sd.enabled) { - _logger_sql->info( - "SQL: enabling service dependency of ({}, {}) on ({}, {})", - sd.dependent_host_id, sd.dependent_service_id, sd.host_id, - sd.service_id); - - // Prepare queries. - if (!_service_dependency_insupdate.prepared()) { - query_preparator::event_unique unique; - unique.insert("dependent_host_id"); - unique.insert("dependent_service_id"); - unique.insert("host_id"); - unique.insert("service_id"); - query_preparator qp(neb::service_dependency::static_type(), unique); - _service_dependency_insupdate = qp.prepare_insert_or_update(_mysql); - } - - // Process object. - _service_dependency_insupdate << sd; - _mysql.run_statement(_service_dependency_insupdate, - database::mysql_error::store_service_dependency, conn); - _add_action(conn, actions::service_dependencies); - } - // Delete. - else { - _logger_sql->info( - "SQL: removing service dependency of ({}, {}) on ({}, {})", - sd.dependent_host_id, sd.dependent_service_id, sd.host_id, - sd.service_id); - std::string query(fmt::format( - "DELETE FROM serivces_services_dependencies WHERE dependent_host_id={} " - "AND dependent_service_id={} AND host_id={} AND service_id={}", - sd.dependent_host_id, sd.dependent_service_id, sd.host_id, - sd.service_id)); - _mysql.run_query(query, database::mysql_error::empty, conn); - _add_action(conn, actions::service_dependencies); - } - *std::get<2>(t) = true; -} - /** * Process a service group event. * @@ -1419,9 +1268,8 @@ void conflict_manager::_process_service_group_member( void conflict_manager::_process_service( std::tuple, uint32_t, bool*>& t) { auto& d = std::get<0>(t); - _finish_action(-1, actions::host_parents | actions::comments | - actions::downtimes | actions::host_dependencies | - actions::service_dependencies); + _finish_action( + -1, actions::host_parents | actions::comments | actions::downtimes); // Processed object. const neb::service& s(*static_cast(d.get())); @@ -1472,9 +1320,8 @@ void conflict_manager::_process_service( void conflict_manager::_process_service_status( std::tuple, uint32_t, bool*>& t) { auto& d = std::get<0>(t); - _finish_action(-1, actions::host_parents | actions::comments | - actions::downtimes | actions::host_dependencies | - actions::service_dependencies); + _finish_action( + -1, actions::host_parents | actions::comments | actions::downtimes); // Processed object. neb::service_status const& ss{ *static_cast(d.get())}; @@ -1771,8 +1618,7 @@ void conflict_manager::_update_downtimes() { _logger_sql->debug("sql: update downtimes"); int32_t conn = special_conn::downtime % _mysql.connections_count(); _finish_action(-1, actions::hosts | actions::instances | actions::downtimes | - actions::host_parents | actions::host_dependencies | - actions::service_dependencies); + actions::host_parents); if (!_downtimes_queue.empty()) { auto it = _downtimes_queue.begin(); std::ostringstream oss; diff --git a/broker/unified_sql/inc/com/centreon/broker/unified_sql/stream.hh b/broker/unified_sql/inc/com/centreon/broker/unified_sql/stream.hh index f0944953f6f..1a86768f5c9 100644 --- a/broker/unified_sql/inc/com/centreon/broker/unified_sql/stream.hh +++ b/broker/unified_sql/inc/com/centreon/broker/unified_sql/stream.hh @@ -159,11 +159,9 @@ class stream : public io::stream { enum special_conn { custom_variable, downtime, - host_dependency, host_group, host_parent, log, - service_dependency, service_group, severity, tag, @@ -176,23 +174,21 @@ class stream : public io::stream { comments = 1 << 1, custom_variables = 1 << 2, downtimes = 1 << 3, - host_dependencies = 1 << 4, - host_hostgroups = 1 << 5, - host_parents = 1 << 6, - hostgroups = 1 << 7, - hosts = 1 << 8, - instances = 1 << 9, - modules = 1 << 10, - service_dependencies = 1 << 11, - service_servicegroups = 1 << 12, - servicegroups = 1 << 13, - services = 1 << 14, - index_data = 1 << 15, - metrics = 1 << 16, - severities = 1 << 17, - tags = 1 << 18, - resources = 1 << 19, - resources_tags = 1 << 20, + host_hostgroups = 1 << 4, + host_parents = 1 << 5, + hostgroups = 1 << 6, + hosts = 1 << 7, + instances = 1 << 8, + modules = 1 << 9, + service_servicegroups = 1 << 10, + servicegroups = 1 << 11, + services = 1 << 12, + index_data = 1 << 13, + metrics = 1 << 14, + severities = 1 << 15, + tags = 1 << 16, + resources = 1 << 17, + resources_tags = 1 << 18, }; struct index_info { @@ -335,8 +331,6 @@ class stream : public io::stream { database::mysql_stmt _flapping_status_insupdate; database::mysql_stmt _host_check_update; database::mysql_stmt _pb_host_check_update; - database::mysql_stmt _host_exe_dependency_insupdate; - database::mysql_stmt _host_notif_dependency_insupdate; database::mysql_stmt _host_group_insupdate; database::mysql_stmt _pb_host_group_insupdate; database::mysql_stmt _host_group_member_delete; @@ -355,8 +349,6 @@ class stream : public io::stream { database::mysql_stmt _pb_instance_status_insupdate; database::mysql_stmt _service_check_update; database::mysql_stmt _pb_service_check_update; - database::mysql_stmt _service_dependency_insupdate; - database::mysql_stmt _pb_service_dependency_insupdate; database::mysql_stmt _service_group_insupdate; database::mysql_stmt _pb_service_group_insupdate; database::mysql_stmt _service_group_member_delete; @@ -419,8 +411,6 @@ class stream : public io::stream { void _process_pb_downtime(const std::shared_ptr& d); void _process_host_check(const std::shared_ptr& d); void _process_pb_host_check(const std::shared_ptr& d); - void _process_host_dependency(const std::shared_ptr& d); - void _process_pb_host_dependency(const std::shared_ptr& d); void _process_host_group(const std::shared_ptr& d); void _process_pb_host_group(const std::shared_ptr& d); void _process_host_group_member(const std::shared_ptr& d); @@ -436,8 +426,6 @@ class stream : public io::stream { void _process_log(const std::shared_ptr& d); void _process_service_check(const std::shared_ptr& d); void _process_pb_service_check(const std::shared_ptr& d); - void _process_service_dependency(const std::shared_ptr& d); - void _process_pb_service_dependency(const std::shared_ptr& d); void _process_service_group(const std::shared_ptr& d); void _process_pb_service_group(const std::shared_ptr& d); void _process_service_group_member(const std::shared_ptr& d); diff --git a/broker/unified_sql/src/stream.cc b/broker/unified_sql/src/stream.cc index eaaa899f879..5193f28662f 100644 --- a/broker/unified_sql/src/stream.cc +++ b/broker/unified_sql/src/stream.cc @@ -73,7 +73,7 @@ constexpr void (stream::*const stream::neb_processing_table[])( nullptr, nullptr, &stream::_process_host_check, - &stream::_process_host_dependency, + nullptr, &stream::_process_host_group, &stream::_process_host_group_member, &stream::_process_host, @@ -84,7 +84,7 @@ constexpr void (stream::*const stream::neb_processing_table[])( &stream::_process_log, nullptr, &stream::_process_service_check, - &stream::_process_service_dependency, + nullptr, &stream::_process_service_group, &stream::_process_service_group_member, &stream::_process_service, @@ -111,8 +111,8 @@ constexpr void (stream::*const stream::neb_processing_table[])( &stream::_process_pb_instance, &stream::_process_pb_acknowledgement, &stream::_process_pb_responsive_instance, - &stream::_process_pb_host_dependency, - &stream::_process_pb_service_dependency, + nullptr, + nullptr, &stream::_process_pb_host_group, &stream::_process_pb_host_group_member, &stream::_process_pb_service_group, @@ -878,8 +878,7 @@ void stream::process_stop(const std::shared_ptr& d) { _finish_action(-1, actions::hosts | actions::acknowledgements | actions::modules | actions::downtimes | actions::comments | actions::servicegroups | - actions::hostgroups | actions::service_dependencies | - actions::host_dependencies); + actions::hostgroups); // Log message. _logger_sql->info("unified_sql: Disabling poller (id: {}, running: no)", @@ -1397,22 +1396,6 @@ void stream::_init_statements() { "last_check=?," // 9: last_check "output=? " // 10: output "WHERE id=? AND parent_id=?"); // 11, 12: service_id and host_id - const std::string host_exe_dep_query( - "INSERT INTO hosts_hosts_dependencies (dependent_host_id, host_id, " - "dependency_period, execution_failure_options, inherits_parent) " - "VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE " - "dependency_period=VALUES(dependency_period), " - "execution_failure_options=VALUES(execution_failure_options), " - "inherits_parent=VALUES(inherits_parent)"); - _host_exe_dependency_insupdate = _mysql.prepare_query(host_exe_dep_query); - const std::string host_notif_dep_query( - "INSERT INTO hosts_hosts_dependencies (dependent_host_id, host_id, " - "dependency_period, notification_failure_options, inherits_parent) " - "VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE " - "dependency_period=VALUES(dependency_period), " - "notification_failure_options=VALUES(notification_failure_options), " - "inherits_parent=VALUES(inherits_parent)"); - _host_notif_dependency_insupdate = _mysql.prepare_query(host_notif_dep_query); if (_store_in_hosts_services) { if (_bulk_prepared_statement) { auto hu = std::make_unique(hscr_query); diff --git a/broker/unified_sql/src/stream_sql.cc b/broker/unified_sql/src/stream_sql.cc index edd91e546ed..a519d57463f 100644 --- a/broker/unified_sql/src/stream_sql.cc +++ b/broker/unified_sql/src/stream_sql.cc @@ -117,18 +117,6 @@ void stream::_clean_tables(uint32_t instance_id) { conn); _add_action(conn, actions::servicegroups); - /* Remove host dependencies. */ - SPDLOG_LOGGER_DEBUG(_logger_sql, - "unified sql: remove host dependencies (instance_id: {})", - instance_id); - query = fmt::format( - "DELETE hhd FROM hosts_hosts_dependencies AS hhd INNER JOIN hosts as " - "h ON hhd.host_id=h.host_id OR hhd.dependent_host_id=h.host_id WHERE " - "h.instance_id={}", - instance_id); - _mysql.run_query(query, database::mysql_error::clean_host_dependencies, conn); - _add_action(conn, actions::host_dependencies); - /* Remove host parents. */ SPDLOG_LOGGER_DEBUG(_logger_sql, "unified sql: remove host parents (instance_id: {})", @@ -141,23 +129,6 @@ void stream::_clean_tables(uint32_t instance_id) { _mysql.run_query(query, database::mysql_error::clean_host_parents, conn); _add_action(conn, actions::host_parents); - /* Remove service dependencies. */ - SPDLOG_LOGGER_DEBUG( - _logger_sql, "unified sql: remove service dependencies (instance_id: {})", - instance_id); - query = fmt::format( - "DELETE ssd FROM services_services_dependencies AS ssd" - " INNER JOIN services as s" - " ON ssd.service_id=s.service_id OR " - "ssd.dependent_service_id=s.service_id" - " INNER JOIN hosts as h" - " ON s.host_id=h.host_id" - " WHERE h.instance_id={}", - instance_id); - _mysql.run_query(query, database::mysql_error::clean_service_dependencies, - conn); - _add_action(conn, actions::service_dependencies); - /* Remove list of modules. */ SPDLOG_LOGGER_DEBUG(_logger_sql, "unified_sql: remove list of modules (instance_id: {})", @@ -564,8 +535,7 @@ void stream::_process_pb_acknowledgement(const std::shared_ptr& d) { */ void stream::_process_comment(const std::shared_ptr& d) { _finish_action(-1, actions::hosts | actions::instances | - actions::host_parents | actions::host_dependencies | - actions::service_dependencies | actions::comments); + actions::host_parents | actions::comments); // Cast object. neb::comment const& cmmnt{*static_cast(d.get())}; @@ -1074,8 +1044,7 @@ bool stream::_host_instance_known(uint64_t host_id) const { */ void stream::_process_host_check(const std::shared_ptr& d) { _finish_action(-1, actions::instances | actions::downtimes | - actions::comments | actions::host_dependencies | - actions::host_parents | actions::service_dependencies); + actions::comments | actions::host_parents); // Cast object. neb::host_check const& hc = *static_cast(d.get()); @@ -1145,8 +1114,7 @@ void stream::_process_host_check(const std::shared_ptr& d) { */ void stream::_process_pb_host_check(const std::shared_ptr& d) { _finish_action(-1, actions::instances | actions::downtimes | - actions::comments | actions::host_dependencies | - actions::host_parents | actions::service_dependencies); + actions::comments | actions::host_parents); // Cast object. const neb::pb_host_check& hc_obj = @@ -1217,140 +1185,6 @@ void stream::_process_pb_host_check(const std::shared_ptr& d) { hc.next_check(), now); } -/** - * Process a host dependency event. - * - * @param[in] e Uncasted host dependency. - * - * @return The number of events that can be acknowledged. - */ -void stream::_process_host_dependency(const std::shared_ptr& d) { - int32_t conn = special_conn::host_dependency % _mysql.connections_count(); - _finish_action(-1, actions::hosts | actions::host_parents | - actions::comments | actions::downtimes | - actions::host_dependencies | - actions::service_dependencies); - - // Cast object. - neb::host_dependency const& hd = - *static_cast(d.get()); - - // Insert/Update. - if (hd.enabled) { - SPDLOG_LOGGER_INFO(_logger_sql, - "SQL: enabling host dependency of {} on {}: execution " - "failure options: {} - notification failure options: {}", - hd.dependent_host_id, hd.host_id, - hd.execution_failure_options, - hd.notification_failure_options); - - // Process object. - if (!hd.execution_failure_options.empty()) { - _host_exe_dependency_insupdate.bind_value_as_i32(0, hd.dependent_host_id); - _host_exe_dependency_insupdate.bind_value_as_i32(1, hd.host_id); - _host_exe_dependency_insupdate.bind_value_as_str(2, hd.dependency_period); - _host_exe_dependency_insupdate.bind_value_as_str( - 3, hd.execution_failure_options); - _host_exe_dependency_insupdate.bind_value_as_tiny(4, hd.inherits_parent); - _mysql.run_statement(_host_exe_dependency_insupdate, - database::mysql_error::store_host_dependency, conn); - } else if (!hd.notification_failure_options.empty()) { - _host_notif_dependency_insupdate.bind_value_as_i32(0, - hd.dependent_host_id); - _host_notif_dependency_insupdate.bind_value_as_i32(1, hd.host_id); - _host_notif_dependency_insupdate.bind_value_as_str(2, - hd.dependency_period); - _host_notif_dependency_insupdate.bind_value_as_str( - 3, hd.notification_failure_options); - _host_notif_dependency_insupdate.bind_value_as_tiny(4, - hd.inherits_parent); - _mysql.run_statement(_host_notif_dependency_insupdate, - database::mysql_error::store_host_dependency, conn); - } - _add_action(conn, actions::host_dependencies); - } - // Delete. - else { - SPDLOG_LOGGER_INFO(_logger_sql, "SQL: removing host dependency of {} on {}", - hd.dependent_host_id, hd.host_id); - std::string query(fmt::format( - "DELETE FROM hosts_hosts_dependencies WHERE dependent_host_id={}" - " AND host_id={}", - hd.dependent_host_id, hd.host_id)); - _mysql.run_query(query, database::mysql_error::empty, conn); - _add_action(conn, actions::host_dependencies); - } -} - -/** - * Process a host dependency event. - * - * @param[in] e Uncasted host dependency. - * - * @return The number of events that can be acknowledged. - */ -void stream::_process_pb_host_dependency(const std::shared_ptr& d) { - int32_t conn = special_conn::host_dependency % _mysql.connections_count(); - _finish_action(-1, actions::hosts | actions::host_parents | - actions::comments | actions::downtimes | - actions::host_dependencies | - actions::service_dependencies); - - // Cast object. - const neb::pb_host_dependency& hd_protobuf = - *static_cast(d.get()); - const HostDependency& hd = hd_protobuf.obj(); - - // Insert/Update. - if (hd.enabled()) { - SPDLOG_LOGGER_INFO( - _logger_sql, - "SQL: enabling pb host dependency of {} on {}: execution failure " - "options: {} - notification failure options: {}", - hd.dependent_host_id(), hd.host_id(), hd.execution_failure_options(), - hd.notification_failure_options()); - - // Process object. - if (!hd.execution_failure_options().empty()) { - _host_exe_dependency_insupdate.bind_value_as_i32(0, - hd.dependent_host_id()); - _host_exe_dependency_insupdate.bind_value_as_i32(1, hd.host_id()); - _host_exe_dependency_insupdate.bind_value_as_str(2, - hd.dependency_period()); - _host_exe_dependency_insupdate.bind_value_as_str( - 3, hd.execution_failure_options()); - _host_exe_dependency_insupdate.bind_value_as_tiny(4, - hd.inherits_parent()); - _mysql.run_statement(_host_exe_dependency_insupdate, - database::mysql_error::store_host_dependency, conn); - } else if (!hd.notification_failure_options().empty()) { - _host_notif_dependency_insupdate.bind_value_as_i32( - 0, hd.dependent_host_id()); - _host_notif_dependency_insupdate.bind_value_as_i32(1, hd.host_id()); - _host_notif_dependency_insupdate.bind_value_as_str( - 2, hd.dependency_period()); - _host_notif_dependency_insupdate.bind_value_as_str( - 3, hd.notification_failure_options()); - _host_notif_dependency_insupdate.bind_value_as_tiny(4, - hd.inherits_parent()); - _mysql.run_statement(_host_notif_dependency_insupdate, - database::mysql_error::store_host_dependency, conn); - } - _add_action(conn, actions::host_dependencies); - } - // Delete. - else { - SPDLOG_LOGGER_INFO(_logger_sql, "SQL: removing host dependency of {} on {}", - hd.dependent_host_id(), hd.host_id()); - std::string query(fmt::format( - "DELETE FROM hosts_hosts_dependencies WHERE dependent_host_id={}" - " AND host_id={}", - hd.dependent_host_id(), hd.host_id())); - _mysql.run_query(query, database::mysql_error::empty, conn); - _add_action(conn, actions::host_dependencies); - } -} - /** * Process a host group event. * @@ -1612,7 +1446,7 @@ void stream::_process_pb_host_group_member(const std::shared_ptr& d) { query_preparator qp(neb::pb_host_group_member::static_type(), unique); _pb_host_group_member_insert = qp.prepare_insert_into( _mysql, "hosts_hostgroups ", /*space is mandatory to avoid - conflict with _process_host_dependency*/ + conflict with _process_host_group_member*/ {{3, "hostgroup_id", io::protobuf_base::invalid_on_zero, 0}, {5, "host_id", io::protobuf_base::invalid_on_zero, 0}}); } @@ -1682,9 +1516,8 @@ void stream::_process_pb_host_group_member(const std::shared_ptr& d) { */ void stream::_process_host(const std::shared_ptr& d) { _finish_action(-1, actions::instances | actions::hostgroups | - actions::host_dependencies | actions::host_parents | - actions::custom_variables | actions::downtimes | - actions::comments | actions::service_dependencies); + actions::host_parents | actions::custom_variables | + actions::downtimes | actions::comments); neb::host& h = *static_cast(d.get()); // Log message. @@ -1743,8 +1576,7 @@ void stream::_process_host(const std::shared_ptr& d) { */ void stream::_process_host_parent(const std::shared_ptr& d) { int32_t conn = special_conn::host_parent % _mysql.connections_count(); - _finish_action(-1, actions::hosts | actions::host_dependencies | - actions::comments | actions::downtimes); + _finish_action(-1, actions::hosts | actions::comments | actions::downtimes); neb::host_parent const& hp(*static_cast(d.get())); @@ -1798,8 +1630,7 @@ void stream::_process_host_parent(const std::shared_ptr& d) { */ void stream::_process_pb_host_parent(const std::shared_ptr& d) { int32_t conn = special_conn::host_parent % _mysql.connections_count(); - _finish_action(-1, actions::hosts | actions::host_dependencies | - actions::comments | actions::downtimes); + _finish_action(-1, actions::hosts | actions::comments | actions::downtimes); std::shared_ptr hpp = std::static_pointer_cast(d); @@ -1867,8 +1698,7 @@ void stream::_process_host_status(const std::shared_ptr& d) { _finish_action(-1, actions::instances | actions::downtimes | actions::comments | actions::custom_variables | - actions::hostgroups | actions::host_dependencies | - actions::host_parents); + actions::hostgroups | actions::host_parents); // Processed object. neb::host_status const& hs(*static_cast(d.get())); @@ -1928,9 +1758,8 @@ void stream::_process_host_status(const std::shared_ptr& d) { */ void stream::_process_pb_host(const std::shared_ptr& d) { _finish_action(-1, actions::instances | actions::hostgroups | - actions::host_dependencies | actions::host_parents | - actions::custom_variables | actions::downtimes | - actions::comments | actions::service_dependencies | + actions::host_parents | actions::custom_variables | + actions::downtimes | actions::comments | actions::severities | actions::resources_tags | actions::tags); auto hst{static_cast(d.get())}; @@ -2409,9 +2238,8 @@ uint64_t stream::_process_pb_host_in_resources(const Host& h, int32_t conn) { */ void stream::_process_pb_adaptive_host(const std::shared_ptr& d) { SPDLOG_LOGGER_INFO(_logger_sql, "unified_sql: processing pb adaptive host"); - _finish_action(-1, actions::host_parents | actions::comments | - actions::downtimes | actions::host_dependencies | - actions::service_dependencies); + _finish_action( + -1, actions::host_parents | actions::comments | actions::downtimes); // Processed object. auto h{static_cast(d.get())}; auto& ah = h->obj(); @@ -2523,8 +2351,8 @@ void stream::_process_pb_adaptive_host(const std::shared_ptr& d) { * */ void stream::_process_pb_host_status(const std::shared_ptr& d) { - _finish_action(-1, actions::host_parents | actions::comments | - actions::downtimes | actions::host_dependencies); + _finish_action( + -1, actions::host_parents | actions::comments | actions::downtimes); // Processed object. auto h{static_cast(d.get())}; auto& hscr = h->obj(); @@ -2749,8 +2577,7 @@ void stream::_process_instance(const std::shared_ptr& d) { _finish_action(-1, actions::hosts | actions::acknowledgements | actions::modules | actions::downtimes | actions::comments | actions::servicegroups | - actions::hostgroups | actions::service_dependencies | - actions::host_dependencies); + actions::hostgroups); // Log message. SPDLOG_LOGGER_INFO( @@ -2801,8 +2628,7 @@ void stream::_process_pb_instance(const std::shared_ptr& d) { _finish_action(-1, actions::hosts | actions::acknowledgements | actions::modules | actions::downtimes | actions::comments | actions::servicegroups | - actions::hostgroups | actions::service_dependencies | - actions::host_dependencies); + actions::hostgroups); /* Now, the local::pb_stop is handled by unified_sql. So the pb_instance with * running = false, seems no more useful. */ @@ -3132,9 +2958,8 @@ void stream::_process_pb_log(const std::shared_ptr& d) { * @return The number of events that can be acknowledged. */ void stream::_process_service_check(const std::shared_ptr& d) { - _finish_action(-1, actions::downtimes | actions::comments | - actions::host_dependencies | actions::host_parents | - actions::service_dependencies); + _finish_action( + -1, actions::downtimes | actions::comments | actions::host_parents); // Cast object. neb::service_check const& sc( @@ -3206,9 +3031,8 @@ void stream::_process_service_check(const std::shared_ptr& d) { * @return The number of events that can be acknowledged. */ void stream::_process_pb_service_check(const std::shared_ptr& d) { - _finish_action(-1, actions::downtimes | actions::comments | - actions::host_dependencies | actions::host_parents | - actions::service_dependencies); + _finish_action( + -1, actions::downtimes | actions::comments | actions::host_parents); // Cast object. const neb::pb_service_check& pb_sc( @@ -3281,140 +3105,6 @@ void stream::_process_pb_service_check(const std::shared_ptr& d) { sc.check_type(), sc.next_check(), now); } -/** - * Process a service dependency event. - * - * @param[in] e Uncasted service dependency. - * - * @return The number of events that can be acknowledged. - */ -void stream::_process_service_dependency(const std::shared_ptr& d) { - int32_t conn = special_conn::service_dependency % _mysql.connections_count(); - _finish_action(-1, actions::hosts | actions::host_parents | - actions::downtimes | actions::comments | - actions::host_dependencies | - actions::service_dependencies); - - // Cast object. - neb::service_dependency const& sd( - *static_cast(d.get())); - - // Insert/Update. - if (sd.enabled) { - SPDLOG_LOGGER_INFO( - _logger_sql, "SQL: enabling service dependency of ({}, {}) on ({}, {})", - sd.dependent_host_id, sd.dependent_service_id, sd.host_id, - sd.service_id); - - // Prepare queries. - if (!_service_dependency_insupdate.prepared()) { - query_preparator::event_unique unique; - unique.insert("dependent_host_id"); - unique.insert("dependent_service_id"); - unique.insert("host_id"); - unique.insert("service_id"); - query_preparator qp(neb::service_dependency::static_type(), unique); - _service_dependency_insupdate = qp.prepare_insert_or_update(_mysql); - } - - // Process object. - _service_dependency_insupdate << sd; - _mysql.run_statement(_service_dependency_insupdate, - database::mysql_error::store_service_dependency, conn); - _add_action(conn, actions::service_dependencies); - } - // Delete. - else { - SPDLOG_LOGGER_INFO( - _logger_sql, "SQL: removing service dependency of ({}, {}) on ({}, {})", - sd.dependent_host_id, sd.dependent_service_id, sd.host_id, - sd.service_id); - std::string query(fmt::format( - "DELETE FROM services_services_dependencies WHERE dependent_host_id={} " - "AND dependent_service_id={} AND host_id={} AND service_id={}", - sd.dependent_host_id, sd.dependent_service_id, sd.host_id, - sd.service_id)); - _mysql.run_query(query, database::mysql_error::empty, conn); - _add_action(conn, actions::service_dependencies); - } -} - -/** - * Process a service dependency event. - * - * @param[in] e Uncasted service dependency. - * - * @return The number of events that can be acknowledged. - */ -void stream::_process_pb_service_dependency( - const std::shared_ptr& d) { - int32_t conn = special_conn::service_dependency % _mysql.connections_count(); - _finish_action(-1, actions::hosts | actions::host_parents | - actions::downtimes | actions::comments | - actions::host_dependencies | - actions::service_dependencies); - - // Cast object. - const neb::pb_service_dependency& proto_obj = - *static_cast(d.get()); - const ServiceDependency& sd = proto_obj.obj(); - - // Insert/Update. - if (sd.enabled()) { - SPDLOG_LOGGER_INFO( - _logger_sql, "SQL: enabling service dependency of ({}, {}) on ({}, {})", - sd.dependent_host_id(), sd.dependent_service_id(), sd.host_id(), - sd.service_id()); - - // Prepare queries. - if (!_pb_service_dependency_insupdate.prepared()) { - query_preparator::event_pb_unique unique{ - {6, "host_id", io::protobuf_base::invalid_on_zero, 0}, - {10, "service_id", io::protobuf_base::invalid_on_zero, 0}, - {3, "dependent_host_id", io::protobuf_base::invalid_on_zero, 0}, - {9, "dependent_service_id", io::protobuf_base::invalid_on_zero, 0}}; - query_preparator qp(neb::pb_service_dependency::static_type(), unique); - _pb_service_dependency_insupdate = qp.prepare_insert_or_update_table( - _mysql, "services_services_dependencies ", /*space is mandatory to - avoid conflict with _process_service_dependency*/ - {{6, "host_id", io::protobuf_base::invalid_on_zero, 0}, - {10, "service_id", io::protobuf_base::invalid_on_zero, 0}, - {3, "dependent_host_id", io::protobuf_base::invalid_on_zero, 0}, - {9, "dependent_service_id", io::protobuf_base::invalid_on_zero, 0}, - {2, "dependency_period", 0, - get_centreon_storage_services_services_dependencies_col_size( - centreon_storage_services_services_dependencies_dependency_period)}, - {5, "execution_failure_options", 0, - get_centreon_storage_services_services_dependencies_col_size( - centreon_storage_services_services_dependencies_execution_failure_options)}, - {7, "inherits_parent", 0, 0}, - {8, "notification_failure_options", 0, - get_centreon_storage_services_services_dependencies_col_size( - centreon_storage_services_services_dependencies_notification_failure_options)}}); - } - - // Process object. - _pb_service_dependency_insupdate << proto_obj; - _mysql.run_statement(_pb_service_dependency_insupdate, - database::mysql_error::store_service_dependency, conn); - _add_action(conn, actions::service_dependencies); - } - // Delete. - else { - SPDLOG_LOGGER_INFO( - _logger_sql, "SQL: removing service dependency of ({}, {}) on ({}, {})", - sd.dependent_host_id(), sd.dependent_service_id(), sd.host_id(), - sd.service_id()); - std::string query(fmt::format( - "DELETE FROM services_services_dependencies WHERE dependent_host_id={} " - "AND dependent_service_id={} AND host_id={} AND service_id={}", - sd.dependent_host_id(), sd.dependent_service_id(), sd.host_id(), - sd.service_id())); - _mysql.run_query(query, database::mysql_error::empty, conn); - _add_action(conn, actions::service_dependencies); - } -} - /** * Process a service group event. * @@ -3745,9 +3435,8 @@ void stream::_process_pb_service_group_member( * @return The number of events that can be acknowledged. */ void stream::_process_service(const std::shared_ptr& d) { - _finish_action(-1, actions::host_parents | actions::comments | - actions::downtimes | actions::host_dependencies | - actions::service_dependencies); + _finish_action( + -1, actions::host_parents | actions::comments | actions::downtimes); // Processed object. const neb::service& s(*static_cast(d.get())); @@ -3804,8 +3493,7 @@ void stream::_process_service(const std::shared_ptr& d) { */ void stream::_process_pb_service(const std::shared_ptr& d) { _finish_action(-1, actions::host_parents | actions::comments | - actions::downtimes | actions::host_dependencies | - actions::service_dependencies | actions::severities | + actions::downtimes | actions::severities | actions::resources_tags | actions::tags); // Processed object. auto svc{static_cast(d.get())}; @@ -4279,9 +3967,8 @@ uint64_t stream::_process_pb_service_in_resources(const Service& s, void stream::_process_pb_adaptive_service(const std::shared_ptr& d) { SPDLOG_LOGGER_DEBUG(_logger_sql, "unified_sql: processing pb adaptive service"); - _finish_action(-1, actions::host_parents | actions::comments | - actions::downtimes | actions::host_dependencies | - actions::service_dependencies); + _finish_action( + -1, actions::host_parents | actions::comments | actions::downtimes); // Processed object. auto s{static_cast(d.get())}; auto& as = s->obj(); @@ -4518,9 +4205,8 @@ void stream::_process_service_status(const std::shared_ptr& d) { if (!_store_in_hosts_services) return; - _finish_action(-1, actions::host_parents | actions::comments | - actions::downtimes | actions::host_dependencies | - actions::service_dependencies); + _finish_action( + -1, actions::host_parents | actions::comments | actions::downtimes); // Processed object. neb::service_status const& ss{ *static_cast(d.get())}; @@ -4588,9 +4274,8 @@ void stream::_process_service_status(const std::shared_ptr& d) { * */ void stream::_process_pb_service_status(const std::shared_ptr& d) { - _finish_action(-1, actions::host_parents | actions::comments | - actions::downtimes | actions::host_dependencies | - actions::service_dependencies); + _finish_action( + -1, actions::host_parents | actions::comments | actions::downtimes); // Processed object. auto s{static_cast(d.get())}; auto& sscr = s->obj(); diff --git a/broker/unified_sql/src/stream_storage.cc b/broker/unified_sql/src/stream_storage.cc index 5c7968c93f6..69964d8302c 100644 --- a/broker/unified_sql/src/stream_storage.cc +++ b/broker/unified_sql/src/stream_storage.cc @@ -817,9 +817,8 @@ void stream::_check_queues(boost::system::error_code ec) { try { if (_bulk_prepared_statement) { - _finish_action(-1, actions::host_parents | actions::comments | - actions::downtimes | actions::host_dependencies | - actions::service_dependencies); + _finish_action( + -1, actions::host_parents | actions::comments | actions::downtimes); if (_store_in_hosts_services) { if (_hscr_bind) { SPDLOG_LOGGER_TRACE( @@ -962,9 +961,7 @@ void stream::_check_queues(boost::system::error_code ec) { SPDLOG_LOGGER_DEBUG(_logger_sql, "{} new downtimes inserted", _downtimes->row_count()); _finish_action(-1, actions::hosts | actions::instances | - actions::downtimes | actions::host_parents | - actions::host_dependencies | - actions::service_dependencies); + actions::downtimes | actions::host_parents); int32_t conn = special_conn::downtime % _mysql.connections_count(); _downtimes->execute(_mysql, database::mysql_error::store_downtime, conn); diff --git a/common/inc/com/centreon/common/utf8.hh b/common/inc/com/centreon/common/utf8.hh index e9a671f6202..a74dd6321cd 100644 --- a/common/inc/com/centreon/common/utf8.hh +++ b/common/inc/com/centreon/common/utf8.hh @@ -42,8 +42,8 @@ fmt::string_view truncate_utf8(const T& str, size_t s) { return fmt::string_view(str.data(), s); } -std::string check_string_utf8(std::string const& str) noexcept; +std::string check_string_utf8(const std::string_view& str) noexcept; size_t adjust_size_utf8(const std::string& str, size_t s); } // namespace com::centreon::common -#endif \ No newline at end of file +#endif diff --git a/common/src/utf8.cc b/common/src/utf8.cc index 7ff784b7167..7ef6ebed5ed 100644 --- a/common/src/utf8.cc +++ b/common/src/utf8.cc @@ -30,8 +30,8 @@ #include "utf8.hh" std::string com::centreon::common::check_string_utf8( - std::string const& str) noexcept { - std::string::const_iterator it; + const std::string_view& str) noexcept { + std::string_view::const_iterator it; for (it = str.begin(); it != str.end();) { uint32_t val = (*it & 0xff); if ((val & 0x80) == 0) { @@ -68,7 +68,7 @@ std::string com::centreon::common::check_string_utf8( } if (it == str.end()) - return str; + return std::string(str); /* Not an UTF-8 string */ bool is_cp1252 = true, is_iso8859 = true; diff --git a/engine/inc/com/centreon/engine/nebstructs.hh b/engine/inc/com/centreon/engine/nebstructs.hh index 00ae56981cb..786e1f56b53 100644 --- a/engine/inc/com/centreon/engine/nebstructs.hh +++ b/engine/inc/com/centreon/engine/nebstructs.hh @@ -98,7 +98,7 @@ typedef struct nebstruct_custom_variable_struct { struct timeval timestamp = {}; std::string_view var_name; std::string_view var_value; - void* object_ptr; + void* object_ptr = nullptr; } nebstruct_custom_variable_data; /* Downtime data structure. */ diff --git a/tests/broker-engine/bbdo-protobuf.robot b/tests/broker-engine/bbdo-protobuf.robot index 835eef63903..f250fcb0cb9 100644 --- a/tests/broker-engine/bbdo-protobuf.robot +++ b/tests/broker-engine/bbdo-protobuf.robot @@ -175,78 +175,6 @@ BEPBCVS [Teardown] Ctn Stop Engine Broker And Save Logs True -BEPB_HOST_DEPENDENCY - [Documentation] BBDO 3 communication of host dependencies. - [Tags] broker engine protobuf bbdo - Ctn Config Engine ${1} - Ctn Config Engine Add Cfg File 0 dependencies.cfg - Ctn Add Host Dependency 0 host_1 host_2 - Ctn Config Broker central - Ctn Config Broker module - Ctn Config BBDO3 ${1} - Ctn Broker Config Log central sql trace - Ctn Config Broker Sql Output central unified_sql - Ctn Clear Retention - ${start} Get Current Date - Ctn Start Broker True - Ctn Start engine - - ${result} Common.Ctn Check Host Dependencies 2 1 24x7 1 ou dp 30 - Should Be True ${result} No notification dependency from 2 to 1 with timeperiod 24x7 on 'ou' - - Ctn Config Engine ${1} - Ctn Reload Engine - - ${result} Common.Ctn Check No Host Dependencies 30 - Should Be True ${result} No host dependency should be defined - - [Teardown] Ctn Stop Engine Broker And Save Logs True - -BEPB_SERVICE_DEPENDENCY - [Documentation] bbdo_version 3 communication of host dependencies. - [Tags] broker engine protobuf bbdo - Ctn Config Engine ${1} - Ctn Config Engine Add Cfg File 0 dependencies.cfg - Ctn Add Service Dependency 0 host_1 host_2 service_1 service_21 - Ctn Config Broker central - Ctn Config Broker module - Ctn Config BBDO3 ${1} - Ctn Broker Config Log central sql trace - Ctn Config Broker Sql Output central unified_sql - Ctn Clear Retention - ${start} Get Current Date - Ctn Start Broker True - Ctn Start engine - - Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort} - - FOR ${index} IN RANGE 30 - ${output} Query - ... SELECT dependent_host_id, dependent_service_id, host_id, service_id, dependency_period, inherits_parent, notification_failure_options FROM services_services_dependencies; - - Log To Console ${output} - Sleep 1s - IF "${output}" == "((2, 21, 1, 1, '24x7', 1, 'c'),)" BREAK - END - Should Be Equal As Strings - ... ${output} - ... ((2, 21, 1, 1, '24x7', 1, 'c'),) - ... host dependency not found in database - - Ctn Config Engine ${1} - Ctn Reload Engine - - FOR ${index} IN RANGE 30 - ${output} Query - ... SELECT dependent_host_id, host_id, dependency_period, inherits_parent, notification_failure_options FROM hosts_hosts_dependencies - Log To Console ${output} - Sleep 1s - IF "${output}" == "()" BREAK - END - Should Be Equal As Strings ${output} () host dependency not deleted from database - - [Teardown] Ctn Stop Engine Broker And Save Logs True - BEPBHostParent [Documentation] bbdo_version 3 communication of host parent relations [Tags] broker engine protobuf bbdo diff --git a/tests/resources/Common.py b/tests/resources/Common.py index daec2c09ed5..b7f3c09ba3f 100644 --- a/tests/resources/Common.py +++ b/tests/resources/Common.py @@ -1638,56 +1638,6 @@ def ctn_check_types_in_resources(lst: list): return False -def ctn_check_host_dependencies(dep_host_id, host_id, dep_period, inherits_parent, notif_fail_opts, exec_fail_opts, timeout=TIMEOUT): - limit = time.time() + timeout - logger.console( - f"SELECT count(*) FROM hosts_hosts_dependencies WHERE dependent_host_id={dep_host_id} AND host_id={host_id} AND dependency_period='{dep_period}' AND inherits_parent={inherits_parent} AND notification_failure_options='{notif_fail_opts}' AND execution_failure_options='{exec_fail_opts}'") - while time.time() < limit: - connection = pymysql.connect(host=DB_HOST, - user=DB_USER, - password=DB_PASS, - database=DB_NAME_STORAGE, - charset='utf8mb4', - autocommit=True, - cursorclass=pymysql.cursors.DictCursor) - - with connection: - with connection.cursor() as cursor: - cursor.execute("SELECT * FROM hosts_hosts_dependencies") - result = cursor.fetchall() - logger.console(result) - cursor.execute( - f"SELECT count(*) FROM hosts_hosts_dependencies WHERE dependent_host_id={dep_host_id} AND host_id={host_id} AND dependency_period='{dep_period}' AND inherits_parent={inherits_parent} AND notification_failure_options='{notif_fail_opts}' AND execution_failure_options='{exec_fail_opts}'") - result = cursor.fetchall() - logger.console(result) - if len(result) > 0 and int(result[0]['count(*)']) > 0: - return True - time.sleep(2) - return False - - -def ctn_check_no_host_dependencies(timeout=TIMEOUT): - limit = time.time() + timeout - logger.console("SELECT count(*) FROM hosts_hosts_dependencies") - while time.time() < limit: - connection = pymysql.connect(host=DB_HOST, - user=DB_USER, - password=DB_PASS, - database=DB_NAME_STORAGE, - charset='utf8mb4', - autocommit=True, - cursorclass=pymysql.cursors.DictCursor) - - with connection: - with connection.cursor() as cursor: - cursor.execute( - "SELECT count(*) FROM hosts_hosts_dependencies") - result = cursor.fetchall() - if len(result) > 0 and int(result[0]['count(*)']) == 0: - return True - return False - - def ctn_get_collect_version(): f = open("../CMakeLists.txt", "r") lines = f.readlines()