From 1edd66954fd86e694af8eaed479220a1dd9e8624 Mon Sep 17 00:00:00 2001 From: Jean Christophe Roques Date: Fri, 21 Jun 2024 15:45:41 +0200 Subject: [PATCH] centreon-agent => centreon-monitoring-agent --- .github/workflows/package-collect.yml | 2 +- agent/CMakeLists.txt | 6 +-- agent/scripts/centagent.service.in | 2 +- agent/src/main.cc | 9 +++-- agent/test/CMakeLists.txt | 3 +- packaging/centreon-agent-selinux.yaml | 40 ------------------- packaging/centreon-engine-daemon.yaml | 5 --- ... centreon-monitoring-agent-debuginfo.yaml} | 12 +++--- .../centreon-monitoring-agent-selinux.yaml | 40 +++++++++++++++++++ ...nt.yaml => centreon-monitoring-agent.yaml} | 28 ++++++------- .../centreon-agent-daemon-postinstall.sh | 25 ------------ .../centreon-agent-daemon-postremove.sh | 8 ---- .../centreon-agent-daemon-preinstall.sh | 10 ----- .../centreon-agent-selinux-preremove.sh | 5 --- .../centreon-engine-daemon-postinstall.sh | 13 ++++++ .../centreon-monitoring-agent-postinstall.sh | 27 +++++++++++++ .../centreon-monitoring-agent-postremove.sh | 8 ++++ .../centreon-monitoring-agent-preinstall.sh | 10 +++++ ...=> centreon-monitoring-agent-preremove.sh} | 0 ...n-monitoring-agent-selinux-postinstall.sh} | 4 +- ...reon-monitoring-agent-selinux-preremove.sh | 5 +++ .../centreon-monitoring-agent.fc} | 0 .../centreon-monitoring-agent.if} | 0 .../centreon-monitoring-agent.te} | 2 +- 24 files changed, 138 insertions(+), 126 deletions(-) delete mode 100644 packaging/centreon-agent-selinux.yaml rename packaging/{centreon-agent-debuginfo.yaml => centreon-monitoring-agent-debuginfo.yaml} (70%) create mode 100644 packaging/centreon-monitoring-agent-selinux.yaml rename packaging/{centreon-agent.yaml => centreon-monitoring-agent.yaml} (62%) delete mode 100644 packaging/scripts/centreon-agent-daemon-postinstall.sh delete mode 100644 packaging/scripts/centreon-agent-daemon-postremove.sh delete mode 100644 packaging/scripts/centreon-agent-daemon-preinstall.sh delete mode 100644 packaging/scripts/centreon-agent-selinux-preremove.sh create mode 100644 packaging/scripts/centreon-monitoring-agent-postinstall.sh create mode 100644 packaging/scripts/centreon-monitoring-agent-postremove.sh create mode 100644 packaging/scripts/centreon-monitoring-agent-preinstall.sh rename packaging/scripts/{centreon-agent-daemon-preremove.sh => centreon-monitoring-agent-preremove.sh} (100%) rename packaging/scripts/{centreon-agent-selinux-postinstall.sh => centreon-monitoring-agent-selinux-postinstall.sh} (58%) create mode 100644 packaging/scripts/centreon-monitoring-agent-selinux-preremove.sh rename selinux/{centreon-agent/centreon-agent.fc => centreon-monitoring-agent/centreon-monitoring-agent.fc} (100%) rename selinux/{centreon-agent/centreon-agent.if => centreon-monitoring-agent/centreon-monitoring-agent.if} (100%) rename selinux/{centreon-agent/centreon-agent.te => centreon-monitoring-agent/centreon-monitoring-agent.te} (99%) diff --git a/.github/workflows/package-collect.yml b/.github/workflows/package-collect.yml index 494d4de8c21..26a87c5890d 100644 --- a/.github/workflows/package-collect.yml +++ b/.github/workflows/package-collect.yml @@ -105,7 +105,7 @@ jobs: if: ${{ matrix.package_extension == 'rpm' }} run: | cd selinux - for MODULE in "centreon-engine" "centreon-broker" "centreon-agent"; do + for MODULE in "centreon-engine" "centreon-broker" "centreon-monitoring-agent"; do cd $MODULE sed -i "s/@VERSION@/${{ inputs.version }}/g" $MODULE.te make -f /usr/share/selinux/devel/Makefile diff --git a/agent/CMakeLists.txt b/agent/CMakeLists.txt index 217a6bed0dc..df32114e5b8 100644 --- a/agent/CMakeLists.txt +++ b/agent/CMakeLists.txt @@ -140,7 +140,7 @@ target_include_directories(${CENTREON_AGENT} PRIVATE ) set(AGENT_VAR_LOG_DIR - "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-agent") + "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-monitoring-agent") install(TARGETS ${CENTREON_AGENT} RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") @@ -150,8 +150,8 @@ if(WITH_TESTING) endif() -set(PREFIX_AGENT_CONF "${CMAKE_INSTALL_FULL_SYSCONFDIR}/centreon-agent") -set(USER_AGENT centreon-agent) +set(PREFIX_AGENT_CONF "${CMAKE_INSTALL_FULL_SYSCONFDIR}/centreon-monitoring-agent") +set(USER_AGENT centreon-monitoring-agent) if(WITH_CONF) diff --git a/agent/scripts/centagent.service.in b/agent/scripts/centagent.service.in index fb68eb5c9a7..3b22ff7e685 100644 --- a/agent/scripts/centagent.service.in +++ b/agent/scripts/centagent.service.in @@ -26,7 +26,7 @@ ReloadPropagatedFrom=centreon.service ExecStart=@CMAKE_INSTALL_FULL_BINDIR@/@CENTREON_AGENT@ @PREFIX_AGENT_CONF@/@CENTREON_AGENT@.json ExecReload=/bin/kill -HUP $MAINPID Type=simple -User=centreon-agent +User=@USER_AGENT@ [Install] WantedBy=default.target diff --git a/agent/src/main.cc b/agent/src/main.cc index 161f9c4f4c5..bd8d339883e 100644 --- a/agent/src/main.cc +++ b/agent/src/main.cc @@ -92,11 +92,12 @@ int main(int argc, char* argv[]) { } SPDLOG_INFO( - "centreon-agent start, you can decrease log verbosity by kill -USR1 " + "centreon-monitoring-agent start, you can decrease log verbosity by kill " + "-USR1 " "{} or increase by kill -USR2 {}", getpid(), getpid()); - const std::string logger_name = "centreon-agent"; + const std::string logger_name = "centreon-monitoring-agent"; if (conf->get_log_type() == config::file) { try { @@ -129,7 +130,7 @@ int main(int argc, char* argv[]) { g_logger->set_level(conf->get_log_level()); SPDLOG_LOGGER_INFO(g_logger, - "centreon-agent start, you can decrease log " + "centreon-monitoring-agent start, you can decrease log " "verbosity by kill -USR1 {} or increase by kill -USR2 {}", getpid(), getpid()); std::shared_ptr grpc_conf; @@ -159,7 +160,7 @@ int main(int argc, char* argv[]) { return -1; } - SPDLOG_LOGGER_INFO(g_logger, "centreon-agent end"); + SPDLOG_LOGGER_INFO(g_logger, "centreon-monitoring-agent end"); return 0; } \ No newline at end of file diff --git a/agent/test/CMakeLists.txt b/agent/test/CMakeLists.txt index a7acf6d8297..c66ffde4ece 100644 --- a/agent/test/CMakeLists.txt +++ b/agent/test/CMakeLists.txt @@ -43,7 +43,8 @@ target_link_libraries(ut_agent PRIVATE GTest::gmock_main -L${Boost_LIBRARY_DIR_RELEASE} boost_program_options - -L${PROTOBUF_LIB_DIR} + stdc++fs + -L${PROTOBUF_LIB_DIR} gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts fmt::fmt pthread crypto ssl diff --git a/packaging/centreon-agent-selinux.yaml b/packaging/centreon-agent-selinux.yaml deleted file mode 100644 index 068b0004b24..00000000000 --- a/packaging/centreon-agent-selinux.yaml +++ /dev/null @@ -1,40 +0,0 @@ -name: "centreon-agent-selinux" -arch: "${ARCH}" -platform: "linux" -version_schema: "none" -version: "${VERSION}" -release: "${RELEASE}${DIST}" -section: "default" -priority: "optional" -maintainer: "Centreon " -description: | - SELinux context for centreon-agent -vendor: "Centreon" -homepage: "https://centreon.com" -license: "Apache-2.0" - -depends: - - policycoreutils - - centreon-common-selinux -replaces: - - centreon-agent-selinux-debuginfo -conflicts: - - centreon-agent-selinux-debuginfo -provides: - - centreon-agent-selinux-debuginfo - -contents: - - src: "../selinux/centreon-agent/centreon-agent.pp" - dst: "/usr/share/selinux/packages/centreon/centreon-agent.pp" - file_info: - mode: 0655 - -scripts: - postinstall: ./scripts/centreon-agent-selinux-postinstall.sh - preremove: ./scripts/centreon-agent-selinux-preremove.sh - -rpm: - summary: SELinux context for centreon-agent - signature: - key_file: ${RPM_SIGNING_KEY_FILE} - key_id: ${RPM_SIGNING_KEY_ID} diff --git a/packaging/centreon-engine-daemon.yaml b/packaging/centreon-engine-daemon.yaml index 71c82f8ac0c..74573db05e8 100644 --- a/packaging/centreon-engine-daemon.yaml +++ b/packaging/centreon-engine-daemon.yaml @@ -114,11 +114,6 @@ contents: owner: centreon-engine group: centreon-engine - - src: "/usr/lib/nagios/plugins" - dst: "/usr/lib64/nagios/plugins" - type: symlink - packager: deb - scripts: preinstall: ./scripts/centreon-engine-daemon-preinstall.sh postinstall: ./scripts/centreon-engine-daemon-postinstall.sh diff --git a/packaging/centreon-agent-debuginfo.yaml b/packaging/centreon-monitoring-agent-debuginfo.yaml similarity index 70% rename from packaging/centreon-agent-debuginfo.yaml rename to packaging/centreon-monitoring-agent-debuginfo.yaml index f2bf9933c05..5aa14410670 100644 --- a/packaging/centreon-agent-debuginfo.yaml +++ b/packaging/centreon-monitoring-agent-debuginfo.yaml @@ -1,4 +1,4 @@ -name: "centreon-agent-debuginfo" +name: "centreon-monitoring-agent-debuginfo" arch: "${ARCH}" platform: "linux" version_schema: "none" @@ -23,16 +23,16 @@ contents: overrides: rpm: depends: - - centreon-agent = ${VERSION}-${RELEASE}${DIST} + - centreon-monitoring-agent = ${VERSION}-${RELEASE}${DIST} deb: depends: - - centreon-agent (= ${VERSION}-${RELEASE}${DIST}) + - centreon-monitoring-agent (= ${VERSION}-${RELEASE}${DIST}) conflicts: - - centreon-agent-dbgsym + - centreon-monitoring-agent-dbgsym replaces: - - centreon-agent-dbgsym + - centreon-monitoring-agent-dbgsym provides: - - centreon-agent-dbgsym + - centreon-monitoring-agent-dbgsym rpm: summary: Debuginfo package for centagent. diff --git a/packaging/centreon-monitoring-agent-selinux.yaml b/packaging/centreon-monitoring-agent-selinux.yaml new file mode 100644 index 00000000000..46ad02ae3ec --- /dev/null +++ b/packaging/centreon-monitoring-agent-selinux.yaml @@ -0,0 +1,40 @@ +name: "centreon-monitoring-agent-selinux" +arch: "${ARCH}" +platform: "linux" +version_schema: "none" +version: "${VERSION}" +release: "${RELEASE}${DIST}" +section: "default" +priority: "optional" +maintainer: "Centreon " +description: | + SELinux context for centreon-monitoring-agent +vendor: "Centreon" +homepage: "https://centreon.com" +license: "Apache-2.0" + +depends: + - policycoreutils + - centreon-common-selinux +replaces: + - centreon-monitoring-agent-selinux-debuginfo +conflicts: + - centreon-monitoring-agent-selinux-debuginfo +provides: + - centreon-monitoring-agent-selinux-debuginfo + +contents: + - src: "../selinux/centreon-monitoring-agent/centreon-monitoring-agent.pp" + dst: "/usr/share/selinux/packages/centreon/centreon-monitoring-agent.pp" + file_info: + mode: 0655 + +scripts: + postinstall: ./scripts/centreon-monitoring-agent-selinux-postinstall.sh + preremove: ./scripts/centreon-monitoring-agent-selinux-preremove.sh + +rpm: + summary: SELinux context for centreon-monitoring-agent + signature: + key_file: ${RPM_SIGNING_KEY_FILE} + key_id: ${RPM_SIGNING_KEY_ID} diff --git a/packaging/centreon-agent.yaml b/packaging/centreon-monitoring-agent.yaml similarity index 62% rename from packaging/centreon-agent.yaml rename to packaging/centreon-monitoring-agent.yaml index 4fd3e0554bf..9803966472f 100644 --- a/packaging/centreon-agent.yaml +++ b/packaging/centreon-monitoring-agent.yaml @@ -1,4 +1,4 @@ -name: "centreon-agent" +name: "centreon-monitoring-agent" arch: "${ARCH}" platform: "linux" version_schema: "none" @@ -16,12 +16,12 @@ license: "Apache-2.0" contents: - src: "../agent/conf/centagent.json" - dst: "/etc/centreon-agent/centagent.json" + dst: "/etc/centreon-monitoring-agent/centagent.json" type: config|noreplace file_info: mode: 0664 - owner: centreon-agent - group: centreon-agent + owner: centreon-monitoring-agent + group: centreon-monitoring-agent - src: "../agent/scripts/centagent.service" dst: "/usr/lib/systemd/system/centagent.service" @@ -37,25 +37,25 @@ contents: - src: "../build/agent/centagent" dst: "/usr/bin/centagent" - - dst: "/etc/centreon-agent" + - dst: "/etc/centreon-monitoring-agent" type: dir file_info: mode: 0775 - owner: centreon-agent - group: centreon-agent + owner: centreon-monitoring-agent + group: centreon-monitoring-agent - - dst: "/var/log/centreon-agent" + - dst: "/var/log/centreon-monitoring-agent" type: dir file_info: mode: 0755 - owner: centreon-agent - group: centreon-agent + owner: centreon-monitoring-agent + group: centreon-monitoring-agent scripts: - preinstall: ./scripts/centreon-agent-daemon-preinstall.sh - postinstall: ./scripts/centreon-agent-daemon-postinstall.sh - preremove: ./scripts/centreon-agent-daemon-preremove.sh - postremove: ./scripts/centreon-agent-daemon-postremove.sh + preinstall: ./scripts/centreon-monitoring-agent-daemon-preinstall.sh + postinstall: ./scripts/centreon-monitoring-agent-daemon-postinstall.sh + preremove: ./scripts/centreon-monitoring-agent-daemon-preremove.sh + postremove: ./scripts/centreon-monitoring-agent-daemon-postremove.sh rpm: diff --git a/packaging/scripts/centreon-agent-daemon-postinstall.sh b/packaging/scripts/centreon-agent-daemon-postinstall.sh deleted file mode 100644 index 87bebfa5649..00000000000 --- a/packaging/scripts/centreon-agent-daemon-postinstall.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -startCentagent() { - systemctl daemon-reload ||: - systemctl unmask centagent.service ||: - systemctl preset centagent.service ||: - systemctl enable centagent.service ||: - systemctl restart centagent.service ||: -} - -# on debian, it is needed to recreate centreon-agent user at each upgrade because it is removed on postrm step on versions < 23.10 -if [ "$1" = "configure" ] ; then - if [ ! "$(getent passwd centreon-agent)" ]; then - adduser --system --group --shell /bin/bash --no-create-home centreon-agent - fi - if [ "$(getent passwd nagios)" ]; then - usermod -a -G centreon-agent nagios - fi - chown -R centreon-agent:centreon-agent \ - /etc/centreon-agent \ - /var/log/centreon-agent -fi - -startCentagent - diff --git a/packaging/scripts/centreon-agent-daemon-postremove.sh b/packaging/scripts/centreon-agent-daemon-postremove.sh deleted file mode 100644 index d550f7b752f..00000000000 --- a/packaging/scripts/centreon-agent-daemon-postremove.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -case "$1" in - purge) - deluser centreon-agent || : - delgroup centreon-agent || : - ;; -esac diff --git a/packaging/scripts/centreon-agent-daemon-preinstall.sh b/packaging/scripts/centreon-agent-daemon-preinstall.sh deleted file mode 100644 index 6a0afa62e14..00000000000 --- a/packaging/scripts/centreon-agent-daemon-preinstall.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -if ! id centreon-agent > /dev/null 2>&1; then - useradd -r centreon-agent > /dev/null 2>&1 -fi - -if id -g nagios > /dev/null 2>&1; then - usermod -a -G centreon-agent nagios -fi - diff --git a/packaging/scripts/centreon-agent-selinux-preremove.sh b/packaging/scripts/centreon-agent-selinux-preremove.sh deleted file mode 100644 index 0b68b4805d5..00000000000 --- a/packaging/scripts/centreon-agent-selinux-preremove.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -if [ "$1" -lt "1" ]; then # Final removal - semodule -r centreon-agent > /dev/null 2>&1 || : -fi diff --git a/packaging/scripts/centreon-engine-daemon-postinstall.sh b/packaging/scripts/centreon-engine-daemon-postinstall.sh index b3b6460a278..4191284d638 100644 --- a/packaging/scripts/centreon-engine-daemon-postinstall.sh +++ b/packaging/scripts/centreon-engine-daemon-postinstall.sh @@ -8,6 +8,12 @@ startCentengine() { systemctl restart centengine.service ||: } +debianLinkNagios() { + if [ ! -r /usr/lib64/nagios/plugins ]; then + ln -s /usr/lib/nagios/plugins /usr/lib64/nagios/plugins + fi +} + # on debian, it is needed to recreate centreon-engine user at each upgrade because it is removed on postrm step on versions < 23.10 if [ "$1" = "configure" ] ; then if [ ! "$(getent passwd centreon-engine)" ]; then @@ -45,6 +51,13 @@ elif [ "$1" = "configure" ] && [ -n "$2" ]; then action="upgrade" fi +#In debian nagios plugins are stored in /usr/lib/nagios/plugins instead of /usr/lib64/nagios/plugins +#so we create a link /usr/lib/nagios/plugins instead => /usr/lib64/nagios/plugins in order to have +#the same commands configuration for all pollers +if [ "$1" = "configure" ]; then + debianLinkNagios +fi + case "$action" in "1" | "install") startCentengine diff --git a/packaging/scripts/centreon-monitoring-agent-postinstall.sh b/packaging/scripts/centreon-monitoring-agent-postinstall.sh new file mode 100644 index 00000000000..4ea243b0a48 --- /dev/null +++ b/packaging/scripts/centreon-monitoring-agent-postinstall.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +startCentagent() { + systemctl daemon-reload ||: + systemctl unmask centagent.service ||: + systemctl preset centagent.service ||: + systemctl enable centagent.service ||: + systemctl restart centagent.service ||: +} + + +debianLinkNagios() { + if [ ! -r /usr/lib64/nagios/plugins ]; then + ln -s /usr/lib/nagios/plugins /usr/lib64/nagios/plugins + fi +} + +#In debian nagios plugins are stored in /usr/lib/nagios/plugins instead of /usr/lib64/nagios/plugins +#so we create a link /usr/lib/nagios/plugins instead => /usr/lib64/nagios/plugins in order to have +#the same commands configuration for all pollers +if [ "$1" = "configure" ]; then + debianLinkNagios +fi + + +startCentagent + diff --git a/packaging/scripts/centreon-monitoring-agent-postremove.sh b/packaging/scripts/centreon-monitoring-agent-postremove.sh new file mode 100644 index 00000000000..28bd8ec8c39 --- /dev/null +++ b/packaging/scripts/centreon-monitoring-agent-postremove.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +case "$1" in + purge) + deluser centreon-monitoring-agent || : + delgroup centreon-monitoring-agent || : + ;; +esac diff --git a/packaging/scripts/centreon-monitoring-agent-preinstall.sh b/packaging/scripts/centreon-monitoring-agent-preinstall.sh new file mode 100644 index 00000000000..ac991e2ea58 --- /dev/null +++ b/packaging/scripts/centreon-monitoring-agent-preinstall.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +if ! id centreon-monitoring-agent > /dev/null 2>&1; then + useradd -r centreon-monitoring-agent > /dev/null 2>&1 +fi + +if id -g nagios > /dev/null 2>&1; then + usermod -a -G centreon-monitoring-agent nagios +fi + diff --git a/packaging/scripts/centreon-agent-daemon-preremove.sh b/packaging/scripts/centreon-monitoring-agent-preremove.sh similarity index 100% rename from packaging/scripts/centreon-agent-daemon-preremove.sh rename to packaging/scripts/centreon-monitoring-agent-preremove.sh diff --git a/packaging/scripts/centreon-agent-selinux-postinstall.sh b/packaging/scripts/centreon-monitoring-agent-selinux-postinstall.sh similarity index 58% rename from packaging/scripts/centreon-agent-selinux-postinstall.sh rename to packaging/scripts/centreon-monitoring-agent-selinux-postinstall.sh index f58e756b6d5..0c48460d63c 100644 --- a/packaging/scripts/centreon-agent-selinux-postinstall.sh +++ b/packaging/scripts/centreon-monitoring-agent-selinux-postinstall.sh @@ -1,11 +1,11 @@ #!/bin/sh install() { - semodule -i /usr/share/selinux/packages/centreon/centreon-engine.pp > /dev/null 2>&1 || : + semodule -i /usr/share/selinux/packages/centreon/centreon-monitoring-agent.pp > /dev/null 2>&1 || : } upgrade() { - semodule -i /usr/share/selinux/packages/centreon/centreon-engine.pp > /dev/null 2>&1 || : + semodule -i /usr/share/selinux/packages/centreon/centreon-monitoring-agent.pp > /dev/null 2>&1 || : } action="$1" diff --git a/packaging/scripts/centreon-monitoring-agent-selinux-preremove.sh b/packaging/scripts/centreon-monitoring-agent-selinux-preremove.sh new file mode 100644 index 00000000000..aa557d9b61b --- /dev/null +++ b/packaging/scripts/centreon-monitoring-agent-selinux-preremove.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ "$1" -lt "1" ]; then # Final removal + semodule -r centreon-monitoring-agent > /dev/null 2>&1 || : +fi diff --git a/selinux/centreon-agent/centreon-agent.fc b/selinux/centreon-monitoring-agent/centreon-monitoring-agent.fc similarity index 100% rename from selinux/centreon-agent/centreon-agent.fc rename to selinux/centreon-monitoring-agent/centreon-monitoring-agent.fc diff --git a/selinux/centreon-agent/centreon-agent.if b/selinux/centreon-monitoring-agent/centreon-monitoring-agent.if similarity index 100% rename from selinux/centreon-agent/centreon-agent.if rename to selinux/centreon-monitoring-agent/centreon-monitoring-agent.if diff --git a/selinux/centreon-agent/centreon-agent.te b/selinux/centreon-monitoring-agent/centreon-monitoring-agent.te similarity index 99% rename from selinux/centreon-agent/centreon-agent.te rename to selinux/centreon-monitoring-agent/centreon-monitoring-agent.te index 9bc1e0013a2..205297ed7af 100644 --- a/selinux/centreon-agent/centreon-agent.te +++ b/selinux/centreon-monitoring-agent/centreon-monitoring-agent.te @@ -1,4 +1,4 @@ -policy_module(centreon-agent, @VERSION@) +policy_module(centreon-monitoring-agent, @VERSION@) ######################################## #