Skip to content

Commit

Permalink
* no native mysql authent
Browse files Browse the repository at this point in the history
* default mariadb plugins directory is configurable and set by default according to the os
* no lib mariadb static link

REFS: MON-120715
  • Loading branch information
jean-christophe81 committed Jun 24, 2024
1 parent dc90889 commit 4c16f99
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/docker/Dockerfile.centreon-collect-alma8
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dnf --best install -y cmake \

dnf update libarchive

pip3 install conan==1.62.0 --prefix=/usr --upgrade
pip3 install conan==1.64.0 --prefix=/usr --upgrade
rm -rf ~/.conan/profiles/default

EOF
Expand Down
3 changes: 2 additions & 1 deletion .github/docker/Dockerfile.centreon-collect-alma9
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dnf --best install -y cmake \
openssh-server \
mariadb-server \
mariadb \
mariadb-connector-c-devel \
gnutls-devel \
libgcrypt-devel \
lua-devel \
Expand All @@ -48,7 +49,7 @@ dnf --best install -y cmake \
nfpm \
sudo

pip3 install conan==1.62.0 --prefix=/usr --upgrade
pip3 install conan==1.64.0 --prefix=/usr --upgrade
rm -rf ~/.conan/profiles/default

EOF
Expand Down
3 changes: 2 additions & 1 deletion .github/docker/Dockerfile.centreon-collect-debian-bullseye
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ apt-get -y install cmake \
mariadb-server \
openssh-server \
libmariadb3 \
libmariadb-dev \
librrd-dev \
libgnutls28-dev \
liblua5.3-dev \
Expand Down Expand Up @@ -50,7 +51,7 @@ localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
pip3 install conan==1.62.0
pip3 install conan==1.64.0
ln -s /usr/local/bin/conan /usr/bin/conan
rm -rf ~/.conan/profiles/default

Expand Down
3 changes: 2 additions & 1 deletion .github/docker/Dockerfile.centreon-collect-mysql-alma9
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dnf --best install -y cmake \
gdb \
gettext \
git \
mariadb-connector-c-devel \
ninja-build \
openssh-server \
mysql-server \
Expand All @@ -48,7 +49,7 @@ dnf --best install -y cmake \
nfpm \
sudo

pip3 install conan==1.62.0 --prefix=/usr --upgrade
pip3 install conan==1.64.0 --prefix=/usr --upgrade
rm -rf ~/.conan/profiles/default

EOF
Expand Down
3 changes: 2 additions & 1 deletion .github/docker/Dockerfile.centreon-collect-mysql-alma9-test
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dnf --best install -y gcc \
gdb \
git \
openssh-server \
mariadb-connector-c \
mysql-server \
mysql \
gnutls \
Expand All @@ -41,7 +42,7 @@ dnf --best install -y gcc \
echo "install robot and dependencies"

pip3 install -U robotframework robotframework-databaselibrary robotframework-httpctrl robotframework-examples pymysql python-dateutil psutil
pip3 install grpcio grpcio_tools py-cpuinfo cython unqlite gitpython boto3
pip3 install grpcio grpcio_tools py-cpuinfo cython unqlite gitpython boto3 cryptography

cd /tmp/collect

Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/collect-prepare-test-robot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ if [ $database_type == 'mysql' ]; then
sleep 5
echo "########################### Init centreon database ############################"

mysql -e "CREATE USER IF NOT EXISTS 'centreon'@'localhost' IDENTIFIED WITH mysql_native_password BY 'centreon';"
mysql -e "CREATE USER IF NOT EXISTS 'root_centreon'@'localhost' IDENTIFIED WITH mysql_native_password BY 'centreon';"
mysql -e "CREATE USER IF NOT EXISTS 'centreon'@'localhost' IDENTIFIED BY 'centreon'"
mysql -e "CREATE USER IF NOT EXISTS 'root_centreon'@'localhost' IDENTIFIED BY 'centreon'"
else
echo "########################### Start MariaDB ######################################"
if [ "$distrib" = "ALMALINUX" ]; then
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:

- name: Compile sources
run: |
sudo pip3 install conan==1.62.0 --prefix=/usr --upgrade
sudo pip3 install conan==1.64.0 --prefix=/usr --upgrade
sudo conan install . -s compiler.cppstd=17 -s compiler.libcxx=libstdc++11 --build=missing
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ set(CMAKE_PROGRAM_PATH ${CONAN_BIN_DIRS_PROTOBUF};${CMAKE_PROGRAM_PATH})

find_package(Protobuf REQUIRED)

include(FindPkgConfig)
pkg_check_modules(MARIADB REQUIRED libmariadb)

message(NOTICE "-- use protoc compiler: ${Protobuf_PROTOC_EXECUTABLE}")

include(GNUInstallDirs)
Expand Down
11 changes: 8 additions & 3 deletions broker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,30 @@ endif()
if(OS_DISTRIBUTOR STREQUAL "Debian" OR OS_DISTRIBUTOR STREQUAL "Ubuntu")
message(STATUS "deb based os")
add_definitions("-DMYSQL_SOCKET=\"/var/run/mysqld/mysqld.sock\"")
add_definitions("-DDEFAULT_MARIADB_EXTENSION_DIR=\"/usr/lib/x86_64-linux-gnu/libmariadb3/plugin\"")
elseif(OS_DISTRIBUTOR STREQUAL "CentOS" OR OS_DISTRIBUTOR STREQUAL "RedHat")
message(STATUS "rpm based os")
add_definitions("-DMYSQL_SOCKET=\"/var/lib/mysql/mysql.sock\"")
add_definitions("-DDEFAULT_MARIADB_EXTENSION_DIR=\"/usr/lib64/mariadb/plugin\"")
else()
message(STATUS "other os: ${OS_DISTRIBUTOR}")
add_definitions("-DMYSQL_SOCKET=/tmp/mysql.sock")
add_definitions("-DMYSQL_SOCKET=\"/tmp/mysql.sock\"")
add_definitions("-DDEFAULT_MARIADB_EXTENSION_DIR=\"/usr/lib/x86_64-linux-gnu/libmariadb3/plugin\"")
endif()

include_directories(
"${PROJECT_SOURCE_DIR}/core/inc"
"${PROJECT_SOURCE_DIR}/neb/inc"
"${CMAKE_SOURCE_DIR}/engine/inc"
"${PROJECT_SOURCE_DIR}/core/multiplexing/inc"
"${PROJECT_SOURCE_DIR}/core/sql/inc")
"${PROJECT_SOURCE_DIR}/core/sql/inc"
"${MARIADB_INCLUDE_DIRS}")
set(INC_DIR "${PROJECT_SOURCE_DIR}/core/inc/com/centreon/broker")
set(SRC_DIR "${PROJECT_SOURCE_DIR}/core/src")
set(TEST_DIR "${PROJECT_SOURCE_DIR}/core/test")

add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)
add_definitions(${spdlog_DEFINITIONS} ${mariadb-connector-c_DEFINITIONS})
add_definitions(${spdlog_DEFINITIONS})

include_directories(${CONAN_INCLUDE_DIRS_MARIADB-CONNECTOR-C})

Expand Down Expand Up @@ -491,6 +495,7 @@ target_link_libraries(
"-Wl,--no-whole-archive"
CONAN_PKG::spdlog
CONAN_PKG::grpc
${MARIADB_LIBRARIES}
stdc++fs)

# Centreon Broker Watchdog
Expand Down
2 changes: 1 addition & 1 deletion broker/core/sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ set(SOURCES
add_library(sql STATIC ${SOURCES})
set_target_properties(sql PROPERTIES COMPILE_FLAGS "-fPIC")
target_precompile_headers(sql PRIVATE ../precomp_inc/precomp.hpp)
target_link_libraries(sql CONAN_PKG::spdlog CONAN_PKG::mariadb-connector-c)
target_link_libraries(sql CONAN_PKG::spdlog)

# if(WITH_TESTING) set( TESTS_SOURCES ${TESTS_SOURCES}
# ${TESTS_DIR}/engine/start_stop.cc ${TESTS_DIR}/muxer/read.cc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class database_config {
int get_connections_count() const;
unsigned get_max_commit_delay() const;
unsigned get_category() const;
const std::string& get_extension_directory() const {
return _extension_directory;
}

void set_type(std::string const& type);
void set_host(std::string const& host);
Expand All @@ -89,6 +92,9 @@ class database_config {
void set_queries_per_transaction(int qpt);
void set_check_replication(bool check_replication);
void set_category(unsigned category);
void set_extension_directory(std::string const& extension_directory) {
_extension_directory = extension_directory;
}

database_config auto_commit_conf() const;

Expand All @@ -107,6 +113,8 @@ class database_config {
int _connections_count;
unsigned _max_commit_delay;
unsigned _category;
// where mariadb will find extension such as caching_sha2_password.so
std::string _extension_directory;
};

std::ostream& operator<<(std::ostream& s, const database_config cfg);
Expand Down
3 changes: 2 additions & 1 deletion broker/core/sql/inc/com/centreon/broker/sql/mysql_column.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
#ifndef CCB_DATABASE_MYSQL_COLUMN_HH
#define CCB_DATABASE_MYSQL_COLUMN_HH

#include <fmt/format.h>
#include <mysql.h>

#include <fmt/format.h>
#include <cmath>
#include "com/centreon/broker/namespace.hh"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class mysql_connection {
const std::string _pwd;
const std::string _name;
const int _port;
const std::string _extension_directory;
const unsigned _max_second_commit_delay;
time_t _last_commit;
std::atomic<connection_state> _state;
Expand Down
20 changes: 15 additions & 5 deletions broker/core/sql/src/database_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ std::ostream& operator<<(std::ostream& s, const database_config cfg) {
}
s << "queries per transaction:" << cfg.get_queries_per_transaction()
<< " check replication:" << cfg.get_check_replication()
<< " connnexion count:" << cfg.get_connections_count()
<< " max comit delay:" << cfg.get_max_commit_delay() << 's';
<< " connection count:" << cfg.get_connections_count()
<< " max commit delay:" << cfg.get_max_commit_delay() << 's'
<< " extension_directory" << cfg.get_extension_directory();
return s;
}

Expand All @@ -48,7 +49,8 @@ database_config::database_config()
: _queries_per_transaction(1),
_check_replication(true),
_connections_count(1),
_category(SHARED) {}
_category(SHARED),
_extension_directory(DEFAULT_MARIADB_EXTENSION_DIR) {}

/**
* Constructor.
Expand Down Expand Up @@ -89,14 +91,16 @@ database_config::database_config(const std::string& type,
_check_replication(check_replication),
_connections_count(connections_count),
_max_commit_delay(max_commit_delay),
_category(SHARED) {}
_category(SHARED),
_extension_directory(DEFAULT_MARIADB_EXTENSION_DIR) {}

/**
* Build a database configuration from a configuration set.
*
* @param[in] cfg Endpoint configuration.
*/
database_config::database_config(config::endpoint const& cfg) {
database_config::database_config(config::endpoint const& cfg)
: _extension_directory(DEFAULT_MARIADB_EXTENSION_DIR) {
std::map<std::string, std::string>::const_iterator it, end;
end = cfg.params.end();

Expand Down Expand Up @@ -208,6 +212,11 @@ database_config::database_config(config::endpoint const& cfg) {
}
} else
_max_commit_delay = 5;

it = cfg.params.find("extension_directory");
if (it != end) {
_extension_directory = it->second;
}
}

/**
Expand Down Expand Up @@ -552,6 +561,7 @@ void database_config::_internal_copy(database_config const& other) {
_check_replication = other._check_replication;
_connections_count = other._connections_count;
_max_commit_delay = other._max_commit_delay;
_extension_directory = other._extension_directory;
}

/**
Expand Down
10 changes: 9 additions & 1 deletion broker/core/sql/src/mysql_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*
* For more information : [email protected]
*/
*/

#include <errmsg.h>

#include "com/centreon/broker/config/applier/init.hh"
Expand Down Expand Up @@ -190,6 +191,9 @@ bool mysql_connection::_try_to_reconnect() {
uint32_t timeout = 10;
mysql_options(_conn, MYSQL_OPT_CONNECT_TIMEOUT, &timeout);

mysql_optionsv(_conn, MYSQL_PLUGIN_DIR,
(const void*)_extension_directory.c_str());

if (!mysql_real_connect(_conn, _host.c_str(), _user.c_str(), _pwd.c_str(),
_name.c_str(), _port,
(_socket == "" ? nullptr : _socket.c_str()),
Expand Down Expand Up @@ -837,6 +841,9 @@ void mysql_connection::_run() {
uint32_t timeout = 10;
mysql_options(_conn, MYSQL_OPT_CONNECT_TIMEOUT, &timeout);

mysql_optionsv(_conn, MYSQL_PLUGIN_DIR,
(const void*)_extension_directory.c_str());

while (config::applier::mode != config::applier::finished &&
!mysql_real_connect(_conn, _host.c_str(), _user.c_str(),
_pwd.c_str(), _name.c_str(), _port,
Expand Down Expand Up @@ -1081,6 +1088,7 @@ mysql_connection::mysql_connection(const database_config& db_cfg,
_pwd(db_cfg.get_password()),
_name(db_cfg.get_name()),
_port(db_cfg.get_port()),
_extension_directory(db_cfg.get_extension_directory()),
_max_second_commit_delay(db_cfg.get_max_commit_delay()),
_last_commit(db_cfg.get_queries_per_transaction() > 1
? 0
Expand Down
8 changes: 6 additions & 2 deletions broker/neb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,14 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
multiplexing
"-Wl,--no-whole-archive"
CONAN_PKG::nlohmann_json
CONAN_PKG::spdlog)
CONAN_PKG::spdlog
${MARIADB_LIBRARIES}
)
else()
target_link_libraries("${CBMOD}" "rokerbase" CONAN_PKG::nlohmann_json
CONAN_PKG::spdlog)
CONAN_PKG::spdlog
${MARIADB_LIBRARIES}
)
endif()

set_target_properties("${CBMOD}" PROPERTIES PREFIX "")
Expand Down
1 change: 0 additions & 1 deletion broker/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ target_link_libraries(
CONAN_PKG::fmt
CONAN_PKG::spdlog
CONAN_PKG::gtest
CONAN_PKG::mariadb-connector-c
CONAN_PKG::openssl
CONAN_PKG::grpc
stdc++fs)
Expand Down
10 changes: 8 additions & 2 deletions broker/unified_sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ set_target_properties("${UNIFIED_SQL}" PROPERTIES PREFIX "" COMPILE_FLAGS
add_dependencies("${UNIFIED_SQL}" target_rebuild_message
target_remove_graph_message target_neb)
target_precompile_headers(${UNIFIED_SQL} PRIVATE precomp_inc/precomp.hpp)
target_link_libraries(${UNIFIED_SQL} rokerbase bbdo_storage CONAN_PKG::spdlog
CONAN_PKG::abseil pb_storage_lib)
target_link_libraries(${UNIFIED_SQL}
rokerbase
bbdo_storage
CONAN_PKG::spdlog
CONAN_PKG::abseil
pb_storage_lib
${MARIADB_LIBRARIES}
)

# Testing.
if(WITH_TESTING)
Expand Down
4 changes: 2 additions & 2 deletions cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ elif [ -r /etc/issue ] ; then
fi
fi

if ! pip3 install conan==1.62.0 --upgrade --break-system-packages ; then
pip3 install conan==1.62.0 --upgrade
if ! pip3 install conan==1.64.0 --upgrade --break-system-packages ; then
pip3 install conan==1.64.0 --upgrade
fi

if which conan ; then
Expand Down
1 change: 0 additions & 1 deletion conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ grpc/1.54.3
gtest/cci.20210126
libcurl/8.0.1
libssh2/1.10.0
mariadb-connector-c/3.3.3
nlohmann_json/3.11.2
openssl/1.1.1t
opentelemetry-cpp/1.14.2
Expand Down
2 changes: 2 additions & 0 deletions packaging/centreon-broker-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ overrides:
- centreon-clib = ${VERSION}-${RELEASE}${DIST}
- centreon-broker = ${VERSION}-${RELEASE}${DIST}
- gnutls >= 3.3.29
- mariadb-connector-c >= 3.1.10
conflicts:
- centreon-broker-storage
- centreon-broker-core-devel
Expand All @@ -58,6 +59,7 @@ overrides:
- centreon-clib (= ${VERSION}-${RELEASE}${DIST})
- centreon-broker (= ${VERSION}-${RELEASE}${DIST})
- libgnutls30
- libmariadb3
conflicts:
- centreon-broker-storage
- centreon-broker-core-dev
Expand Down
1 change: 0 additions & 1 deletion tests/mysql_docker_conf/centreon16.cnf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[mysqld]
#mariadb conf optimized for a 16Gb ram machine
port = 3306
default-authentication-plugin=mysql_native_password

max_heap_table_size=1G
open_files_limit = 32000
Expand Down

0 comments on commit 4c16f99

Please sign in to comment.