Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Engine configuration using protobuf #1541

Merged
merged 21 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e975db2
enh(engine/configuration): First implementation of the common/engine_…
bouda1 Jul 24, 2024
4de577b
fix(common/engine_conf): various fixes after code review
bouda1 Aug 27, 2024
d64dd0e
fix(broker/lua): Several fix in the lua Stream
bouda1 Jul 24, 2024
c494cf1
fix(broker/simu): compilation warning removed
bouda1 Jul 30, 2024
b133f5a
enh(broker/misc): Header file reformatted
bouda1 Jul 24, 2024
16e6e6d
enh(broker/neb): fixes in the neb stream
bouda1 Jul 24, 2024
a1d76aa
fix(broker/rebuilder): values are floats and not doubles and some tra…
bouda1 Aug 5, 2024
efd6abe
fix(broker/victoria_metrics): warning removed
bouda1 Jul 24, 2024
ce0e57b
cleanup(broker/core): little improvement to follow new standard
bouda1 Jul 24, 2024
10e9436
enh(broker): HostDependencies and ServiceDependencies are not used by…
bouda1 Jul 24, 2024
0148da5
enh(engine/tests): unit tests are migrated to also work with the prot…
bouda1 Jul 24, 2024
3696ef2
fix(tests/bam): test simplified
bouda1 Aug 6, 2024
625c643
enh(tests): hostgroups tests are more complete
bouda1 Aug 6, 2024
15504a6
fix(tests): external-commands2 fixed
bouda1 Aug 5, 2024
410b31b
fix(tests/opentelemetry): current tests on opentelemetry have an issu…
bouda1 Jul 26, 2024
afd52d5
enh(tests): hostgroups/servicegroups more complete
bouda1 Jul 31, 2024
6583be8
fix(tests): severities tests were broken because name must be replace…
bouda1 Aug 1, 2024
fce8973
fix(tests): an issue with start date of tests is fixed, the duplicate…
bouda1 Aug 5, 2024
9d35964
fix(tests): One index can return several metrics
bouda1 Aug 5, 2024
0392a93
doc(tests): README updated
bouda1 Aug 5, 2024
0db7a54
doc(common): a little explanation on the new engine_conf module
bouda1 Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
# Get distributions name
#
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
file(STRINGS "/etc/os-release" release REGEX "^ID")
file(STRINGS "/etc/os-release" release REGEX "ID")

foreach(line ${release})
if(${line} MATCHES "ID_LIKE=.*")
Expand All @@ -80,6 +80,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(${line} MATCHES "ID=.*")
string(REGEX REPLACE "ID=\"(.*)\"" "\\1" id ${line})
endif()

if(${line} MATCHES "VERSION_ID=.*")
string(REGEX REPLACE "VERSION_ID=\"([0-9]+)\..*" "\\1" os_version ${line})
endif()
endforeach()

string(TOLOWER "${like}" like)
Expand All @@ -100,6 +104,11 @@ else()
set(OS_DISTRIBUTOR "${CMAKE_SYSTEM_NAME}")
endif()

if(OS_DISTRIBUTOR STREQUAL "CentOS" AND os_version STREQUAL "8")
message(STATUS "Legacy gettimeofday")
add_definitions("-DLEGACY_GETTIMEOFDAY")
endif()

message(STATUS "${id} detected (compatible with ${OS_DISTRIBUTOR})")

# set -latomic if OS is Raspbian.
Expand Down
4 changes: 2 additions & 2 deletions CMakeListsLinux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# Global settings.
#


option(WITH_ASAN
"Add the libasan to check memory leaks and other memory issues." OFF)

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions broker/core/inc/com/centreon/broker/time/timeperiod.hh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class timeperiod {
bool set_timerange(std::string const& timerange_text, int day);
std::list<timerange> const& get_timeranges_by_day(int day) const throw();

std::string const& get_timezone() const throw();
std::string const& get_timezone() const noexcept;
void set_timezone(std::string const& tz);

bool is_valid(time_t preferred_time) const;
Expand All @@ -120,6 +120,6 @@ class timeperiod {
};
} // namespace time

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

#endif // !CCB_CORE_TIME_TIMEPERIOD_HH
162 changes: 77 additions & 85 deletions broker/core/sql/inc/com/centreon/broker/sql/mysql_error.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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[]{
Expand All @@ -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: ",
Expand Down Expand Up @@ -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: ",
Expand All @@ -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: ",
Expand Down
32 changes: 16 additions & 16 deletions broker/core/src/misc/string.cc
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
* Copyright 2011-2013 Centreon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : [email protected]
*/
* Copyright 2011-2013 Centreon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : [email protected]
*/

#include "com/centreon/broker/misc/string.hh"
#include "com/centreon/common/utf8.hh"
Expand Down
17 changes: 15 additions & 2 deletions broker/lua/inc/com/centreon/broker/lua/macro_cache.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "com/centreon/broker/neb/host_group.hh"
#include "com/centreon/broker/neb/host_group_member.hh"
#include "com/centreon/broker/neb/instance.hh"
#include "com/centreon/broker/neb/internal.hh"
#include "com/centreon/broker/neb/service.hh"
#include "com/centreon/broker/neb/service_group.hh"
#include "com/centreon/broker/neb/service_group_member.hh"
Expand All @@ -42,14 +43,26 @@ class macro_cache {
std::shared_ptr<persistent_cache> _cache;
absl::flat_hash_map<uint64_t, std::shared_ptr<io::data>> _instances;
absl::flat_hash_map<uint64_t, std::shared_ptr<io::data>> _hosts;
absl::flat_hash_map<uint64_t, std::shared_ptr<io::data>> _host_groups;
/* The host groups cache stores also a set with the pollers telling they need
* the cache. So if no more poller needs a host group, we can remove it from
* the cache. */
absl::flat_hash_map<uint64_t,
std::pair<std::shared_ptr<neb::pb_host_group>,
absl::flat_hash_set<uint32_t>>>
_host_groups;
absl::btree_map<std::pair<uint64_t, uint64_t>, std::shared_ptr<io::data>>
_host_group_members;
absl::flat_hash_map<std::pair<uint64_t, uint64_t>, std::shared_ptr<io::data>>
_custom_vars;
absl::flat_hash_map<std::pair<uint64_t, uint64_t>, std::shared_ptr<io::data>>
_services;
absl::flat_hash_map<uint64_t, std::shared_ptr<io::data>> _service_groups;
/* The service groups cache stores also a set with the pollers telling they
* need the cache. So if no more poller needs a service group, we can remove
* it from the cache. */
absl::flat_hash_map<uint64_t,
std::pair<std::shared_ptr<neb::pb_service_group>,
absl::flat_hash_set<uint32_t>>>
_service_groups;
absl::btree_map<std::tuple<uint64_t, uint64_t, uint64_t>,
std::shared_ptr<io::data>>
_service_group_members;
Expand Down
39 changes: 34 additions & 5 deletions broker/lua/src/broker_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "absl/strings/string_view.h"
#include "com/centreon/broker/config/applier/state.hh"

#include <openssl/md5.h>
#include <openssl/evp.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
Expand Down Expand Up @@ -810,6 +810,34 @@ static int l_broker_stat(lua_State* L) {
}
}

static void md5_message(const unsigned char* message,
size_t message_len,
unsigned char** digest,
unsigned int* digest_len) {
EVP_MD_CTX* mdctx;
auto handle_error = [](const std::string& msg) {
auto logger = log_v2::instance().get(log_v2::LUA);
logger->error(msg);
};
if ((mdctx = EVP_MD_CTX_new()) == nullptr) {
handle_error("lua: fail to call MD5 (EVP_MD_CTX_new call)");
}
if (1 != EVP_DigestInit_ex(mdctx, EVP_md5(), nullptr)) {
handle_error("lua: fail to call MD5 (EVP_DigestInit_ex call)");
}
if (1 != EVP_DigestUpdate(mdctx, message, message_len)) {
handle_error("lua: fail to call MD5 (EVP_DigestUpdate call)");
}
if ((*digest = (unsigned char*)OPENSSL_malloc(EVP_MD_size(EVP_md5()))) ==
nullptr) {
handle_error("lua: fail to call MD5 (OPENSSL_malloc call)");
}
if (1 != EVP_DigestFinal_ex(mdctx, *digest, digest_len)) {
handle_error("lua: fail to call MD5 (EVP_DigestFinal_ex call)");
}
EVP_MD_CTX_free(mdctx);
}

static int l_broker_md5(lua_State* L) {
auto digit = [](unsigned char d) -> char {
if (d < 10)
Expand All @@ -820,11 +848,12 @@ static int l_broker_md5(lua_State* L) {
size_t len;
const unsigned char* str =
reinterpret_cast<const unsigned char*>(lua_tolstring(L, -1, &len));
unsigned char md5[MD5_DIGEST_LENGTH];
MD5(str, len, md5);
char result[2 * MD5_DIGEST_LENGTH + 1];
unsigned char* md5;
uint32_t md5_len;
md5_message(str, len, &md5, &md5_len);
char result[2 * md5_len + 1];
char* tmp = result;
for (int i = 0; i < MD5_DIGEST_LENGTH; i++) {
for (uint32_t i = 0; i < md5_len; i++) {
*tmp = digit(md5[i] >> 4);
++tmp;
*tmp = digit(md5[i] & 0xf);
Expand Down
Loading
Loading