From c2d7c3f307369d9f2ef16ab42feff7bcb5cd31eb Mon Sep 17 00:00:00 2001 From: Paul LOUIS THERESE <53221698+paloth@users.noreply.github.com> Date: Mon, 16 Jan 2023 15:35:56 +0100 Subject: [PATCH] Release #18909# MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * enh(broker): cbd with multiargs and robot tests (#306) -enh(broker): cbd with multiargs and robot tests -Validate with tests/broker/command-line.robot -Update README.md -Common.py : fix find in log with timeout REFS: MON-13901 * fix(broker/bam): downtimes on kpi can be more than one * enh(tests/bam): new tests to reproduce a bug * chore(doc): CHANGELOG updated and version set to 21.10.3 * chore(tests): README updated REFS: MON-14091 * fix(broker/engine): grpc api can be changed through configuration. Otherwise it is fixed to localhost (#320) REFS: MON-13904 * fix(broker/rrd): rebuild fixed in 21.10 (#340) * Also an issue due to conan fixed, python 3.8 is needed. REFS: MON-14092 * fix(ci): issues with conan fixed * fix(ci/scripts): conan bad path * fix(broker/bam): overlapping downtimes on kpi service are well handled now. (#341) REFS: MON-14091 * fix(ci/tests): missing dependencies for python38 * fix(broker/lua): lua stream connector accepts empty parameters(21.10) (#359) REFS: MON-13875 * fix(broker/muxer): poller waits at most 5s to send goodbye to broker before shutdown (#360) REFS: MON-14511 * fix(broker/config): if failovers are badly defined, error logs are raised but this does not stop broker (#365) REFS: MON-6986 * chore(release):rebase dev-21.10.x on 21.10.x (#388) * chore(release): merge release 21.10.next into 21.10.x (#386) * enh(broker): cbd with multiargs and robot tests (#306) -enh(broker): cbd with multiargs and robot tests -Validate with tests/broker/command-line.robot -Update README.md -Common.py : fix find in log with timeout REFS: MON-13901 * fix(broker/bam): downtimes on kpi can be more than one * enh(tests/bam): new tests to reproduce a bug * chore(doc): CHANGELOG updated and version set to 21.10.3 * chore(tests): README updated REFS: MON-14091 * fix(broker/engine): grpc api can be changed through configuration. Otherwise it is fixed to localhost (#320) REFS: MON-13904 * fix(broker/rrd): rebuild fixed in 21.10 (#340) * Also an issue due to conan fixed, python 3.8 is needed. REFS: MON-14092 * fix(ci): issues with conan fixed * fix(ci/scripts): conan bad path * fix(broker/bam): overlapping downtimes on kpi service are well handled now. (#341) REFS: MON-14091 * fix(ci/tests): missing dependencies for python38 * fix(broker/lua): lua stream connector accepts empty parameters(21.10) (#359) REFS: MON-13875 * fix(broker/muxer): poller waits at most 5s to send goodbye to broker before shutdown (#360) REFS: MON-14511 Co-authored-by: denliA <91119589+denliA@users.noreply.github.com> Co-authored-by: David Boucher Co-authored-by: jean-christophe81 <98889244+jean-christophe81@users.noreply.github.com> * fix(broker/config): if failovers are badly defined, error logs are raised but this does not stop broker (#365) REFS: MON-6986 Co-authored-by: denliA <91119589+denliA@users.noreply.github.com> Co-authored-by: David Boucher Co-authored-by: jean-christophe81 <98889244+jean-christophe81@users.noreply.github.com> * fix(broker/config): file failover should not stop broker * delete from hostgroups and servicegroups is delayed of one minute (#379) REFS-MON-14908 * fix(broker/stats): center concurrent access changed to use mutexes (#412) REFS: MON-15575 * fix(broker/bam): no need to read last_level in bam (#417) It is not stored in kpis, just computed on demand and stored in db. REFS: MON-15622 * update credentials (#432) * MON-15761 compiled are saved in bin, lib, tests directories (#431) * MON-15761 compiled are saved in bin, lib, tests directories * MON-15761 ci use new directories * MON-15761 import 22.04 ci files * MON-15761 import suite * MON-15761 connector install correction * MON-15761 use of WITH_PREFIX_LIB_CLIB and PREFIX_LIB * MON-15761 clib include location * MON-15761 engine * MON-15761 modules * MON-15761 cbd * MON-15761 no pc and no duplicate engine log file * MON-15761 no connector test REFS:MON-15761 * enh(ci): workflow+actions added to develop * fix(ci): docker builder improved * enh(ci): build scripts added * fix(ci): docker-builder is updated with password variable * fix(ci): docker-builder fixed * fix(ci): docker folder missing * fix(ci): password fixed * fix(ci): fail-fast set to false * fix(ci): artifactory path updated * fix(ci): registry and runners updated * enh(ci): packaging updated * fix(ci): username updated * fix(ci): Jenkinsfiles removed * feat(chore): update .gitignore and remove deprecated scripts (#437) * fix(ci): new build workflow * fix(ci): cmake.sh improved * enh(cmake): cmake called as in 22.04, and newer versions of collect * enh(cmake): cmake called as in 22.04, and newer versions of collect * fix(cmake): bad paths on tests * fix(cmake): the script could fail with devtool * fix(ci): actions copied from develop branch * fix(ci): collect tests script updated REFS: MON-15860 * fix(ci): debian build was broken * fix(ci): debian packaging had bad paths * fix(ci): poller-module.json is a bad name * fix(ci): bad path * fix(ci): bad path in rpm packaging * fix(ci): release simplified * fix(connector): unit tests may fail on centos7 * fix(delivery): add delivery to old yum repo (#458) * enh(ci): rebuild yum metadata only one time (#463) * fix(ci): fix workflow trigger on push dev-21.10.x (#464) * enh(packaging): add rpm sign to workflow 2110 (#470) * fix(packaging): fix cmake parameter for broker config path (#467) * chore(release):set version to 21.10.4 * chore(release): remove workflow file * chore(release):fix conflict * MON-16310 fix some robot issues * MON-16310 fix tests ESS3 ESS4 BEDB4 and BLDIS1 * enh(ci): Add rpm delivery cleanup and structure (#499) * MON-16310 help cmake to find protoc * fix(ci):correct docker registry link (#501) * fix(ci): fix FOLDER variable * enh(ci): remove buster from build and delivery (#471) * enh(ci): remove buster from build and delivery * remove buster dockerfile * Disable debian delivery on 21.10 collect Co-authored-by: denliA <91119589+denliA@users.noreply.github.com> Co-authored-by: David Boucher Co-authored-by: jean-christophe81 <98889244+jean-christophe81@users.noreply.github.com> Co-authored-by: Charles Gautier <33026375+chgautier@users.noreply.github.com> Co-authored-by: Stéphane Chapron <34628915+sc979@users.noreply.github.com> Co-authored-by: tuntoja <58987095+tuntoja@users.noreply.github.com> Co-authored-by: Kevin Duret Co-authored-by: chgautier Co-authored-by: Jean Christophe Roques Co-authored-by: tuntoja --- .github/ISSUE_TEMPLATE.md | 90 ++ .github/PULL_REQUEST_TEMPLATE.md | 36 + .github/actions/delivery/action.yml | 172 ++++ .github/actions/get-packages/action.yml | 84 ++ .github/actions/package-sign/action.yml | 36 + .github/actions/release/action.yml | 58 ++ .github/actions/runner-docker/action.yml | 27 + .github/actions/sync-branches/action.yml | 22 + .github/scripts/rpm-signing.sh | 5 + .github/workflows/centreon-collect.yml | 224 +++++ .github/workflows/docker-builder.yml | 77 ++ .github/workflows/rebase-master.yml | 28 + .github/workflows/rebase-version.yml | 28 + .github/workflows/release-collect.yml | 30 + .github/workflows/robot-nightly.yml | 81 ++ .gitignore | 132 ++- CHANGELOG.md | 9 +- CMakeLists.txt | 82 +- Jenkinsfile | 133 --- .../.github/workflows/centreon-collect.yml | 232 +++++ .../.github/workflows/centreon-gorgone.yml | 197 ++++ .../.github/workflows/dependabot_jira.yml | 79 -- .../.github/workflows/docker-builder.yml | 67 ++ .../.github/workflows/robot-nightly.yml | 44 + centreon-broker/.gitignore | 35 - centreon-broker/CMakeLists.txt | 894 +++++++++--------- centreon-broker/bam/CMakeLists.txt | 80 +- .../centreon/broker/bam/configuration/kpi.hh | 3 - centreon-broker/bam/src/configuration/kpi.cc | 44 +- .../bam/src/configuration/reader_v2.cc | 25 +- ...-module.json.in => central-module.json.in} | 0 .../centreon/broker/exceptions/deprecated.hh | 49 + .../inc/com/centreon/broker/stats/center.hh | 19 +- .../core/src/config/applier/endpoint.cc | 99 +- centreon-broker/core/src/config/parser.cc | 72 +- centreon-broker/core/src/log_v2.cc | 6 +- centreon-broker/core/src/stats/center.cc | 122 +-- centreon-broker/core/test/bbdo/output.cc | 16 +- centreon-broker/core/test/mysql/mysql.cc | 34 +- centreon-broker/core/test/rpc/brokerrpc.cc | 18 +- centreon-broker/graphite/CMakeLists.txt | 72 +- centreon-broker/influxdb/CMakeLists.txt | 76 +- centreon-broker/lua/CMakeLists.txt | 71 +- centreon-broker/lua/test/lua.cc | 28 +- centreon-broker/neb/CMakeLists.txt | 251 ++--- centreon-broker/rrd/CMakeLists.txt | 129 ++- centreon-broker/script/debian/cbd.init.d.in | 4 +- centreon-broker/script/other/cbd.init.d.in | 4 +- centreon-broker/script/redhat/cbd.init.d.in | 4 +- centreon-broker/script/systemd/cbd.service.in | 2 +- centreon-broker/simu/CMakeLists.txt | 84 +- centreon-broker/simu/test/simu.cc | 4 +- centreon-broker/sql/CMakeLists.txt | 53 +- centreon-broker/stats/CMakeLists.txt | 71 +- centreon-broker/stats/test/stats.cc | 10 +- centreon-broker/storage/CMakeLists.txt | 104 +- .../broker/storage/conflict_manager.hh | 4 + .../storage/src/conflict_manager.cc | 5 + .../storage/src/conflict_manager_sql.cc | 35 + .../storage/test/conflict_manager.cc | 2 +- centreon-broker/tcp/CMakeLists.txt | 98 +- centreon-broker/test/CMakeLists.txt | 100 +- centreon-broker/tls/CMakeLists.txt | 63 +- centreon-broker/watchdog/CMakeLists.txt | 75 +- centreon-clib/.gitignore | 8 - centreon-clib/CMakeLists.txt | 397 ++++---- centreon-clib/test/CMakeLists.txt | 105 +- centreon-clib/test/library.cc | 4 +- centreon-clib/test/process.cc | 34 +- centreon-connector/.gitignore | 7 - centreon-connector/CMakeLists.txt | 108 ++- centreon-connector/cmake/Findclib.cmake | 51 - centreon-connector/perl/.gitignore | 1 - centreon-connector/perl/CMakeLists.txt | 77 +- centreon-connector/perl/test/connector.cc | 5 +- centreon-connector/ssh/CMakeLists.txt | 88 +- centreon-engine/.gitignore | 26 - centreon-engine/CMakeLists.txt | 803 ++++++++-------- centreon-engine/enginerpc/CMakeLists.txt | 107 +-- centreon-engine/modules/bench/CMakeLists.txt | 57 +- .../modules/external_commands/CMakeLists.txt | 59 +- centreon-engine/src/simumod/CMakeLists.txt | 54 +- centreon-engine/test/commands/CMakeLists.txt | 61 +- centreon-engine/tests/CMakeLists.txt | 251 ++--- ci/Jenkinsfile | 42 - .../centreon-broker-cbmod.install | 2 + .../centreon-broker-cbmod.postinst | 12 + ci/debian-collect/centreon-broker-core.dirs | 1 + .../centreon-broker-core.install | 7 + ci/debian-collect/centreon-broker-dev.install | 1 + .../centreon-broker-graphite.install | 1 + .../centreon-broker-influxdb.install | 1 + .../centreon-broker-storage.install | 2 + ci/debian-collect/centreon-broker.dirs | 3 + ci/debian-collect/centreon-broker.install | 6 + ci/debian-collect/centreon-broker.logrotate | 10 + ci/debian-collect/centreon-broker.postinst | 21 + ci/debian-collect/centreon-broker.postrm | 7 + ci/debian-collect/centreon-clib-dev.install | 1 + ci/debian-collect/centreon-clib.install | 1 + .../centreon-connector-perl.install | 1 + .../centreon-connector-ssh.install | 1 + .../centreon-engine-bench.install | 2 + ci/debian-collect/centreon-engine-dev.install | 1 + .../centreon-engine-extcommands.dirs | 1 + .../centreon-engine-extcommands.install | 1 + ci/debian-collect/centreon-engine.dirs | 2 + ci/debian-collect/centreon-engine.install | 5 + ci/debian-collect/centreon-engine.logrotate | 25 + ci/debian-collect/centreon-engine.postinst | 38 + ci/debian-collect/centreon-engine.postrm | 14 + ci/debian-collect/control | 171 ++++ ci/debian-collect/copyright | 29 + .../extra/centreon-broker/cbd.service | 34 + .../extra/centreon-engine/centengine.service | 33 + ci/debian-collect/rules | 31 + ci/debian-collect/source/format | 1 + ci/debian-collect/source/include-binaries | 7 + ci/debian-collect/source/local-options | 2 + ci/debian-collect/substvars | 1 + ci/debian-gorgone/centreon-gorgone.dirs | 6 + ci/debian-gorgone/centreon-gorgone.install | 12 + ci/debian-gorgone/centreon-gorgone.logrotate | 10 + ci/debian-gorgone/centreon-gorgone.postinst | 67 ++ ci/debian-gorgone/control | 59 ++ ci/debian-gorgone/copyright | 29 + ci/debian-gorgone/extra/gorgoned | 6 + ci/debian-gorgone/extra/gorgoned.service | 33 + ci/debian-gorgone/rules | 11 + ci/debian-gorgone/source/format | 1 + ci/debian-gorgone/substvars | 1 + ...-dependencies => Dockerfile.collect-alma8} | 7 +- ...ependencies => Dockerfile.collect-centos7} | 11 +- ci/docker/Dockerfile.collect-debian-bullseye | 38 + .../Dockerfile.collect-debian-dependencies | 34 - ci/docker/Dockerfile.gorgone-alma8 | 21 + ci/docker/Dockerfile.gorgone-centos7 | 23 + ci/docker/Dockerfile.gorgone-debian-bullseye | 30 + ci/release/Jenkinsfile | 21 - ci/release/collect-release.sh | 9 +- ci/scripts/collect-deb-package.sh | 32 + ci/scripts/collect-release.sh | 25 - ci/scripts/collect-rpm-delivery.sh | 20 +- ci/scripts/collect-rpm-package.sh | 70 +- ci/scripts/collect-sonar-scanner-common.sh | 82 -- ci/scripts/collect-sources-analysis.sh | 59 -- ci/scripts/collect-test-robot.sh | 42 +- ci/scripts/collect-unit-tests.sh | 26 +- ci/scripts/gorgone-deb-package.sh | 69 ++ ci/scripts/gorgone-rpm-package.sh | 27 + cmake.sh | 80 +- conanfile.txt | 29 +- packaging/rpm/centreon-collect.spec | 473 +++++++++ ...gine_integrate_centreon_engine2centreon.sh | 130 +++ packaging/script/rpmbuild.sh | 41 + resources/centreon.sql | 5 +- tests/Jenkinsfile | 25 - tests/broker-engine/hostgroups.robot | 56 ++ .../hosts-with-notes-and-actions.robot | 3 - tests/broker-engine/scheduler.robot | 45 - tests/broker-engine/services-increased.robot | 48 - .../services-with-notes-and-actions.robot | 3 - tests/broker/sql.robot | 26 - tests/engine/start-stop.robot | 3 + tests/init-sql.sh | 21 +- tests/resources/Broker.py | 8 +- tests/resources/Engine.py | 554 +++++------ tests/resources/db_variables.robot | 15 +- 168 files changed, 6221 insertions(+), 3884 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/actions/delivery/action.yml create mode 100644 .github/actions/get-packages/action.yml create mode 100644 .github/actions/package-sign/action.yml create mode 100644 .github/actions/release/action.yml create mode 100644 .github/actions/runner-docker/action.yml create mode 100644 .github/actions/sync-branches/action.yml create mode 100755 .github/scripts/rpm-signing.sh create mode 100644 .github/workflows/centreon-collect.yml create mode 100644 .github/workflows/docker-builder.yml create mode 100644 .github/workflows/rebase-master.yml create mode 100644 .github/workflows/rebase-version.yml create mode 100644 .github/workflows/release-collect.yml create mode 100644 .github/workflows/robot-nightly.yml delete mode 100644 Jenkinsfile create mode 100644 centreon-broker/.github/workflows/centreon-collect.yml create mode 100644 centreon-broker/.github/workflows/centreon-gorgone.yml create mode 100644 centreon-broker/.github/workflows/docker-builder.yml create mode 100644 centreon-broker/.github/workflows/robot-nightly.yml rename centreon-broker/config/{poller-module.json.in => central-module.json.in} (100%) create mode 100644 centreon-broker/core/inc/com/centreon/broker/exceptions/deprecated.hh delete mode 100644 centreon-connector/cmake/Findclib.cmake delete mode 100644 ci/Jenkinsfile create mode 100644 ci/debian-collect/centreon-broker-cbmod.install create mode 100644 ci/debian-collect/centreon-broker-cbmod.postinst create mode 100644 ci/debian-collect/centreon-broker-core.dirs create mode 100644 ci/debian-collect/centreon-broker-core.install create mode 100644 ci/debian-collect/centreon-broker-dev.install create mode 100644 ci/debian-collect/centreon-broker-graphite.install create mode 100644 ci/debian-collect/centreon-broker-influxdb.install create mode 100644 ci/debian-collect/centreon-broker-storage.install create mode 100644 ci/debian-collect/centreon-broker.dirs create mode 100644 ci/debian-collect/centreon-broker.install create mode 100644 ci/debian-collect/centreon-broker.logrotate create mode 100644 ci/debian-collect/centreon-broker.postinst create mode 100644 ci/debian-collect/centreon-broker.postrm create mode 100644 ci/debian-collect/centreon-clib-dev.install create mode 100644 ci/debian-collect/centreon-clib.install create mode 100644 ci/debian-collect/centreon-connector-perl.install create mode 100644 ci/debian-collect/centreon-connector-ssh.install create mode 100644 ci/debian-collect/centreon-engine-bench.install create mode 100644 ci/debian-collect/centreon-engine-dev.install create mode 100644 ci/debian-collect/centreon-engine-extcommands.dirs create mode 100644 ci/debian-collect/centreon-engine-extcommands.install create mode 100644 ci/debian-collect/centreon-engine.dirs create mode 100644 ci/debian-collect/centreon-engine.install create mode 100644 ci/debian-collect/centreon-engine.logrotate create mode 100644 ci/debian-collect/centreon-engine.postinst create mode 100644 ci/debian-collect/centreon-engine.postrm create mode 100644 ci/debian-collect/control create mode 100644 ci/debian-collect/copyright create mode 100644 ci/debian-collect/extra/centreon-broker/cbd.service create mode 100644 ci/debian-collect/extra/centreon-engine/centengine.service create mode 100644 ci/debian-collect/rules create mode 100644 ci/debian-collect/source/format create mode 100644 ci/debian-collect/source/include-binaries create mode 100644 ci/debian-collect/source/local-options create mode 100644 ci/debian-collect/substvars create mode 100644 ci/debian-gorgone/centreon-gorgone.dirs create mode 100644 ci/debian-gorgone/centreon-gorgone.install create mode 100644 ci/debian-gorgone/centreon-gorgone.logrotate create mode 100644 ci/debian-gorgone/centreon-gorgone.postinst create mode 100644 ci/debian-gorgone/control create mode 100644 ci/debian-gorgone/copyright create mode 100644 ci/debian-gorgone/extra/gorgoned create mode 100644 ci/debian-gorgone/extra/gorgoned.service create mode 100644 ci/debian-gorgone/rules create mode 100644 ci/debian-gorgone/source/format create mode 100644 ci/debian-gorgone/substvars rename ci/docker/{Dockerfile.collect-alma8-dependencies => Dockerfile.collect-alma8} (89%) rename ci/docker/{Dockerfile.collect-centos7-dependencies => Dockerfile.collect-centos7} (95%) create mode 100644 ci/docker/Dockerfile.collect-debian-bullseye delete mode 100644 ci/docker/Dockerfile.collect-debian-dependencies create mode 100644 ci/docker/Dockerfile.gorgone-alma8 create mode 100644 ci/docker/Dockerfile.gorgone-centos7 create mode 100644 ci/docker/Dockerfile.gorgone-debian-bullseye delete mode 100644 ci/release/Jenkinsfile create mode 100755 ci/scripts/collect-deb-package.sh delete mode 100755 ci/scripts/collect-release.sh delete mode 100755 ci/scripts/collect-sonar-scanner-common.sh delete mode 100755 ci/scripts/collect-sources-analysis.sh create mode 100755 ci/scripts/gorgone-deb-package.sh create mode 100755 ci/scripts/gorgone-rpm-package.sh create mode 100644 packaging/rpm/centreon-collect.spec create mode 100755 packaging/rpm/centreonengine_integrate_centreon_engine2centreon.sh create mode 100755 packaging/script/rpmbuild.sh delete mode 100644 tests/Jenkinsfile delete mode 100644 tests/broker-engine/scheduler.robot delete mode 100644 tests/broker-engine/services-increased.robot diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000000..c70f74df233 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,90 @@ + + +# BUG REPORT INFORMATION + +### Prerequisites + +> The opened issue, must be code related. GitHub is not meant for support. Feel free to check the CONTRIBUTING section for more details. + +***Versions*** + +For the RPM based systems + +-- Copy/Paste the result of the following command -- +``` +$ rpm -qa | grep centreon +``` + +***Operating System*** + +*CentOS, Debian ...* + +***How the the component has been installed and versions*** + +- [ ] *From sources, from packages* +- [ ] *components versions* + +Version: -- + +***Additional environment details (AWS, VirtualBox, physical, etc.):*** + +### Description + +-- Describe the encountered issue -- + +### Steps to Reproduce + +Please describe precisely the steps to reproduce the encountered issue. + +1. I logged in Centreon +2. I reached the Custom View +3. And so on... + +### Describe the received result + +### Describe the expected result + +### Logs + +**PHP error logs** + +``` +tail -f /var/opt/rh/rh-php72/log/php-fpm/centreon-error.log +``` +**centreon-engine logs (*if needed*)** + +``` +tail -f /var/log/centreon-engine/centengine.log +``` +**centreon-broker logs (*if needed*)** + +``` +tail -f /var/log/centreon-broker/central-broker-master.log +``` +**centcore logs (*if needed*)** + +``` +tail -f /var/log/centreon/centcore.log +``` + +### Additional relevant information (e.g. frequency, ...) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000000..a2a84022cac --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,36 @@ +## Description + +Please include a short resume of the changes and what is the purpose of PR. Any relevant information should be added to help: +* **QA Team** (Quality Assurance) with tests. +* **reviewers** to understand what are the stakes of the pull request. + +**Fixes** # (issue) + +## Type of change + +- [ ] Patch fixing an issue (non-breaking change) +- [ ] New functionality (non-breaking change) +- [ ] Breaking change (patch or feature) that might cause side effects breaking part of the Software +- [ ] Updating documentation (missing information, typo...) + +## Target serie + +- [ ] 21.10.x +- [ ] 22.04.x +- [ ] 22.10.x +- [ ] 23.04.x (master) + +

How this pull request can be tested ?

+ +Please describe the **procedure** to verify that the goal of the PR is matched. Provide clear instructions so that it can be **correctly tested**. + +Any **relevant details** of the configuration to perform the test should be added. + +## Checklist + +- [ ] I have followed the **coding style guidelines** provided by Centreon +- [ ] I have commented my code, especially new **classes**, **functions** or any **legacy code** modified. (***docblock***) +- [ ] I have commented my code, especially **hard-to-understand areas** of the PR. +- [ ] I have made corresponding changes to the **documentation**. +- [ ] I have **rebased** my development branch on the base branch (master, maintenance). + diff --git a/.github/actions/delivery/action.yml b/.github/actions/delivery/action.yml new file mode 100644 index 00000000000..9f0a076f14b --- /dev/null +++ b/.github/actions/delivery/action.yml @@ -0,0 +1,172 @@ +name: "delivery" +description: "RPM and DEB packages delivery Centreon" +inputs: + module_name: + description: "The name of the module" + required: true + distrib: + description: "The distribution used for packaging" + required: true + repos_username: + description: "Artifact Manager technical username" + required: true + repos_password: + description: "Artifact Manager technical password" + required: true + version: + description: "Centreon packaged version" + required: true + minor_version: + description: "Centreon packaged version" + required: true + release: + description: The release number + required: true + cache_key: + description: "The cached package key" + required: true + update_repo_path: + description: "The update repo script path" + required: true + cloudfront_id: + description: "The cloudfront ID for repo url" + required: true + yum_repo_address: + description: "The yum legacy repo address" + required: true + yum_repo_key: + description: "The yum repo key" + required: true + yum_repo_url: + description: "The legacy yum repo url" + required: true + +runs: + using: "composite" + steps: + - name: Build name for RPM + shell: bash + if: ${{ inputs.distrib == 'el7' || inputs.distrib == 'el8' }} + run: | + echo "build=rpmbuild-centreon-collect" >> $GITHUB_ENV + echo "extfile=rpm" >> $GITHUB_ENV + + - name: Build name for DEB + shell: bash + if: ${{ inputs.distrib == 'bullseye' }} + run: | + echo "build=debbuild-centreon-collect" >> $GITHUB_ENV + echo "extfile=deb" >> $GITHUB_ENV + + - name: Use cache files + uses: actions/cache@v3 + with: + path: ./*.${{ env.extfile }} + key: ${{ inputs.cache_key }}-${{ env.build }}-${{ inputs.distrib }} + restore-keys: ${{ inputs.cache_key }}-${{ env.build }}-${{ inputs.distrib }} + + - name: Setup awscli + run: | + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" + sudo unzip -q awscliv2.zip + sudo ./aws/install + shell: bash + + - name: Publish packages + run: | + if [[ -z "$GITHUB_HEAD_REF" ]]; + then + BRANCHNAME="$GITHUB_REF_NAME" + else + BRANCHNAME="$GITHUB_HEAD_REF" + fi + echo "[DEBUG] - Branch name: $BRANCHNAME" + case "$BRANCHNAME" in + develop | dev-[2-9][0-9].[0-9][0-9].x) + SUBREPO="unstable" + ;; + release* | hotfix*) + SUBREPO="testing" + ;; + master | [2-9][0-9].[0-9][0-9].x) + SUBREPO="stable" + ;; + *) + echo -n "[INFO] NO DELIVERY FOR THIS BRANCH" + exit 0 + ;; + esac + + if [[ "${{ env.extfile }}" == "rpm" ]] ; then + eval `ssh-agent` + ssh-add - <<< "${{ inputs.yum_repo_key }}" + fi + + FILES="*.${{ env.extfile }}" + + for FILE in $FILES + do + echo "[DEBUG] - File: $FILE" + VERSION=${{ inputs.version }} + MAJOR="$VERSION" + MINOR=${{ inputs.minor_version }} + RELEASE=${{ inputs.release }} + REPOTYPE="$SUBREPO" + PROJECT=${{ inputs.module_name }} + PROJECT_PATH="standard" + + echo "[DEBUG] - Suprepo: $SUBREPO" + echo "[DEBUG] - Version: $VERSION" + if [[ "${{ env.extfile }}" == "deb" ]] ; then + echo "No delivery to debian in 21.10" + #curl -u "${{ inputs.repo_username }}":"${{ inputs.repo_password }}" -H "Content-Type: multipart/form-data" --data-binary "@./$FILE" https://apt.centreon.com/repository/23.04-$SUBREPO/ + else + DISTRIB="${{ inputs.distrib }}" + ARCH=$(echo $FILE | grep -oP '(x86_64|noarch)') + + echo "[DEBUG] - DISTRIB: $DISTRIB" + echo "[DEBUG] - Arch: $ARCH" + + if [[ "$SUBREPO" == "stable" ]] ; then + TARGET="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH/RPMS" + else + FOLDER="$PROJECT-$MAJOR.$MINOR-$RELEASE" + TARGET="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH/$PROJECT/$FOLDER" + PROJECT_LOCATION="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH/$PROJECT" + fi + + echo "[DEBUG] - Folder: $FOLDER" + echo "[DEBUG] - Project : $PROJECT" + echo "[DEBUG] - Target : $TARGET" + echo "[DEBUG] - PROJECT_LOCATION : $PROJECT_LOCATION" + + ssh -o StrictHostKeyChecking=no "${{ inputs.yum_repo_address }}" mkdir -p "$TARGET" 2>&- + scp -o StrictHostKeyChecking=no "$FILE" "${{ inputs.yum_repo_address }}:$TARGET" 2>&- + fi + done + + # run this only for rpm + if [[ "${{ env.extfile }}" == "rpm" ]] ; then + # Cleanup is done on unstable repository only + if [[ "$SUBREPO" == "unstable" ]] ; then + ssh -o StrictHostKeyChecking=no "${{ inputs.yum_repo_address }}" "ls -drc $PROJECT_LOCATION/* 2>&- | head -n -1 | xargs rm -rf" + fi + + # Update repository metadata + METADATAS="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH" + ssh -o StrictHostKeyChecking=no "${{ inputs.yum_repo_address }}" "sh "${{ inputs.update_repo_path }}" $METADATAS" 2>&- + + # Invalidate cloudfront cache + ID="${{ inputs.cloudfront_id }}" + PATHS="/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH/*" + ITERATIONS=1 + until aws cloudfront create-invalidation --distribution-id "$ID" --paths "$PATHS"; do + if [ ${ITERATIONS} -eq 10 ]; then + return 0 + fi + echo "couldn't invalidate cache, AWS quota might have been reached, retrying in 30 seconds..." + sleep 30s + ITERATIONS=$((ITERATIONS+1)) + done + fi + shell: bash diff --git a/.github/actions/get-packages/action.yml b/.github/actions/get-packages/action.yml new file mode 100644 index 00000000000..786c41a42a0 --- /dev/null +++ b/.github/actions/get-packages/action.yml @@ -0,0 +1,84 @@ +name: "get-packages" +description: "Get RPM Centreon packages from the repository" +inputs: + distrib: + description: "The distribution used for packaging" + required: true + repos_username: + description: "Artifact Manager technical username" + required: true + repos_password: + description: "Artifact Manager technical password" + required: true + version: + description: "Centreon packaged version" + required: true + patch: + description: "Centreon packaged version patch" + required: true + release: + description: "Centreon packaged release" + required: true + cache_key: + description: "The cached package key" + required: true + +runs: + using: "composite" + steps: + - name: Build name for RPM + shell: bash + if: ${{ inputs.distrib == 'el7' || inputs.distrib == 'el8' }} + run: | + echo "build=rpmbuild-centreon-collect" >> $GITHUB_ENV + echo "extfile=rpm" >> $GITHUB_ENV + + - name: Build name for DEB + shell: bash + if: ${{ inputs.distrib == 'bullseye' }} + run: | + echo "build=debbuild-centreon-collect" >> $GITHUB_ENV + echo "extfile=deb" >> $GITHUB_ENV + + - name: Get packages + run: | + if [[ -z "$GITHUB_HEAD_REF" ]]; + then + BRANCHNAME="$GITHUB_REF_NAME" + else + BRANCHNAME="$GITHUB_HEAD_REF" + fi + echo "[DEBUG] - Branch name: $BRANCHNAME" + case "$BRANCHNAME" in + develop | dev-[2-9][0-9].[0-9][0-9].x) + REPO="unstable" + ;; + release* | hotfix*) + REPO="testing" + ;; + master | [2-9][0-9].[0-9][0-9].x) + REPO="stable" + ;; + *) + echo -n "[INFO] NO DELIVERY FOR THIS BRANCH" + exit 0 + ;; + esac + FILES="centreon-broker centreon-broker-cbd centreon-broker-cbmod centreon-broker-core centreon-broker-storage centreon-clib centreon-collect centreon-collect-client centreon-connector centreon-connector-perl centreon-connector-ssh centreon-engine centreon-engine-daemon centreon-engine-extcommands" + FULL_VERSION="${{ inputs.version }}.${{ inputs.patch }}" + #RELEASE="1668587986.332470bb4948f05263630f26f7b507c9e388ed98" + RELEASE="${{ inputs.release }}" + + for FILE in $FILES ; do + if [[ "${{ env.extfile }}" == "deb" ]] ; then + echo "[DEBUG] - https://artifactory.apps.centreon.com/artifactory/debian-$VERSION-$REPO/pool/$FILE;deb.distribution=bullseye;deb.component=main;deb.architecture=amd64" + curl -v -u "${{ inputs.repos_username }}":"${{ inputs.repos_password }}" -X PUT "https://artifactory.apps.centreon.com/artifactory/debian-$VERSION-$REPO/pool/$FILE;deb.distribution=bullseye;deb.component=main;deb.architecture=amd64" -T "./$FILE" + else + echo "[DEBUG] - https://artifactory.apps.centreon.com/artifactory/rpm-${{ inputs.version }}-$REPO/${{ inputs.distrib }}/$REPO/x86_64/centreon-collect/$FILE-$FULL_VERSION-$RELEASE.${{ inputs.distrib }}.x86_64.rpm" + curl -v -u "${{ inputs.repos_username }}":"${{ inputs.repos_password }}" -O "https://artifactory.apps.centreon.com/artifactory/rpm-${{ inputs.version }}-$REPO/${{ inputs.distrib }}/$REPO/x86_64/centreon-collect/$FILE-$FULL_VERSION-$RELEASE.${{ inputs.distrib }}.x86_64.rpm" + fi + done + + ls -l *.rpm + for i in *.rpm ; do file $i ; done + shell: bash diff --git a/.github/actions/package-sign/action.yml b/.github/actions/package-sign/action.yml new file mode 100644 index 00000000000..3d197b0edd2 --- /dev/null +++ b/.github/actions/package-sign/action.yml @@ -0,0 +1,36 @@ +name: rpm-sign-in-docker +description: Run step in docker container +inputs: + script_name: + description: "script_name" + required: true + image_name: + description: "image_name" + required: true + image_version: + description: "image_version" + required: true + centreon_pat: + description: "Secret" + required: false + username: + description: The artifactory username + required: true + password: + description: The artifactory password + required: true + params: + description: "params for script" + required: false +runs: + using: "composite" + steps: + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: docker.centreon.com + username: ${{ inputs.username }} + password: ${{ inputs.password }} + + - run: docker run -i -e TOKEN=${{ inputs.centreon_pat }} --entrypoint /src/.github/scripts/${{ inputs.script_name }}.sh -v "$PWD:/src" docker.centreon.com/${{ inputs.image_name }}:${{ inputs.image_version}} ${{ inputs.params }} + shell: bash \ No newline at end of file diff --git a/.github/actions/release/action.yml b/.github/actions/release/action.yml new file mode 100644 index 00000000000..63c941c2ad6 --- /dev/null +++ b/.github/actions/release/action.yml @@ -0,0 +1,58 @@ +name: "tag version" +description: "Tag package" +inputs: + jira_token: + description: "Token to authenticate to Jira" + required: true +runs: + using: "composite" + steps: + - name: Publish RPMS to Repositories + run: | + NEW_VERSION="" + MAJOR_VERSION=$(echo $GITHUB_REF_NAME | grep -oP '([0-9]{2}\.[0-9]{2})') + echo "Major version: $MAJOR_VERSION" + HOTFIX=$(echo $GITHUB_REF_NAME | grep -oP '(hotfix|)') + echo "Hotfix: $HOTFIX" + BETA=$(echo $GITHUB_REF_NAME | grep -oP '(beta|)') + echo "Beta: $BETA" + RELEASE_ID=$(git log -1 --pretty=%B | grep -oP '(#[0-9]{4,}#)' | grep -oP '([0-9]+)') + echo "Release Id: $RELEASE_ID" + + OLDV=$(git tag --sort=-v:refname --list "centreon-collect-$MAJOR_VERSION.*" | head -n 1) + echo "Old version: $OLDV" + + git config --global user.email "release@centreon.com" + git config --global user.name "Centreon" + + if [ -z "$OLDV" ]; then + echo "No existing version, starting at $MAJOR_VERSION.0" + NEW_VERSION="$MAJOR_VERSION.0" + git tag -a "centreon-collect-$NEW_VERSION" -m "version $NEW_VERSION" + git push --follow-tags + else + OLD_MINOR_VERSION=$(echo $OLDV | grep -oP '([0-9]+$)') + NEW_MINOR_VERSION=$(echo $((OLD_MINOR_VERSION + 1))) + NEW_VERSION=$MAJOR_VERSION.$NEW_MINOR_VERSION + git tag -a "centreon-collect-$NEW_VERSION" -m "version $NEW_VERSION" + git push --follow-tags + fi + + if [ "$HOTFIX" == "hotfix" ]; then + TYPE=Hotfix + elif [ "$BETA" == "beta" ]; then + TYPE=Beta + else + TYPE=Release + fi + + VERSION_DATA="{\"archived\":false,\"releaseDate\":\"$(date +%Y-%m-%d)\",\"name\":\"centreon-collect-$NEW_VERSION\",\"description\":\"$TYPE:$RELEASE_ID\",\"projectId\":11789,\"released\":false}" + + curl --request POST \ + --url 'https://centreon.atlassian.net/rest/api/3/version' \ + --header 'Authorization: Basic ${{ inputs.jira_token }}' \ + --header 'Accept: application/json' \ + --header 'Content-Type: application/json' \ + --data ''$VERSION_DATA'' + + shell: bash diff --git a/.github/actions/runner-docker/action.yml b/.github/actions/runner-docker/action.yml new file mode 100644 index 00000000000..90d8e50249d --- /dev/null +++ b/.github/actions/runner-docker/action.yml @@ -0,0 +1,27 @@ +name: "runner docker Centreon" +description: "runner docker Centreon" +inputs: + script_name: + description: "script name" + required: true + image_name: + description: "image name" + required: true + image_version: + description: "image version" + required: true + env_variable: + description: "environnment variable" + required: false + params: + description: "params for script" + required: false + +env: + REGISTRY: docker.centreon.com + +runs: + using: "composite" + steps: + - run: docker run -i --entrypoint ${{ inputs.script_name }}.sh -v "$PWD:/src" ${{ inputs.env_variable }} ${{ env.REGISTRY }}/${{ inputs.image_name }}:${{ inputs.image_version}} ${{ inputs.params }} + shell: bash diff --git a/.github/actions/sync-branches/action.yml b/.github/actions/sync-branches/action.yml new file mode 100644 index 00000000000..ebc8c6044fd --- /dev/null +++ b/.github/actions/sync-branches/action.yml @@ -0,0 +1,22 @@ +name: "Sync Branches" +description: "Sync dev branch with develop" +inputs: + src_branch: + description: "The source branch" + required: true + dest_branch: + description: "The destination branch" + required: true + +runs: + using: "composite" + steps: + - name: Rebase branches + id: rebase + run: | + git config --global user.email "release@centreon.com" + git config --global user.name "Centreon" + git checkout ${{ inputs.dest_branch }} + git rebase ${{ inputs.src_branch }} + git push origin ${{ inputs.dest_branch }} + shell: bash diff --git a/.github/scripts/rpm-signing.sh b/.github/scripts/rpm-signing.sh new file mode 100755 index 00000000000..2f42905b059 --- /dev/null +++ b/.github/scripts/rpm-signing.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -ex +export GPG_TTY=$(tty) +rpmsign --addsign /src/*.rpm \ No newline at end of file diff --git a/.github/workflows/centreon-collect.yml b/.github/workflows/centreon-collect.yml new file mode 100644 index 00000000000..00937458021 --- /dev/null +++ b/.github/workflows/centreon-collect.yml @@ -0,0 +1,224 @@ +name: Centreon collect + +on: + workflow_dispatch: + pull_request: + push: + branches: + - dev-21.10.x + +env: + REGISTRY: docker.centreon.com + +jobs: + create-version: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - id: version + run: | + IMG_VERSION=$(md5sum conanfile.txt | awk '{print substr($1, 0, 8)}') + echo "imgversion=$IMG_VERSION" >> $GITHUB_OUTPUT + VERSION=$(awk '$1 ~ "COLLECT_MAJOR" {maj=substr($2, 1, length($2)-1)} $1 ~ "COLLECT_MINOR" {min=substr($2, 1, length($2)-1) ; print maj "." min}' CMakeLists.txt) + PATCH=$(awk '$1 ~ "COLLECT_PATCH" {print substr($2, 1, length($2) - 1)}' CMakeLists.txt) + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "patch=$PATCH" >> $GITHUB_OUTPUT + + if [[ -z "$GITHUB_HEAD_REF" ]] ; then + BRANCHNAME="$GITHUB_REF_NAME" + else + BRANCHNAME="$GITHUB_HEAD_REF" + fi + case "$BRANCHNAME" in + master | [2-9][0-9].[0-9][0-9].x | release* | hotfix*) + echo "release=$GITHUB_RUN_ATTEMPT" >> $GITHUB_OUTPUT + ;; + *) + echo "release=`date +%s`.`echo ${{ github.sha }} | cut -c -7`" >> $GITHUB_OUTPUT + ;; + esac + shell: bash + - run: | + echo "ImgVersion is ${{ steps.version.outputs.imgversion }}" + echo "Version is ${{ steps.version.outputs.version }}.${{ steps.version.outputs.patch }}" + echo "Release is ${{ steps.version.outputs.release }}" + outputs: + imgversion: ${{ steps.version.outputs.imgversion }} + version: ${{ steps.version.outputs.version }} + patch: ${{ steps.version.outputs.patch }} + release: ${{ steps.version.outputs.release }} + + centreon-collect-test: + needs: create-version + runs-on: [self-hosted, collect] + env: + imgversion: ${{ needs.create-version.outputs.imgversion }} + version: ${{ needs.create-version.outputs.version }}.${{ needs.create-version.outputs.patch }} + release: ${{ needs.create-version.outputs.release }} + + strategy: + matrix: + include: + - image: centos7 + - image: alma8 + - image: debian-bullseye + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REPOS_USERNAME }} + password: ${{ secrets.REPOS_PASSWORD }} + - name: Test ${{ matrix.image }} + uses: ./.github/actions/runner-docker + with: + script_name: /src/ci/scripts/collect-unit-tests + image_name: centreon-collect-${{ matrix.image }} + image_version: ${{ env.imgversion }} + + rpm-packaging: + needs: create-version + runs-on: [self-hosted, collect] + env: + version: ${{ needs.create-version.outputs.version }}.${{ needs.create-version.outputs.patch }} + imgversion: ${{ needs.create-version.outputs.imgversion }} + release: ${{ needs.create-version.outputs.release }} + + strategy: + matrix: + include: + - image: centos7 + distrib: el7 + - image: alma8 + distrib: el8 + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REPOS_USERNAME }} + password: ${{ secrets.REPOS_PASSWORD }} + + - name: make rpm ${{ matrix.image }} + uses: ./.github/actions/runner-docker + with: + script_name: /src/ci/scripts/collect-rpm-package + image_name: centreon-collect-${{ matrix.image }} + image_version: ${{ env.imgversion }} + env_variable: -e DISTRIB="${{ matrix.distrib }}" -e VERSION="${{ env.version }}" -e RELEASE="${{ env.release }}" + + - name: sign rpm ${{ matrix.image }} + uses: ./.github/actions/package-sign + with: + script_name: rpm-signing + image_name: rpm-signing + image_version: ubuntu + username: ${{ secrets.REPOS_USERNAME }} + password: ${{ secrets.REPOS_PASSWORD }} + + - name: Use cache RPM files + uses: actions/cache@v3 + env: + cache-name-rpmbuild: cache-${{ github.sha }}-${{ github.run_id }}-rpmbuild-centreon-collect-${{ matrix.distrib }} + with: + path: ./*.rpm + key: ${{ env.cache-name-rpmbuild }} + + debian-packaging: + needs: create-version + runs-on: [self-hosted, collect] + env: + imgversion: ${{ needs.create-version.outputs.imgversion }} + version: ${{ needs.create-version.outputs.version }}.${{ needs.create-version.outputs.patch }} + release: ${{ needs.create-version.outputs.release }} + + strategy: + matrix: + include: + - image: debian-bullseye + distrib: bullseye + steps: + - name: Checkout sources + uses: actions/checkout@v3 + with: + path: centreon-collect + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REPOS_USERNAME }} + password: ${{ secrets.REPOS_PASSWORD }} + + - name: debmake ${{ matrix.image }} + uses: ./centreon-collect/.github/actions/runner-docker + with: + script_name: /src/centreon-collect/ci/scripts/collect-deb-package + image_name: centreon-collect-${{ matrix.image }} + image_version: ${{ env.imgversion }} + env_variable: -e DISTRIB="${{ matrix.distrib }}" -e VERSION="${{ env.version }}" -e RELEASE="${{ env.release }}" + + - name: Use cache DEB files + uses: actions/cache@v3 + env: + cache-name-debbuild: cache-${{ github.sha }}-${{ github.run_id }}-debbuild-centreon-collect-${{ matrix.distrib }} + with: + path: ./*.deb + key: ${{ env.cache-name-debbuild }} + + delivery-debian: + needs: [debian-packaging, create-version] + env: + version: ${{ needs.create-version.outputs.version }} + runs-on: [self-hosted, common] + name: Delivery + strategy: + matrix: + distrib: [bullseye] + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Publish DEB packages + uses: ./.github/actions/delivery + with: + distrib: ${{ matrix.distrib }} + version: ${{ env.version }} + repos_username: ${{ secrets.REPOS_USERNAME }} + repos_password: ${{ secrets.REPOS_PASSWORD }} + cache_key: cache-${{ github.sha }}-${{ github.run_id }} + + delivery-centos: + needs: [rpm-packaging, create-version] + env: + version: ${{ needs.create-version.outputs.version }} + runs-on: [self-hosted, common] + name: Delivery + strategy: + matrix: + distrib: [el7, el8] + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Publish RPM packages + uses: ./.github/actions/delivery + with: + distrib: ${{ matrix.distrib }} + version: ${{ env.version }} + minor_version: ${{ needs.create-version.outputs.patch }} + release: ${{ needs.create-version.outputs.release }} + module_name: centreon-collect + repos_username: ${{ secrets.REPOS_USERNAME }} + repos_password: ${{ secrets.REPOS_PASSWORD }} + cache_key: cache-${{ github.sha }}-${{ github.run_id }} + update_repo_path: ${{ secrets.UPDATE_REPO_PATH }} + cloudfront_id: ${{ secrets.CLOUDFRONT_ID }} + yum_repo_address: ${{ secrets.YUM_REPO_ADDRESS }} + yum_repo_key: ${{ secrets.YUM_REPO_KEY }} + yum_repo_url: ${{ secrets.YUM_REPO_URL }} diff --git a/.github/workflows/docker-builder.yml b/.github/workflows/docker-builder.yml new file mode 100644 index 00000000000..41b25b093d0 --- /dev/null +++ b/.github/workflows/docker-builder.yml @@ -0,0 +1,77 @@ +name: Centreon collect build docker + +on: + pull_request_target: + types: + - closed + branches: + - develop + paths: + - '.github/workflows/docker-builder.yml' + - 'ci/docker/**' + workflow_dispatch: + pull_request: + paths: + - '.github/workflows/docker-builder.yml' + - 'ci/docker/**' + +env: + REGISTRY: docker.centreon.com + +jobs: + create-version: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - run: | + IMG_VERSION=$(md5sum conanfile.txt | awk '{print substr($1, 0, 8)}') + echo "imgversion=$IMG_VERSION" >> $GITHUB_OUTPUT + id: imgversion + - run: | + echo "Version based on conanfile is ${{ steps.imgversion.outputs.imgversion }}" + outputs: + imgversion: ${{ steps.imgversion.outputs.imgversion }} + + + create-and-push-docker: + needs: create-version + runs-on: [self-hosted, collect] + continue-on-error: false + env: + imgversion: ${{ needs.create-version.outputs.imgversion }} + + strategy: + fail-fast: false + matrix: + include: + - project: collect + distrib: centos7 + - project: collect + distrib: alma8 + - project: collect + distrib: debian-bullseye + - project: gorgone + distrib: centos7 + - project: gorgone + distrib: alma8 + - project: gorgone + distrib: debian-bullseye + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REPOS_USERNAME }} + password: ${{ secrets.REPOS_PASSWORD }} + + - name: build docker ${{ matrix.distrib }} + run: docker build --no-cache . -f ci/docker/Dockerfile.${{ matrix.project }}-${{ matrix.distrib }} -t $REGISTRY/centreon-${{ matrix.project }}-${{ matrix.distrib }}:${{ env.imgversion }} + + - name: push docker ${{ matrix.distrib }} + run: docker push $REGISTRY/centreon-${{ matrix.project }}-${{ matrix.distrib }}:${{ env.imgversion }} + diff --git a/.github/workflows/rebase-master.yml b/.github/workflows/rebase-master.yml new file mode 100644 index 00000000000..2e8a9d4e363 --- /dev/null +++ b/.github/workflows/rebase-master.yml @@ -0,0 +1,28 @@ +--- +name: Sync Back to Develop + +on: + pull_request_target: + types: + - closed + branches: + - "master" + workflow_dispatch: + +jobs: + main: + name: Create PR Release to Main + runs-on: [self-hosted, common] + if: github.event.pull_request.merged == true + steps: + - name: git checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Sync Branches + id: release + uses: ./.github/actions/sync-branches + with: + src_branch: master + dest_branch: develop diff --git a/.github/workflows/rebase-version.yml b/.github/workflows/rebase-version.yml new file mode 100644 index 00000000000..6265cdb3ef7 --- /dev/null +++ b/.github/workflows/rebase-version.yml @@ -0,0 +1,28 @@ +--- +name: Sync Back to Dev branch + +on: + pull_request_target: + types: + - closed + branches: + - "*.x" + - "!dev*" + workflow_dispatch: + +jobs: + main: + name: Sync Stable Branches + runs-on: [self-hosted, common] + steps: + - name: git checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Sync Branches + id: release + uses: ./.github/actions/sync-branches + with: + src_branch: ${{ github.ref_name }} + dest_branch: dev-${{ github.ref_name }} diff --git a/.github/workflows/release-collect.yml b/.github/workflows/release-collect.yml new file mode 100644 index 00000000000..0b740b0f81d --- /dev/null +++ b/.github/workflows/release-collect.yml @@ -0,0 +1,30 @@ +--- +name: Tag centreon collect releases + +on: + pull_request_target: + types: + - closed + branches: + - "master" + - "*.x" + - "!dev*" + paths: + - ".github/actions/release/action.yml" + - ".github/workflows/release-collect.yml" + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-22.04 + steps: + - name: Checkout sources + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Release + id: release + uses: ./.github/actions/release + with: + jira_token: ${{ secrets.JIRA_TOKEN }} diff --git a/.github/workflows/robot-nightly.yml b/.github/workflows/robot-nightly.yml new file mode 100644 index 00000000000..60a5345496a --- /dev/null +++ b/.github/workflows/robot-nightly.yml @@ -0,0 +1,81 @@ +name: centreon collect nightly robot + +on: + workflow_dispatch: + pull_request: + paths: + - '.github/workflows/robot-nightly.yml' + schedule: + - cron: '0 0 * * *' + +env: + REGISTRY: docker.centreon.com + +jobs: + robot-test: + runs-on: [self-hosted, collect] + strategy: + matrix: + # branch: [develop, master] + include: + - image: centreon-collect-centos7 + distrib: el7 + folder_report: tests/ + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - id: version + run: | + IMG_VERSION=$(md5sum conanfile.txt | awk '{print substr($1, 0, 8)}') + echo "imgversion=$IMG_VERSION" >> $GITHUB_ENV + VERSION=$(awk '$1 ~ "COLLECT_MAJOR" {maj=substr($2, 1, length($2)-1)} $1 ~ "COLLECT_MINOR" {min=substr($2, 1, length($2)-1) ; print maj "." min}' CMakeLists.txt) + PATCH=$(awk '$1 ~ "COLLECT_PATCH" {print substr($2, 1, length($2) - 1)}' CMakeLists.txt) + echo "version=$VERSION" >> $GITHUB_ENV + echo "patch=$PATCH" >> $GITHUB_ENV + + if [[ -z "$GITHUB_HEAD_REF" ]] ; then + BRANCHNAME="$GITHUB_REF_NAME" + else + BRANCHNAME="$GITHUB_HEAD_REF" + fi + case "$BRANCHNAME" in + master | [2-9][0-9].[0-9][0-9].x | release* | hotfix*) + echo "release=$GITHUB_RUN_ATTEMPT" >> $GITHUB_ENV + ;; + *) + echo "release=${{ github.sha }}" >> $GITHUB_ENV + ;; + esac + shell: bash + + - name: Install RPM packages + uses: ./.github/actions/get-packages + with: + distrib: ${{ matrix.distrib }} + repos_username: ${{ secrets.REPOS_USERNAME }} + repos_password: ${{ secrets.REPOS_PASSWORD }} + version: ${{ env.version }} + patch: ${{ env.patch }} + release: ${{ env.release }} + cache_key: cache-${{ github.sha }}-${{ github.run_id }} + + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REPOS_USERNAME }} + password: ${{ secrets.REPOS_PASSWORD }} + + - name: Test robot Centos7 + uses: ./.github/actions/runner-docker + with: + script_name: /src/ci/scripts/collect-test-robot + image_name: ${{ matrix.image }} + image_version: ${{ env.imgversion }} + + - name: Send report to commit + uses: joonvena/robotframework-reporter-action@v2 + with: + gh_access_token: ${{ secrets.GITHUB_TOKEN }} + report_path: ${{ matrix.folder_report }} diff --git a/.gitignore b/.gitignore index 677cd4b614e..796b418d2f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,11 @@ +# ingore local env files +.env.local + *.pb.cc *.pb.h *.so *.swp -.idea -.vscode + CMakeCache.txt CMakeFiles CTest*.cmake @@ -15,11 +17,12 @@ broker_pb2.pyc broker_pb2_grpc.py broker_pb2_grpc.pyc build -centreon-broker/core/inc/com/centreon/broker/database/table_max_size.hh -centreon-broker/core/inc/com/centreon/broker/vars.hh -centreon-broker/core/inc/com/centreon/broker/version.hh -doc/_build -doc/devel-doc +build_my_host +build_centos7 +cbd +cbwd +cppcheck-build +cppcheck-report.txt engine_pb2.py engine_pb2.pyc engine_pb2_grpc.py @@ -30,10 +33,9 @@ libroker.a librokerbase.a tags test-coverage -test/python/*.crt -test/python/*.key ut -### + +### apps/ build/* @@ -41,54 +43,98 @@ build/* node_modules/ ### vscode ### -.vscode/ +**/.vscode/ +**/.idea +.scannerwork ### temp build files ### logs/* - workspace.* +**/*.swp +**/.*.swp +**/__pycache__/* +**/build/* +**/engine_pb2*.py -# ingore local env files -.env.local +**/CMakeFiles/* +CMakeLists.txt.user +**/cmake-build-debug/* +CMakeCache.txt +cmake_install.cmake +CTest*.cmake +Makefile + +log.html +output.xml +log.html +report.html + +# bbdo +bbdo/*_accessor.hh -src/config/centreon-engine/*.cfg +# broker +centreon-broker/core/inc/com/centreon/broker/database/table_max_size.hh +centreon-broker/core/inc/com/centreon/broker/vars.hh +centreon-broker/core/inc/com/centreon/broker/version.hh +centreon-broker/config/central-rrd.json +centreon-broker/config/central-broker.json +centreon-broker/config/central-module.json +centreon-broker/script/cbd.init +centreon-broker/script/watchdog.json +centreon-broker/script/misc/grpc/broker_pb2.py +centreon-broker/script/misc/grpc/broker_pb2_grpc.py +centreon-broker/libgtest*.a +centreon-broker/libnebbase.a +centreon-broker/libroker.a +centreon-broker/librokerbase.a +centreon-broker/test/python/*.crt +centreon-broker/test/python/*.key +#ci +ci/repo/* -*.swp -**/.idea/* -**/.vscode/* -**/build/* +# clib +centreon-clib/inc/com/centreon/clib/version.hh +centreon-clib/script/* + +# connectors +centreon-connector/perl/src/xs_init.cc +centreon-connector/perl/test/connector/paths.hh +centreon-connector/ssh/test/connector/binary.hh + +# doc +**/doc/devel-doc +**/doc/_build + +# engine +centreon-engine/benchmark/lib/* +centreon-engine/benchmark/log/* centreon-engine/conf/centengine.cfg -centreon-engine/conf/objects/*.cfg +centreon-engine/conf/timeperiods.cfg +centreon-engine/conf/commands.cfg centreon-engine/conf/resource.cfg +centreon-engine/conf/objects/*.cfg centreon-engine/doc/_build +centreon-engine/enginerpc/engine.*pb.cc +centreon-engine/enginerpc/engine.*pb.h +centreon-engine/gtest.cbp centreon-engine/inc/com/centreon/engine/version.hh centreon-engine/inc/compatibility/common.h centreon-engine/inc/compatibility/locations.h +centreon-engine/modules/bench/passive/paths.hh centreon-engine/scripts/centengine.pc centreon-engine/scripts/centengine.sh centreon-engine/src/simumod/neb.cc centreon-engine/tags -centreon-engine/gtest.cbp -**/CMakeFiles/* -centreon-engine/cmake-build-debug/* -centreon-engine/modules/bench/passive/paths.hh -centreon-engine/enginerpc/engine.*pb.cc -centreon-engine/enginerpc/engine.*pb.h -**/__pycache__/* -**/engine_pb2*.py -centreon-engine/benchmark/centreon-engine/* -centreon-engine/benchmark/log/* -centreon-engine/benchmark/lib/* -**/.*.swp -centreon-connectors/perl/src/xs_init.cc -centreon-connectors/perl/test/connector/paths.hh -centreon-connectors/ssh/test/connector/binary.hh -build/* -.idea/* -cmake-build-debug/* -centreon-clib/script/* -centreon-clib/inc/com/centreon/clib/version.hh -output.xml -log.html -report.html +centreon-engine/doc/devel-doc + +# gorgone +gorgone/log + +# tests +tests/apps/ +tests/src/config/centreon-engine/*.cfg +tests/src/config/centreon-engine/config*/* +test/python/*.crt +test/python/*.key +tests/logs/* diff --git a/CHANGELOG.md b/CHANGELOG.md index 1449fb358bf..32b14178b15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ with the Broker configuration file. #### Fixes +*core* + +A possible deadlock has been removed from stats center. + *rrd* Rebuild of graphs should work better. @@ -41,6 +45,7 @@ with the Engine configuration file. *core* Unknown filters applied in the configuration file do not hang broker anymore. +Improve future usage *log* @@ -48,8 +53,7 @@ If a logger was at the 'off'/'disabled' state, then broker did not start. *sql* -Hostgroups and servicegroups are no more deleted during an instance restart. -This could lead to issues when several pollers are restarted simultaneously. +Hostgroups and servicegroups are deleted 5s after the last instance restart. Size of notes\_url, notes and action\_url columns are reviewed to match the web configuration. @@ -70,6 +74,7 @@ too much. *lua* New function `broker.bbdo_version()` implemented in broker streamconnector. +stream connector accepts empty parameters ### centreon-engine diff --git a/CMakeLists.txt b/CMakeLists.txt index 676e9dc122b..44a8928a159 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,23 @@ ## ## For more information : contact@centreon.com ## +# +# Copyright 2009-2022 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 +# # # Global settings. @@ -22,55 +39,60 @@ # Set necessary settings. set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.16) project("Centreon Collect" C CXX) -if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - message(FATAL_ERROR "You can build broker with g++ or clang++. CMake will exit.") -endif () + +if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_ID + STREQUAL "Clang") + message( + FATAL_ERROR "You can build broker with g++ or clang++. CMake will exit.") +endif() + set(ALLOW_DUPLICATE_EXECUTABLE TRUE) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") +set(CMAKE_CXX_STANDARD 14) # set -latomic if OS is Raspbian. -if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm") +if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic") -endif () +endif() # Version. set(COLLECT_MAJOR 21) set(COLLECT_MINOR 10) -set(COLLECT_PATCH 3) +set(COLLECT_PATCH 4) set(COLLECT_VERSION "${COLLECT_MAJOR}.${COLLECT_MINOR}.${COLLECT_PATCH}") add_definitions(-DCENTREON_CONNECTOR_VERSION=\"${COLLECT_VERSION}\") -# add_definitions(-DCENTREON_BROKER_VERSION=\"${COLLECT_VERSION}\") +# add_definitions(-DCENTREON_BROKER_VERSION=\"${COLLECT_VERSION}\") -############ CONSTANTS ########### +# ########### CONSTANTS ########### set(USER_BROKER centreon-broker) set(USER_ENGINE centreon-engine) -################################## +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) +link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) + +# ############################################################################## +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +set(CMAKE_PROGRAM_PATH ${CONAN_BIN_DIRS_PROTOBUF};${CMAKE_PROGRAM_PATH}) + +find_package(Protobuf REQUIRED) + +message(NOTICE "-- use protoc compiler: ${Protobuf_PROTOC_EXECUTABLE}") +include_directories(${CONAN_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/centreon-clib/inc) +set(CMAKE_INSTALL_PREFIX "/usr") add_subdirectory(centreon-broker) add_subdirectory(centreon-clib) add_subdirectory(centreon-engine) add_subdirectory(centreon-connector) -add_custom_target(test-broker - WORKING_DIRECTORY centreon-broker - COMMAND test/ut - ) -add_custom_target(test-engine - WORKING_DIRECTORY centreon-engine - COMMAND tests/ut_engine - ) -add_custom_target(test-clib - WORKING_DIRECTORY centreon-clib - COMMAND test/ut-clib - ) -add_custom_target(test-connector - WORKING_DIRECTORY centreon-connector - COMMAND ut_connector - ) +add_custom_target(test-broker COMMAND test/ut_broker) +add_custom_target(test-engine COMMAND tests/ut_engine) +add_custom_target(test-clib COMMAND tests/ut_clib) -add_custom_target(test - DEPENDS test-broker test-engine test-clib test-connector - ) +# add_custom_target(test-connector COMMAND ut_connector) +add_custom_target(test DEPENDS test-broker test-engine test-clib test-connector) diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 52db4d6d461..00000000000 --- a/Jenkinsfile +++ /dev/null @@ -1,133 +0,0 @@ -@Library("centreon-shared-library")_ - -/* -** Variables. -*/ - -env.REF_BRANCH = 'master' -env.PROJECT='centreon-collect' -def serie = '21.10' -def maintenanceBranch = "${serie}.x" -def qaBranch = "dev-${serie}.x" -def buildBranch = env.BRANCH_NAME -if (env.CHANGE_BRANCH) { - buildBranch = env.CHANGE_BRANCH -} - -/* -** Branch management -*/ -if (env.BRANCH_NAME.startsWith('release-')) { - env.BUILD = 'RELEASE' -} else if ((env.BRANCH_NAME == env.REF_BRANCH) || (env.BRANCH_NAME == maintenanceBranch)) { - env.BUILD = 'REFERENCE' -} else if ((env.BRANCH_NAME == 'develop') || (env.BRANCH_NAME == qaBranch)) { - env.BUILD = 'QA' -} else { - env.BUILD = 'CI' -} - -/* -** Pipeline code. -*/ -stage('Deliver sources') { - node("C++") { - dir('centreon-collect-centos7') { - checkout scm - loadCommonScripts() - sh 'ci/scripts/collect-sources-delivery.sh' - source = readProperties file: 'source.properties' - env.VERSION = "${source.VERSION}" - env.RELEASE = "${source.RELEASE}" - } - } -} - -stage('Build / Unit tests // Packaging / Signing') { - parallel 'centos7 Build and UT': { - node("C++") { - dir('centreon-collect-centos7') { - checkout scm - sh 'docker run -i --entrypoint /src/ci/scripts/collect-unit-tests.sh -v "$PWD:/src" registry.centreon.com/centreon-collect-centos7-dependencies:21.10' - } - } - }, - 'centos7 SQ analysis': { - node("C++") { - dir('centreon-collect-centos7') { - checkout scm - loadCommonScripts() - withSonarQubeEnv('SonarQubeDev') { - sh 'ci/scripts/collect-sonar-scanner-common.sh "get" "dev-21.10.x"' - if (env.CHANGE_ID) { - sh 'docker run -i --entrypoint /src/ci/scripts/collect-sources-analysis.sh -v "$PWD:/src" registry.centreon.com/centreon-collect-centos7-dependencies:21.10 "PR" "$SONAR_AUTH_TOKEN" "$SONAR_HOST_URL" "$VERSION" "$CHANGE_TARGET" "$CHANGE_BRANCH" "$CHANGE_ID"' - } else { - sh 'docker run -i --entrypoint /src/ci/scripts/collect-sources-analysis.sh -v "$PWD:/src" registry.centreon.com/centreon-collect-centos7-dependencies:21.10 "NotPR" "$SONAR_AUTH_TOKEN" "$SONAR_HOST_URL" "$VERSION" "$BRANCH_NAME"' - } - sh 'ci/scripts/collect-sonar-scanner-common.sh "set"' - } - } - } - }, - 'centos7 rpm packaging and signing': { - node("C++") { - dir('centreon-collect-centos7') { - checkout scm - sh 'docker run -i --entrypoint /src/ci/scripts/collect-rpm-package.sh -v "$PWD:/src" -e DISTRIB="el7" -e VERSION=$VERSION -e RELEASE=$RELEASE registry.centreon.com/centreon-collect-centos7-dependencies:21.10' - sh 'rpmsign --addsign *.rpm' - stash name: 'el7-rpms', includes: '*.rpm' - archiveArtifacts artifacts: "*.rpm" - sh 'rm -rf *.rpm' - } - } - }, - 'alma8 rpm packaging and signing': { - node("C++") { - dir('centreon-collect-alma8') { - checkout scm - sh 'docker run -i --entrypoint /src/ci/scripts/collect-rpm-package.sh -v "$PWD:/src" -e DISTRIB="el8" -e VERSION=$VERSION -e RELEASE=$RELEASE registry.centreon.com/centreon-collect-alma8-dependencies:21.10' - sh 'rpmsign --addsign *.rpm' - stash name: 'el8-rpms', includes: '*.rpm' - archiveArtifacts artifacts: "*.rpm" - sh 'rm -rf *.rpm' - } - } - }, - 'debian buster Build and UT': { - node("C++") { - dir('centreon-collect-debian') { - checkout scm - sh 'docker run -i --entrypoint /src/ci/scripts/collect-unit-tests.sh -v "$PWD:/src" registry.centreon.com/centreon-collect-debian-dependencies:21.10' - } - } - } -} - -stage('Quality Gate') { - node("C++") { - timeout(time: 10, unit: 'MINUTES') { - def qualityGate = waitForQualityGate() - if (qualityGate.status != 'OK') { - error "Pipeline aborted due to quality gate failure: ${qualityGate.status}" - } - } - if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') { - error("Quality gate failure: ${qualityGate.status}."); - } - } -} - -if ((env.BUILD == 'RELEASE') || (env.BUILD == 'QA')) { - stage('Delivery') { - node("C++") { - unstash 'el8-rpms' - unstash 'el7-rpms' - dir('centreon-collect-delivery') { - checkout scm - loadCommonScripts() - sh 'rm -rf output && mkdir output && mv ../*.rpm output' - sh './ci/scripts/collect-rpm-delivery.sh' - } - } - } -} diff --git a/centreon-broker/.github/workflows/centreon-collect.yml b/centreon-broker/.github/workflows/centreon-collect.yml new file mode 100644 index 00000000000..c613d8c58db --- /dev/null +++ b/centreon-broker/.github/workflows/centreon-collect.yml @@ -0,0 +1,232 @@ +name: Centreon collect + +on: + pull_request_target: + types: + - closed + branches: + - develop + paths-ignore: + - 'gorgone/**' + workflow_dispatch: + pull_request: + paths-ignore: + - 'gorgone/**' + +env: + REGISTRY: registry-docker.centreon.com/docker-global + +jobs: + centreon-collect-test: + runs-on: ubuntu-latest +# runs-on: [self-hosted, collect] + strategy: + matrix: + include: + - image: centos7 + version: test-22.10 + - image: alma8 + version: test-22.10 + - image: debian-buster + version: test-22.10 + - image: debian-bullseye + version: test-22.10 + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REPOS_USERNAME }} + password: ${{ secrets.REPOS_PASSWORD }} + - name: Test ${{ matrix.image }} + uses: ./.github/actions/runner-docker + with: + script_name: /src/ci/scripts/collect-unit-tests + image_name: centreon-collect-${{ matrix.image }} + image_version: ${{ matrix.version }} + + rpm-packaging: + runs-on: ubuntu-latest +#runs-on: [self-hosted, collect] + strategy: + matrix: + include: + - image: centos7 + version: test-22.10 + distrib: el7 + - image: alma8 + version: test-22.10 + distrib: el8 + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REPOS_USERNAME }} + password: ${{ secrets.REPOS_PASSWORD }} + + - name: make rpm ${{ matrix.image }} + uses: ./.github/actions/runner-docker + with: + script_name: /src/ci/scripts/collect-rpm-package + image_name: centreon-collect-${{ matrix.image }} + image_version: ${{ matrix.version }} + env_variable: -e DISTRIB="${{ matrix.distrib }}" -e VERSION="22.10.1" -e RELEASE="1" + + - name: Use cache RPM files + uses: actions/cache@v3 + env: + cache-name-rpmbuild: cache-${{ github.sha }}-${{ github.run_id }}-rpmbuild-centreon-collect-${{ matrix.distrib }} + with: + path: ./*.rpm + key: ${{ env.cache-name-rpmbuild }} + + debian-packaging: + runs-on: ubuntu-latest +#runs-on: [self-hosted, collect] + strategy: + matrix: + include: + - image: debian-buster + version: test-22.10 + distrib: buster + - image: debian-bullseye + version: test-22.10 + distrib: bullseye + steps: + - name: Checkout sources + uses: actions/checkout@v3 + with: + path: centreon-collect + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REPOS_USERNAME }} + password: ${{ secrets.REPOS_PASSWORD }} + + - name: debmake ${{ matrix.image }} + uses: ./centreon-collect/.github/actions/runner-docker + with: + script_name: /src/centreon-collect/ci/scripts/collect-deb-package + image_name: centreon-collect-${{ matrix.image }} + image_version: ${{ matrix.version }} + env_variable: -e DISTRIB="${{ matrix.distrib }}" -e VERSION="22.10.1" -e RELEASE="1" + + - name: Use cache DEB files + uses: actions/cache@v3 + env: + cache-name-debbuild: cache-${{ github.sha }}-${{ github.run_id }}-debbuild-centreon-collect-${{ matrix.distrib }} + with: + path: ./*.deb + key: ${{ env.cache-name-debbuild }} + + delivery-debian: + needs: [debian-packaging] + runs-on: ubuntu-22.04 + name: Delivery + strategy: + matrix: + distrib: [buster, bullseye] + steps: + - name: Use cache DEB files + uses: actions/cache@v3 + env: + cache-name-debbuild: cache-${{ github.sha }}-${{ github.run_id }}-debbuild-centreon-collect-${{ matrix.distrib }} + with: + path: ./*.deb + key: ${{ env.cache-name-debbuild }} + restore-keys: | + ${{ env.cache-name-debbuild }} + + - name: Publish DEB to Nexus + run: | + case $GITHUB_HEAD_REF in + MON*) + REPO=unstable + ;; + release* | hotfix*) + REPO=testing + ;; + master | main | [0-9]{2}\.[0-9]{2}.) + REPO=stable + ;; + *) + echo -n "[INFO] Non conventional branch name. Please rename your branch to meet the requirements" + exit 1 + ;; + esac + + for FILE in *.deb; + do + + VERSION=$(echo $FILE | grep -oP '[0-9]{2}\.[0-9]{2}') + DISTRIB=${{ matrix.distrib }} + ARCH=$(echo $FILE | grep -oP '(amd64)') + MODULE=$(echo $FILE | grep -oP 'centreon-([a-z]+)') + + echo "Repo: $REPO" + echo "Version: $VERSION" + echo "Distrib: $DISTRIB" + echo "Arch: $ARCH" + echo "Module: $MODULE" + + curl -v -u ${{ secrets.NEXUS_RPMS_REPOSITORY_USERNAME }}:${{ secrets.NEXUS_RPMS_REPOSITORY_PASSWORD }} -H "Content-Type: multipart/form-data" --data-binary "@./$FILE" "http://nexus-svc.nexus.svc.cluster.local:8081/repository/$VERSION-$REPO/" + done + + delivery-centos: + needs: [rpm-packaging] + runs-on: ubuntu-22.04 + name: Delivery + strategy: + matrix: + distrib: [el7, el8] + steps: + - name: Use cache RPM files + uses: actions/cache@v3 + env: + cache-name-rpmbuild: cache-${{ github.sha }}-${{ github.run_id }}-rpmbuild-centreon-collect-${{ matrix.distrib }} + with: + path: ./*.rpm + key: ${{ env.cache-name-rpmbuild }} + restore-keys: | + ${{ env.cache-name-rpmbuild }} + + - name: Publish RPMS to Nexus + run: | + case $GITHUB_HEAD_REF in + MON*) + REPO=unstable + ;; + release* | hotfix*) + REPO=testing + ;; + master | main | [0-9]{2}\.[0-9]{2}.) + REPO=stable + ;; + *) + echo -n "[INFO] Non conventional branch name. Please rename your branch to meet the requirements" + exit 1 + ;; + esac + + + for FILE in *.rpm; + do + VERSION=$(echo $FILE | grep -oP '[0-9]{2}\.[0-9]{2}') + DISTRIB=$(echo $FILE | grep -oP 'el[0-9]') + ARCH=$(echo $FILE | grep -oP '(x86_64|noarch)') + MODULE=$(echo $FILE | grep -oP 'centreon-([a-z]+)') + + echo "Repo: $REPO" + echo "Version: $VERSION" + echo "Distrib: $DISTRIB" + echo "Arch: $ARCH" + echo "Module: $MODULE" + + curl -v -u ${{ secrets.NEXUS_RPMS_REPOSITORY_USERNAME }}:${{ secrets.NEXUS_RPMS_REPOSITORY_PASSWORD }} --upload-file ./$FILE "http://nexus-svc.nexus.svc.cluster.local:8081/repository/standard/$VERSION/$DISTRIB/$REPO/$ARCH/$MODULE/" + done diff --git a/centreon-broker/.github/workflows/centreon-gorgone.yml b/centreon-broker/.github/workflows/centreon-gorgone.yml new file mode 100644 index 00000000000..3a1afbf8d1b --- /dev/null +++ b/centreon-broker/.github/workflows/centreon-gorgone.yml @@ -0,0 +1,197 @@ +name: Centreon gorgone + +on: + pull_request_target: + types: + - closed + branches: + - develop + paths: + - '.github/workflows/centreon-gorgone.yml' + - 'ci/scripts/gorgone-deb-package.sh' + - 'ci/scripts/gorgone-rpm-package.sh' + - 'ci/debian-gorgone/**' + - 'gorgone/**' + workflow_dispatch: + pull_request: + paths: + - '.github/workflows/centreon-gorgone.yml' + - 'ci/scripts/gorgone-deb-package.sh' + - 'ci/scripts/gorgone-rpm-package.sh' + - 'ci/debian-gorgone/**' + - 'gorgone/**' + +jobs: + rpm-packaging: + runs-on: ubuntu-22.04 + strategy: + matrix: + include: + - image: centos7 + version: test-22.10 + distrib: el7 + - image: alma8 + version: test-22.10 + distrib: el8 + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: make rpm ${{ matrix.image }} + uses: ./.github/actions/runner-docker + with: + script_name: /src/ci/scripts/gorgone-rpm-package + image_name: centreon-gorgone-${{ matrix.image }} + image_version: ${{ matrix.version }} + env_variable: -e DISTRIB="${{ matrix.distrib }}" -e VERSION="22.10.1" -e RELEASE="1" + + - name: Use cache RPM files + uses: actions/cache@v3 + env: + cache-name-rpmbuild: cache-${{ github.sha }}-${{ github.run_id }}-rpmbuild-centreon-gorgone-${{ matrix.distrib }} + with: + path: ./*.rpm + key: ${{ env.cache-name-rpmbuild }} + + debian-packaging: + runs-on: ubuntu-22.04 + strategy: + matrix: + include: + - image: centreon-gorgone-debian-bullseye + version: test-22.10 + distrib: bullseye + steps: + - name: Checkout sources + uses: actions/checkout@v3 + with: + path: centreon-collect + + - name: debmake Debian Bullseye + uses: ./centreon-collect/.github/actions/runner-docker + with: + script_name: /src/centreon-collect/ci/scripts/gorgone-deb-package + image_name: ${{ matrix.image }} + image_version: ${{ matrix.version }} + env_variable: -e DISTRIB="${{ matrix.distrib }}" -e VERSION="22.10.1" -e RELEASE="1" + + - name: Use cache DEB files + uses: actions/cache@v3 + env: + cache-name-debbuild: cache-${{ github.sha }}-${{ github.run_id }}-debbuild-centreon-gorgone-${{ matrix.distrib }} + with: + path: ./bullseye/*.deb + key: ${{ env.cache-name-debbuild }} + + delivery-debian: + needs: [debian-packaging] + runs-on: ubuntu-22.04 + name: Delivery + strategy: + matrix: + distrib: [bullseye] + steps: + - name: Use cache DEB files + uses: actions/cache@v3 + env: + cache-name-debbuild: cache-${{ github.sha }}-${{ github.run_id }}-debbuild-centreon-gorgone-${{ matrix.distrib }} + with: + path: ./${{ matrix.distrib }}/*.deb + key: ${{ env.cache-name-debbuild }} + restore-keys: | + ${{ env.cache-name-debbuild }} + + - name: cd ${{ matrix.distrib }} + run: cd ${{ matrix.distrib }} + + - name: Publish DEB to Nexus + run: | + case $GITHUB_HEAD_REF in + MON*) + REPO=unstable + ;; + release* | hotfix*) + REPO=testing + ;; + master | main | [0-9]{2}\.[0-9]{2}.) + REPO=stable + ;; + *) + echo -n "[INFO] Non conventional branch name. Please rename your branch to meet the requirements" + exit 1 + ;; + esac + + echo "$REPO" + + cd ${{ matrix.distrib }}/ + echo 'ls -l' + for FILE in *.deb; + do + + VERSION="22.10" + # DISTRIB=${{ matrix.distrib }} + # ARCH=$(echo $FILE | grep -oP '(amd64)') + # MODULE=$(echo $FILE | grep -oP 'centreon-([a-z]+)') + + echo "Repo: $REPO" + echo "Version: $VERSION" + # echo "Distrib: $DISTRIB" + # echo "Arch: $ARCH" + # echo "Module: $MODULE" + + curl -v -u ${{ secrets.NEXUS_RPMS_REPOSITORY_USERNAME }}:${{ secrets.NEXUS_RPMS_REPOSITORY_PASSWORD }} -H "Content-Type: multipart/form-data" --data-binary "@./$FILE" "http://nexus-svc.nexus.svc.cluster.local:8081/repository/$VERSION-$REPO/" + done + + + delivery-centos: + needs: [rpm-packaging] + runs-on: ubuntu-22.04 + name: Delivery + strategy: + matrix: + distrib: [el7, el8] + steps: + - name: Use cache RPM files + uses: actions/cache@v3 + env: + cache-name-rpmbuild: cache-${{ github.sha }}-${{ github.run_id }}-rpmbuild-centreon-gorgone-${{ matrix.distrib }} + with: + path: ./*.rpm + key: ${{ env.cache-name-rpmbuild }} + restore-keys: | + ${{ env.cache-name-rpmbuild }} + + - name: Publish RPMS to Nexus + run: | + case $GITHUB_HEAD_REF in + MON*) + REPO=unstable + ;; + release* | hotfix*) + REPO=testing + ;; + master | main | [0-9]{2}\.[0-9]{2}.) + REPO=stable + ;; + *) + echo -n "[INFO] Non conventional branch name. Please rename your branch to meet the requirements" + exit 1 + ;; + esac + + for FILE in *.rpm; + do + VERSION=$(echo $FILE | grep -oP '[0-9]{2}\.[0-9]{2}') + DISTRIB=$(echo $FILE | grep -oP 'el[0-9]') + ARCH=$(echo $FILE | grep -oP '(x86_64|noarch)') + MODULE=$(echo $FILE | grep -oP '^centreon-([a-z]+)') + + echo "Repo: $REPO" + echo "Version: $VERSION" + echo "Distrib: $DISTRIB" + echo "Arch: $ARCH" + echo "Module: $MODULE" + + curl -v -u ${{ secrets.NEXUS_RPMS_REPOSITORY_USERNAME }}:${{ secrets.NEXUS_RPMS_REPOSITORY_PASSWORD }} --upload-file ./$FILE "http://nexus-svc.nexus.svc.cluster.local:8081/repository/standard/$VERSION/$DISTRIB/$REPO/$ARCH/$MODULE/" + done diff --git a/centreon-broker/.github/workflows/dependabot_jira.yml b/centreon-broker/.github/workflows/dependabot_jira.yml index acaec2996f4..e69de29bb2d 100644 --- a/centreon-broker/.github/workflows/dependabot_jira.yml +++ b/centreon-broker/.github/workflows/dependabot_jira.yml @@ -1,79 +0,0 @@ -name: Create Dependabot Ticket on Jira - -on: - pull_request: - types: [ opened, reopened ] - branches: [ develop ] - -permissions: - pull-requests: read - -env: - JIRA_PROJECT_KEY: "MON" - JIRA_ISSUE_TYPE: "Technical" - COMPONENT_NAME: "${{ github.event.pull_request.base.repo.name }}" - -jobs: - create_ticket: - name: Create Jira ticket on dependaBot PR - if: github.event.pull_request.user.id == 49699333 - runs-on: ubuntu-latest - steps: - - name: Get current date - id: date - run: echo "CURRENT_DATE=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV - - - name: Check components name - id: name - if: ${{ env.COMPONENT_NAME == 'centreon'}} - run: echo "COMPONENT_NAME=centreon-web" >> $GITHUB_ENV - - - name: debug - id: debug - run: echo "component is ${{ env.COMPONENT_NAME }}." - - - name: Login to Jira - uses: atlassian/gajira-login@v2.0.0 - id: login - env: - JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} - JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} - JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} - - - name: Create Jira Issue - uses: atlassian/gajira-create@v2.0.1 - id: create - env: - JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} - JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} - JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} - with: - project: ${{ env.JIRA_PROJECT_KEY }} - issuetype: ${{ env.JIRA_ISSUE_TYPE }} - summary: | - [${{ github.event.repository.name }}] - ${{ github.event.pull_request.title }} - description: | - - {panel:title=Recommandation} - ${{ github.event.pull_request.title }} - {panel} - - More details are available in the *PR n°${{ github.event.pull_request.number }}* - - Github link is: ${{ github.event.pull_request.html_url }} - - {panel:title=CVSS details} - More details are available on snyk - {panel} - - *Github Advisory* - - fields: - '{ - "customfield_10880": "Internal", - "customfield_10881": "Dependabot", - "customfield_10866": "${{ env.CURRENT_DATE }}", - "labels": ["Dependabot"], - "priority": {"name": "Highest"}, - "components":[{"name": "${{ env.COMPONENT_NAME }}"}] - }' diff --git a/centreon-broker/.github/workflows/docker-builder.yml b/centreon-broker/.github/workflows/docker-builder.yml new file mode 100644 index 00000000000..056247c1a56 --- /dev/null +++ b/centreon-broker/.github/workflows/docker-builder.yml @@ -0,0 +1,67 @@ +name: Centreon collect build docker + +on: + pull_request_target: + types: + - closed + branches: + - develop + paths: + - '.github/workflows/docker-builder.yml' + - 'ci/docker/**' + workflow_dispatch: + pull_request: + paths: + - '.github/workflows/docker-builder.yml' + - 'ci/docker/**' + +env: + REGISTRY: registry-docker.centreon.com/docker-global + +jobs: + create-and-push-docker: +#runs-on: [self-hosted, collect] + runs-on: ubuntu-latest + continue-on-error: false + strategy: + fail-fast: false + matrix: + include: + - project: collect + distrib: centos7 + version: test-22.10 + - project: collect + distrib: alma8 + version: test-22.10 + - project: collect + distrib: debian-buster + version: test-22.10 + - project: collect + distrib: debian-bullseye + version: test-22.10 + - project: gorgone + distrib: centos7 + version: test-22.10 + - project: gorgone + distrib: alma8 + version: test-22.10 + - project: gorgone + distrib: debian-bullseye + version: test-22.10 + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REPOS_USERNAME }} + password: ${{ secrets.REPOS_PASSWORD }} + + - name: build docker ${{ matrix.distrib }} + run: docker build --no-cache . -f ci/docker/Dockerfile.${{ matrix.project }}-${{ matrix.distrib }} -t $REGISTRY/centreon-${{ matrix.project }}-${{ matrix.distrib }}:${{ matrix.version }} + + - name: push docker ${{ matrix.distrib }} + run: docker push $REGISTRY/centreon-${{ matrix.project }}-${{ matrix.distrib }}:${{ matrix.version }} + diff --git a/centreon-broker/.github/workflows/robot-nightly.yml b/centreon-broker/.github/workflows/robot-nightly.yml new file mode 100644 index 00000000000..dd42fe0a299 --- /dev/null +++ b/centreon-broker/.github/workflows/robot-nightly.yml @@ -0,0 +1,44 @@ +name: centreon collect nightly robot + +on: + workflow_dispatch: + push: + branches: + - master + - develop + pull_request: + paths: + - '.github/workflows/robot-nightly.yml' + schedule: + - cron: '0 0 * * *' + +jobs: + robot-test: + runs-on: ubuntu-latest +#runs-on: [self-hosted, collect] + strategy: + matrix: + # branch: [develop, master] + include: + - image: centreon-collect-centos7 + version: test-22.10 + folder_report: tests/ + steps: + - name: Checkout sources + uses: actions/checkout@v3 + # with: + # ref: ${{ matrix.branch }} + + - name: Test robot centos7 + uses: ./.github/actions/runner-docker + with: + script_name: /src/ci/scripts/collect-test-robot + image_name: ${{ matrix.image }} + image_version: ${{ matrix.version }} + params: ${{ matrix.branch }} + + - name: Send report to commit + uses: joonvena/robotframework-reporter-action@v2 + with: + gh_access_token: ${{ secrets.GITHUB_TOKEN }} + report_path: ${{ matrix.folder_report }} diff --git a/centreon-broker/.gitignore b/centreon-broker/.gitignore index 450c51f90b8..e69de29bb2d 100644 --- a/centreon-broker/.gitignore +++ b/centreon-broker/.gitignore @@ -1,35 +0,0 @@ -*.pb.cc -*.pb.h -*.so -*.swp -.idea -.vscode -CMakeCache.txt -CMakeFiles -CTest*.cmake -Makefile -Testing -__ -build -cbd -cbwd -cmake-build-debug -cmake_install.cmake -core/inc/com/centreon/broker/database/table_max_size.hh -core/inc/com/centreon/broker/vars.hh -core/inc/com/centreon/broker/version.hh -deps.png -doc/_build -doc/devel-doc -libgtest*.a -libnebbase.a -libroker.a -librokerbase.a -script/misc/grpc/broker_pb2.py -script/misc/grpc/broker_pb2_grpc.py -tags -test-coverage -test/python/*.crt -test/python/*.key -ut -ut.xml diff --git a/centreon-broker/CMakeLists.txt b/centreon-broker/CMakeLists.txt index a6e90b26ff9..f7c2cafef37 100644 --- a/centreon-broker/CMakeLists.txt +++ b/centreon-broker/CMakeLists.txt @@ -1,20 +1,19 @@ -## -## Copyright 2009-2021 Centreon -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -## For more information : contact@centreon.com -## +# +# Copyright 2009-2021 Centreon +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# For more information : contact@centreon.com +# # # Global settings. @@ -23,157 +22,140 @@ # Set necessary settings. cmake_minimum_required(VERSION 2.8) project("Centreon Broker" C CXX) -if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - message(FATAL_ERROR "You can build broker with g++ or clang++. CMake will exit.") -endif () -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") +if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_ID + STREQUAL "Clang") + message( + FATAL_ERROR "You can build broker with g++ or clang++. CMake will exit.") +endif() + +add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1") +set(CMAKE_CXX_STANDARD 14) # set -latomic if OS is Raspbian. -if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm") +if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic") -endif () - -add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1") +endif() option(WITH_LIBCXX "compiles and link cbd with clang++/libc++") -if (WITH_LIBCXX) + +if(WITH_LIBCXX) set(CMAKE_CXX_COMPILER "clang++") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") -# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -Werror -O1 -fno-omit-frame-pointer") -endif () + + # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -Werror -O1 + # -fno-omit-frame-pointer") +endif() # With ASIO DEBUGGING ENABLED option(WITH_DEBUG_ASIO "Add the Asio debugging flags." OFF) -if (WITH_DEBUG_ASIO) + +if(WITH_DEBUG_ASIO) set(CMAKE_BUILD_TYPE Debug) - set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DASIO_ENABLE_BUFFER_DEBUGGING -DASIO_ENABLE_HANDLER_TRACKING") -endif () + set(CMAKE_CXX_FLAGS_DEBUG + "${CMAKE_CXX_FLAGS_DEBUG} -DASIO_ENABLE_BUFFER_DEBUGGING -DASIO_ENABLE_HANDLER_TRACKING" + ) +endif() # With libasan -option(WITH_ASAN "Add the libasan to check memory leaks and other memory issues." OFF) -if (WITH_ASAN) +option(WITH_ASAN + "Add the libasan to check memory leaks and other memory issues." OFF) + +if(WITH_ASAN) set(CMAKE_BUILD_TYPE Debug) - set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") - set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") -endif () + set(CMAKE_CXX_FLAGS_DEBUG + "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") + set(CMAKE_LINKER_FLAGS_DEBUG + "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") +endif() include_directories("${PROJECT_SOURCE_DIR}/core/inc") include_directories("${PROJECT_SOURCE_DIR}/neb/inc") 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") -include(${CMAKE_BINARY_DIR}/conan_paths.cmake) add_custom_command( - DEPENDS ${SRC_DIR}/database/table_max_size.py "${CMAKE_SOURCE_DIR}/resources/centreon.sql" "${CMAKE_SOURCE_DIR}/resources/centreon_storage.sql" + DEPENDS ${SRC_DIR}/database/table_max_size.py + "${CMAKE_SOURCE_DIR}/resources/centreon.sql" + "${CMAKE_SOURCE_DIR}/resources/centreon_storage.sql" COMMENT "Generating table_max_size.hh" OUTPUT ${INC_DIR}/database/table_max_size.hh - COMMAND python3 - ARGS ${SRC_DIR}/database/table_max_size.py ${INC_DIR}/database/table_max_size.hh "${CMAKE_SOURCE_DIR}/resources/centreon.sql" "${CMAKE_SOURCE_DIR}/resources/centreon_storage.sql" -) + COMMAND + python3 ARGS ${SRC_DIR}/database/table_max_size.py + ${INC_DIR}/database/table_max_size.hh + "${CMAKE_SOURCE_DIR}/resources/centreon.sql" + "${CMAKE_SOURCE_DIR}/resources/centreon_storage.sql") add_custom_target(table_max_size DEPENDS ${INC_DIR}/database/table_max_size.hh) -set_source_files_properties(${INC_DIR}/database/table_max_size.hh PROPERTIES GENERATED TRUE) +set_source_files_properties(${INC_DIR}/database/table_max_size.hh + PROPERTIES GENERATED TRUE) set(protobuf_MODULE_COMPATIBLE True) -find_package(nlohmann_json REQUIRED) -find_package(fmt REQUIRED) -find_package(spdlog REQUIRED) -find_package(asio REQUIRED) -find_package(Protobuf REQUIRED) -find_package(gRPC REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(c-ares REQUIRED) -find_package(ZLIB REQUIRED) -find_package(mariadb-connector-c REQUIRED) add_definitions(${spdlog_DEFINITIONS} ${mariadb-connector-c_DEFINITIONS}) -include_directories(${nlohmann_json_INCLUDE_DIRS}) -include_directories(${fmt_INCLUDE_DIRS}) -include_directories(${spdlog_INCLUDE_DIRS}) -include_directories(${asio_INCLUDE_DIRS}) -include_directories(${protobuf_INCLUDE_DIRS}) -include_directories(${absl_INCLUDE_DIRS}) -include_directories(${gRPC_INCLUDE_DIRS}) -include_directories(${ZLIB_INCLUDE_DIRS}) -include_directories(${mariadb-connector-c_INCLUDE_DIRS}) - -link_directories(${nlohmann_json_LIB_DIRS}) -link_directories(${fmt_LIB_DIRS}) -link_directories(${spdlog_LIB_DIRS}) -link_directories(${protobuf_LIB_DIRS}) -link_directories(${gRPC_LIB_DIRS}) -link_directories(${c-ares_LIB_DIRS}) -link_directories(${OpenSSL_LIB_DIRS}) -link_directories(${ZLIB_LIB_DIRS}) -link_directories(${mariadb-connector-c_LIB_DIRS}) - set(PROTOBUF_PREFIX "${protobuf_LIB_DIRS}/..") message(STATUS "${PROTOBUF_PREFIX}/bin/protoc") -set(GRPC_PREFIX "${gRPC_LIB_DIRS}/..") add_custom_command( DEPENDS ${SRC_DIR}/broker.proto COMMENT "Generating interface files of the proto file (grpc)" OUTPUT ${SRC_DIR}/broker.grpc.pb.cc ${SRC_DIR}/broker.grpc.pb.h - COMMAND ${PROTOBUF_PREFIX}/bin/protoc - ARGS --plugin=protoc-gen-grpc=${GRPC_PREFIX}/bin/grpc_cpp_plugin --proto_path=${SRC_DIR} --grpc_out="${SRC_DIR}" ${SRC_DIR}/broker.proto - + COMMAND + ${Protobuf_PROTOC_EXECUTABLE} ARGS + --plugin=protoc-gen-grpc=${CONAN_BIN_DIRS_GRPC}/grpc_cpp_plugin + --proto_path=${SRC_DIR} --grpc_out="${SRC_DIR}" ${SRC_DIR}/broker.proto DEPENDS ${SRC_DIR}/broker.proto COMMENT "Generating interface files of the proto file (protobuf)" OUTPUT ${SRC_DIR}/broker.pb.cc ${SRC_DIR}/broker.pb.h - COMMAND ${PROTOBUF_PREFIX}/bin/protoc - ARGS --cpp_out="${SRC_DIR}" --proto_path=${SRC_DIR} ${SRC_DIR}/broker.proto -) + COMMAND ${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out="${SRC_DIR}" + --proto_path=${SRC_DIR} ${SRC_DIR}/broker.proto) include_directories(${SRC_DIR}) -add_library( - berpc - STATIC - - ${SRC_DIR}/broker.grpc.pb.cc - ${SRC_DIR}/broker.pb.cc - ${SRC_DIR}/broker.grpc.pb.h - ${SRC_DIR}/broker.pb.h) -target_link_libraries(berpc ${protobuf_LIBS}) +add_library(berpc STATIC ${SRC_DIR}/broker.grpc.pb.cc ${SRC_DIR}/broker.pb.cc + ${SRC_DIR}/broker.grpc.pb.h ${SRC_DIR}/broker.pb.h) +target_link_libraries(berpc CONAN_PKG::protobuf) set_target_properties(berpc PROPERTIES COMPILE_FLAGS "-fPIC") set(VERSION "$ENV{VERSION}") -if ("${VERSION}" STREQUAL "") + +if("${VERSION}" STREQUAL "") set(CENTREON_BROKER_MAJOR ${COLLECT_MAJOR}) set(CENTREON_BROKER_MINOR ${COLLECT_MINOR}) set(CENTREON_BROKER_PATCH ${COLLECT_PATCH}) -else () +else() string(REGEX MATCHALL "([0-9]*)\\.([0-9]*)\\.([0-9]*)" _ "${VERSION}") - # Version. + # Version. set(CENTREON_BROKER_MAJOR ${CMAKE_MATCH_1}) set(CENTREON_BROKER_MINOR ${CMAKE_MATCH_2}) set(CENTREON_BROKER_PATCH ${CMAKE_MATCH_3}) -endif () - -if (CENTREON_BROKER_PRERELEASE) - set(CENTREON_BROKER_VERSION "${CENTREON_BROKER_MAJOR}.${CENTREON_BROKER_MINOR}.${CENTREON_BROKER_PATCH}-${CENTREON_BROKER_PRERELEASE}") -else () - set(CENTREON_BROKER_VERSION "${CENTREON_BROKER_MAJOR}.${CENTREON_BROKER_MINOR}.${CENTREON_BROKER_PATCH}") -endif () -add_definitions(-DCENTREON_BROKER_VERSION=\"${CENTREON_BROKER_VERSION}\" -DCENTREON_BROKER_PATCH=${CENTREON_BROKER_PATCH}) -configure_file( - ${INC_DIR}/version.hh.in - ${INC_DIR}/version.hh - @ONLY -) +endif() + +if(CENTREON_BROKER_PRERELEASE) + set(CENTREON_BROKER_VERSION + "${CENTREON_BROKER_MAJOR}.${CENTREON_BROKER_MINOR}.${CENTREON_BROKER_PATCH}-${CENTREON_BROKER_PRERELEASE}" + ) +else() + set(CENTREON_BROKER_VERSION + "${CENTREON_BROKER_MAJOR}.${CENTREON_BROKER_MINOR}.${CENTREON_BROKER_PATCH}" + ) +endif() + +message(STATUS "Broker version ${CENTREON_BROKER_VERSION}") + +add_definitions(-DCENTREON_BROKER_VERSION=\"${CENTREON_BROKER_VERSION}\" + -DCENTREON_BROKER_PATCH=${CENTREON_BROKER_PATCH}) +configure_file(${INC_DIR}/version.hh.in ${INC_DIR}/version.hh @ONLY) include(cmake/tool.cmake) # # Check and/or find required components. # - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") add_definitions("-DASIO_STANDALONE") @@ -182,407 +164,417 @@ find_package(PkgConfig REQUIRED) # # Get distributions name # -if (CMAKE_SYSTEM_NAME STREQUAL "Linux") +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") message(STATUS "Attempting to determine OS distributor.") - execute_process(COMMAND "lsb_release" "--short" "--id" + execute_process( + COMMAND "lsb_release" "--short" "--id" RESULT_VARIABLE RETCODE OUTPUT_VARIABLE OS_DISTRIBUTOR ERROR_QUIET) - if (RETCODE EQUAL 0) + + if(RETCODE EQUAL 0) string(REGEX REPLACE "\n$" "" OS_DISTRIBUTOR "${OS_DISTRIBUTOR}") - else () + else() message(WARNING "lsb_release in not installed") set(OS_DISTRIBUTOR "${CMAKE_SYSTEM_NAME}") - endif () -elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") + endif() +elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(OS_DISTRIBUTOR "${CMAKE_SYSTEM_NAME}") -endif () - +endif() # # Options. # -# Main directory. -if (WITH_PREFIX) - set(CMAKE_INSTALL_PREFIX "${WITH_PREFIX}") -endif () - # Executable directory. -if (WITH_PREFIX_BIN) +if(WITH_PREFIX_BIN) set(PREFIX_BIN "${WITH_PREFIX_BIN}") -else () +else() set(PREFIX_BIN "${CMAKE_INSTALL_PREFIX}/bin") -endif () +endif() # Configuration directory. -if (WITH_PREFIX_CONF_BROKER) - set(PREFIX_CONF "${WITH_PREFIX_CONF_BROKER}") -else () - set(PREFIX_CONF "${CMAKE_INSTALL_PREFIX}/etc") -endif () +if(WITH_PREFIX_CONF_BROKER) + set(PREFIX_BROKER_CONF "${WITH_PREFIX_CONF_BROKER}") +else() + set(PREFIX_BROKER_CONF "${CMAKE_INSTALL_PREFIX}/etc") +endif() # Library directory. -if (WITH_PREFIX_LIB_BROKER) +if(WITH_PREFIX_LIB_BROKER) set(PREFIX_LIB "${WITH_PREFIX_LIB_BROKER}") -else () +else() set(PREFIX_LIB "${CMAKE_INSTALL_PREFIX}/lib") -endif () +endif() # Modules directory. -if (WITH_PREFIX_MODULES) +if(WITH_PREFIX_MODULES) set(PREFIX_MODULES "${WITH_PREFIX_MODULES}") -else () +else() set(PREFIX_MODULES "${PREFIX_LIB}/centreon-broker") -endif () +endif() + +set(PREFIX_CBMOD "${CMAKE_INSTALL_PREFIX}/lib64/nagios") # var directory. -if (WITH_PREFIX_VAR) +if(WITH_PREFIX_VAR) set(PREFIX_VAR "${WITH_PREFIX_VAR}") -else () +else() set(PREFIX_VAR "${CMAKE_INSTALL_PREFIX}/var") -endif () +endif() # Development headers directory. -if (WITH_PREFIX_INC) +if(WITH_PREFIX_INC) set(PREFIX_INC "${WITH_PREFIX_INC}") -else () +else() set(PREFIX_INC "${CMAKE_INSTALL_PREFIX}/include/centreon-broker") -endif () +endif() # User. -if (WITH_USER_BROKER) +if(WITH_USER_BROKER) set(USER "${WITH_USER_BROKER}") -else () +else() set(USER "root") -endif () +endif() # Group. -if (WITH_GROUP_BROKER) +if(WITH_GROUP_BROKER) set(GROUP "${WITH_GROUP_BROKER}") -else () +else() set(GROUP "root") -endif () +endif() # Code coverage on unit tests option(WITH_COVERAGE "Add code coverage on unit tests." OFF) -if (WITH_TESTING AND WITH_COVERAGE) + +if(WITH_TESTING AND WITH_COVERAGE) set(CMAKE_BUILD_TYPE "Debug") include(cmake/CodeCoverage.cmake) - APPEND_COVERAGE_COMPILER_FLAGS() -endif () + append_coverage_compiler_flags() +endif() # Set startup script to auto if not defined. -if (NOT WITH_STARTUP_SCRIPT) +if(NOT WITH_STARTUP_SCRIPT) set(WITH_STARTUP_SCRIPT "auto") -endif () +endif() # Check which startup script to use. -if (WITH_STARTUP_SCRIPT STREQUAL "auto") - if (CMAKE_SYSTEM_NAME STREQUAL "Linux") +if(WITH_STARTUP_SCRIPT STREQUAL "auto") + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(WITH_STARTUP_SCRIPT "sysv") - else () - message(STATUS "Centreon Broker does not provide startup script for ${CMAKE_SYSTEM_NAME}.") + else() + message( + STATUS + "Centreon Broker does not provide startup script for ${CMAKE_SYSTEM_NAME}." + ) set(WITH_STARTUP_SCRIPT "no") - endif () -endif () + endif() +endif() # Startup dir. -if (WITH_STARTUP_SCRIPT STREQUAL "sysv" - OR WITH_STARTUP_SCRIPT STREQUAL "systemd") +if(WITH_STARTUP_SCRIPT STREQUAL "sysv" OR WITH_STARTUP_SCRIPT STREQUAL + "systemd") # Set destination directory. - if (WITH_STARTUP_DIR) + if(WITH_STARTUP_DIR) set(STARTUP_DIR "${WITH_STARTUP_DIR}") - else () + else() set(STARTUP_DIR "/etc/init.d") - endif () -endif () + endif() +endif() # Configure files. -if (WITH_DAEMONS) - if (WITH_STARTUP_SCRIPT STREQUAL "systemd") +if(WITH_DAEMONS) + if(WITH_STARTUP_SCRIPT STREQUAL "systemd") configure_file("${PROJECT_SOURCE_DIR}/script/systemd/cbd.service.in" - "${PROJECT_SOURCE_DIR}/script/cbd.service" - @ONLY) + "${PROJECT_SOURCE_DIR}/script/cbd.service" @ONLY) install(FILES "${PROJECT_SOURCE_DIR}/script/cbd.service" - DESTINATION "${STARTUP_DIR}") - elseif (OS_DISTRIBUTOR STREQUAL "CentOS" OR OS_DISTRIBUTOR STREQUAL "RedHat") + DESTINATION "${STARTUP_DIR}") + elseif(OS_DISTRIBUTOR STREQUAL "CentOS" OR OS_DISTRIBUTOR STREQUAL "RedHat") configure_file("${PROJECT_SOURCE_DIR}/script/redhat/cbd.init.d.in" - "${PROJECT_SOURCE_DIR}/script/cbd.init" - @ONLY) - elseif (OS_DISTRIBUTOR STREQUAL "Debian" OR OS_DISTRIBUTOR STREQUAL "Ubuntu") + "${PROJECT_SOURCE_DIR}/script/cbd.init" @ONLY) + elseif(OS_DISTRIBUTOR STREQUAL "Debian" OR OS_DISTRIBUTOR STREQUAL "Ubuntu") configure_file("${PROJECT_SOURCE_DIR}/script/debian/cbd.init.d.in" - "${PROJECT_SOURCE_DIR}/script/cbd.init" - @ONLY) + "${PROJECT_SOURCE_DIR}/script/cbd.init" @ONLY) configure_file("${PROJECT_SOURCE_DIR}/script/debian/cbd.default.in" - "${PROJECT_SOURCE_DIR}/script/cbd.default" - @ONLY) - install(FILES "${PROJECT_SOURCE_DIR}/script/cbd.default" + "${PROJECT_SOURCE_DIR}/script/cbd.default" @ONLY) + install( + FILES "${PROJECT_SOURCE_DIR}/script/cbd.default" DESTINATION "/etc/default" RENAME "cbd") - else () + else() configure_file("${PROJECT_SOURCE_DIR}/script/other/cbd.init.d.in" - "${PROJECT_SOURCE_DIR}/script/cbd.init" - @ONLY) - endif () + "${PROJECT_SOURCE_DIR}/script/cbd.init" @ONLY) + endif() - foreach (DAEMON_NAME IN LISTS WITH_DAEMONS) + foreach(DAEMON_NAME IN LISTS WITH_DAEMONS) set(DAEMONS_CONFIGURATION - "${DAEMONS_CONFIGURATION} \"cbd\": [ { \"name\": \"${DAEMON_NAME}\", \"configuration_file\": \"${PREFIX_CONF}/${DAEMON_NAME}.json\", \"run\": true, \"reload\": true } ],\n") - endforeach () + "${DAEMONS_CONFIGURATION} \"cbd\": [ { \"name\": \"${DAEMON_NAME}\", \"configuration_file\": \"${PREFIX_BROKER_CONF}/${DAEMON_NAME}.json\", \"run\": true, \"reload\": true } ],\n" + ) + endforeach() configure_file("${PROJECT_SOURCE_DIR}/script/watchdog.json.in" - "${PROJECT_SOURCE_DIR}/script/watchdog.json" - @ONLY) + "${PROJECT_SOURCE_DIR}/script/watchdog.json" @ONLY) install(FILES "${PROJECT_SOURCE_DIR}/script/watchdog.json" - DESTINATION "${PREFIX_CONF}") - if (WITH_STARTUP_SCRIPT STREQUAL "sysv") - install(PROGRAMS "${PROJECT_SOURCE_DIR}/script/cbd.init" + DESTINATION "${PREFIX_BROKER_CONF}") + + if(WITH_STARTUP_SCRIPT STREQUAL "sysv") + install( + PROGRAMS "${PROJECT_SOURCE_DIR}/script/cbd.init" DESTINATION "${STARTUP_DIR}" RENAME "cbd") - endif () -endif () + endif() +endif() -if (WITH_CONFIG_FILES) - configure_file("${PROJECT_SOURCE_DIR}/config/poller-module.json.in" - "${PROJECT_SOURCE_DIR}/config/poller-module.json" - @ONLY) +if(WITH_CONFIG_FILES) + configure_file("${PROJECT_SOURCE_DIR}/config/central-module.json.in" + "${PROJECT_SOURCE_DIR}/config/central-module.json" @ONLY) configure_file("${PROJECT_SOURCE_DIR}/config/central-broker.json.in" - "${PROJECT_SOURCE_DIR}/config/central-broker.json" - @ONLY) + "${PROJECT_SOURCE_DIR}/config/central-broker.json" @ONLY) configure_file("${PROJECT_SOURCE_DIR}/config/central-rrd.json.in" - "${PROJECT_SOURCE_DIR}/config/central-rrd.json" - @ONLY) + "${PROJECT_SOURCE_DIR}/config/central-rrd.json" @ONLY) - install(FILES "${PROJECT_SOURCE_DIR}/config/poller-module.json" - DESTINATION "${PREFIX_CONF}") + install(FILES "${PROJECT_SOURCE_DIR}/config/central-module.json" + DESTINATION "${PREFIX_BROKER_CONF}") install(FILES "${PROJECT_SOURCE_DIR}/config/central-rrd.json" - DESTINATION "${PREFIX_CONF}") + DESTINATION "${PREFIX_BROKER_CONF}") install(FILES "${PROJECT_SOURCE_DIR}/config/central-broker.json" - DESTINATION "${PREFIX_CONF}") -endif () + DESTINATION "${PREFIX_BROKER_CONF}") +endif() # Monitoring engine (for testing). -if (WITH_MONITORING_ENGINE) +if(WITH_MONITORING_ENGINE) set(MONITORING_ENGINE_ADDITIONAL "") set(MONITORING_ENGINE "${WITH_MONITORING_ENGINE}") - if (WITH_MONITORING_ENGINE_MODULES) - foreach (MODULE IN LISTS WITH_MONITORING_ENGINE_MODULES) + + if(WITH_MONITORING_ENGINE_MODULES) + foreach(MODULE IN LISTS WITH_MONITORING_ENGINE_MODULES) set(MONITORING_ENGINE_ADDITIONAL - "${MONITORING_ENGINE_ADDITIONAL}broker_module=${MODULE}\\n") - endforeach () - endif () - if (WITH_MONITORING_ENGINE_INTERVAL_LENGTH) - set(MONITORING_ENGINE_INTERVAL_LENGTH "${WITH_MONITORING_ENGINE_INTERVAL_LENGTH}") - else () + "${MONITORING_ENGINE_ADDITIONAL}broker_module=${MODULE}\\n") + endforeach() + endif() + + if(WITH_MONITORING_ENGINE_INTERVAL_LENGTH) + set(MONITORING_ENGINE_INTERVAL_LENGTH + "${WITH_MONITORING_ENGINE_INTERVAL_LENGTH}") + else() set(MONITORING_ENGINE_INTERVAL_LENGTH 1) - endif () -endif () + endif() +endif() # Broker vars -configure_file( - "${INC_DIR}/vars.hh.in" - "${INC_DIR}/vars.hh" - "@ONLY" -) +configure_file("${INC_DIR}/vars.hh.in" "${INC_DIR}/vars.hh" "@ONLY") # Core library. set(LIBROKER_SOURCES - # Sources. - ${SRC_DIR}/bbdo/acceptor.cc - ${SRC_DIR}/bbdo/ack.cc - ${SRC_DIR}/bbdo/connector.cc - ${SRC_DIR}/bbdo/factory.cc - ${SRC_DIR}/bbdo/internal.cc - ${SRC_DIR}/bbdo/stop.cc - ${SRC_DIR}/bbdo/stream.cc - ${SRC_DIR}/bbdo/version_response.cc - ${SRC_DIR}/broker_impl.cc - ${SRC_DIR}/brokerrpc.cc - ${SRC_DIR}/compression/factory.cc - ${SRC_DIR}/compression/opener.cc - ${SRC_DIR}/compression/stack_array.cc - ${SRC_DIR}/compression/stream.cc - ${SRC_DIR}/compression/zlib.cc - ${SRC_DIR}/config/applier/endpoint.cc - ${SRC_DIR}/config/applier/modules.cc - ${SRC_DIR}/config/applier/state.cc - ${SRC_DIR}/config/endpoint.cc - ${SRC_DIR}/config/parser.cc - ${SRC_DIR}/config/state.cc - ${SRC_DIR}/database_config.cc - ${SRC_DIR}/file/cfile.cc - ${SRC_DIR}/file/directory_event.cc - ${SRC_DIR}/file/directory_watcher.cc - ${SRC_DIR}/file/factory.cc - ${SRC_DIR}/file/fifo.cc - ${SRC_DIR}/file/opener.cc - ${SRC_DIR}/file/splitter.cc - ${SRC_DIR}/file/stream.cc - ${SRC_DIR}/instance_broadcast.cc - ${SRC_DIR}/io/data.cc - ${SRC_DIR}/io/endpoint.cc - ${SRC_DIR}/io/events.cc - ${SRC_DIR}/io/factory.cc - ${SRC_DIR}/io/protocols.cc - ${SRC_DIR}/io/raw.cc - ${SRC_DIR}/io/stream.cc - ${SRC_DIR}/log_v2.cc - ${SRC_DIR}/mapping/entry.cc - ${SRC_DIR}/misc/diagnostic.cc - ${SRC_DIR}/misc/filesystem.cc - ${SRC_DIR}/misc/global_lock.cc - ${SRC_DIR}/misc/misc.cc - ${SRC_DIR}/misc/processing_speed_computer.cc - ${SRC_DIR}/misc/string.cc - ${SRC_DIR}/misc/stringifier.cc - ${SRC_DIR}/misc/tokenizer.cc - ${SRC_DIR}/misc/uuid.cc - ${SRC_DIR}/misc/variant.cc - ${SRC_DIR}/modules/handle.cc - ${SRC_DIR}/multiplexing/engine.cc - ${SRC_DIR}/multiplexing/muxer.cc - ${SRC_DIR}/multiplexing/publisher.cc - ${SRC_DIR}/mysql.cc - ${SRC_DIR}/pool.cc - ${SRC_DIR}/database/mysql_bind.cc - ${SRC_DIR}/database/mysql_column.cc - ${SRC_DIR}/mysql_manager.cc - ${SRC_DIR}/database/mysql_result.cc - ${SRC_DIR}/database/mysql_stmt.cc - ${SRC_DIR}/mysql_connection.cc - ${SRC_DIR}/query_preparator.cc - ${SRC_DIR}/persistent_cache.cc - ${SRC_DIR}/persistent_file.cc - ${SRC_DIR}/processing/acceptor.cc - ${SRC_DIR}/processing/failover.cc - ${SRC_DIR}/processing/feeder.cc - ${SRC_DIR}/processing/stat_visitable.cc - ${SRC_DIR}/stats/center.cc - ${SRC_DIR}/stats/helper.cc - ${SRC_DIR}/time/daterange.cc - ${SRC_DIR}/time/timeperiod.cc - ${SRC_DIR}/time/timerange.cc - ${SRC_DIR}/time/timezone_locker.cc - ${SRC_DIR}/time/timezone_manager.cc - # Headers. - ${INC_DIR}/bbdo/acceptor.hh - ${INC_DIR}/bbdo/ack.hh - ${INC_DIR}/bbdo/connector.hh - ${INC_DIR}/bbdo/factory.hh - ${INC_DIR}/bbdo/internal.hh - ${INC_DIR}/bbdo/stop.hh - ${INC_DIR}/bbdo/stream.hh - ${INC_DIR}/bbdo/version_response.hh - ${INC_DIR}/broker_impl.hh - ${INC_DIR}/brokerrpc.hh - ${INC_DIR}/compression/factory.hh - ${INC_DIR}/compression/opener.hh - ${INC_DIR}/compression/stack_array.hh - ${INC_DIR}/compression/stream.hh - ${INC_DIR}/config/applier/endpoint.hh - ${INC_DIR}/config/applier/init.hh - ${INC_DIR}/config/applier/modules.hh - ${INC_DIR}/config/applier/state.hh - ${INC_DIR}/config/endpoint.hh - ${INC_DIR}/config/parser.hh - ${INC_DIR}/config/state.hh - ${INC_DIR}/database_config.hh - ${INC_DIR}/exceptions/config.hh - ${INC_DIR}/exceptions/interrupt.hh - ${INC_DIR}/exceptions/shutdown.hh - ${INC_DIR}/exceptions/timeout.hh - ${INC_DIR}/file/cfile.hh - ${INC_DIR}/file/directory_event.hh - ${INC_DIR}/file/directory_watcher.hh - ${INC_DIR}/file/factory.hh - ${INC_DIR}/file/fifo.hh - ${INC_DIR}/file/fs_file.hh - ${INC_DIR}/file/opener.hh - ${INC_DIR}/file/splitter.hh - ${INC_DIR}/file/stream.hh - ${INC_DIR}/instance_broadcast.hh - ${INC_DIR}/io/data.hh - ${INC_DIR}/io/endpoint.hh - ${INC_DIR}/io/event_info.hh - ${INC_DIR}/io/events.hh - ${INC_DIR}/io/factory.hh - ${INC_DIR}/io/protocols.hh - ${INC_DIR}/io/raw.hh - ${INC_DIR}/io/stream.hh - ${INC_DIR}/mapping/entry.hh - ${INC_DIR}/mapping/property.hh - ${INC_DIR}/mapping/source.hh - ${INC_DIR}/misc/diagnostic.hh - ${INC_DIR}/misc/filesystem.hh - ${INC_DIR}/misc/global_lock.hh - ${INC_DIR}/misc/misc.hh - ${INC_DIR}/misc/pair.hh - ${INC_DIR}/misc/processing_speed_computer.hh - ${INC_DIR}/misc/shared_mutex.hh - ${INC_DIR}/misc/string.hh - ${INC_DIR}/misc/stringifier.hh - ${INC_DIR}/misc/tokenizer.hh - ${INC_DIR}/misc/variant.hh - ${INC_DIR}/modules/handle.hh - ${INC_DIR}/multiplexing/engine.hh - ${INC_DIR}/multiplexing/muxer.hh - ${INC_DIR}/multiplexing/publisher.hh - ${INC_DIR}/multiplexing/subscriber.hh - ${INC_DIR}/mysql.hh - ${INC_DIR}/pool.hh - ${INC_DIR}/database/mysql_bind.hh - ${INC_DIR}/database/mysql_column.hh - ${INC_DIR}/database/mysql_error.hh - ${INC_DIR}/mysql_manager.hh - ${INC_DIR}/database/mysql_result.hh - ${INC_DIR}/database/mysql_stmt.hh - ${INC_DIR}/database/mysql_task.hh - ${INC_DIR}/database/table_max_size.hh - ${INC_DIR}/mysql_connection.hh - ${INC_DIR}/query_preparator.hh - ${INC_DIR}/persistent_cache.hh - ${INC_DIR}/persistent_file.hh - ${INC_DIR}/processing/acceptor.hh - ${INC_DIR}/processing/failover.hh - ${INC_DIR}/processing/feeder.hh - ${INC_DIR}/processing/stat_visitable.hh - ${INC_DIR}/stats/helper.hh - ${INC_DIR}/time/daterange.hh - ${INC_DIR}/time/ptr_typedef.hh - ${INC_DIR}/time/time_info.hh - ${INC_DIR}/time/timeperiod.hh - ${INC_DIR}/time/timerange.hh - ${INC_DIR}/time/timezone_locker.hh - ${INC_DIR}/time/timezone_manager.hh - ${INC_DIR}/timestamp.hh - ${INC_DIR}/vars.hh - ${INC_DIR}/version.hh - ) + # Sources. + ${SRC_DIR}/bbdo/acceptor.cc + ${SRC_DIR}/bbdo/ack.cc + ${SRC_DIR}/bbdo/connector.cc + ${SRC_DIR}/bbdo/factory.cc + ${SRC_DIR}/bbdo/internal.cc + ${SRC_DIR}/bbdo/stop.cc + ${SRC_DIR}/bbdo/stream.cc + ${SRC_DIR}/bbdo/version_response.cc + ${SRC_DIR}/broker_impl.cc + ${SRC_DIR}/brokerrpc.cc + ${SRC_DIR}/compression/factory.cc + ${SRC_DIR}/compression/opener.cc + ${SRC_DIR}/compression/stack_array.cc + ${SRC_DIR}/compression/stream.cc + ${SRC_DIR}/compression/zlib.cc + ${SRC_DIR}/config/applier/endpoint.cc + ${SRC_DIR}/config/applier/modules.cc + ${SRC_DIR}/config/applier/state.cc + ${SRC_DIR}/config/endpoint.cc + ${SRC_DIR}/config/parser.cc + ${SRC_DIR}/config/state.cc + ${SRC_DIR}/database_config.cc + ${SRC_DIR}/file/cfile.cc + ${SRC_DIR}/file/directory_event.cc + ${SRC_DIR}/file/directory_watcher.cc + ${SRC_DIR}/file/factory.cc + ${SRC_DIR}/file/fifo.cc + ${SRC_DIR}/file/opener.cc + ${SRC_DIR}/file/splitter.cc + ${SRC_DIR}/file/stream.cc + ${SRC_DIR}/instance_broadcast.cc + ${SRC_DIR}/io/data.cc + ${SRC_DIR}/io/endpoint.cc + ${SRC_DIR}/io/events.cc + ${SRC_DIR}/io/factory.cc + ${SRC_DIR}/io/protocols.cc + ${SRC_DIR}/io/raw.cc + ${SRC_DIR}/io/stream.cc + ${SRC_DIR}/log_v2.cc + ${SRC_DIR}/mapping/entry.cc + ${SRC_DIR}/misc/diagnostic.cc + ${SRC_DIR}/misc/filesystem.cc + ${SRC_DIR}/misc/global_lock.cc + ${SRC_DIR}/misc/misc.cc + ${SRC_DIR}/misc/processing_speed_computer.cc + ${SRC_DIR}/misc/string.cc + ${SRC_DIR}/misc/stringifier.cc + ${SRC_DIR}/misc/tokenizer.cc + ${SRC_DIR}/misc/uuid.cc + ${SRC_DIR}/misc/variant.cc + ${SRC_DIR}/modules/handle.cc + ${SRC_DIR}/multiplexing/engine.cc + ${SRC_DIR}/multiplexing/muxer.cc + ${SRC_DIR}/multiplexing/publisher.cc + ${SRC_DIR}/mysql.cc + ${SRC_DIR}/pool.cc + ${SRC_DIR}/database/mysql_bind.cc + ${SRC_DIR}/database/mysql_column.cc + ${SRC_DIR}/mysql_manager.cc + ${SRC_DIR}/database/mysql_result.cc + ${SRC_DIR}/database/mysql_stmt.cc + ${SRC_DIR}/mysql_connection.cc + ${SRC_DIR}/query_preparator.cc + ${SRC_DIR}/persistent_cache.cc + ${SRC_DIR}/persistent_file.cc + ${SRC_DIR}/processing/acceptor.cc + ${SRC_DIR}/processing/failover.cc + ${SRC_DIR}/processing/feeder.cc + ${SRC_DIR}/processing/stat_visitable.cc + ${SRC_DIR}/stats/center.cc + ${SRC_DIR}/stats/helper.cc + ${SRC_DIR}/time/daterange.cc + ${SRC_DIR}/time/timeperiod.cc + ${SRC_DIR}/time/timerange.cc + ${SRC_DIR}/time/timezone_locker.cc + ${SRC_DIR}/time/timezone_manager.cc + # Headers. + ${INC_DIR}/bbdo/acceptor.hh + ${INC_DIR}/bbdo/ack.hh + ${INC_DIR}/bbdo/connector.hh + ${INC_DIR}/bbdo/factory.hh + ${INC_DIR}/bbdo/internal.hh + ${INC_DIR}/bbdo/stop.hh + ${INC_DIR}/bbdo/stream.hh + ${INC_DIR}/bbdo/version_response.hh + ${INC_DIR}/broker_impl.hh + ${INC_DIR}/brokerrpc.hh + ${INC_DIR}/compression/factory.hh + ${INC_DIR}/compression/opener.hh + ${INC_DIR}/compression/stack_array.hh + ${INC_DIR}/compression/stream.hh + ${INC_DIR}/config/applier/endpoint.hh + ${INC_DIR}/config/applier/init.hh + ${INC_DIR}/config/applier/modules.hh + ${INC_DIR}/config/applier/state.hh + ${INC_DIR}/config/endpoint.hh + ${INC_DIR}/config/parser.hh + ${INC_DIR}/config/state.hh + ${INC_DIR}/database_config.hh + ${INC_DIR}/exceptions/config.hh + ${INC_DIR}/exceptions/interrupt.hh + ${INC_DIR}/exceptions/shutdown.hh + ${INC_DIR}/exceptions/timeout.hh + ${INC_DIR}/file/cfile.hh + ${INC_DIR}/file/directory_event.hh + ${INC_DIR}/file/directory_watcher.hh + ${INC_DIR}/file/factory.hh + ${INC_DIR}/file/fifo.hh + ${INC_DIR}/file/fs_file.hh + ${INC_DIR}/file/opener.hh + ${INC_DIR}/file/splitter.hh + ${INC_DIR}/file/stream.hh + ${INC_DIR}/instance_broadcast.hh + ${INC_DIR}/io/data.hh + ${INC_DIR}/io/endpoint.hh + ${INC_DIR}/io/event_info.hh + ${INC_DIR}/io/events.hh + ${INC_DIR}/io/factory.hh + ${INC_DIR}/io/protocols.hh + ${INC_DIR}/io/raw.hh + ${INC_DIR}/io/stream.hh + ${INC_DIR}/mapping/entry.hh + ${INC_DIR}/mapping/property.hh + ${INC_DIR}/mapping/source.hh + ${INC_DIR}/misc/diagnostic.hh + ${INC_DIR}/misc/filesystem.hh + ${INC_DIR}/misc/global_lock.hh + ${INC_DIR}/misc/misc.hh + ${INC_DIR}/misc/pair.hh + ${INC_DIR}/misc/processing_speed_computer.hh + ${INC_DIR}/misc/shared_mutex.hh + ${INC_DIR}/misc/string.hh + ${INC_DIR}/misc/stringifier.hh + ${INC_DIR}/misc/tokenizer.hh + ${INC_DIR}/misc/variant.hh + ${INC_DIR}/modules/handle.hh + ${INC_DIR}/multiplexing/engine.hh + ${INC_DIR}/multiplexing/muxer.hh + ${INC_DIR}/multiplexing/publisher.hh + ${INC_DIR}/multiplexing/subscriber.hh + ${INC_DIR}/mysql.hh + ${INC_DIR}/pool.hh + ${INC_DIR}/database/mysql_bind.hh + ${INC_DIR}/database/mysql_column.hh + ${INC_DIR}/database/mysql_error.hh + ${INC_DIR}/mysql_manager.hh + ${INC_DIR}/database/mysql_result.hh + ${INC_DIR}/database/mysql_stmt.hh + ${INC_DIR}/database/mysql_task.hh + ${INC_DIR}/database/table_max_size.hh + ${INC_DIR}/mysql_connection.hh + ${INC_DIR}/query_preparator.hh + ${INC_DIR}/persistent_cache.hh + ${INC_DIR}/persistent_file.hh + ${INC_DIR}/processing/acceptor.hh + ${INC_DIR}/processing/failover.hh + ${INC_DIR}/processing/feeder.hh + ${INC_DIR}/processing/stat_visitable.hh + ${INC_DIR}/stats/helper.hh + ${INC_DIR}/time/daterange.hh + ${INC_DIR}/time/ptr_typedef.hh + ${INC_DIR}/time/time_info.hh + ${INC_DIR}/time/timeperiod.hh + ${INC_DIR}/time/timerange.hh + ${INC_DIR}/time/timezone_locker.hh + ${INC_DIR}/time/timezone_manager.hh + ${INC_DIR}/timestamp.hh + ${INC_DIR}/vars.hh + ${INC_DIR}/version.hh) # Static libraries. add_library(rokerbase STATIC ${LIBROKER_SOURCES}) set_target_properties(rokerbase PROPERTIES COMPILE_FLAGS "-fPIC") -target_link_libraries(rokerbase ${ZLIB_LIBRARIES} ${OpenSSL_LIBS} ${mariadb-connector-c_LIBS} pthread dl berpc) - -add_library(roker STATIC - ${SRC_DIR}/config/applier/init.cc) -target_link_libraries(roker rokerbase dl ${c-ares_LIBS} ${OpenSSL_LIBS} ${gRPC_LIBS} ${absl_LIBS} pthread) - +target_link_libraries( + rokerbase + CONAN_PKG::zlib + CONAN_PKG::spdlog + CONAN_PKG::openssl + CONAN_PKG::mariadb-connector-c + pthread + dl + berpc) + +add_library(roker STATIC ${SRC_DIR}/config/applier/init.cc) +target_link_libraries(roker rokerbase dl CONAN_PKG::openssl CONAN_PKG::grpc + pthread) # Standalone binary. set(DAEMON cbd) add_executable(${DAEMON} ${SRC_DIR}/main.cc) -#Flags needed to include all symbols in binary. -target_link_libraries("${DAEMON}" - "-Wl,--whole-archive" rokerbase roker "-Wl,--no-whole-archive" ${nlohmann_json_LIBS} ${fmt_LIBS} ${spdlog_LIBS} ${gRPC_LIBS} ${re2_LIBS} ${absl_LIBS} ) +# Flags needed to include all symbols in binary. +target_link_libraries( + "${DAEMON}" + "-Wl,--whole-archive" + rokerbase + roker + "-Wl,--no-whole-archive" + CONAN_PKG::nlohmann_json + CONAN_PKG::spdlog + CONAN_PKG::grpc) # Centreon Broker Watchdog option(WITH_CBWD "Build centreon broker watchdog." ON) -if (WITH_CBWD) + +if(WITH_CBWD) add_subdirectory(watchdog) -endif () +endif() # Module list. unset(MODULE_LIST) @@ -604,41 +596,48 @@ add_broker_module(DUMP OFF) # Lua module. option(WITH_MODULE_LUA "Build lua module." ON) + # Simu module. option(WITH_MODULE_SIMU "Build simu module." OFF) -if (WITH_MODULE_LUA OR WITH_MODULE_SIMU) - foreach (vers "Lua" "Lua52" "Lua51") + +if(WITH_MODULE_LUA OR WITH_MODULE_SIMU) + foreach(vers "Lua" "Lua52" "Lua51") find_package("${vers}") - if (DEFINED LUA_VERSION_STRING) - string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.[0-9]+" "\\1\\2" v "${LUA_VERSION_STRING}") + + if(DEFINED LUA_VERSION_STRING) + string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.[0-9]+" "\\1\\2" v + "${LUA_VERSION_STRING}") add_definitions(-DLUA${v}) include_directories("${LUA_INCLUDE_DIR}") - if (WITH_MODULE_LUA) + + if(WITH_MODULE_LUA) add_subdirectory("lua") list(APPEND MODULE_LIST "lua") - endif () - if (WITH_MODULE_SIMU) + endif() + + if(WITH_MODULE_SIMU) add_subdirectory("simu") list(APPEND MODULE_LIST "simu") - endif () + endif() break() - endif () - endforeach () - if (NOT DEFINED LUA_VERSION_STRING) + endif() + endforeach() + + if(NOT DEFINED LUA_VERSION_STRING) message(FATAL_ERROR "No Lua development package found.") - endif () -endif () + endif() +endif() # Format string. string(REPLACE ";" ", " MODULE_LIST "${MODULE_LIST}") - # # Install stuff. # # Create directories. -install(CODE " +install( + CODE " function(mkdir_chown user group path) if (APPLE OR (UNIX AND NOT CYGWIN)) if (NOT EXISTS \"\$ENV{DESTDIR}\${path}\") @@ -665,8 +664,9 @@ install(CODE " mkdir_chown(\"${USER}\" \"${GROUP}\" \"${PREFIX_BIN}\") mkdir_chown(\"${USER}\" \"${GROUP}\" \"${PREFIX_LIB}\") mkdir_chown(\"${USER}\" \"${GROUP}\" \"${PREFIX_MODULES}\") + mkdir_chown(\"${USER}\" \"${GROUP}\" \"${PREFIX_CBMOD}\") mkdir_chown(\"${USER}\" \"${GROUP}\" \"${PREFIX_INC}\") - mkdir_chown(\"${USER}\" \"${GROUP}\" \"${PREFIX_CONF}\") + mkdir_chown(\"${USER}\" \"${GROUP}\" \"${PREFIX_BROKER_CONF}\") mkdir_chown(\"${USER}\" \"${GROUP}\" \"${PREFIX_VAR}\") if (WITH_STARTUP_SCRIPT STREQUAL \"sysv\") mkdir_chown(\"${USER}\" \"${GROUP}\" \"${STARTUP_DIR}\") @@ -674,22 +674,20 @@ install(CODE " ") # Install rule. -install(TARGETS "${DAEMON}" - RUNTIME DESTINATION "${PREFIX_BIN}" - ) - +install(TARGETS "${DAEMON}" RUNTIME DESTINATION "${PREFIX_BIN}") # Install header files for development. -install(DIRECTORY "${INC_DIR}/../../../" +install( + DIRECTORY "${INC_DIR}/../../../" DESTINATION "${PREFIX_INC}/" COMPONENT "development" - FILES_MATCHING PATTERN "*.hh" PATTERN "*.h" - ) + FILES_MATCHING + PATTERN "*.hh" + PATTERN "*.h") # # Packaging. # - include(cmake/package.cmake) # @@ -697,16 +695,16 @@ include(cmake/package.cmake) # # Enable testing. option(WITH_TESTING "Generate unit tests." OFF) -if (WITH_TESTING) + +if(WITH_TESTING) add_subdirectory(test) -endif () +endif() option(WITH_SQL_TESTS "Sql unit tests are enabled." OFF) # # Print summary. # - message(STATUS "") message(STATUS "") message(STATUS "Configuration Summary") @@ -722,28 +720,36 @@ message(STATUS " - Version ${CMAKE_SYSTEM_VERSION}") message(STATUS " - Processor ${CMAKE_SYSTEM_PROCESSOR}") message(STATUS "") message(STATUS " Build") -message(STATUS " - Compiler ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_ID})") +message( + STATUS + " - Compiler ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_ID})" +) message(STATUS " - Extra compilation flags ${CMAKE_CXX_FLAGS}") -if (WITH_TESTING) + +if(WITH_TESTING) message(STATUS " - Unit tests enabled") - if (MONITORING_ENGINE) + + if(MONITORING_ENGINE) message(STATUS " - Monitoring engine ${MONITORING_ENGINE}") - else () + else() message(STATUS " - Monitoring engine none") - endif () - if (WITH_COVERAGE) + endif() + + if(WITH_COVERAGE) message(STATUS " - Code coverage enabled") - else () + else() message(STATUS " - Code coverage disabled") - endif () -else () + endif() +else() message(STATUS " - Unit tests disabled") -endif () -if (WITH_STARTUP_SCRIPT STREQUAL "no") +endif() + +if(WITH_STARTUP_SCRIPT STREQUAL "no") message(STATUS " - Startup script disabled") -else () +else() message(STATUS " - Startup script ${WITH_STARTUP_SCRIPT}") -endif () +endif() + message(STATUS " - Module ${MODULE_LIST}") message(STATUS "") message(STATUS " Install") @@ -752,10 +758,12 @@ message(STATUS " - Binary prefix ${PREFIX_BIN}") message(STATUS " - Library prefix ${PREFIX_LIB}") message(STATUS " - Modules prefix ${PREFIX_MODULES}") message(STATUS " - Include prefix ${PREFIX_INC}") -message(STATUS " - Configuration prefix ${PREFIX_CONF}") -if (NOT WITH_STARTUP_SCRIPT STREQUAL "no") +message(STATUS " - Configuration prefix ${PREFIX_BROKER_CONF}") + +if(NOT WITH_STARTUP_SCRIPT STREQUAL "no") message(STATUS " - Startup dir ${STARTUP_DIR}") -endif () +endif() + message(STATUS " - User ${USER}") message(STATUS " - Group ${GROUP}") message(STATUS " - Package ${PACKAGE_LIST}") diff --git a/centreon-broker/bam/CMakeLists.txt b/centreon-broker/bam/CMakeLists.txt index 8c5b293aa2a..ee6aeb63244 100644 --- a/centreon-broker/bam/CMakeLists.txt +++ b/centreon-broker/bam/CMakeLists.txt @@ -1,20 +1,20 @@ -## -## Copyright 2011-2021 Centreon -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -## For more information : contact@centreon.com -## +# +# Copyright 2011-2021 Centreon +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# For more information : contact@centreon.com +# # Global options. set(INC_DIR "${PROJECT_SOURCE_DIR}/bam/inc") @@ -27,8 +27,11 @@ set(INC_DIR "${INC_DIR}/com/centreon/broker/bam") # BAM module. set(BAM "20-bam") -set(BAM "${BAM}" PARENT_SCOPE) -add_library("${BAM}" SHARED +set(BAM + "${BAM}" + PARENT_SCOPE) +add_library( + "${BAM}" SHARED # Sources. "${SRC_DIR}/availability_builder.cc" "${SRC_DIR}/availability_thread.cc" @@ -158,21 +161,18 @@ add_library("${BAM}" SHARED "${INC_DIR}/reporting_stream.hh" "${INC_DIR}/service_book.hh" "${INC_DIR}/service_listener.hh" - "${INC_DIR}/timeperiod_map.hh" -) -set_target_properties("${BAM}" PROPERTIES - PREFIX "") -target_link_libraries("${BAM}" ${absl_LIBS}) + "${INC_DIR}/timeperiod_map.hh") +set_target_properties("${BAM}" PROPERTIES PREFIX "") +target_link_libraries("${BAM}" CONAN_PKG::spdlog CONAN_PKG::abseil) # Testing. -if (WITH_SQL_TESTS) - set(TESTS_SOURCES ${TESTS_SOURCES} ${TEST_DIR}/monitoring_stream.cc) - set(TESTS_SOURCES ${TESTS_SOURCES} ${TEST_DIR}/reporting_stream.cc) -endif (WITH_SQL_TESTS) +if(WITH_SQL_TESTS) + set(TESTS_SOURCES ${TESTS_SOURCES} ${TEST_DIR}/monitoring_stream.cc) + set(TESTS_SOURCES ${TESTS_SOURCES} ${TEST_DIR}/reporting_stream.cc) +endif(WITH_SQL_TESTS) -if (WITH_TESTING ) - set( - TESTS_SOURCES +if(WITH_TESTING) + set(TESTS_SOURCES ${TESTS_SOURCES} ${TEST_DIR}/ba/kpi_service.cc ${TEST_DIR}/ba/kpi_ba.cc @@ -182,17 +182,11 @@ if (WITH_TESTING ) ${TEST_DIR}/exp_parser/get_postfix.cc ${TEST_DIR}/exp_tokenizer/next.cc ${TEST_DIR}/time/check_timeperiod.cc - PARENT_SCOPE - ) - set( - TESTS_LIBRARIES - ${TESTS_LIBRARIES} - ${BAM} - PARENT_SCOPE - ) -endif (WITH_TESTING) + PARENT_SCOPE) + set(TESTS_LIBRARIES + ${TESTS_LIBRARIES} ${BAM} + PARENT_SCOPE) +endif(WITH_TESTING) # Install rule. -install(TARGETS "${BAM}" - LIBRARY DESTINATION "${PREFIX_MODULES}" -) +install(TARGETS "${BAM}" LIBRARY DESTINATION "${PREFIX_MODULES}") diff --git a/centreon-broker/bam/inc/com/centreon/broker/bam/configuration/kpi.hh b/centreon-broker/bam/inc/com/centreon/broker/bam/configuration/kpi.hh index 13d72b3372c..a15a798e1c2 100644 --- a/centreon-broker/bam/inc/com/centreon/broker/bam/configuration/kpi.hh +++ b/centreon-broker/bam/inc/com/centreon/broker/bam/configuration/kpi.hh @@ -73,7 +73,6 @@ class kpi { uint32_t get_meta_id() const; uint32_t get_boolexp_id() const; short get_status() const; - short get_last_level() const; bool is_downtimed() const; bool is_acknowledged() const; bool ignore_downtime() const; @@ -92,7 +91,6 @@ class kpi { void set_meta_id(uint32_t meta_id); void set_boolexp_id(uint32_t boolexp_id); void set_status(short status); - void set_last_level(short last_level); void set_downtimed(bool downtimed); void set_acknowledged(bool acknowledged); void ignore_downtime(bool ignore); @@ -112,7 +110,6 @@ class kpi { uint32_t _meta_id; uint32_t _boolexp_id; short _status; - short _last_level; bool _downtimed; bool _acknowledged; bool _ignore_downtime; diff --git a/centreon-broker/bam/src/configuration/kpi.cc b/centreon-broker/bam/src/configuration/kpi.cc index 94a92c5c0fb..bc7cba82667 100644 --- a/centreon-broker/bam/src/configuration/kpi.cc +++ b/centreon-broker/bam/src/configuration/kpi.cc @@ -49,7 +49,6 @@ kpi::kpi(uint32_t id, _meta_id(meta_id), _boolexp_id(boolexp_id), _status(status), - _last_level(last_level), _downtimed(downtimed), _acknowledged(acknowledged), _ignore_downtime(ignore_downtime), @@ -74,7 +73,6 @@ kpi::kpi(kpi const& other) _meta_id(other._meta_id), _boolexp_id(other._boolexp_id), _status(other._status), - _last_level(other._last_level), _downtimed(other._downtimed), _acknowledged(other._acknowledged), _ignore_downtime(other._ignore_downtime), @@ -107,7 +105,6 @@ kpi& kpi::operator=(kpi const& other) { _meta_id = other._meta_id; _boolexp_id = other._boolexp_id; _status = other._status; - _last_level = other._last_level; _downtimed = other._downtimed; _acknowledged = other._acknowledged; _ignore_downtime = other._ignore_downtime; @@ -129,19 +126,16 @@ kpi& kpi::operator=(kpi const& other) { */ bool kpi::operator==(kpi const& other) const { return _id == other._id && _state_type == other._state_type && - _host_id == other._host_id && _service_id == other._service_id && - _ba_id == other._ba_id && - _indicator_ba_id == other._indicator_ba_id && - _meta_id == other._meta_id && _boolexp_id == other._boolexp_id && - _status == other._status && _last_level == other._last_level && - _downtimed == other._downtimed && - _acknowledged == other._acknowledged && - _ignore_downtime == other._ignore_downtime && - _ignore_acknowledgement == other._ignore_acknowledgement && - _impact_warning == other._impact_warning && - _impact_critical == other._impact_critical && - _impact_unknown == other._impact_unknown && - _event == other._event; + _host_id == other._host_id && _service_id == other._service_id && + _ba_id == other._ba_id && _indicator_ba_id == other._indicator_ba_id && + _meta_id == other._meta_id && _boolexp_id == other._boolexp_id && + _status == other._status && _downtimed == other._downtimed && + _acknowledged == other._acknowledged && + _ignore_downtime == other._ignore_downtime && + _ignore_acknowledgement == other._ignore_acknowledgement && + _impact_warning == other._impact_warning && + _impact_critical == other._impact_critical && + _impact_unknown == other._impact_unknown && _event == other._event; } /** @@ -281,15 +275,6 @@ short kpi::get_status() const { return _status; } -/** - * Get the last level of this kpi. - * - * @return The last level of this kpi. - */ -short kpi::get_last_level() const { - return _last_level; -} - /** * Is this kpi set to downtime mode ? * @@ -437,15 +422,6 @@ void kpi::set_status(short s) { _status = s; } -/** - * Set last_level. - * - * @param[in] s Set the last level of the kpi. - */ -void kpi::set_last_level(short s) { - _last_level = s; -} - /** * Set downtimed. * diff --git a/centreon-broker/bam/src/configuration/reader_v2.cc b/centreon-broker/bam/src/configuration/reader_v2.cc index 3bae3e1d713..335c6737a83 100644 --- a/centreon-broker/bam/src/configuration/reader_v2.cc +++ b/centreon-broker/bam/src/configuration/reader_v2.cc @@ -91,7 +91,7 @@ void reader_v2::_load(state::kpis& kpis) { std::string query(fmt::format( "SELECT k.kpi_id, k.state_type, k.host_id, k.service_id, k.id_ba," " k.id_indicator_ba, k.meta_id, k.boolean_id," - " k.current_status, k.last_level, k.downtime," + " k.current_status, k.downtime," " k.acknowledged, k.ignore_downtime," " k.ignore_acknowledged," " COALESCE(COALESCE(k.drop_warning, ww.impact), " @@ -138,21 +138,20 @@ void reader_v2::_load(state::kpis& kpis) { res.value_as_u32(6), // Meta-service ID. res.value_as_u32(7), // Boolean expression ID. res.value_as_i32(8), // Status. - res.value_as_i32(9), // Last level. - res.value_as_f32(10), // Downtimed. - res.value_as_f32(11), // Acknowledged. - res.value_as_bool(12), // Ignore downtime. - res.value_as_bool(13), // Ignore acknowledgement. - res.value_as_f64(14), // Warning. - res.value_as_f64(15), // Critical. - res.value_as_f64(16)); // Unknown. + res.value_as_f32(9), // Downtimed. + res.value_as_f32(10), // Acknowledged. + res.value_as_bool(11), // Ignore downtime. + res.value_as_bool(12), // Ignore acknowledgement. + res.value_as_f64(13), // Warning. + res.value_as_f64(14), // Critical. + res.value_as_f64(15)); // Unknown. // KPI state. - if (!res.value_is_null(17)) { - kpi_event e(kpi_id, res.value_as_u32(4), res.value_as_u64(17)); + if (!res.value_is_null(16)) { + kpi_event e(kpi_id, res.value_as_u32(4), res.value_as_u64(16)); e.status = res.value_as_i32(8); - e.in_downtime = res.value_as_bool(18); - e.impact_level = res.value_is_null(19) ? -1 : res.value_as_f64(19); + e.in_downtime = res.value_as_bool(17); + e.impact_level = res.value_is_null(18) ? -1 : res.value_as_f64(18); kpis[kpi_id].set_opened_event(e); } } diff --git a/centreon-broker/config/poller-module.json.in b/centreon-broker/config/central-module.json.in similarity index 100% rename from centreon-broker/config/poller-module.json.in rename to centreon-broker/config/central-module.json.in diff --git a/centreon-broker/core/inc/com/centreon/broker/exceptions/deprecated.hh b/centreon-broker/core/inc/com/centreon/broker/exceptions/deprecated.hh new file mode 100644 index 00000000000..f339ee92d14 --- /dev/null +++ b/centreon-broker/core/inc/com/centreon/broker/exceptions/deprecated.hh @@ -0,0 +1,49 @@ +/* +** Copyright 2022 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_EXCEPTIONS_DEPRECATED_HH +#define CCB_EXCEPTIONS_DEPRECATED_HH + +#include "com/centreon/broker/namespace.hh" +#include "com/centreon/exceptions/msg_fmt.hh" + +CCB_BEGIN() + +namespace exceptions { +/** + * @class deprecated deprecated.hh + * "com/centreon/broker/exceptions/deprecated.hh" + * @brief Shutdown exception class. + * + * This exception is thrown when someone attemps to read from a + * stream that has been deprecated. + */ +class deprecated : public com::centreon::exceptions::msg_fmt { + public: + template + explicit deprecated(std::string const& str, const Args&... args) + : msg_fmt(str, args...) {} + deprecated() = delete; + ~deprecated() noexcept = default; + deprecated& operator=(const deprecated&) = delete; +}; +} // namespace exceptions + +CCB_END() + +#endif // !CCB_EXCEPTIONS_DEPRECATED_HH diff --git a/centreon-broker/core/inc/com/centreon/broker/stats/center.hh b/centreon-broker/core/inc/com/centreon/broker/stats/center.hh index c217a6776e8..2873f7002e2 100644 --- a/centreon-broker/core/inc/com/centreon/broker/stats/center.hh +++ b/centreon-broker/core/inc/com/centreon/broker/stats/center.hh @@ -55,8 +55,8 @@ namespace stats { */ class center { static center* _instance; - asio::io_context::strand _strand; BrokerStats _stats; + std::mutex _stats_m; int _json_stats_file_creation; center(); @@ -91,7 +91,8 @@ class center { */ template void update(T* ptr, T value) { - _strand.post([ptr, value = std::move(value)] { *ptr = value; }); + std::lock_guard lck(_stats_m); + *ptr = std::move(value); } /** @@ -121,17 +122,19 @@ class center { */ template void update(void (U::*f)(T), U* ptr, T value) { - _strand.post([ptr, f, value] { (ptr->*f)(value); }); + std::lock_guard lck(_stats_m); + (ptr->*f)(value); } - void execute(std::function f) { _strand.post(f); } + void execute(std::function f) { + std::lock_guard lck(_stats_m); + f(); + } template const T& get(T (U::*f)() const, const U* ptr) { - std::promise p; - std::future retval = p.get_future(); - _strand.post([&p, ptr, f] { p.set_value((ptr->*f)()); }); - return retval.get(); + std::lock_guard lck(_stats_m); + return (ptr->*f)(); } }; diff --git a/centreon-broker/core/src/config/applier/endpoint.cc b/centreon-broker/core/src/config/applier/endpoint.cc index 9f449636e27..72343a2ce4c 100644 --- a/centreon-broker/core/src/config/applier/endpoint.cc +++ b/centreon-broker/core/src/config/applier/endpoint.cc @@ -1,5 +1,5 @@ /* -** Copyright 2011-2012,2015,2017-2021 Centreon +** Copyright 2011-2012,2015,2017-2022 Centreon ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. @@ -370,40 +370,42 @@ processing::failover* endpoint::_create_failover( std::list::iterator it( std::find_if(l.begin(), l.end(), failover_match_name(front_failover))); if (it == l.end()) - throw msg_fmt( + log_v2::config()->error( "endpoint applier: could not find failover '{}' for endpoint '{}'", front_failover, cfg.name); - bool is_acceptor; - std::shared_ptr e(_create_endpoint(*it, is_acceptor)); - if (is_acceptor) - throw msg_fmt( - "endpoint applier: cannot allow acceptor '{}' " - "as failover for endpoint '{}'", - front_failover, cfg.name); - failovr = std::shared_ptr( - _create_failover(*it, sbscrbr, e, l)); - - // Add secondary failovers - for (std::list::const_iterator - failover_it(++cfg.failovers.begin()), - failover_end(cfg.failovers.end()); - failover_it != failover_end; ++failover_it) { - auto it = - std::find_if(l.begin(), l.end(), failover_match_name(*failover_it)); - if (it == l.end()) + else { + bool is_acceptor; + std::shared_ptr e(_create_endpoint(*it, is_acceptor)); + if (is_acceptor) throw msg_fmt( - "endpoint applier: could not find " - "secondary failover '{}' for endpoint '{}'", - *failover_it, cfg.name); - bool is_acceptor{false}; - std::shared_ptr endp(_create_endpoint(*it, is_acceptor)); - if (is_acceptor) { - log_v2::config()->error( - "endpoint applier: secondary failover '{}' is an acceptor and " - "cannot therefore be instantiated for endpoint '{}'", - *failover_it, cfg.name); + "endpoint applier: cannot allow acceptor '{}' " + "as failover for endpoint '{}'", + front_failover, cfg.name); + failovr = std::shared_ptr( + _create_failover(*it, sbscrbr, e, l)); + + // Add secondary failovers + for (std::list::const_iterator + failover_it(++cfg.failovers.begin()), + failover_end(cfg.failovers.end()); + failover_it != failover_end; ++failover_it) { + auto it = + std::find_if(l.begin(), l.end(), failover_match_name(*failover_it)); + if (it == l.end()) + throw msg_fmt( + "endpoint applier: could not find " + "secondary failover '{}' for endpoint '{}'", + *failover_it, cfg.name); + bool is_acceptor{false}; + std::shared_ptr endp(_create_endpoint(*it, is_acceptor)); + if (is_acceptor) { + log_v2::config()->error( + "endpoint applier: secondary failover '{}' is an acceptor and " + "cannot therefore be instantiated for endpoint '{}'", + *failover_it, cfg.name); + } + failovr->add_secondary_endpoint(endp); } - failovr->add_secondary_endpoint(endp); } } @@ -430,20 +432,21 @@ std::shared_ptr endpoint::_create_endpoint(config::endpoint& cfg, std::shared_ptr endp; int level{0}; for (std::map::const_iterator - it(io::protocols::instance().begin()), - end(io::protocols::instance().end()); + it = io::protocols::instance().begin(), + end = io::protocols::instance().end(); it != end; ++it) { if (it->second.osi_from == 1 && it->second.endpntfactry->has_endpoint(cfg, nullptr)) { std::shared_ptr cache; - if (cfg.cache_enabled) { - std::string cache_path(config::applier::state::instance().cache_dir()); - cache_path.append(".cache."); - cache_path.append(cfg.name); - cache = std::make_shared(cache_path); - } + if (cfg.cache_enabled) + cache = std::make_shared(fmt::format( + "{}.cache.{}", config::applier::state::instance().cache_dir(), + cfg.name)); + endp = std::shared_ptr( it->second.endpntfactry->new_endpoint(cfg, is_acceptor, cache)); + log_v2::config()->info(" create endpoint {} for endpoint '{}'", it->first, + cfg.name); level = it->second.osi_to + 1; break; } @@ -464,6 +467,8 @@ std::shared_ptr endpoint::_create_endpoint(config::endpoint& cfg, (it->second.endpntfactry->has_endpoint(cfg, nullptr))) { std::shared_ptr current( it->second.endpntfactry->new_endpoint(cfg, is_acceptor)); + log_v2::config()->info(" create endpoint {} for endpoint '{}'", + it->first, cfg.name); current->from(endp); endp = current; level = it->second.osi_to; @@ -523,12 +528,14 @@ void endpoint::_diff_endpoints( list_it = std::find_if(new_ep.begin(), new_ep.end(), failover_match_name(failover)); if (list_it == new_ep.end()) - throw msg_fmt( - "endpoint applier: could not find failover '{}'" - "' for endpoint '{}'", + log_v2::config()->error( + "endpoint applier: could not find failover '{}' for endpoint " + "'{}'", failover, entry.name); - entries.push_back(*list_it); - new_ep.erase(list_it); + else { + entries.push_back(*list_it); + new_ep.erase(list_it); + } } } @@ -561,8 +568,8 @@ std::unordered_set endpoint::_filters( it = tmp_elements.cbegin(), end = tmp_elements.cend(); it != end; ++it) { - log_v2::config()->info("endpoint applier: new filtering element: {}", - it->first); + log_v2::config()->debug("endpoint applier: new filtering element: {}", + it->first); elements.insert(it->first); retval = true; } diff --git a/centreon-broker/core/src/config/parser.cc b/centreon-broker/core/src/config/parser.cc index 43624db123e..aad54c0e674 100644 --- a/centreon-broker/core/src/config/parser.cc +++ b/centreon-broker/core/src/config/parser.cc @@ -1,5 +1,5 @@ /* -** Copyright 2011-2013,2015,2017-2021 Centreon +** Copyright 2011-2013,2015,2017-2022 Centreon ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ #include #include +#include "com/centreon/broker/exceptions/deprecated.hh" #include "com/centreon/broker/log_v2.hh" #include "com/centreon/broker/misc/string.hh" #include "com/centreon/exceptions/msg_fmt.hh" @@ -34,6 +35,9 @@ using namespace com::centreon::broker; using namespace com::centreon::broker::config; using namespace nlohmann; +using msg_fmt = com::centreon::exceptions::msg_fmt; +using deprecated = com::centreon::broker::exceptions::deprecated; + /** * Default constructor. */ @@ -52,15 +56,12 @@ static bool get_conf(std::pair const& obj, bool (json::*is_goodtype)() const, T (json::*get_value)() const) { if (obj.first == key) { - json const& value = obj.second; + const json& value = obj.second; if ((value.*is_goodtype)()) (s.*set_state)((value.*get_value)()); else throw msg_fmt( - "config parser: cannot parse key '{}': " - "value type is invalid", - key); - ; + "config parser: cannot parse key '{}': value type is invalid", key); return true; } return false; @@ -73,7 +74,7 @@ static bool get_conf(std::pair const& obj, void (U::*set_state)(const std::string&), bool (json::*is_goodtype)() const) { if (obj.first == key) { - json const& value = obj.second; + const json& value = obj.second; if ((value.*is_goodtype)()) (s.*set_state)(value.get()); else @@ -186,20 +187,32 @@ state parser::parse(std::string const& file) { else if (it.key() == "output") { if (it.value().is_array()) { for (json const& node : it.value()) { + try { + endpoint out(endpoint::io_type::output); + out.read_filters.insert("all"); + out.write_filters.insert("all"); + _parse_endpoint(node, out, module); + retval.add_module(std::move(module)); + retval.add_endpoint(std::move(out)); + } catch (const deprecated& e) { + log_v2::config()->warn( + "Deprecated endpoint found in the output configuration: {}", + e.what()); + } + } + } else if (it.value().is_object()) { + try { endpoint out(endpoint::io_type::output); out.read_filters.insert("all"); out.write_filters.insert("all"); - _parse_endpoint(node, out, module); + _parse_endpoint(it.value(), out, module); retval.add_module(std::move(module)); retval.add_endpoint(std::move(out)); + } catch (const deprecated& e) { + log_v2::config()->warn( + "Deprecated endpoint found in the output configuration: {}", + e.what()); } - } else if (it.value().is_object()) { - endpoint out(endpoint::io_type::output); - out.read_filters.insert("all"); - out.write_filters.insert("all"); - _parse_endpoint(it.value(), out, module); - retval.add_module(std::move(module)); - retval.add_endpoint(std::move(out)); } else throw msg_fmt( "config parser: cannot parse key '" @@ -207,18 +220,30 @@ state parser::parse(std::string const& file) { } else if (it.key() == "input") { if (it.value().is_array()) { for (json const& node : it.value()) { + try { + endpoint in(endpoint::io_type::input); + in.read_filters.insert("all"); + _parse_endpoint(node, in, module); + retval.add_module(std::move(module)); + retval.add_endpoint(std::move(in)); + } catch (const deprecated& e) { + log_v2::config()->warn( + "Deprecated endpoint found in the input configuration: {}", + e.what()); + } + } + } else if (it.value().is_object()) { + try { endpoint in(endpoint::io_type::input); in.read_filters.insert("all"); - _parse_endpoint(node, in, module); + _parse_endpoint(it.value(), in, module); retval.add_module(std::move(module)); retval.add_endpoint(std::move(in)); + } catch (const deprecated& e) { + log_v2::config()->warn( + "Deprecated endpoint found in the input configuration: {}", + e.what()); } - } else if (it.value().is_object()) { - endpoint in(endpoint::io_type::input); - in.read_filters.insert("all"); - _parse_endpoint(it.value(), in, module); - retval.add_module(std::move(module)); - retval.add_endpoint(std::move(in)); } else throw msg_fmt( "config parser: cannot parse key '" @@ -415,6 +440,9 @@ void parser::_parse_endpoint(json const& elem, module = "70-graphite.so"; else if (e.type == "influxdb") module = "70-influxdb.so"; + else if (e.type == "file") + throw deprecated( + "'file' endpoint is deprecated and should not be used anymore"); else throw msg_fmt("config parser: endpoint of invalid type '{}'", e.type); } diff --git a/centreon-broker/core/src/log_v2.cc b/centreon-broker/core/src/log_v2.cc index b28ab044a82..59d7b0e7538 100644 --- a/centreon-broker/core/src/log_v2.cc +++ b/centreon-broker/core/src/log_v2.cc @@ -94,11 +94,6 @@ void log_v2::apply(const config::state& conf) { file_sink = std::make_shared(_log_name); _core_log = std::make_shared("core", file_sink); - _core_log->set_level(level::info); - _core_log->flush_on(level::info); - _core_log->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); - _core_log->info("{} : log started", _log_name); - _bam_log = std::make_shared("bam", null_sink); _bbdo_log = std::make_shared("bbdo", null_sink); _config_log = std::make_shared("config", null_sink); @@ -166,6 +161,7 @@ void log_v2::apply(const config::state& conf) { (*l)->set_pattern("[%Y-%m-%dT%H:%M:%S.%e%z] [%n] [%l] %v"); } } + _core_log->info("{} : log started", _log_name); } /** diff --git a/centreon-broker/core/src/stats/center.cc b/centreon-broker/core/src/stats/center.cc index b8bf25a9fa6..64b8806ca81 100644 --- a/centreon-broker/core/src/stats/center.cc +++ b/centreon-broker/core/src/stats/center.cc @@ -1,5 +1,5 @@ /* -** Copyright 2020-2021 Centreon +** Copyright 2020-2022 Centreon ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. @@ -23,9 +23,9 @@ #include "com/centreon/broker/config/applier/modules.hh" #include "com/centreon/broker/config/applier/state.hh" +#include "com/centreon/broker/log_v2.hh" #include "com/centreon/broker/misc/filesystem.hh" #include "com/centreon/broker/version.hh" -#include "com/centreon/broker/log_v2.hh" using namespace com::centreon::broker; using namespace com::centreon::broker::stats; @@ -49,7 +49,7 @@ void center::unload() { _instance = nullptr; } -center::center() : _strand(pool::instance().io_context()) { +center::center() { *_stats.mutable_version() = version::string; *_stats.mutable_asio_version() = fmt::format("{}.{}.{}", ASIO_VERSION / 100000, ASIO_VERSION / 100 % 1000, @@ -79,12 +79,6 @@ center::center() : _strand(pool::instance().io_context()) { * @brief The destructor. */ center::~center() { - /* Before destroying the strand, we have to wait it is really empty. We post - * a last action and wait it is over. */ - std::promise p; - std::future f{p.get_future()}; - _strand.post([&p] { p.set_value(true); }); - f.get(); pool::instance().stop_stats(); } @@ -99,42 +93,26 @@ center::~center() { * @return A pointer to the engine statistics. */ EngineStats* center::register_engine() { - std::promise p; - std::future retval = p.get_future(); - _strand.post([this, &p] { - auto eng = _stats.mutable_engine(); - p.set_value(eng); - }); - return retval.get(); + std::lock_guard lck(_stats_m); + return _stats.mutable_engine(); } SqlConnectionStats* center::add_connection() { - std::promise p; - std::future retval = p.get_future(); - _strand.post([this, &p] { - auto m = _stats.mutable_sql_manager()->add_connections(); - p.set_value(m); - }); - return retval.get(); + std::lock_guard lck(_stats_m); + return _stats.mutable_sql_manager()->add_connections(); } void center::remove_connection(SqlConnectionStats* stats) { - std::promise p; - _strand.post([this, stats, &p] { - auto* mc = _stats.mutable_sql_manager()->mutable_connections(); - for (auto it = mc->begin(); it != mc->end(); ++it) { - if (&(*it) == stats) { - mc->erase(it); - p.set_value(); - return; - } + std::lock_guard lck(_stats_m); + auto* mc = _stats.mutable_sql_manager()->mutable_connections(); + for (auto it = mc->begin(); it != mc->end(); ++it) { + if (&(*it) == stats) { + mc->erase(it); + break; } - p.set_value(); - }); - return p.get_future().wait(); + } } - /** * @brief When a feeder needs to write statistics, it primarily has to * call this function to be registered in the statistic center and to get @@ -249,13 +227,8 @@ void center::remove_connection(SqlConnectionStats* stats) { * @return A pointer to the conflict_manager statistics. */ ConflictManagerStats* center::register_conflict_manager() { - std::promise p; - std::future retval = p.get_future(); - _strand.post([this, &p] { - auto cm = _stats.mutable_conflict_manager(); - p.set_value(cm); - }); - return retval.get(); + std::lock_guard lck(_stats_m); + return _stats.mutable_conflict_manager(); } /** @@ -282,62 +255,25 @@ ConflictManagerStats* center::register_conflict_manager() { * @return a string with the object in json format. */ std::string center::to_string() { - std::promise p; - std::future retval = p.get_future(); - _strand.post( - [&s = this->_stats, &p, &tmpnow = this->_json_stats_file_creation] { - const JsonPrintOptions options; - std::string retval; - std::time_t now; - time(&now); - tmpnow = (int)now; - s.set_now(now); - MessageToJsonString(s, &retval, options); - p.set_value(std::move(retval)); - }); - - return retval.get(); + const JsonPrintOptions options; + std::string retval; + std::time_t now; + time(&now); + std::lock_guard lck(_stats_m); + _json_stats_file_creation = now; + _stats.set_now(now); + MessageToJsonString(_stats, &retval, options); + return retval; } void center::get_sql_manager_stats(SqlManagerStats* response) { - std::promise p; - _strand.post([&s = this->_stats, &p, response] { - *response = s.sql_manager(); - p.set_value(); - }); - - // We wait for the response. - p.get_future().wait(); + std::lock_guard lck(_stats_m); + *response = _stats.sql_manager(); } -// void center::get_stats(const StatsQuery* request, BrokerStats* response) { -// std::promise p; -// std::future done = p.get_future(); -// _strand.post([&s = this->_stats, &p, request, response] { -// for (auto& q : request->query()) { -// switch (q) { -// case StatsQuery::ENGINE: -// *response->mutable_engine() = s.engine(); -// break; -// } -// } -// p.set_value(true); -// }); -// -// // We wait for the response. -// done.get(); -//} - void center::get_conflict_manager_stats(ConflictManagerStats* response) { - std::promise p; - std::future done = p.get_future(); - _strand.post([&s = this->_stats, &p, response] { - *response = s.conflict_manager(); - p.set_value(true); - }); - - // We wait for the response. - done.get(); + std::lock_guard lck(_stats_m); + *response = _stats.conflict_manager(); } int center::get_json_stats_file_creation(void) { diff --git a/centreon-broker/core/test/bbdo/output.cc b/centreon-broker/core/test/bbdo/output.cc index f83786a2952..e3de02c6ba4 100644 --- a/centreon-broker/core/test/bbdo/output.cc +++ b/centreon-broker/core/test/bbdo/output.cc @@ -95,7 +95,7 @@ class OutputTest : public ::testing::Test { // function. TEST_F(OutputTest, WriteService) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); std::shared_ptr svc(std::make_shared()); svc->host_id = 12345; @@ -140,7 +140,7 @@ TEST_F(OutputTest, WriteService) { TEST_F(OutputTest, WriteLongService) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); auto svc = std::make_shared(); svc->host_id = 12; @@ -188,7 +188,7 @@ TEST_F(OutputTest, WriteLongService) { TEST_F(OutputTest, WriteReadService) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); std::shared_ptr svc(new neb::service); svc->host_id = 12345; @@ -232,7 +232,7 @@ TEST_F(OutputTest, WriteReadService) { TEST_F(OutputTest, ShortPersistentFile) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); std::shared_ptr svc(new neb::service_status); svc->host_id = 12345; @@ -276,7 +276,7 @@ TEST_F(OutputTest, ShortPersistentFile) { TEST_F(OutputTest, LongPersistentFile) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); std::shared_ptr svc(new neb::service); svc->host_id = 12345; @@ -320,7 +320,7 @@ TEST_F(OutputTest, LongPersistentFile) { TEST_F(OutputTest, WriteReadBadChksum) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); std::shared_ptr svc(new neb::service); svc->host_id = 12345; @@ -359,7 +359,7 @@ TEST_F(OutputTest, WriteReadBadChksum) { TEST_F(OutputTest, ServiceTooShort) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); std::shared_ptr svc(new neb::service); svc->host_id = 12345; @@ -405,7 +405,7 @@ TEST_F(OutputTest, ServiceTooShort) { TEST_F(OutputTest, ServiceTooShortAndAGoodOne) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); std::shared_ptr svc(new neb::service); svc->host_id = 12345; diff --git a/centreon-broker/core/test/mysql/mysql.cc b/centreon-broker/core/test/mysql/mysql.cc index 083a26d9179..6aa1ebe4544 100644 --- a/centreon-broker/core/test/mysql/mysql.cc +++ b/centreon-broker/core/test/mysql/mysql.cc @@ -387,7 +387,7 @@ TEST_F(DatabaseStorageTest, RepeatPrepareQuery) { // Instance (15) statement TEST_F(DatabaseStorageTest, InstanceStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -442,7 +442,7 @@ TEST_F(DatabaseStorageTest, InstanceStatement) { // Host (12) statement TEST_F(DatabaseStorageTest, HostStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -531,7 +531,7 @@ TEST_F(DatabaseStorageTest, HostStatement) { TEST_F(DatabaseStorageTest, CustomVarStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -583,7 +583,7 @@ TEST_F(DatabaseStorageTest, CustomVarStatement) { TEST_F(DatabaseStorageTest, ModuleStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -619,7 +619,7 @@ TEST_F(DatabaseStorageTest, ModuleStatement) { // log_entry (17) statement queries TEST_F(DatabaseStorageTest, LogStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -660,7 +660,7 @@ TEST_F(DatabaseStorageTest, LogStatement) { // Instance status (16) statement TEST_F(DatabaseStorageTest, InstanceStatusStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -704,7 +704,7 @@ TEST_F(DatabaseStorageTest, InstanceStatusStatement) { // Host check (8) statement TEST_F(DatabaseStorageTest, HostCheckStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -734,7 +734,7 @@ TEST_F(DatabaseStorageTest, HostCheckStatement) { // Host status (14) statement TEST_F(DatabaseStorageTest, HostStatusStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -791,7 +791,7 @@ TEST_F(DatabaseStorageTest, HostStatusStatement) { // Service (23) statement TEST_F(DatabaseStorageTest, ServiceStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -843,7 +843,7 @@ TEST_F(DatabaseStorageTest, ServiceStatement) { // Service Check (19) statement TEST_F(DatabaseStorageTest, ServiceCheckStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -879,7 +879,7 @@ TEST_F(DatabaseStorageTest, ServiceCheckStatement) { // Service Status (24) statement TEST_F(DatabaseStorageTest, ServiceStatusStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -910,7 +910,7 @@ TEST_F(DatabaseStorageTest, ServiceStatusStatement) { TEST_F(DatabaseStorageTest, CustomvariableStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -959,7 +959,7 @@ TEST_F(DatabaseStorageTest, CustomvariableStatement) { TEST_F(DatabaseStorageTest, SelectStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -978,7 +978,7 @@ TEST_F(DatabaseStorageTest, SelectStatement) { TEST_F(DatabaseStorageTest, DowntimeStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -1036,7 +1036,7 @@ TEST_F(DatabaseStorageTest, DowntimeStatement) { TEST_F(DatabaseStorageTest, HostGroupMemberStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -1095,7 +1095,7 @@ TEST_F(DatabaseStorageTest, HostGroupMemberStatement) { TEST_F(DatabaseStorageTest, HostParentStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); @@ -1142,7 +1142,7 @@ TEST_F(DatabaseStorageTest, HostParentStatement) { TEST_F(DatabaseStorageTest, ServiceGroupMemberStatement) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); database_config db_cfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", "centreon_storage", 5, true, 5); std::unique_ptr ms(new mysql(db_cfg)); diff --git a/centreon-broker/core/test/rpc/brokerrpc.cc b/centreon-broker/core/test/rpc/brokerrpc.cc index cad92fbe8ae..ed0879d3582 100644 --- a/centreon-broker/core/test/rpc/brokerrpc.cc +++ b/centreon-broker/core/test/rpc/brokerrpc.cc @@ -18,14 +18,14 @@ */ #include "com/centreon/broker/brokerrpc.hh" -#include "com/centreon/broker/stats/center.hh" #include "com/centreon/broker/pool.hh" +#include "com/centreon/broker/stats/center.hh" #include +#include #include #include -#include #include #include "com/centreon/broker/log_v2.hh" @@ -50,7 +50,7 @@ class BrokerRpc : public ::testing::Test { std::list retval; char path[1024]; std::ostringstream oss; - oss << "test/rpc_client " << command; + oss << "tests/rpc_client " << command; FILE* fp = popen(oss.str().c_str(), "r"); while (fgets(path, sizeof(path), fp) != nullptr) { @@ -71,11 +71,13 @@ TEST_F(BrokerRpc, GetVersion) { auto output = execute("GetVersion"); #if CENTREON_BROKER_PATCH == 0 ASSERT_EQ(output.size(), 2u); - ASSERT_EQ(output.front(), fmt::format("GetVersion: major: {}\n", version::major)); + ASSERT_EQ(output.front(), + fmt::format("GetVersion: major: {}\n", version::major)); ASSERT_EQ(output.back(), fmt::format("minor: {}\n", version::minor)); #else ASSERT_EQ(output.size(), 3u); - ASSERT_EQ(output.front(), fmt::format("GetVersion: major: {}\n", version::major)); + ASSERT_EQ(output.front(), + fmt::format("GetVersion: major: {}\n", version::major)); ASSERT_EQ(output.back(), fmt::format("patch: {}\n", version::patch)); #endif brpc.shutdown(); @@ -86,13 +88,13 @@ TEST_F(BrokerRpc, GetConflictManagerStats) { ConflictManagerStats* _stats; _stats = stats::center::instance().register_conflict_manager(); - stats::center::instance().update(&ConflictManagerStats::set_events_handled, _stats, 3); + stats::center::instance().update(&ConflictManagerStats::set_events_handled, + _stats, 3); stats::center::instance().update(&ConflictManagerStats::set_loop_timeout, - _stats, 30u); + _stats, 30u); auto output = execute("GetConflictManagerStats"); std::cout << output.front(); brpc.shutdown(); } - diff --git a/centreon-broker/graphite/CMakeLists.txt b/centreon-broker/graphite/CMakeLists.txt index 71060aaba3d..c864c5f60cd 100644 --- a/centreon-broker/graphite/CMakeLists.txt +++ b/centreon-broker/graphite/CMakeLists.txt @@ -1,20 +1,20 @@ -## -## Copyright 2011-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 -## +# +# Copyright 2011-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 +# # Global options. set(INC_DIR "${PROJECT_SOURCE_DIR}/graphite/inc") @@ -27,8 +27,11 @@ set(INC_DIR "${INC_DIR}/com/centreon/broker/graphite") # GRAPHITE module. set(GRAPHITE "70-graphite") -set(GRAPHITE "${GRAPHITE}" PARENT_SCOPE) -add_library("${GRAPHITE}" SHARED +set(GRAPHITE + "${GRAPHITE}" + PARENT_SCOPE) +add_library( + "${GRAPHITE}" SHARED # Sources. "${SRC_DIR}/main.cc" "${SRC_DIR}/factory.cc" @@ -41,29 +44,20 @@ add_library("${GRAPHITE}" SHARED "${INC_DIR}/stream.hh" "${INC_DIR}/connector.hh" "${INC_DIR}/query.hh" - "${INC_DIR}/macro_cache.hh" -) + "${INC_DIR}/macro_cache.hh") set_target_properties("${GRAPHITE}" PROPERTIES PREFIX "") +target_link_libraries("${GRAPHITE}" CONAN_PKG::spdlog) # Testing. -if (WITH_TESTING) - set( - TESTS_SOURCES - ${TESTS_SOURCES} - ${TEST_DIR}/query.cc - ${TEST_DIR}/factory.cc - ${TEST_DIR}/stream.cc - PARENT_SCOPE - ) - set( - TESTS_LIBRARIES - ${TESTS_LIBRARIES} - ${GRAPHITE} - PARENT_SCOPE - ) +if(WITH_TESTING) + set(TESTS_SOURCES + ${TESTS_SOURCES} ${TEST_DIR}/query.cc ${TEST_DIR}/factory.cc + ${TEST_DIR}/stream.cc + PARENT_SCOPE) + set(TESTS_LIBRARIES + ${TESTS_LIBRARIES} ${GRAPHITE} + PARENT_SCOPE) endif(WITH_TESTING) # Install rule. -install(TARGETS "${GRAPHITE}" - LIBRARY DESTINATION "${PREFIX_MODULES}" -) +install(TARGETS "${GRAPHITE}" LIBRARY DESTINATION "${PREFIX_MODULES}") diff --git a/centreon-broker/influxdb/CMakeLists.txt b/centreon-broker/influxdb/CMakeLists.txt index 95bc89d7f1c..5e4ab1cbe9a 100644 --- a/centreon-broker/influxdb/CMakeLists.txt +++ b/centreon-broker/influxdb/CMakeLists.txt @@ -1,20 +1,20 @@ -## -## Copyright 2011-2017 Centreon -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -## For more information : contact@centreon.com -## +# +# Copyright 2011-2017 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 +# # Global options. set(INC_DIR "${PROJECT_SOURCE_DIR}/influxdb/inc") @@ -27,8 +27,11 @@ set(INC_DIR "${INC_DIR}/com/centreon/broker/influxdb") # INFLUXDB module. set(INFLUXDB "70-influxdb") -set(INFLUXDB "${INFLUXDB}" PARENT_SCOPE) -add_library("${INFLUXDB}" SHARED +set(INFLUXDB + "${INFLUXDB}" + PARENT_SCOPE) +add_library( + "${INFLUXDB}" SHARED # Sources. "${SRC_DIR}/column.cc" "${SRC_DIR}/connector.cc" @@ -46,32 +49,21 @@ add_library("${INFLUXDB}" SHARED "${INC_DIR}/influxdb12.hh" "${INC_DIR}/line_protocol_query.hh" "${INC_DIR}/macro_cache.hh" - "${INC_DIR}/stream.hh" -) + "${INC_DIR}/stream.hh") set_target_properties("${INFLUXDB}" PROPERTIES PREFIX "") +target_link_libraries("${INFLUXDB}" CONAN_PKG::spdlog) # Testing. -if (WITH_TESTING) - set( - TESTS_SOURCES - ${TESTS_SOURCES} - ${TEST_DIR}/column.cc - ${TEST_DIR}/factory.cc - ${TEST_DIR}/influxdb12.cc - ${TEST_DIR}/line_protocol_query.cc - ${TEST_DIR}/stream.cc - PARENT_SCOPE - ) - set( - TESTS_LIBRARIES - ${TESTS_LIBRARIES} - ${INFLUXDB} - PARENT_SCOPE - ) +if(WITH_TESTING) + set(TESTS_SOURCES + ${TESTS_SOURCES} ${TEST_DIR}/column.cc ${TEST_DIR}/factory.cc + ${TEST_DIR}/influxdb12.cc ${TEST_DIR}/line_protocol_query.cc + ${TEST_DIR}/stream.cc + PARENT_SCOPE) + set(TESTS_LIBRARIES + ${TESTS_LIBRARIES} ${INFLUXDB} + PARENT_SCOPE) endif(WITH_TESTING) - # Install rule. -install(TARGETS "${INFLUXDB}" - LIBRARY DESTINATION "${PREFIX_MODULES}" -) +install(TARGETS "${INFLUXDB}" LIBRARY DESTINATION "${PREFIX_MODULES}") diff --git a/centreon-broker/lua/CMakeLists.txt b/centreon-broker/lua/CMakeLists.txt index 9bc711f9b6c..9cfc888455f 100644 --- a/centreon-broker/lua/CMakeLists.txt +++ b/centreon-broker/lua/CMakeLists.txt @@ -1,20 +1,20 @@ -## -## Copyright 2018-2021 Centreon -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -## For more information : contact@centreon.com -## +# +# Copyright 2018-2021 Centreon +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# For more information : contact@centreon.com +# # Global options. @@ -30,8 +30,11 @@ set(INC_DIR "${INC_DIR}/com/centreon/broker/lua") # Storage module. set(LUA "70-lua") -set(LUA "${LUA}" PARENT_SCOPE) -add_library("${LUA}" SHARED +set(LUA + "${LUA}" + PARENT_SCOPE) +add_library( + "${LUA}" SHARED # Sources. "${SRC_DIR}/broker_cache.cc" "${SRC_DIR}/broker_event.cc" @@ -54,27 +57,19 @@ add_library("${LUA}" SHARED "${INC_DIR}/factory.hh" "${INC_DIR}/luabinding.hh" "${INC_DIR}/macro_cache.hh" - "${INC_DIR}/stream.hh" -) -target_link_libraries("${LUA}" ${LUA_LIBRARIES} ${OpenSSL_LIBS}) + "${INC_DIR}/stream.hh") +target_link_libraries("${LUA}" ${LUA_LIBRARIES} CONAN_PKG::spdlog + CONAN_PKG::openssl) set_target_properties("${LUA}" PROPERTIES PREFIX "") # Testing. -if (WITH_TESTING) - set( - TESTS_SOURCES - ${TESTS_SOURCES} - "${TEST_DIR}/lua.cc" - PARENT_SCOPE - ) - set( - TESTS_LIBRARIES - ${TESTS_LIBRARIES} - "${LUA}" - PARENT_SCOPE - ) +if(WITH_TESTING) + set(TESTS_SOURCES + ${TESTS_SOURCES} "${TEST_DIR}/lua.cc" + PARENT_SCOPE) + set(TESTS_LIBRARIES + ${TESTS_LIBRARIES} "${LUA}" + PARENT_SCOPE) endif() # Install rule. -install(TARGETS "${LUA}" - LIBRARY DESTINATION "${PREFIX_MODULES}" -) +install(TARGETS "${LUA}" LIBRARY DESTINATION "${PREFIX_MODULES}") diff --git a/centreon-broker/lua/test/lua.cc b/centreon-broker/lua/test/lua.cc index 75c8a1918dd..22bd59bb205 100644 --- a/centreon-broker/lua/test/lua.cc +++ b/centreon-broker/lua/test/lua.cc @@ -169,7 +169,7 @@ TEST_F(LuaTest, SimpleScript) { conf.insert({"address", "127.0.0.1"}); conf.insert({"port", 8857}); config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); std::string filename("/tmp/test-lua3.lua"); CreateScript( @@ -229,7 +229,7 @@ TEST_F(LuaTest, WriteAcknowledgement) { conf.insert({"port", 8857}); conf.insert({"name", "test-centreon"}); config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); std::unique_ptr bnd(new luabinding(FILE3, conf, *_cache)); ASSERT_TRUE(bnd.get()); @@ -546,7 +546,7 @@ TEST_F(LuaTest, CacheTest) { // Then the hostname is returned from the lua method. TEST_F(LuaTest, HostCacheTest) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); misc::string_to_variant_map conf; std::string filename("/tmp/cache_test.lua"); std::shared_ptr hst(new neb::host); @@ -712,7 +712,7 @@ TEST_F(LuaTest, MetricMappingCacheTestV1) { TEST_F(LuaTest, MetricMappingCacheTestV2) { config::applier::modules modules; - modules.load_file("./storage/20-storage.so"); + modules.load_file("./lib/20-storage.so"); misc::string_to_variant_map conf; std::string filename("/tmp/cache_test.lua"); std::shared_ptr mm(new storage::metric_mapping); @@ -1075,7 +1075,7 @@ TEST_F(LuaTest, BamCacheTestBaV1) { TEST_F(LuaTest, BamCacheTestBaV2) { config::applier::modules modules; - modules.load_file("./bam/20-bam.so"); + modules.load_file("./lib/20-bam.so"); misc::string_to_variant_map conf; std::string filename("/tmp/cache_test.lua"); std::shared_ptr ba(new bam::dimension_ba_event); @@ -1171,7 +1171,7 @@ TEST_F(LuaTest, BamCacheTestBvV1) { TEST_F(LuaTest, BamCacheTestBvV2) { config::applier::modules modules; - modules.load_file("./bam/20-bam.so"); + modules.load_file("./lib/20-bam.so"); misc::string_to_variant_map conf; std::string filename("/tmp/cache_test.lua"); std::shared_ptr bv(new bam::dimension_bv_event); @@ -1930,7 +1930,7 @@ TEST_F(LuaTest, CacheSeverity) { TEST_F(LuaTest, BrokerEventIndex) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); misc::string_to_variant_map conf; std::shared_ptr svc(new neb::service); svc->host_id = 1; @@ -1972,7 +1972,7 @@ TEST_F(LuaTest, BrokerEventIndex) { TEST_F(LuaTest, BrokerEventPairs) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); misc::string_to_variant_map conf; std::shared_ptr svc(new neb::service); svc->host_id = 1; @@ -2006,7 +2006,7 @@ TEST_F(LuaTest, BrokerEventPairs) { TEST_F(LuaTest, BrokerEventJsonEncode) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); misc::string_to_variant_map conf; std::shared_ptr svc(new neb::service); svc->host_id = 1; @@ -2072,7 +2072,7 @@ TEST_F(LuaTest, BrokerEventJsonEncode) { TEST_F(LuaTest, TestHostApiV1) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); misc::string_to_variant_map conf; std::shared_ptr hst(new neb::host); hst->host_id = 1; @@ -2100,7 +2100,7 @@ TEST_F(LuaTest, TestHostApiV1) { TEST_F(LuaTest, TestHostApiV2) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); misc::string_to_variant_map conf; std::shared_ptr hst(new neb::host); hst->host_id = 1; @@ -2128,7 +2128,7 @@ TEST_F(LuaTest, TestHostApiV2) { TEST_F(LuaTest, TestSvcApiV2) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); misc::string_to_variant_map conf; std::shared_ptr svc(new neb::service); svc->host_id = 1; @@ -2160,7 +2160,7 @@ TEST_F(LuaTest, TestSvcApiV2) { TEST_F(LuaTest, TestSvcApiV1) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); misc::string_to_variant_map conf; std::shared_ptr svc(new neb::service); svc->host_id = 1; @@ -2192,7 +2192,7 @@ TEST_F(LuaTest, TestSvcApiV1) { TEST_F(LuaTest, BrokerEventCache) { config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); misc::string_to_variant_map conf; std::shared_ptr svc(new neb::service); svc->host_id = 1; diff --git a/centreon-broker/neb/CMakeLists.txt b/centreon-broker/neb/CMakeLists.txt index 269400a9dee..8e3f5fc6b15 100644 --- a/centreon-broker/neb/CMakeLists.txt +++ b/centreon-broker/neb/CMakeLists.txt @@ -1,20 +1,19 @@ -## -## 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 -## +# +# 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 +# # Global options. set(INC_DIR "${PROJECT_SOURCE_DIR}/neb/inc") @@ -24,77 +23,76 @@ include_directories("${INC_DIR}") # NEB sources. set(NEB_SOURCES - # Sources. - # Headers. - ${SRC_DIR}/acknowledgement.cc - ${SRC_DIR}/check.cc - ${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}/event_handler.cc - ${SRC_DIR}/flapping_status.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 - ${SRC_DIR}/host_service.cc - ${SRC_DIR}/host_service_status.cc - ${SRC_DIR}/host_status.cc - ${SRC_DIR}/instance.cc - ${SRC_DIR}/instance_configuration.cc - ${SRC_DIR}/instance_status.cc - ${SRC_DIR}/log_entry.cc - ${SRC_DIR}/module.cc - ${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 - ${SRC_DIR}/status.cc - ${INC_DIR}/com/centreon/broker/neb/acknowledgement.hh - ${INC_DIR}/com/centreon/broker/neb/check.hh - ${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/event_handler.hh - ${INC_DIR}/com/centreon/broker/neb/events.hh - ${INC_DIR}/com/centreon/broker/neb/flapping_status.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 - ${INC_DIR}/com/centreon/broker/neb/host_service.hh - ${INC_DIR}/com/centreon/broker/neb/host_service_status.hh - ${INC_DIR}/com/centreon/broker/neb/host_status.hh - ${INC_DIR}/com/centreon/broker/neb/instance.hh - ${INC_DIR}/com/centreon/broker/neb/instance_configuration.hh - ${INC_DIR}/com/centreon/broker/neb/instance_status.hh - ${INC_DIR}/com/centreon/broker/neb/internal.hh - ${INC_DIR}/com/centreon/broker/neb/log_entry.hh - ${INC_DIR}/com/centreon/broker/neb/module.hh - ${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 - ${INC_DIR}/com/centreon/broker/neb/status.hh -) + # Sources. + # Headers. + ${SRC_DIR}/acknowledgement.cc + ${SRC_DIR}/check.cc + ${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}/event_handler.cc + ${SRC_DIR}/flapping_status.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 + ${SRC_DIR}/host_service.cc + ${SRC_DIR}/host_service_status.cc + ${SRC_DIR}/host_status.cc + ${SRC_DIR}/instance.cc + ${SRC_DIR}/instance_configuration.cc + ${SRC_DIR}/instance_status.cc + ${SRC_DIR}/log_entry.cc + ${SRC_DIR}/module.cc + ${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 + ${SRC_DIR}/status.cc + ${INC_DIR}/com/centreon/broker/neb/acknowledgement.hh + ${INC_DIR}/com/centreon/broker/neb/check.hh + ${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/event_handler.hh + ${INC_DIR}/com/centreon/broker/neb/events.hh + ${INC_DIR}/com/centreon/broker/neb/flapping_status.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 + ${INC_DIR}/com/centreon/broker/neb/host_service.hh + ${INC_DIR}/com/centreon/broker/neb/host_service_status.hh + ${INC_DIR}/com/centreon/broker/neb/host_status.hh + ${INC_DIR}/com/centreon/broker/neb/instance.hh + ${INC_DIR}/com/centreon/broker/neb/instance_configuration.hh + ${INC_DIR}/com/centreon/broker/neb/instance_status.hh + ${INC_DIR}/com/centreon/broker/neb/internal.hh + ${INC_DIR}/com/centreon/broker/neb/log_entry.hh + ${INC_DIR}/com/centreon/broker/neb/module.hh + ${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 + ${INC_DIR}/com/centreon/broker/neb/status.hh) # Static library. add_library(nebbase STATIC ${NEB_SOURCES}) @@ -104,29 +102,30 @@ set_property(TARGET nebbase PROPERTY COMPILE_FLAGS ${NEBBASE_CXXFLAGS}) # Centreon Broker module. set(NEB "10-neb") -set(NEB "${NEB}" PARENT_SCOPE) -add_library("${NEB}" SHARED +set(NEB + "${NEB}" + PARENT_SCOPE) +add_library( + "${NEB}" SHARED # Main source. "${SRC_DIR}/broker.cc" "${SRC_DIR}/node_id.cc" "${SRC_DIR}/downtime_map.cc" - # Inc "${INC_DIR}/com/centreon/broker/neb/node_id.hh" - "${INC_DIR}/com/centreon/broker/neb/downtime_map.hh" -) + "${INC_DIR}/com/centreon/broker/neb/downtime_map.hh") # Flags needed to include all symbols in binary. -target_link_libraries(${NEB} nebbase) -# "-Wl,--whole-archive" nebbase "-Wl,--no-whole-archive") +target_link_libraries(${NEB} nebbase CONAN_PKG::spdlog) + +# "-Wl,--whole-archive" nebbase "-Wl,--no-whole-archive") set_target_properties("${NEB}" PROPERTIES PREFIX "") -install(TARGETS "${NEB}" - LIBRARY DESTINATION "${PREFIX_MODULES}" -) +install(TARGETS "${NEB}" LIBRARY DESTINATION "${PREFIX_MODULES}") # Centreon Engine/Nagios module. set(CBMOD "cbmod") -add_library("${CBMOD}" SHARED +add_library( + "${CBMOD}" SHARED # Sources. "${PROJECT_SOURCE_DIR}/core/src/config/applier/init.cc" "${SRC_DIR}/callback.cc" @@ -203,30 +202,38 @@ add_library("${CBMOD}" SHARED "${INC_DIR}/com/centreon/broker/neb/statistics/total_host_state_change.hh" "${INC_DIR}/com/centreon/broker/neb/statistics/total_hosts.hh" "${INC_DIR}/com/centreon/broker/neb/statistics/total_service_state_change.hh" - "${INC_DIR}/com/centreon/broker/neb/statistics/total_services.hh" -) -get_property(CBMOD_DEFINES + "${INC_DIR}/com/centreon/broker/neb/statistics/total_services.hh") +get_property( + CBMOD_DEFINES TARGET "${CBMOD}" PROPERTY COMPILE_DEFINITIONS) list(APPEND CBMOD_DEFINES CBMOD) -set_property(TARGET "${CBMOD}" - PROPERTY COMPILE_DEFINITIONS "${CBMOD_DEFINES}") -if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +set_property(TARGET "${CBMOD}" PROPERTY COMPILE_DEFINITIONS "${CBMOD_DEFINES}") + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # Flags needed to include all symbols in shared library. - target_link_libraries("${CBMOD}" - "-Wl,--whole-archive" "rokerbase" "-Wl,--no-whole-archive" ${nlohmann_json_LIBS} ${fmt_LIBS} ${spdlog_LIBS} ${asio_LIBS} ${OpenSSL_LIBS}) -else () - target_link_libraries("${CBMOD}" "rokerbase" ${nlohmann_json_LIBS} ${fmt_LIBS} ${spdlog_LIBS} ${asio_LIBS} ${OpenSSL_LIBS}) -endif () + target_link_libraries( + "${CBMOD}" + "-Wl,--whole-archive" + "rokerbase" + "-Wl,--no-whole-archive" + CONAN_PKG::nlohmann_json + CONAN_PKG::spdlog + CONAN_PKG::asio + CONAN_PKG::openssl) +else() + target_link_libraries("${CBMOD}" "rokerbase" CONAN_PKG::nlohmann_json + CONAN_PKG::spdlog CONAN_PKG::asio CONAN_PKG::openssl) +endif() + set_target_properties("${CBMOD}" PROPERTIES PREFIX "") # Testing. -if (WITH_TESTING) - set( - TESTS_SOURCES +if(WITH_TESTING) + set(TESTS_SOURCES ${TESTS_SOURCES} ${SRC_DIR}/set_log_data.cc - #Actual tests + # Actual tests ${TEST_DIR}/custom_variable.cc ${TEST_DIR}/custom_variable_status.cc ${TEST_DIR}/event_handler.cc @@ -247,17 +254,11 @@ if (WITH_TESTING) ${TEST_DIR}/service_dependency.cc ${TEST_DIR}/service_status.cc ${TEST_DIR}/set_log_data.cc - PARENT_SCOPE - ) - set( - TESTS_LIBRARIES - ${TESTS_LIBRARIES} - ${NEB} - PARENT_SCOPE - ) + PARENT_SCOPE) + set(TESTS_LIBRARIES + ${TESTS_LIBRARIES} ${NEB} + PARENT_SCOPE) endif() # Install rules. -install(TARGETS "${CBMOD}" - LIBRARY DESTINATION "${PREFIX_LIB}" -) +install(TARGETS "${CBMOD}" LIBRARY DESTINATION "${PREFIX_CBMOD}") diff --git a/centreon-broker/rrd/CMakeLists.txt b/centreon-broker/rrd/CMakeLists.txt index cbf0c8e8990..3260dd9e002 100644 --- a/centreon-broker/rrd/CMakeLists.txt +++ b/centreon-broker/rrd/CMakeLists.txt @@ -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 : contact@centreon.com -## +# +# 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 : contact@centreon.com +# # Global options. set(INC_DIR "${PROJECT_SOURCE_DIR}/rrd/inc") @@ -26,33 +26,42 @@ include_directories("${PROJECT_SOURCE_DIR}/neb/inc") # Find librrd. include(FindPkgConfig) -if (PKG_CONFIG_FOUND) +if(PKG_CONFIG_FOUND) pkg_check_modules(LIBRRD REQUIRED "librrd") - if (LIBRRD_INCLUDE_DIRS) + if(LIBRRD_INCLUDE_DIRS) include_directories("${LIBRRD_INCLUDE_DIRS}") - set(LIBRRD_INCLUDE_DIRS "${LIBRRD_INCLUDE_DIRS}" PARENT_SCOPE) - endif () -else () + set(LIBRRD_INCLUDE_DIRS + "${LIBRRD_INCLUDE_DIRS}" + PARENT_SCOPE) + endif() +else() # Find rrd.h find_path(LIBRRD_INCLUDE_DIR "rrd.h") - if (NOT LIBRRD_INCLUDE_DIR) + if(NOT LIBRRD_INCLUDE_DIR) message(FATAL_ERROR "Could not find librrd's headers.") - endif () + endif() include_directories("${LIBRRD_INCLUDE_DIR}") - set(LIBRRD_INCLUDE_DIRS "${LIBRRD_INCLUDE_DIR}" PARENT_SCOPE) + set(LIBRRD_INCLUDE_DIRS + "${LIBRRD_INCLUDE_DIR}" + PARENT_SCOPE) # Find librrd. find_library(LIBRRD_LDFLAGS "rrd") - if (NOT LIBRRD_LDFLAGS) + if(NOT LIBRRD_LDFLAGS) message(FATAL_ERROR "Could not find librrd's library.") - endif () - set(LIBRRD_LDFLAGS "${LIBRRD_LDFLAGS}" PARENT_SCOPE) -endif () + endif() + set(LIBRRD_LDFLAGS + "${LIBRRD_LDFLAGS}" + PARENT_SCOPE) +endif() # RRD module. set(RRD "70-rrd") -set(RRD "${RRD}" PARENT_SCOPE) -add_library("${RRD}" SHARED +set(RRD + "${RRD}" + PARENT_SCOPE) +add_library( + "${RRD}" SHARED # Sources. "${SRC_DIR}/connector.cc" "${SRC_DIR}/creator.cc" @@ -68,44 +77,34 @@ add_library("${RRD}" SHARED "${INC_DIR}/com/centreon/broker/rrd/exceptions/update.hh" "${INC_DIR}/com/centreon/broker/rrd/factory.hh" "${INC_DIR}/com/centreon/broker/rrd/lib.hh" - "${INC_DIR}/com/centreon/broker/rrd/output.hh" - ) + "${INC_DIR}/com/centreon/broker/rrd/output.hh") set_target_properties("${RRD}" PROPERTIES PREFIX "") # Compile with librrd flags. -if (LIBRRD_CFLAGS) - get_source_file_property(RRD_SOURCE_CXXFLAGS "${SRC_DIR}/lib.cc" COMPILE_FLAGS) - if (LIBRRD_SOURCE_CXXFLAGS) - set_source_files_properties("${SRC_DIR}/lib.cc" PROPERTIES - COMPILE_FLAGS "${RRD_SOURCE_CXXFLAGS} ${LIBRRD_CFLAGS}") - else () - set_source_files_properties("${SRC_DIR}/lib.cc" PROPERTIES - COMPILE_FLAGS "${LIBRRD_CFLAGS}") - endif () -endif () -target_link_libraries("${RRD}" ${LIBRRD_LDFLAGS}) +if(LIBRRD_CFLAGS) + get_source_file_property(RRD_SOURCE_CXXFLAGS "${SRC_DIR}/lib.cc" + COMPILE_FLAGS) + if(LIBRRD_SOURCE_CXXFLAGS) + set_source_files_properties( + "${SRC_DIR}/lib.cc" PROPERTIES COMPILE_FLAGS + "${RRD_SOURCE_CXXFLAGS} ${LIBRRD_CFLAGS}") + else() + set_source_files_properties("${SRC_DIR}/lib.cc" + PROPERTIES COMPILE_FLAGS "${LIBRRD_CFLAGS}") + endif() +endif() +target_link_libraries("${RRD}" ${LIBRRD_LDFLAGS} CONAN_PKG::spdlog) # Testing. -if (WITH_TESTING) - set( - TESTS_SOURCES - ${TESTS_SOURCES} - "${TEST_DIR}/cached.cc" - "${TEST_DIR}/exceptions.cc" - "${TEST_DIR}/factory.cc" - "${TEST_DIR}/lib.cc" - "${TEST_DIR}/rrd.cc" - PARENT_SCOPE - ) - set( - TESTS_LIBRARIES - ${TESTS_LIBRARIES} - "${RRD}" - PARENT_SCOPE - ) -endif () +if(WITH_TESTING) + set(TESTS_SOURCES + ${TESTS_SOURCES} "${TEST_DIR}/cached.cc" "${TEST_DIR}/exceptions.cc" + "${TEST_DIR}/factory.cc" "${TEST_DIR}/lib.cc" "${TEST_DIR}/rrd.cc" + PARENT_SCOPE) + set(TESTS_LIBRARIES + ${TESTS_LIBRARIES} "${RRD}" + PARENT_SCOPE) +endif() # Install rule. -install(TARGETS "${RRD}" - LIBRARY DESTINATION "${PREFIX_MODULES}" - ) +install(TARGETS "${RRD}" LIBRARY DESTINATION "${PREFIX_MODULES}") diff --git a/centreon-broker/script/debian/cbd.init.d.in b/centreon-broker/script/debian/cbd.init.d.in index 96f3e303926..1d6d0f1fd75 100755 --- a/centreon-broker/script/debian/cbd.init.d.in +++ b/centreon-broker/script/debian/cbd.init.d.in @@ -35,8 +35,8 @@ PKGNAME=cbd DESC="Centreon Broker" DAEMON="@PREFIX_BIN@/cbwd" PID_PATH="/var/run" -WATCHDOG_FILE="@PREFIX_CONF@/watchdog.json" -CONFIG_DIR="@PREFIX_CONF@" +WATCHDOG_FILE="@PREFIX_BROKER_CONF@/watchdog.json" +CONFIG_DIR="@PREFIX_BROKER_CONF@" pidfile="${PID_PATH}/cbwd.pid" # Check that cbd is executable. diff --git a/centreon-broker/script/other/cbd.init.d.in b/centreon-broker/script/other/cbd.init.d.in index 1007abbe5ce..58438ed857c 100644 --- a/centreon-broker/script/other/cbd.init.d.in +++ b/centreon-broker/script/other/cbd.init.d.in @@ -38,8 +38,8 @@ ### END INIT INFO # Configuration parameters. -watchdog_file="@PREFIX_CONF@/master.run" -config_dir="@PREFIX_CONF@" +watchdog_file="@PREFIX_BROKER_CONF@/master.run" +config_dir="@PREFIX_BROKER_CONF@" cbwd="@PREFIX_BIN@/cbwd" pid_path="@PREFIX_VAR@/run" stop_timeout=10 diff --git a/centreon-broker/script/redhat/cbd.init.d.in b/centreon-broker/script/redhat/cbd.init.d.in index ba00bc3f202..3e795c93f19 100644 --- a/centreon-broker/script/redhat/cbd.init.d.in +++ b/centreon-broker/script/redhat/cbd.init.d.in @@ -32,8 +32,8 @@ . /etc/init.d/functions # Configuration parameters. -watchdog_file="@PREFIX_CONF@/watchdog.json" -config_dir="@PREFIX_CONF@" +watchdog_file="@PREFIX_BROKER_CONF@/watchdog.json" +config_dir="@PREFIX_BROKER_CONF@" cbwd="@PREFIX_BIN@/cbwd" pid_path=/var/run lockfile=/var/lock/subsys/cbd diff --git a/centreon-broker/script/systemd/cbd.service.in b/centreon-broker/script/systemd/cbd.service.in index 97b2262585a..68c97c22b3c 100644 --- a/centreon-broker/script/systemd/cbd.service.in +++ b/centreon-broker/script/systemd/cbd.service.in @@ -24,7 +24,7 @@ ReloadPropagatedFrom=centreon.service After=mariadb.service [Service] -ExecStart=@PREFIX_BIN@/cbwd @PREFIX_CONF@/watchdog.json +ExecStart=@PREFIX_BIN@/cbwd @PREFIX_BROKER_CONF@/watchdog.json ExecReload=/bin/kill -HUP $MAINPID Type=simple User=centreon-broker diff --git a/centreon-broker/simu/CMakeLists.txt b/centreon-broker/simu/CMakeLists.txt index 597012da9d6..537fc180c44 100644 --- a/centreon-broker/simu/CMakeLists.txt +++ b/centreon-broker/simu/CMakeLists.txt @@ -1,20 +1,20 @@ -## -## Copyright 2018 Centreon -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -## For more information : contact@centreon.com -## +# +# Copyright 2018 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 +# # Global options. @@ -22,50 +22,44 @@ set(INC_DIR "${PROJECT_SOURCE_DIR}/simu/inc") set(SRC_DIR "${PROJECT_SOURCE_DIR}/simu/src") set(TEST_DIR "${PROJECT_SOURCE_DIR}/simu/test") include_directories("${INC_DIR}") -include_directories("${PROJECT_SOURCE_DIR}/bam/inc" - "${PROJECT_SOURCE_DIR}/lua/inc" - "${PROJECT_SOURCE_DIR}/neb/inc" - "${PROJECT_SOURCE_DIR}/storage/inc") +include_directories( + "${PROJECT_SOURCE_DIR}/bam/inc" "${PROJECT_SOURCE_DIR}/lua/inc" + "${PROJECT_SOURCE_DIR}/neb/inc" "${PROJECT_SOURCE_DIR}/storage/inc") set(INC_DIR "${INC_DIR}/com/centreon/broker/simu") # Storage module. set(SIMU "70-simu") -set(SIMU "${SIMU}" PARENT_SCOPE) -add_library("${SIMU}" SHARED +set(SIMU + "${SIMU}" + PARENT_SCOPE) +add_library( + "${SIMU}" + SHARED # Sources. -#"${SRC_DIR}/broker_log.cc" -# "${SRC_DIR}/broker_utils.cc" + # "${SRC_DIR}/broker_log.cc" + # "${SRC_DIR}/broker_utils.cc" "${SRC_DIR}/connector.cc" "${SRC_DIR}/factory.cc" "${SRC_DIR}/luabinding.cc" "${SRC_DIR}/main.cc" "${SRC_DIR}/stream.cc" # Headers. -# "${INC_DIR}/broker_log.hh" -# "${INC_DIR}/broker_utils.hh" + # "${INC_DIR}/broker_log.hh" + # "${INC_DIR}/broker_utils.hh" "${INC_DIR}/connector.hh" "${INC_DIR}/factory.hh" "${INC_DIR}/luabinding.hh" - "${INC_DIR}/stream.hh" -) -target_link_libraries("${SIMU}" ${LUA_LIBRARIES}) + "${INC_DIR}/stream.hh") +target_link_libraries("${SIMU}" ${LUA_LIBRARIES} CONAN_PKG::spdlog) set_target_properties("${SIMU}" PROPERTIES PREFIX "") # Testing. -set( - TESTS_SOURCES - ${TESTS_SOURCES} - "${TEST_DIR}/simu.cc" - PARENT_SCOPE -) -set( - TESTS_LIBRARIES - ${TESTS_LIBRARIES} - "${SIMU}" - PARENT_SCOPE -) +set(TESTS_SOURCES + ${TESTS_SOURCES} "${TEST_DIR}/simu.cc" + PARENT_SCOPE) +set(TESTS_LIBRARIES + ${TESTS_LIBRARIES} "${SIMU}" + PARENT_SCOPE) # Install rule. -install(TARGETS "${SIMU}" - LIBRARY DESTINATION "${PREFIX_MODULES}" -) +install(TARGETS "${SIMU}" LIBRARY DESTINATION "${PREFIX_MODULES}") diff --git a/centreon-broker/simu/test/simu.cc b/centreon-broker/simu/test/simu.cc index aeb9275ec9d..3d1404935cd 100644 --- a/centreon-broker/simu/test/simu.cc +++ b/centreon-broker/simu/test/simu.cc @@ -182,7 +182,7 @@ TEST_F(SimuGenericTest, ReadReturnValue4) { "end\n"); std::map conf; config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); std::unique_ptr lb = std::make_unique(filename, conf); std::shared_ptr d; ASSERT_TRUE(lb->read(d)); @@ -218,7 +218,7 @@ TEST_F(SimuGenericTest, ReadReturnCustomVariable) { "end\n"); std::map conf; config::applier::modules modules; - modules.load_file("./neb/10-neb.so"); + modules.load_file("./lib/10-neb.so"); std::unique_ptr lb(new luabinding(filename, conf)); std::shared_ptr d; ASSERT_TRUE(lb->read(d)); diff --git a/centreon-broker/sql/CMakeLists.txt b/centreon-broker/sql/CMakeLists.txt index 61089c89807..8f9ef433014 100644 --- a/centreon-broker/sql/CMakeLists.txt +++ b/centreon-broker/sql/CMakeLists.txt @@ -1,20 +1,20 @@ -## -## Copyright 2011-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 -## +# +# Copyright 2011-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 +# # Global options. @@ -27,8 +27,11 @@ include_directories("${PROJECT_SOURCE_DIR}/storage/inc") # SQL module. set(SQL "80-sql") -set(SQL "${SQL}" PARENT_SCOPE) -add_library("${SQL}" SHARED +set(SQL + "${SQL}" + PARENT_SCOPE) +add_library( + "${SQL}" SHARED # Sources. "${SRC_DIR}/cleanup.cc" "${SRC_DIR}/connector.cc" @@ -39,14 +42,10 @@ add_library("${SQL}" SHARED "${INC_DIR}/com/centreon/broker/sql/cleanup.hh" "${INC_DIR}/com/centreon/broker/sql/connector.hh" "${INC_DIR}/com/centreon/broker/sql/factory.hh" - "${INC_DIR}/com/centreon/broker/sql/stream.hh" -) + "${INC_DIR}/com/centreon/broker/sql/stream.hh") +target_link_libraries("${SQL}" CONAN_PKG::spdlog) -set_target_properties("${SQL}" PROPERTIES - PREFIX "" - COMPILE_FLAGS "-fPIC") +set_target_properties("${SQL}" PROPERTIES PREFIX "" COMPILE_FLAGS "-fPIC") # Install rule. -install(TARGETS "${SQL}" - LIBRARY DESTINATION "${PREFIX_MODULES}" -) +install(TARGETS "${SQL}" LIBRARY DESTINATION "${PREFIX_MODULES}") diff --git a/centreon-broker/stats/CMakeLists.txt b/centreon-broker/stats/CMakeLists.txt index aa7443769c2..9764d4a95ae 100644 --- a/centreon-broker/stats/CMakeLists.txt +++ b/centreon-broker/stats/CMakeLists.txt @@ -1,19 +1,19 @@ -## Copyright 2012-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 : contact@centreon.com -## +# Copyright 2012-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 : contact@centreon.com +# # Global options. set(INC_DIR "${PROJECT_SOURCE_DIR}/stats/inc/com/centreon/broker/stats") @@ -25,8 +25,11 @@ include_directories("${PROJECT_SOURCE_DIR}/neb/inc") # Stats module. set(STATS "15-stats") -set(STATS "${STATS}" PARENT_SCOPE) -add_library("${STATS}" SHARED +set(STATS + "${STATS}" + PARENT_SCOPE) +add_library( + "${STATS}" SHARED # Sources. ${SRC_DIR}/builder.cc ${SRC_DIR}/main.cc @@ -37,29 +40,19 @@ add_library("${STATS}" SHARED ${INC_DIR}/builder.hh ${INC_DIR}/parser.hh ${INC_DIR}/worker.hh - ${INC_DIR}/worker_pool.hh - -) -set_target_properties("${STATS}" PROPERTIES - PREFIX "") + ${INC_DIR}/worker_pool.hh) +set_target_properties("${STATS}" PROPERTIES PREFIX "") +target_link_libraries("${STATS}" CONAN_PKG::spdlog) # Testing. -if (WITH_TESTING) - set( - TESTS_SOURCES - ${TESTS_SOURCES} - ${TEST_DIR}/stats.cc - PARENT_SCOPE - ) - set( - TESTS_LIBRARIES - ${TESTS_LIBRARIES} - ${STATS} - PARENT_SCOPE - ) +if(WITH_TESTING) + set(TESTS_SOURCES + ${TESTS_SOURCES} ${TEST_DIR}/stats.cc + PARENT_SCOPE) + set(TESTS_LIBRARIES + ${TESTS_LIBRARIES} ${STATS} + PARENT_SCOPE) endif(WITH_TESTING) # Install rule. -install(TARGETS "${STATS}" - LIBRARY DESTINATION "${PREFIX_MODULES}" -) +install(TARGETS "${STATS}" LIBRARY DESTINATION "${PREFIX_MODULES}") diff --git a/centreon-broker/stats/test/stats.cc b/centreon-broker/stats/test/stats.cc index ba6b0e2e663..0ecfce1bcfc 100644 --- a/centreon-broker/stats/test/stats.cc +++ b/centreon-broker/stats/test/stats.cc @@ -89,8 +89,8 @@ TEST_F(StatsTest, Builder) { TEST_F(StatsTest, BuilderWithModules) { stats::builder build; auto& modules = config::applier::state::instance().get_modules(); - modules.apply({"storage/20-storage.so", "neb/10-neb.so", "lua/70-lua.so"}, - ".", nullptr); + modules.apply({"lib/20-storage.so", "lib/10-neb.so", "lib/70-lua.so"}, ".", + nullptr); build.build(); @@ -105,11 +105,11 @@ TEST_F(StatsTest, BuilderWithModules) { ASSERT_TRUE(result["mysql manager"].is_object()); ASSERT_TRUE(result["mysql manager"]["delay since last check"].is_string()); - ASSERT_EQ(result["module./neb/10-neb.so"]["state"].get(), + ASSERT_EQ(result["module./lib/10-neb.so"]["state"].get(), "loaded"); - ASSERT_EQ(result["module./storage/20-storage.so"]["state"].get(), + ASSERT_EQ(result["module./lib/20-storage.so"]["state"].get(), "loaded"); - ASSERT_EQ(result["module./lua/70-lua.so"]["state"].get(), + ASSERT_EQ(result["module./lib/70-lua.so"]["state"].get(), "loaded"); } diff --git a/centreon-broker/storage/CMakeLists.txt b/centreon-broker/storage/CMakeLists.txt index 86edb2a8422..8abdf540d31 100644 --- a/centreon-broker/storage/CMakeLists.txt +++ b/centreon-broker/storage/CMakeLists.txt @@ -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 : contact@centreon.com -## +# +# 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 : contact@centreon.com +# # Global options. set(INC_DIR "${PROJECT_SOURCE_DIR}/storage/inc") @@ -25,25 +25,29 @@ include_directories("${PROJECT_SOURCE_DIR}/neb/inc") set(INC_DIR "${INC_DIR}/com/centreon/broker/storage") # conflict_manager library. -add_library(conflictmgr STATIC +add_library( + conflictmgr STATIC # Sources. "${SRC_DIR}/conflict_manager.cc" "${SRC_DIR}/conflict_manager_sql.cc" "${SRC_DIR}/conflict_manager_storage.cc" "${SRC_DIR}/stored_timestamp.cc" - # Headers. "${INC_DIR}/conflict_manager.hh" - "${INC_DIR}/stored_timestamp.hh" -) -set(CONFLICTMGR conflictmgr PARENT_SCOPE) -set_target_properties(conflictmgr PROPERTIES - COMPILE_FLAGS "-fPIC") + "${INC_DIR}/stored_timestamp.hh") +set(CONFLICTMGR + conflictmgr + PARENT_SCOPE) +target_link_libraries(conflictmgr CONAN_PKG::spdlog) +set_target_properties(conflictmgr PROPERTIES COMPILE_FLAGS "-fPIC") # Storage module. set(STORAGE "20-storage") -set(STORAGE "${STORAGE}" PARENT_SCOPE) -add_library("${STORAGE}" SHARED +set(STORAGE + "${STORAGE}" + PARENT_SCOPE) +add_library( + "${STORAGE}" SHARED # Sources. "${SRC_DIR}/connector.cc" "${SRC_DIR}/factory.cc" @@ -73,41 +77,31 @@ add_library("${STORAGE}" SHARED "${INC_DIR}/rebuilder.hh" "${INC_DIR}/remove_graph.hh" "${INC_DIR}/status.hh" - "${INC_DIR}/stream.hh" -) -set_target_properties("${STORAGE}" PROPERTIES - PREFIX "" - COMPILE_FLAGS "-fPIC") + "${INC_DIR}/stream.hh") +set_target_properties("${STORAGE}" PROPERTIES PREFIX "" COMPILE_FLAGS "-fPIC") target_link_libraries(${STORAGE} conflictmgr) # Testing. -if (WITH_TESTING) - if (WITH_SQL_TESTS) +if(WITH_TESTING) + if(WITH_SQL_TESTS) set(TEST_SOURCES ${TESTS_SOURCES} ${TEST_DIR}/conflict_manager.cc) - endif (WITH_SQL_TESTS) + endif(WITH_SQL_TESTS) # Testing. - set( - TESTS_SOURCES - ${TESTS_SOURCES} - ${TEST_DIR}/connector.cc - ${TEST_DIR}/metric.cc - ${TEST_DIR}/perfdata.cc - ${TEST_DIR}/rebuild.cc - ${TEST_DIR}/remove_graph.cc - ${TEST_DIR}/status.cc - ${TEST_DIR}/status-entry.cc - PARENT_SCOPE - ) - set( - TESTS_LIBRARIES - ${TESTS_LIBRARIES} - ${STORAGE} - PARENT_SCOPE - ) + set(TESTS_SOURCES + ${TESTS_SOURCES} + ${TEST_DIR}/connector.cc + ${TEST_DIR}/metric.cc + ${TEST_DIR}/perfdata.cc + ${TEST_DIR}/rebuild.cc + ${TEST_DIR}/remove_graph.cc + ${TEST_DIR}/status.cc + ${TEST_DIR}/status-entry.cc + PARENT_SCOPE) + set(TESTS_LIBRARIES + ${TESTS_LIBRARIES} ${STORAGE} + PARENT_SCOPE) endif() # Install rule. -install(TARGETS "${STORAGE}" - LIBRARY DESTINATION "${PREFIX_MODULES}" -) +install(TARGETS "${STORAGE}" LIBRARY DESTINATION "${PREFIX_MODULES}") diff --git a/centreon-broker/storage/inc/com/centreon/broker/storage/conflict_manager.hh b/centreon-broker/storage/inc/com/centreon/broker/storage/conflict_manager.hh index 12b51c96679..105e6aafe3d 100644 --- a/centreon-broker/storage/inc/com/centreon/broker/storage/conflict_manager.hh +++ b/centreon-broker/storage/inc/com/centreon/broker/storage/conflict_manager.hh @@ -199,6 +199,9 @@ class conflict_manager { _metric_cache; std::mutex _metric_cache_m; + std::mutex _group_clean_timer_m; + asio::system_timer _group_clean_timer; + std::unordered_set _hostgroup_cache; std::unordered_set _servicegroup_cache; @@ -333,6 +336,7 @@ class conflict_manager { void _load_deleted_instances(); void _load_caches(); void _clean_tables(uint32_t instance_id); + void _clean_group_table(); void _prepare_hg_insupdate_statement(); void _prepare_sg_insupdate_statement(); void _finish_action(int32_t conn, uint32_t action); diff --git a/centreon-broker/storage/src/conflict_manager.cc b/centreon-broker/storage/src/conflict_manager.cc index ec5f2588371..182dd7939bd 100644 --- a/centreon-broker/storage/src/conflict_manager.cc +++ b/centreon-broker/storage/src/conflict_manager.cc @@ -87,6 +87,7 @@ conflict_manager::conflict_manager(database_config const& dbcfg, _instance_timeout{instance_timeout}, _stats{stats::center::instance().register_conflict_manager()}, _ref_count{0}, + _group_clean_timer{pool::io_context()}, _oldest_timestamp{std::numeric_limits::max()} { log_v2::sql()->debug("conflict_manager: class instanciation"); stats::center::instance().update(&ConflictManagerStats::set_loop_timeout, @@ -98,6 +99,10 @@ conflict_manager::conflict_manager(database_config const& dbcfg, conflict_manager::~conflict_manager() { log_v2::sql()->debug("conflict_manager: destruction"); + { + std::lock_guard l(_group_clean_timer_m); + _group_clean_timer.cancel(); + } } /** diff --git a/centreon-broker/storage/src/conflict_manager_sql.cc b/centreon-broker/storage/src/conflict_manager_sql.cc index 152022e5dd2..4ceeadff4d8 100644 --- a/centreon-broker/storage/src/conflict_manager_sql.cc +++ b/centreon-broker/storage/src/conflict_manager_sql.cc @@ -40,6 +40,12 @@ using namespace com::centreon::broker::storage; * @param[in] instance_id Instance ID to remove. */ void conflict_manager::_clean_tables(uint32_t instance_id) { + // no hostgroup and servicegroup clean during this function + { + std::lock_guard l(_group_clean_timer_m); + _group_clean_timer.cancel(); + } + /* Database version. */ int32_t conn = _mysql.choose_connection_by_instance(instance_id); @@ -167,6 +173,35 @@ void conflict_manager::_clean_tables(uint32_t instance_id) { _mysql.run_query(query, database::mysql_error::clean_customvariables, false, conn); _add_action(conn, actions::custom_variables); + + std::lock_guard l(_group_clean_timer_m); + _group_clean_timer.expires_after(std::chrono::minutes(1)); + _group_clean_timer.async_wait([this](const asio::error_code& err) { + if (!err) { + _clean_group_table(); + } + }); +} + +void conflict_manager::_clean_group_table() { + int32_t conn = _mysql.choose_best_connection(-1); + /* Remove host groups. */ + log_v2::sql()->debug("conflict_manager: remove empty host groups "); + _mysql.run_query( + "DELETE hg FROM hostgroups AS hg LEFT JOIN hosts_hostgroups AS hhg ON " + "hg.hostgroup_id=hhg.hostgroup_id WHERE hhg.hostgroup_id IS NULL", + database::mysql_error::clean_empty_hostgroups, false, conn); + _add_action(conn, actions::hostgroups); + + /* Remove service groups. */ + log_v2::sql()->debug("conflict_manager: remove empty service groups"); + + _mysql.run_query( + "DELETE sg FROM servicegroups AS sg LEFT JOIN services_servicegroups as " + "ssg ON sg.servicegroup_id=ssg.servicegroup_id WHERE ssg.servicegroup_id " + "IS NULL", + database::mysql_error::clean_empty_servicegroups, false, conn); + _add_action(conn, actions::servicegroups); } /** diff --git a/centreon-broker/storage/test/conflict_manager.cc b/centreon-broker/storage/test/conflict_manager.cc index f1b249a9778..f3486ce28ac 100644 --- a/centreon-broker/storage/test/conflict_manager.cc +++ b/centreon-broker/storage/test/conflict_manager.cc @@ -62,7 +62,7 @@ TEST_F(ConflictManagerTest, OpenClose) { TEST_F(ConflictManagerTest, InstCVConflict) { modules::loader l; - l.load_file("./neb/10-neb.so"); + l.load_file("./lib/10-neb.so"); uint32_t loop_timeout = 5; uint32_t instance_timeout = 5; database_config dbcfg("MySQL", "127.0.0.1", 3306, "centreon", "centreon", diff --git a/centreon-broker/tcp/CMakeLists.txt b/centreon-broker/tcp/CMakeLists.txt index 75ab322f2df..4bf18c7392d 100644 --- a/centreon-broker/tcp/CMakeLists.txt +++ b/centreon-broker/tcp/CMakeLists.txt @@ -1,76 +1,60 @@ -## -## Copyright 2011 Centreon -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -## For more information : contact@centreon.com -## +# +# Copyright 2011 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 +# # Global options. set(INC_DIR "${PROJECT_SOURCE_DIR}/tcp/inc/com/centreon/broker/tcp") set(SRC_DIR "${PROJECT_SOURCE_DIR}/tcp/src") set(TEST_DIR "${PROJECT_SOURCE_DIR}/tcp/test") -include_directories(${PROJECT_SOURCE_DIR}/tcp/inc - ${PROJECT_SOURCE_DIR}/neb/inc -) +include_directories(${PROJECT_SOURCE_DIR}/tcp/inc ${PROJECT_SOURCE_DIR}/neb/inc) # Sources. set(SOURCES - "${SRC_DIR}/acceptor.cc" - "${SRC_DIR}/connector.cc" - "${SRC_DIR}/factory.cc" - "${SRC_DIR}/main.cc" - "${SRC_DIR}/stream.cc" - "${SRC_DIR}/tcp_async.cc" - "${SRC_DIR}/tcp_connection.cc" -) + "${SRC_DIR}/acceptor.cc" + "${SRC_DIR}/connector.cc" + "${SRC_DIR}/factory.cc" + "${SRC_DIR}/main.cc" + "${SRC_DIR}/stream.cc" + "${SRC_DIR}/tcp_async.cc" + "${SRC_DIR}/tcp_connection.cc") # Headers. set(HEADERS - "${INC_DIR}/acceptor.hh" - "${INC_DIR}/connector.hh" - "${INC_DIR}/factory.hh" - "${INC_DIR}/stream.hh" - "${INC_DIR}/tcp_async.hh" -) + "${INC_DIR}/acceptor.hh" "${INC_DIR}/connector.hh" "${INC_DIR}/factory.hh" + "${INC_DIR}/stream.hh" "${INC_DIR}/tcp_async.hh") # TCP module. set(TCP "50-tcp") -set(TCP "${TCP}" PARENT_SCOPE) -add_library("${TCP}" SHARED - ${SOURCES} - ${HEADERS} -) +set(TCP + "${TCP}" + PARENT_SCOPE) +add_library("${TCP}" SHARED ${SOURCES} ${HEADERS}) set_target_properties("${TCP}" PROPERTIES PREFIX "") +target_link_libraries("${TCP}" CONAN_PKG::spdlog) # Testing. -if (WITH_TESTING) - set( - TESTS_SOURCES - ${TESTS_SOURCES} - ${TEST_DIR}/acceptor.cc - ${TEST_DIR}/connector.cc - ${TEST_DIR}/factory.cc - PARENT_SCOPE - ) - set( - TESTS_LIBRARIES - ${TESTS_LIBRARIES} - ${TCP} - PARENT_SCOPE - ) +if(WITH_TESTING) + set(TESTS_SOURCES + ${TESTS_SOURCES} ${TEST_DIR}/acceptor.cc ${TEST_DIR}/connector.cc + ${TEST_DIR}/factory.cc + PARENT_SCOPE) + set(TESTS_LIBRARIES + ${TESTS_LIBRARIES} ${TCP} + PARENT_SCOPE) endif(WITH_TESTING) # Install rule. -install(TARGETS "${TCP}" - LIBRARY DESTINATION "${PREFIX_MODULES}" -) +install(TARGETS "${TCP}" LIBRARY DESTINATION "${PREFIX_MODULES}") diff --git a/centreon-broker/test/CMakeLists.txt b/centreon-broker/test/CMakeLists.txt index 5e77d8f1154..91075284eb5 100644 --- a/centreon-broker/test/CMakeLists.txt +++ b/centreon-broker/test/CMakeLists.txt @@ -1,20 +1,20 @@ -## -## Copyright 2016-2017 Centreon -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -## For more information : contact@centreon.com -## +# +# Copyright 2016-2022 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 +# find_package(GTest REQUIRED) include_directories(${GTest_INCLUDE_DIRS}) @@ -43,22 +43,32 @@ include_directories(${PROJECT_SOURCE_DIR}/tcp/inc) add_definitions(-DCENTREON_BROKER_TEST_MODULE_PATH="${CMAKE_BINARY_DIR}/test/") add_definitions(-DCENTREON_BROKER_BAM_TEST_PATH="${BAM_TESTS_DIR}") add_definitions(-DCENTREON_BROKER_WD_TEST="${WDOG_TESTS_DIR}") -add_definitions(-DCENTREON_BROKER_LUA_SCRIPT_PATH="${PROJECT_SOURCE_DIR}/lua/test") +add_definitions( + -DCENTREON_BROKER_LUA_SCRIPT_PATH="${PROJECT_SOURCE_DIR}/lua/test") add_definitions(-DCENTREON_BROKER_NEB_TEST="${PROJECT_SOURCE_DIR}/neb/test") add_library(null_module SHARED ${TEST_DIR}/modules/null_module.cc) add_library(bad_version_module SHARED ${TEST_DIR}/modules/bad_version_module.cc) + # Unit test executable. -if (WITH_SQL_TESTS) +if(WITH_SQL_TESTS) set(TEST_SOURCES ${TESTS_SOURCES} ${TESTS_DIR}/mysql/mysql.cc) -endif (WITH_SQL_TESTS) +endif(WITH_SQL_TESTS) add_definitions(-DBROKERRPC_TESTS_PATH="${TESTS_DIR}/rpc") add_executable(rpc_client ${TESTS_DIR}/rpc/client.cc) -target_link_libraries(rpc_client berpc ${gRPC_LIBS} ${re2_LIBS} ${absl_LIBS} ${OpenSSL_LIBS} ${c-ares_LIBS} ${ZLIB_LIBS} dl pthread) +target_link_libraries( + rpc_client + berpc + CONAN_PKG::grpc + CONAN_PKG::openssl + CONAN_PKG::zlib + dl + pthread) -add_executable(ut +add_executable( + ut_broker # Core sources. ${TESTS_DIR}/bbdo/category.cc ${TESTS_DIR}/bbdo/output.cc @@ -95,23 +105,39 @@ add_executable(ut ${TESTS_DIR}/io.cc ${TESTS_DIR}/main.cc ${TESTS_DIR}/test_server.cc - # Module sources. - ${TESTS_SOURCES} - ) + ${TESTS_SOURCES}) + +target_link_libraries( + ut_broker + rokerbase + roker + ${TESTS_LIBRARIES} + conflictmgr + CONAN_PKG::nlohmann_json + CONAN_PKG::asio + CONAN_PKG::spdlog + CONAN_PKG::gtest + CONAN_PKG::mariadb-connector-c + CONAN_PKG::openssl + CONAN_PKG::grpc) -#set_target_properties("ut" PROPERTIES COMPILE_FLAGS "${MYSQL_CFLAGS}") +set_target_properties( + ut_broker rpc_client + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/tests) -target_link_libraries(ut rokerbase roker ${TESTS_LIBRARIES} conflictmgr - ${nlohmann_json_LIBS} ${asio_LIBS} ${fmt_LIBS} ${spdlog_LIBS} ${GTest_LIBS} ${mariadb-connector-c_LIBS} ${OpenSSL_LIBS} ${gRPC_LIBS} ${re2_LIBS} ${absl_LIBS} ) +add_test(NAME tests COMMAND ut_broker) -add_test(NAME tests COMMAND ut) +if(WITH_COVERAGE) + set(COVERAGE_EXCLUDES '*/main.cc' '*/test/*' '/usr/include/*' + '${CMAKE_BINARY_DIR}/*') + setup_target_for_coverage(NAME test-coverage EXECUTABLE ut_broker + DEPENDENCIES ut_broker) +endif() -if (WITH_COVERAGE) - set(COVERAGE_EXCLUDES '*/main.cc' '*/test/*' '/usr/include/*' '${CMAKE_BINARY_DIR}/*') - SETUP_TARGET_FOR_COVERAGE( - NAME test-coverage - EXECUTABLE ut - DEPENDENCIES ut - ) -endif () +set_target_properties(ut_broker rpc_client PROPERTIES RUNTIME_OUTPUT_DIRECTORY + ${CMAKE_BINARY_DIR}/tests) diff --git a/centreon-broker/tls/CMakeLists.txt b/centreon-broker/tls/CMakeLists.txt index 2948bd52062..73751935505 100644 --- a/centreon-broker/tls/CMakeLists.txt +++ b/centreon-broker/tls/CMakeLists.txt @@ -1,20 +1,20 @@ -## -## Copyright 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 : contact@centreon.com -## +# +# Copyright 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 : contact@centreon.com +# # Global options. set(INC_DIR "${PROJECT_SOURCE_DIR}/tls/inc") @@ -25,26 +25,28 @@ set(INC_DIR "${INC_DIR}/com/centreon/broker/tls") # Find GNU TLS. find_file( - GNUTLS_FOUND - "gnutls.h" + GNUTLS_FOUND "gnutls.h" PATHS "/usr/gnutls2/include/gnutls" NO_DEFAULT_PATH) -if (GNUTLS_FOUND) +if(GNUTLS_FOUND) set(GNUTLS_INCLUDE_DIR "/usr/gnutls2/include") set(GNUTLS_LIBRARIES "/usr/gnutls2/lib/libgnutls.so") -else () +else() include(FindGnuTLS) - if (NOT GNUTLS_FOUND) + if(NOT GNUTLS_FOUND) message(FATAL_ERROR "Could not find GNU TLS.") - endif () -endif () + endif() +endif() include_directories("${GNUTLS_INCLUDE_DIR}") # TLS module. set(TLS "60-tls") -set(TLS "${TLS}" PARENT_SCOPE) -add_library("${TLS}" SHARED +set(TLS + "${TLS}" + PARENT_SCOPE) +add_library( + "${TLS}" SHARED # Sources "${SRC_DIR}/acceptor.cc" "${SRC_DIR}/connector.cc" @@ -59,14 +61,11 @@ add_library("${TLS}" SHARED "${INC_DIR}/factory.hh" "${INC_DIR}/internal.hh" "${INC_DIR}/params.hh" - "${INC_DIR}/stream.hh" -) + "${INC_DIR}/stream.hh") -target_link_libraries("${TLS}" ${GNUTLS_LIBRARIES}) +target_link_libraries("${TLS}" ${GNUTLS_LIBRARIES} CONAN_PKG::spdlog) set_target_properties("${TLS}" PROPERTIES PREFIX "") # Install rule. -install(TARGETS "${TLS}" - LIBRARY DESTINATION "${PREFIX_MODULES}" -) +install(TARGETS "${TLS}" LIBRARY DESTINATION "${PREFIX_MODULES}") diff --git a/centreon-broker/watchdog/CMakeLists.txt b/centreon-broker/watchdog/CMakeLists.txt index ee237ce9ef7..948b694b131 100644 --- a/centreon-broker/watchdog/CMakeLists.txt +++ b/centreon-broker/watchdog/CMakeLists.txt @@ -1,33 +1,34 @@ -## -## Copyright 2014-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 -## +# +# Copyright 2014-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 +# # Global options. set(INC_DIR "${PROJECT_SOURCE_DIR}/watchdog/inc/com/centreon/broker/watchdog") set(SRC_DIR "${PROJECT_SOURCE_DIR}/watchdog/src") set(TEST_DIR "${PROJECT_SOURCE_DIR}/watchdog/test") include_directories(${PROJECT_SOURCE_DIR}/watchdog/inc/ - ${PROJECT_SOURCE_DIR}/neb/inc/ -) + ${PROJECT_SOURCE_DIR}/neb/inc/) # Watchdog binary. set(WATCHDOG "cbwd") -set(WATCHDOG "${WATCHDOG}" PARENT_SCOPE) -add_executable("${WATCHDOG}" +set(WATCHDOG + "${WATCHDOG}" + PARENT_SCOPE) +add_executable( + "${WATCHDOG}" # Sources. ${SRC_DIR}/main.cc ${SRC_DIR}/configuration.cc @@ -38,28 +39,20 @@ add_executable("${WATCHDOG}" ${INC_DIR}/configuration.hh ${INC_DIR}/configuration_parser.hh ${INC_DIR}/instance.hh - ${INC_DIR}/instance_configuration.hh -) + ${INC_DIR}/instance_configuration.hh) -target_link_libraries(${WATCHDOG} pthread ${fmt_LIBS} ${spdlog_LIBS} ${nlohmann_json_LIBS}) +target_link_libraries(${WATCHDOG} pthread CONAN_PKG::spdlog + CONAN_PKG::nlohmann_json) -if (WITH_WATCHDOG_TESTS) +if(WITH_WATCHDOG_TESTS) # Testing. - set( - TESTS_SOURCES - ${TESTS_SOURCES} - "${TEST_DIR}/watchdog.cc" - PARENT_SCOPE - ) - set( - TESTS_LIBRARIES - ${TESTS_LIBRARIES} - "${STORAGE}" - PARENT_SCOPE - ) -endif (WITH_WATCHDOG_TESTS) + set(TESTS_SOURCES + ${TESTS_SOURCES} "${TEST_DIR}/watchdog.cc" + PARENT_SCOPE) + set(TESTS_LIBRARIES + ${TESTS_LIBRARIES} "${STORAGE}" + PARENT_SCOPE) +endif(WITH_WATCHDOG_TESTS) # Install rule. -install(TARGETS "${WATCHDOG}" - RUNTIME DESTINATION "${PREFIX_BIN}" -) +install(TARGETS "${WATCHDOG}" RUNTIME DESTINATION "${PREFIX_BIN}") diff --git a/centreon-clib/.gitignore b/centreon-clib/.gitignore index 95c77ea0902..e69de29bb2d 100644 --- a/centreon-clib/.gitignore +++ b/centreon-clib/.gitignore @@ -1,8 +0,0 @@ -.*.swp -build/* -inc/com/centreon/clib/version.hh -script/centreon-clib.pc -CMakeLists.txt.user -deps.png -tags -.vscode diff --git a/centreon-clib/CMakeLists.txt b/centreon-clib/CMakeLists.txt index 800db303ff0..90a74060e82 100644 --- a/centreon-clib/CMakeLists.txt +++ b/centreon-clib/CMakeLists.txt @@ -1,28 +1,28 @@ -## -## Copyright 2011-2014,2018-2019 Centreon -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -## For more information : contact@centreon.com -## +# +# Copyright 2011-2014,2018-2019 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 +# # Global options. -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.16) project("Centreon Clib" C CXX) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -stdlib=libc++") -#set(CMAKE_CXX_COMPILER "clang++") add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1") +set(CMAKE_CXX_STANDARD 14) + +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -stdlib=libc++") +# set(CMAKE_CXX_COMPILER "clang++") # Set directories. set(INCLUDE_DIR "${PROJECT_SOURCE_DIR}/inc") @@ -30,322 +30,245 @@ set(INC_DIR "${INCLUDE_DIR}/com/centreon") set(SRC_DIR "${PROJECT_SOURCE_DIR}/src") set(SCRIPT_DIR "${PROJECT_SOURCE_DIR}/script") - # Version. set(VERSION "$ENV{VERSION}") -if ("${VERSION}" STREQUAL "") + +if("${VERSION}" STREQUAL "") set(CLIB_MAJOR ${COLLECT_MAJOR}) set(CLIB_MINOR ${COLLECT_MINOR}) set(CLIB_PATCH ${COLLECT_PATCH}) -else () +else() string(REGEX MATCHALL "([0-9]*)\\.([0-9]*)\\.([0-9]*)" _ "${VERSION}") - # Version. + # Version. set(CLIB_MAJOR ${CMAKE_MATCH_1}) set(CLIB_MINOR ${CMAKE_MATCH_2}) set(CLIB_PATCH ${CMAKE_MATCH_3}) -endif () +endif() set(CLIB_VERSION "${CLIB_MAJOR}.${CLIB_MINOR}.${CLIB_PATCH}") - # Include module to check existing libraries. include(CheckLibraryExists) -include(${CMAKE_BINARY_DIR}/conan_paths.cmake) + # Include module CTest if necessary. -if (WITH_TESTING) +if(WITH_TESTING) include(CTest) -endif () +endif() # Code coverage on unit tests option(WITH_COVERAGE "Add code coverage on unit tests." OFF) -if (WITH_TESTING AND WITH_COVERAGE) + +if(WITH_TESTING AND WITH_COVERAGE) set(CMAKE_BUILD_TYPE "Debug") include(cmake/CodeCoverage.cmake) - APPEND_COVERAGE_COMPILER_FLAGS() -endif () + append_coverage_compiler_flags() +endif() set(CMAKE_THREAD_PREFER_PTHREAD) include(FindThreads) -if (NOT CMAKE_USE_PTHREADS_INIT) + +if(NOT CMAKE_USE_PTHREADS_INIT) message(FATAL_ERROR "Could not find pthreads library.") -endif () +endif() -if (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" AND CMAKE_COMPILER_IS_GNUCXX) +if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" AND CMAKE_COMPILER_IS_GNUCXX) set(LIB_THREAD "-pthread -lpthread") -else () +else() set(LIB_THREAD "${CMAKE_THREAD_LIBS_INIT}") -endif () +endif() # Find real time library. -if (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" - OR CMAKE_SYSTEM_NAME STREQUAL "Windows") +if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR CMAKE_SYSTEM_NAME STREQUAL "Windows") set(LIB_RT "") -else () +else() set(LIB_RT "rt") -endif () - -check_library_exists( - "${LIB_RT}" - "clock_gettime" - "${CMAKE_LIBRARY_PATH}" - FIND_LIB_RT - ) -if (NOT FIND_LIB_RT) +endif() + +check_library_exists("${LIB_RT}" "clock_gettime" "${CMAKE_LIBRARY_PATH}" + FIND_LIB_RT) + +if(NOT FIND_LIB_RT) message(FATAL_ERROR "Could not find real time library.") -endif () +endif() # Find dynamic linking library. -if (CMAKE_SYSTEM_NAME STREQUAL "Linux") +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(LIB_DL "dl") -elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" - OR CMAKE_SYSTEM_NAME STREQUAL "NetBSD" - OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") +elseif( + CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" + OR CMAKE_SYSTEM_NAME STREQUAL "NetBSD" + OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") set(LIB_DL "c") -else () +else() set(LIB_DL "") -endif () - -check_library_exists( - "${LIB_DL}" - "dlopen" - "${CMAKE_LIBRARY_PATH}" - FIND_LIB_DL - ) -if (NOT FIND_LIB_DL) - message(FATAL_ERROR "Could not find dynamic linking library.") -endif () +endif() +check_library_exists("${LIB_DL}" "dlopen" "${CMAKE_LIBRARY_PATH}" FIND_LIB_DL) + +if(NOT FIND_LIB_DL) + message(FATAL_ERROR "Could not find dynamic linking library.") +endif() # Set path. -if (WITH_PREFIX) +if(WITH_PREFIX) set(PREFIX "${WITH_PREFIX}") - set(CMAKE_INSTALL_PREFIX "${PREFIX}") -else () +else() set(PREFIX "${CMAKE_INSTALL_PREFIX}") -endif () -if (WITH_PREFIX_LIB_CLIB) +endif() + +if(WITH_PREFIX_LIB_CLIB) set(PREFIX_LIB "${WITH_PREFIX_LIB_CLIB}") -else () +else() set(PREFIX_LIB "${CMAKE_INSTALL_PREFIX}/lib") -endif () -if (WITH_PREFIX_INC) +endif() + +if(WITH_PREFIX_INC) set(PREFIX_INC "${WITH_PREFIX_INC}") -else () +else() set(PREFIX_INC "${CMAKE_INSTALL_PREFIX}/include") -endif () - +endif() # Set pkg-config options. option(WITH_PKGCONFIG_SCRIPT "Generate and install pkg-config script." ON) -if (WITH_PKGCONFIG_SCRIPT) + +if(WITH_PKGCONFIG_SCRIPT) # Generate pkg-config file. message(STATUS "Generating pkg-config file.") - configure_file( - "${SCRIPT_DIR}/centreon-clib.pc.in" - "${SCRIPT_DIR}/centreon-clib.pc" - @ONLY - ) + configure_file("${SCRIPT_DIR}/centreon-clib.pc.in" + "${SCRIPT_DIR}/centreon-clib.pc" @ONLY) # pkg-config file install directory. - if (WITH_PKGCONFIG_DIR) + if(WITH_PKGCONFIG_DIR) set(PKGCONFIG_DIR "${WITH_PKGCONFIG_DIR}") - else () + else() set(PKGCONFIG_DIR "${PREFIX_LIB}/pkgconfig") - endif () + endif() # Install rule. install( FILES "${SCRIPT_DIR}/centreon-clib.pc" DESTINATION "${PKGCONFIG_DIR}" - COMPONENT "runtime" - ) -endif () - + COMPONENT "runtime") +endif() # Set options. -option(WITH_ASAN "Add the libasan to check memory leaks and other memory issues." OFF) -if (WITH_ASAN) +option(WITH_ASAN + "Add the libasan to check memory leaks and other memory issues." OFF) + +if(WITH_ASAN) set(CMAKE_BUILD_TYPE Debug) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") - set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") -endif () + set(CMAKE_CXX_FLAGS_DEBUG + "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") + set(CMAKE_LINKER_FLAGS_DEBUG + "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") +endif() -option(WITH_TSAN "Add the libtsan to check threads and other multithreading issues." OFF) -if (WITH_TSAN) +option(WITH_TSAN + "Add the libtsan to check threads and other multithreading issues." OFF) + +if(WITH_TSAN) set(CMAKE_BUILD_TYPE Debug) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") - set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") -endif () + set(CMAKE_CXX_FLAGS_DEBUG + "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") + set(CMAKE_LINKER_FLAGS_DEBUG + "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") +endif() set(UNIT_TEST "No") -if (WITH_TESTING) + +if(WITH_TESTING) set(UNIT_TEST "Yes") -endif () +endif() set(DEB_PACKAGE "No") -if (CPACK_BINARY_DEB) + +if(CPACK_BINARY_DEB) set(DEB_PACKAGE "Yes") -endif () +endif() set(RPM_PACKAGE "No") -if (CPACK_BINARY_RPM) - set(RPM_PACKAGE "Yes") -endif () - -# Set libraries. -if (NOT WITH_SHARED_LIB AND NOT WITH_STATIC_LIB) - set(WITH_SHARED_LIB 1) -endif () - -set(SHARED_LIB "No") -if (WITH_SHARED_LIB) - set(SHARED_LIB "Yes") +if(CPACK_BINARY_RPM) + set(RPM_PACKAGE "Yes") endif() -set(STATIC_LIB "No") -if (WITH_STATIC_LIB) - set(STATIC_LIB "Yes") -endif () - -if (WITH_SHARED_LIB) - set(DEFAULT_LINK_NAME "centreon_clib_shared") -else () - set(DEFAULT_LINK_NAME "centreon_clib_static") -endif () - - # Find headers. include(CheckIncludeFileCXX) check_include_file_cxx("spawn.h" HAVE_SPAWN_H) -if (HAVE_SPAWN_H) + +if(HAVE_SPAWN_H) add_definitions(-DHAVE_SPAWN_H) -else () +else() message(WARNING "Your plateform does not have spawn.h. Some features might " - "be disabled.") -endif () + "be disabled.") +endif() # Set sources. -set( - SOURCES - "${SRC_DIR}/library.cc" - "${SRC_DIR}/process_manager.cc" - "${SRC_DIR}/process.cc" - "${SRC_DIR}/handle_manager.cc" - "${SRC_DIR}/handle_action.cc" - "${SRC_DIR}/task_manager.cc" - "${SRC_DIR}/timestamp.cc" -) - +set(SOURCES + "${SRC_DIR}/library.cc" + "${SRC_DIR}/process_manager.cc" + "${SRC_DIR}/process.cc" + "${SRC_DIR}/handle_manager.cc" + "${SRC_DIR}/handle_action.cc" + "${SRC_DIR}/task_manager.cc" + "${SRC_DIR}/timestamp.cc") # Set headers. -set( - HEADERS - ${SPECIFIC_HEADERS} - "${INC_DIR}/clib.hh" - "${INC_DIR}/handle.hh" - "${INC_DIR}/handle_action.hh" - "${INC_DIR}/handle_listener.hh" - "${INC_DIR}/handle_manager.hh" - "${INC_DIR}/hash.hh" - "${INC_DIR}/library.hh" - "${INC_DIR}/namespace.hh" - "${INC_DIR}/process_manager.hh" - "${INC_DIR}/process.hh" - "${INC_DIR}/task.hh" - "${INC_DIR}/task_manager.hh" - "${INC_DIR}/timestamp.hh" - "${INC_DIR}/unique_array_ptr.hh" - "${INC_DIR}/unordered_hash.hh" -) - +set(HEADERS + ${SPECIFIC_HEADERS} + "${INC_DIR}/clib.hh" + "${INC_DIR}/handle.hh" + "${INC_DIR}/handle_action.hh" + "${INC_DIR}/handle_listener.hh" + "${INC_DIR}/handle_manager.hh" + "${INC_DIR}/hash.hh" + "${INC_DIR}/library.hh" + "${INC_DIR}/namespace.hh" + "${INC_DIR}/process_manager.hh" + "${INC_DIR}/process.hh" + "${INC_DIR}/task.hh" + "${INC_DIR}/task_manager.hh" + "${INC_DIR}/timestamp.hh" + "${INC_DIR}/unique_array_ptr.hh" + "${INC_DIR}/unordered_hash.hh") # Include directories. include_directories("${INCLUDE_DIR}") - # Add subdirectories. add_subdirectory(src/clib) add_subdirectory(src/exceptions) add_subdirectory(src/logging) add_subdirectory(src/misc) add_subdirectory(src/io) -if (WITH_TESTING) + +if(WITH_TESTING) add_subdirectory(test) -endif () - - -if (WITH_SHARED_LIB) - # Create shared library. - add_library( - "centreon_clib_shared" - SHARED - ${SOURCES} - ${HEADERS} - ) - # Link target with required libraries. - target_link_libraries( - "centreon_clib_shared" - ${LIB_THREAD} - ${LIB_RT} - ${LIB_DL} - ) - # Set output name for the shared library. - set_target_properties( - "centreon_clib_shared" - PROPERTIES - OUTPUT_NAME - "centreon_clib" - ) - # Install shared library. - install( - TARGETS "centreon_clib_shared" - DESTINATION "${PREFIX_LIB}" - COMPONENT "runtime" - ) -endif () - - -if (WITH_STATIC_LIB) - # Create static library. - add_library( - "centreon_clib_static" - STATIC - ${SOURCES} - ${HEADERS} - ) - # Link target with required libraries. - target_link_libraries( - "centreon_clib_static" - ${LIB_THREAD} - ${LIB_RT} - ${LIB_DL} - ) - # Set output name for the static library. - set_target_properties( - "centreon_clib_static" - PROPERTIES - OUTPUT_NAME - "centreon_clib" - ) - # Install static library. - install( - TARGETS "centreon_clib_static" - DESTINATION "${PREFIX_LIB}" - COMPONENT "runtime" - ) -endif () +endif() +# Create shared library. +add_library(centreon_clib SHARED ${SOURCES} ${HEADERS}) + +# Link target with required libraries. +target_link_libraries(centreon_clib ${LIB_THREAD} ${LIB_RT} ${LIB_DL}) + +# Set output name for the shared library. +set_target_properties(centreon_clib PROPERTIES OUTPUT_NAME centreon_clib) + +# Install shared library. +install( + TARGETS centreon_clib + DESTINATION "${PREFIX_LIB}" + COMPONENT "runtime") # Install header files for devel. install( DIRECTORY "${INCLUDE_DIR}/" - DESTINATION "${PREFIX_INC}" + DESTINATION "${PREFIX_INC}/centreon-clib" COMPONENT "development" - FILES_MATCHING PATTERN "*.hh" -) - + FILES_MATCHING + PATTERN "*.hh") # Include build package. include(cmake/package.cmake) @@ -368,7 +291,7 @@ message(STATUS " - Processor ${CMAKE_SYSTEM_PROCESSOR}") message(STATUS "") message(STATUS " Build") message(STATUS " - Compiler ${CMAKE_CXX_COMPILER} " - "(${CMAKE_CXX_COMPILER_ID})") + "(${CMAKE_CXX_COMPILER_ID})") message(STATUS " - Extra compilation flags ${CMAKE_CXX_FLAGS}") message(STATUS " - Build unit tests ${UNIT_TEST}") message(STATUS "") @@ -377,7 +300,9 @@ message(STATUS " - Prefix ${PREFIX}") message(STATUS " - Library directory ${PREFIX_LIB}") message(STATUS " - Include directory ${PREFIX_INC}") message(STATUS " - Package ${PACKAGE_LIST}") -if (WITH_PKGCONFIG_SCRIPT) + +if(WITH_PKGCONFIG_SCRIPT) message(STATUS " - pkg-config directory ${PKGCONFIG_DIR}") -endif () +endif() + message(STATUS "") diff --git a/centreon-clib/test/CMakeLists.txt b/centreon-clib/test/CMakeLists.txt index 3d08192f8e4..0823b1aae2b 100644 --- a/centreon-clib/test/CMakeLists.txt +++ b/centreon-clib/test/CMakeLists.txt @@ -1,37 +1,68 @@ -find_package(GTest REQUIRED) -include_directories(${GTest_INCLUDE_DIRS}) -link_directories(${GTest_LIB_DIRS}) -add_executable(bin_test_process_output ${PROJECT_SOURCE_DIR}/test/bin_test_process_output.cc) - - -add_library(shared_testing_library - SHARED - ${PROJECT_SOURCE_DIR}/test/shared_testing_library.cc - ) - -include_directories(${PROJECT_SOURCE_DIR}/test/) - -add_executable(ut-clib - ${PROJECT_SOURCE_DIR}/test/process.cc - ${PROJECT_SOURCE_DIR}/test/exceptions.cc - ${PROJECT_SOURCE_DIR}/test/handle_manager.cc - ${PROJECT_SOURCE_DIR}/test/io.cc - ${PROJECT_SOURCE_DIR}/test/library.cc - ${PROJECT_SOURCE_DIR}/test/logging.cc - ${PROJECT_SOURCE_DIR}/test/main.cc - ${PROJECT_SOURCE_DIR}/test/misc.cc - ${PROJECT_SOURCE_DIR}/test/task_manager.cc - ${PROJECT_SOURCE_DIR}/test/timestamp.cc - ${PROJECT_SOURCE_DIR}/test/version.cc) - -if (WITH_COVERAGE) - set(COVERAGE_EXCLUDES '${PROJECT_BINARY_DIR}/*' '${PROJECT_SOURCE_DIR}/tests/*' '/usr/include/* ') - SETUP_TARGET_FOR_COVERAGE( - NAME test-coverage - EXECUTABLE ut-clib - DEPENDENCIES ut-clib - ) - set(GCOV gcov) -endif () -add_test(NAME tests COMMAND ut-clib) -target_link_libraries(ut-clib ${GTest_LIBS} pthread centreon_clib_shared) +# +# Copyright 2018-2022 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 +# + +find_package(GTest REQUIRED) +include_directories(${GTest_INCLUDE_DIRS}) +link_directories(${GTest_LIB_DIRS}) +add_executable(bin_test_process_output + ${PROJECT_SOURCE_DIR}/test/bin_test_process_output.cc) + +add_library(shared_testing_library SHARED + ${PROJECT_SOURCE_DIR}/test/shared_testing_library.cc) + +include_directories(${PROJECT_SOURCE_DIR}/test/) + +add_executable( + ut_clib + ${PROJECT_SOURCE_DIR}/test/process.cc + ${PROJECT_SOURCE_DIR}/test/exceptions.cc + ${PROJECT_SOURCE_DIR}/test/handle_manager.cc + ${PROJECT_SOURCE_DIR}/test/io.cc + ${PROJECT_SOURCE_DIR}/test/library.cc + ${PROJECT_SOURCE_DIR}/test/logging.cc + ${PROJECT_SOURCE_DIR}/test/main.cc + ${PROJECT_SOURCE_DIR}/test/misc.cc + ${PROJECT_SOURCE_DIR}/test/task_manager.cc + ${PROJECT_SOURCE_DIR}/test/timestamp.cc + ${PROJECT_SOURCE_DIR}/test/version.cc) + +set_target_properties( + shared_testing_library + PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests + LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/tests + LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/tests + LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/tests + LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/tests) +set_target_properties( + ut_clib bin_test_process_output + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/tests) + +if(WITH_COVERAGE) + set(COVERAGE_EXCLUDES '${PROJECT_BINARY_DIR}/*' + '${PROJECT_SOURCE_DIR}/tests/*' '/usr/include/* ') + setup_target_for_coverage(NAME test-coverage EXECUTABLE ut_clib DEPENDENCIES + ut_clib) + set(GCOV gcov) +endif() + +add_test(NAME tests COMMAND ut_clib) +target_link_libraries(ut_clib CONAN_PKG::gtest pthread centreon_clib) diff --git a/centreon-clib/test/library.cc b/centreon-clib/test/library.cc index 2fee2b60a42..783a4c96919 100644 --- a/centreon-clib/test/library.cc +++ b/centreon-clib/test/library.cc @@ -26,7 +26,7 @@ using namespace com::centreon::exceptions; void load_library_success() { // create library object. - library lib("./test/libshared_testing_library.so"); + library lib("./tests/libshared_testing_library.so"); if (lib.is_loaded()) throw(basic_error() << "constructor failed"); @@ -59,7 +59,7 @@ TEST(ClibLibrary, Load) { TEST(ClibLibrary, Resolve) { // create library object. - library lib("./test/libshared_testing_library.so"); + library lib("./tests/libshared_testing_library.so"); // load library. lib.load(); diff --git a/centreon-clib/test/process.cc b/centreon-clib/test/process.cc index d2207e8b221..c382a0e672b 100644 --- a/centreon-clib/test/process.cc +++ b/centreon-clib/test/process.cc @@ -38,7 +38,7 @@ TEST(ClibProcess, ProcessEnv) { char* env[] = {(char*)"key1=value1", (char*)"key2=value2", (char*)"key3=value3", NULL}; p.exec( - "./test/bin_test_process_output check_env " + "./tests/bin_test_process_output check_env " "key1=value1 key2=value2 key3=value3", env); p.wait(); @@ -59,7 +59,7 @@ TEST(ClibProcess, ProcessEnvSerial) { char* env[] = {(char*)"key1=value1", (char*)"key2=value2", (char*)"key3=value3", NULL}; p.exec( - "./test/bin_test_process_output check_env " + "./tests/bin_test_process_output check_env " "key1=value1 key2=value2 key3=value3", env); p.wait(); @@ -82,7 +82,7 @@ TEST(ClibProcess, ProcessEnvRep) { char* env[] = {(char*)"key1=value1", (char*)"key2=value2", (char*)"key3=value3", NULL}; p.exec( - "./test/bin_test_process_output check_env " + "./tests/bin_test_process_output check_env " "key1=value1 key2=value2 key3=value3", env); p.wait(); @@ -107,7 +107,7 @@ TEST(ClibProcess, ProcessEnvMT) { char* env[] = {(char*)"key1=value1", (char*)"key2=value2", (char*)"key3=value3", NULL}; p.exec( - "./test/bin_test_process_output check_env " + "./tests/bin_test_process_output check_env " "key1=value1 key2=value2 key3=value3", env); p.wait(); @@ -129,7 +129,7 @@ TEST(ClibProcess, ProcessEnvMT) { */ TEST(ClibProcess, ProcessKill) { process p; - p.exec("./test/bin_test_process_output check_sleep 1"); + p.exec("./tests/bin_test_process_output check_sleep 1"); p.kill(); timestamp start(timestamp::now()); p.wait(); @@ -148,7 +148,7 @@ TEST(ClibProcess, ProcessKillRep) { int sum = 0; process p; for (int i = 0; i < count; i++) { - p.exec("./test/bin_test_process_output check_sleep 1"); + p.exec("./tests/bin_test_process_output check_sleep 1"); p.kill(); timestamp start(timestamp::now()); p.wait(); @@ -169,7 +169,7 @@ TEST(ClibProcess, ProcessKillSerial) { int sum = 0; for (int i = 0; i < count; i++) { process p; - p.exec("./test/bin_test_process_output check_sleep 1"); + p.exec("./tests/bin_test_process_output check_sleep 1"); p.kill(); timestamp start(timestamp::now()); p.wait(); @@ -192,7 +192,7 @@ TEST(ClibProcess, ProcessKillMT) { for (int i = 0; i < count; i++) { v.emplace_back([&sum] { process p; - p.exec("./test/bin_test_process_output check_sleep 1"); + p.exec("./tests/bin_test_process_output check_sleep 1"); p.kill(); timestamp start(timestamp::now()); p.wait(); @@ -216,7 +216,7 @@ TEST(ClibProcess, ProcessKillMT) { */ TEST(ClibProcess, ProcessStdout) { process p(nullptr, false, true, false); - p.exec("./test/bin_test_process_output check_stdout 0"); + p.exec("./tests/bin_test_process_output check_stdout 0"); std::string output; p.read(output); p.wait(); @@ -235,7 +235,7 @@ TEST(ClibProcess, ProcessStdoutRep) { int sum = 0; process p(nullptr, false, true, false); for (int i = 0; i < count; i++) { - p.exec("./test/bin_test_process_output check_stdout 0"); + p.exec("./tests/bin_test_process_output check_stdout 0"); std::string output; p.read(output); p.wait(); @@ -256,7 +256,7 @@ TEST(ClibProcess, ProcessStdoutSerial) { int sum = 0; for (int i = 0; i < count; i++) { process p(nullptr, false, true, false); - p.exec("./test/bin_test_process_output check_stdout 0"); + p.exec("./tests/bin_test_process_output check_stdout 0"); std::string output; p.read(output); p.wait(); @@ -268,7 +268,7 @@ TEST(ClibProcess, ProcessStdoutSerial) { TEST(ClibProcess, ProcessOutput) { constexpr int size = 10 * 1024; - std::string cmd("./test/bin_test_process_output check_output out"); + std::string cmd("./tests/bin_test_process_output check_output out"); process p; p.exec(cmd); @@ -301,7 +301,7 @@ TEST(ClibProcess, ProcessOutput) { TEST(ClibProcess, ProcessErr) { constexpr int size = 10 * 1024; - std::string cmd("./test/bin_test_process_output check_output err"); + std::string cmd("./tests/bin_test_process_output check_output err"); process p; p.exec(cmd); @@ -333,14 +333,14 @@ TEST(ClibProcess, ProcessErr) { TEST(ClibProcess, ProcessReturn) { process p; - p.exec("./test/bin_test_process_output check_return 42"); + p.exec("./tests/bin_test_process_output check_return 42"); p.wait(); ASSERT_EQ(p.exit_code(), 42); } TEST(ClibProcess, ProcessTerminate) { process p; - p.exec("./test/bin_test_process_output check_sleep 1"); + p.exec("./tests/bin_test_process_output check_sleep 1"); p.terminate(); timestamp start(timestamp::now()); p.wait(); @@ -350,7 +350,7 @@ TEST(ClibProcess, ProcessTerminate) { TEST(ClibProcess, ProcessTimeout) { process p; - p.exec("./test/bin_test_process_output check_sleep 5", NULL, 1); + p.exec("./tests/bin_test_process_output check_sleep 5", NULL, 1); p.wait(); timestamp exectime(p.end_time() - p.start_time()); ASSERT_LT(exectime.to_seconds(), 2); @@ -358,7 +358,7 @@ TEST(ClibProcess, ProcessTimeout) { TEST(ClibProcess, ProcessWaitTimeout) { process p; - p.exec("./test/bin_test_process_output check_sleep 1"); + p.exec("./tests/bin_test_process_output check_sleep 1"); ASSERT_FALSE(p.wait(500) == true); ASSERT_FALSE(p.wait(1500) == false); } diff --git a/centreon-connector/.gitignore b/centreon-connector/.gitignore index 315f3ab862f..e69de29bb2d 100644 --- a/centreon-connector/.gitignore +++ b/centreon-connector/.gitignore @@ -1,7 +0,0 @@ -**/.*.swp -perl/src/xs_init.cc -perl/test/connector/paths.hh -ssh/test/connector/binary.hh -build/* -.idea/* -cmake-build-debug/* diff --git a/centreon-connector/CMakeLists.txt b/centreon-connector/CMakeLists.txt index 2a96759bf58..854a997eb8b 100644 --- a/centreon-connector/CMakeLists.txt +++ b/centreon-connector/CMakeLists.txt @@ -1,73 +1,80 @@ +# +# Copyright 2021-2022 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 +# + # Global options. cmake_minimum_required(VERSION 3.16) project(connectors CXX) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1") - +set(CMAKE_CXX_STANDARD 14) set(VERSION "$ENV{VERSION}") -if ("${VERSION}" STREQUAL "") + +if("${VERSION}" STREQUAL "") set(CONNECTOR_MAJOR ${COLLECT_MAJOR}) set(CONNECTOR_MINOR ${COLLECT_MINOR}) set(CONNECTOR_PATCH ${COLLECT_PATCH}) -else () +else() string(REGEX MATCHALL "([0-9]*)\\.([0-9]*)\\.([0-9]*)" _ "${VERSION}") - # Version. + # Version. set(CONNECTOR_MAJOR ${CMAKE_MATCH_1}) set(CONNECTOR_MINOR ${CMAKE_MATCH_2}) set(CONNECTOR_PATCH ${CMAKE_MATCH_3}) -endif () -set(CONNECTOR_VERSION "${CONNECTOR_MAJOR}.${CONNECTOR_MINOR}.${CONNECTOR_PATCH}") +endif() + +set(CONNECTOR_VERSION + "${CONNECTOR_MAJOR}.${CONNECTOR_MINOR}.${CONNECTOR_PATCH}") add_definitions(-DCENTREON_CONNECTOR_VERSION=\"${CONNECTOR_VERSION}\") -include(${PROJECT_SOURCE_DIR}/cmake/Findclib.cmake) include(${PROJECT_SOURCE_DIR}/cmake/Findperl.cmake) -include(${CMAKE_BINARY_DIR}/conan_paths.cmake) -find_package(fmt REQUIRED) -find_package(spdlog REQUIRED) -find_package(asio REQUIRED) -find_package(absl REQUIRED) -find_package(Boost REQUIRED) -find_package(Libssh2 REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(ZLIB REQUIRED) - - -add_definitions(${spdlog_DEFINITIONS}) - -include_directories(${fmt_INCLUDE_DIRS}) -include_directories(${spdlog_INCLUDE_DIRS}) -include_directories(${asio_INCLUDE_DIRS}) -include_directories(${absl_INCLUDE_DIRS}) -include_directories(${Boost_INCLUDE_DIRS}) - # Generate code to dynamically load modules. # Disable some warnings generated by Embedded Perl. -get_property(EMBEDDED_PERL_CXXFLAGS SOURCE ${PROJECT_SOURCE_DIR}/perl/src/embedded_perl.cc +get_property( + EMBEDDED_PERL_CXXFLAGS + SOURCE ${PROJECT_SOURCE_DIR}/perl/src/embedded_perl.cc PROPERTY COMPILE_FLAGS) -if (EMBEDDED_PERL_CXXFLAGS) - string(REGEX REPLACE "-pedantic *" - EMBEDDED_PERL_CXXFLAGS "${EMBEDDED_PERL_CXXFLAGS}") + +if(EMBEDDED_PERL_CXXFLAGS) + string(REGEX REPLACE "-pedantic *" EMBEDDED_PERL_CXXFLAGS + "${EMBEDDED_PERL_CXXFLAGS}") set_property(SOURCE "${PROJECT_SOURCE_DIR}/perl/src/embedded_perl.cc" - PROPERTY COMPILE_FLAGS "${EMBEDDED_PERL_CXXFLAGS}") -endif () + PROPERTY COMPILE_FLAGS "${EMBEDDED_PERL_CXXFLAGS}") +endif() # We will use pkg-config if available. include_directories(${PROJECT_SOURCE_DIR}/common/inc) +# Installation path. +set(PREFIX_CONNECTORS "${CMAKE_INSTALL_PREFIX}/lib64/centreon-connector/") + add_subdirectory(perl) add_subdirectory(ssh) -link_directories(${CMAKE_SOURCE_DIR}/build/centreon-clib/) # Testing. option(WITH_TESTING "Build unit tests." OFF) -if (WITH_TESTING) + +if(WITH_TESTING) find_package(GTest REQUIRED) - set_source_files_properties(${PROJECT_SOURCE_DIR}/perl/src/xs_init.cc PROPERTIES GENERATED TRUE) + set_source_files_properties(${PROJECT_SOURCE_DIR}/perl/src/xs_init.cc + PROPERTIES GENERATED TRUE) include_directories(${GTest_INCLUDE_DIRS}) include_directories(/usr/lib64/perl5/CORE) @@ -79,7 +86,8 @@ if (WITH_TESTING) add_definitions(-DBUILD_PATH="${CMAKE_BINARY_DIR}") - add_executable(ut_connector + add_executable( + ut_connector # Core sources ${PROJECT_SOURCE_DIR}/perl/src/embedded_perl.cc ${PROJECT_SOURCE_DIR}/common/src/log.cc @@ -104,13 +112,23 @@ if (WITH_TESTING) ${PROJECT_SOURCE_DIR}/ssh/test/fake_listener.cc ${PROJECT_SOURCE_DIR}/ssh/test/orders.cc ${PROJECT_SOURCE_DIR}/ssh/test/reporter.cc - ${PROJECT_SOURCE_DIR}/ssh/test/sessions.cc - ) + ${PROJECT_SOURCE_DIR}/ssh/test/sessions.cc) add_dependencies(ut_connector centreon_connector_perl) - add_dependencies(ut_connector centreon_clib_shared) - target_link_libraries(ut_connector ${GTest_LIBS} centreon_clib ${PERL_LIBRARIES} ${fmt_LIBS} ${spdlog_LIBS} ${absl_LIBS} ${Libssh2_LIBS} ${OpenSSL_LIBS} ${ZLIB_LIBS} pthread dl) + add_dependencies(ut_connector centreon_clib) + target_link_libraries( + ut_connector + CONAN_PKG::gtest + centreon_clib + ${PERL_LIBRARIES} + CONAN_PKG::spdlog + CONAN_PKG::libssh2 + CONAN_PKG::abseil) target_precompile_headers(ut_connector PRIVATE ssh/precomp_inc/precomp.hh) - - - -endif (WITH_TESTING) + set_target_properties( + ut_connector + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/tests) +endif(WITH_TESTING) diff --git a/centreon-connector/cmake/Findclib.cmake b/centreon-connector/cmake/Findclib.cmake deleted file mode 100644 index cdb084073c2..00000000000 --- a/centreon-connector/cmake/Findclib.cmake +++ /dev/null @@ -1,51 +0,0 @@ -# Find Centreon Clib's headers. -include(FindPkgConfig) -if (PKG_CONFIG_FOUND) - pkg_check_modules(CLIB QUIET "centreon-clib") # Will be used below. -endif (PKG_CONFIG_FOUND) - -if (WITH_CENTREON_CLIB_INCLUDE_DIR) - find_file( - CLIB_HEADER_FOUND - "com/centreon/clib/version.hh" - PATHS "${WITH_CENTREON_CLIB_INCLUDE_DIR}" - NO_DEFAULT_PATH) - if (NOT CLIB_HEADER_FOUND) - message(FATAL_ERROR "Could not find Centreon Clib's headers in ${WITH_CENTREON_CLIB_INCLUDE_DIR}.") - endif () - include_directories("${WITH_CENTREON_CLIB_INCLUDE_DIR}") - set(CLIB_INCLUDE_DIR "${WITH_CENTREON_CLIB_INCLUDE_DIR}") -elseif (CLIB_FOUND) # Was Centreon Clib detected with pkg-config ? - if (CMAKE_CXX_FLAGS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLIB_CFLAGS}") - else () - set(CMAKE_CXX_FLAGS "${CLIB_CFLAGS}") - endif () -else () - find_path(CLIB_INCLUDE_DIR "com/centreon/clib/version.hh" PATH_SUFFIXES "centreon-clib") - if (NOT CLIB_INCLUDE_DIR) - message(FATAL_ERROR "Could not find Centreon Clib's headers (try WITH_CENTREON_CLIB_INCLUDE_DIR).") - endif () - include_directories("${CLIB_INCLUDE_DIR}") -endif () - -# Find Centreon Clib's library. -if (WITH_CENTREON_CLIB_LIBRARIES) - set(CLIB_LIBRARIES "${WITH_CENTREON_CLIB_LIBRARIES}") -elseif (WITH_CENTREON_CLIB_LIBRARY_DIR) - find_library( - CLIB_LIBRARIES - "centreon_clib" - PATHS "${WITH_CENTREON_CLIB_LIBRARY_DIR}" - NO_DEFAULT_PATH) - if (NOT CLIB_LIBRARIES) - message(FATAL_ERROR "Could not find Centreon Clib's library in ${WITH_CENTREON_CLIB_LIBRARY_DIR}.") - endif () -elseif (CLIB_FOUND) # Was Centreon Clib detected with pkg-config ? - set(CLIB_LIBRARIES "${CLIB_LDFLAGS}") -else () - find_library(CLIB_LIBRARIES "centreon_clib") - if (NOT CLIB_LIBRARIES) - message(FATAL_ERROR "Could not find Centreon Clib's library (try WITH_CENTREON_CLIB_LIBRARY_DIR or WITH_CENTREON_CLIB_LIBRARIES).") - endif () -endif () \ No newline at end of file diff --git a/centreon-connector/perl/.gitignore b/centreon-connector/perl/.gitignore index 378eac25d31..e69de29bb2d 100644 --- a/centreon-connector/perl/.gitignore +++ b/centreon-connector/perl/.gitignore @@ -1 +0,0 @@ -build diff --git a/centreon-connector/perl/CMakeLists.txt b/centreon-connector/perl/CMakeLists.txt index 59af16e6f2c..9e716886837 100644 --- a/centreon-connector/perl/CMakeLists.txt +++ b/centreon-connector/perl/CMakeLists.txt @@ -1,29 +1,32 @@ -## -## Copyright 2011-2015,2017-2019 Centreon -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -## For more information : contact@centreon.com -## +# +# Copyright 2011-2022 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 +# # Generate code to dynamically load modules. -add_custom_command(OUTPUT "${PROJECT_SOURCE_DIR}/perl/src/xs_init.cc" - COMMAND "${PERL_EXECUTABLE}" "-MExtUtils::Embed" "-e" "xsinit" "--" "-o" "${PROJECT_SOURCE_DIR}/perl/src/xs_init.cc") +add_custom_command( + OUTPUT "${PROJECT_SOURCE_DIR}/perl/src/xs_init.cc" + COMMAND "${PERL_EXECUTABLE}" "-MExtUtils::Embed" "-e" "xsinit" "--" "-o" + "${PROJECT_SOURCE_DIR}/perl/src/xs_init.cc") include_directories(${PROJECT_SOURCE_DIR}/perl/inc/) -link_directories(${CMAKE_SOURCE_DIR}/build/centreon-clib/) +link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) + # Perl connector. -add_executable(centreon_connector_perl +add_executable( + centreon_connector_perl # Sources. ${PROJECT_SOURCE_DIR}/common/src/log.cc ${PROJECT_SOURCE_DIR}/common/src/reporter.cc @@ -47,35 +50,33 @@ add_executable(centreon_connector_perl ${PROJECT_SOURCE_DIR}/perl/inc/com/centreon/connector/perl/namespace.hh ${PROJECT_SOURCE_DIR}/perl/inc/com/centreon/connector/perl/options.hh ${PROJECT_SOURCE_DIR}/perl/inc/com/centreon/connector/perl/orders/parser.hh - ${PROJECT_SOURCE_DIR}/perl/inc/com/centreon/connector/perl/policy.hh - ) + ${PROJECT_SOURCE_DIR}/perl/inc/com/centreon/connector/perl/policy.hh) -if (TARGET centreon_clib_shared) - add_dependencies(centreon_connector_perl centreon_clib_shared) +if(TARGET centreon_clib) + add_dependencies(centreon_connector_perl centreon_clib) endif() -target_link_libraries(centreon_connector_perl centreon_clib ${PERL_LIBRARIES} ${spdlog_LIBS} ${fmt_LIBS} ${absl_LIBS} pthread) +target_link_libraries(centreon_connector_perl centreon_clib ${PERL_LIBRARIES} + CONAN_PKG::spdlog CONAN_PKG::abseil pthread) -target_precompile_headers(centreon_connector_perl PRIVATE precomp_inc/precomp.hh) +target_precompile_headers(centreon_connector_perl PRIVATE + precomp_inc/precomp.hh) -# Installation path. -if (WITH_PREFIX) - set(CMAKE_INSTALL_PREFIX "${WITH_PREFIX}") -endif () -if (WITH_PREFIX_BINARY) +if(WITH_PREFIX_BINARY) set(PREFIX_BINARY "${WITH_PREFIX_BINARY}") -else () - set(PREFIX_BINARY "${CMAKE_INSTALL_PREFIX}/bin") -endif () +else() + set(PREFIX_BINARY ${PREFIX_CONNECTORS}) +endif() # Install rules. install(TARGETS centreon_connector_perl RUNTIME DESTINATION ${PREFIX_BINARY}) # Code coverage on unit tests option(WITH_COVERAGE "Add code coverage on unit tests." OFF) -if (WITH_COVERAGE) + +if(WITH_COVERAGE) set(WITH_TESTING ON) set(CMAKE_BUILD_TYPE "Debug") include(CodeCoverage.cmake) - APPEND_COVERAGE_COMPILER_FLAGS() -endif () + append_coverage_compiler_flags() +endif() diff --git a/centreon-connector/perl/test/connector.cc b/centreon-connector/perl/test/connector.cc index 30026cebd10..88e66bd6f91 100644 --- a/centreon-connector/perl/test/connector.cc +++ b/centreon-connector/perl/test/connector.cc @@ -29,8 +29,7 @@ using namespace com::centreon; using namespace com::centreon::connector; -static std::string perl_connector = - BUILD_PATH "/centreon-connector/perl/centreon_connector_perl"; +static std::string perl_connector = BUILD_PATH "/bin/centreon_connector_perl"; static constexpr const char cmd1[] = "2\x00" @@ -209,7 +208,7 @@ TEST_F(TestConnector, ExecuteModuleLoading) { _write_file(script_path.c_str(), "#!/usr/bin/perl\n" "\n" - "use Error::Simple;\n" + "use Sys::Hostname;\n" "use IO::Socket;\n" "\n" "print \"Centreon is wonderful\\n\";\n" diff --git a/centreon-connector/ssh/CMakeLists.txt b/centreon-connector/ssh/CMakeLists.txt index 92adb6dcba7..bff798ad0d1 100644 --- a/centreon-connector/ssh/CMakeLists.txt +++ b/centreon-connector/ssh/CMakeLists.txt @@ -1,31 +1,35 @@ -## -## Copyright 2011-2015,2017-2019 Centreon -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -## For more information : contact@centreon.com -## +# +# Copyright 2011-2015,2017-2019 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 +# # Should the connector perform check against known_hosts file ? -option(WITH_KNOWN_HOSTS_CHECK "Check hosts against user's known_hosts file." OFF) -if (WITH_KNOWN_HOSTS_CHECK) +option(WITH_KNOWN_HOSTS_CHECK "Check hosts against user's known_hosts file." + OFF) + +if(WITH_KNOWN_HOSTS_CHECK) add_definitions(-DWITH_KNOWN_HOSTS_CHECK) -endif () +endif() + +include_directories(${PROJECT_SOURCE_DIR}/ssh/inc ${Boost_INCLUDE_DIRS} + ${Libssh2_INCLUDE_DIR}) +link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) -include_directories(${PROJECT_SOURCE_DIR}/ssh/inc ${Boost_INCLUDE_DIRS} ${Libssh2_INCLUDE_DIR}) -link_directories(${CMAKE_SOURCE_DIR}/build/centreon-clib/) # SSH connector. -add_executable(centreon_connector_ssh +add_executable( + centreon_connector_ssh # Sources. ${PROJECT_SOURCE_DIR}/common/src/log.cc ${PROJECT_SOURCE_DIR}/common/src/parser.cc @@ -49,36 +53,40 @@ add_executable(centreon_connector_ssh ${PROJECT_SOURCE_DIR}/ssh/inc/com/centreon/connector/ssh/orders/options.hh ${PROJECT_SOURCE_DIR}/ssh/inc/com/centreon/connector/ssh/policy.hh ${PROJECT_SOURCE_DIR}/ssh/inc/com/centreon/connector/ssh/sessions/credentials.hh - ${PROJECT_SOURCE_DIR}/ssh/inc/com/centreon/connector/ssh/sessions/session.hh -) + ${PROJECT_SOURCE_DIR}/ssh/inc/com/centreon/connector/ssh/sessions/session.hh) -if (TARGET centreon_clib_shared) - add_dependencies(centreon_connector_ssh centreon_clib_shared) +if(TARGET centreon_clib) + add_dependencies(centreon_connector_ssh centreon_clib) endif() -target_link_libraries(centreon_connector_ssh - centreon_clib ${spdlog_LIBS} ${fmt_LIBS} ${absl_LIBS} ${Libssh2_LIBS} ${OpenSSL_LIBS} ${ZLIB_LIBS} pthread dl) +target_link_libraries( + centreon_connector_ssh + centreon_clib + CONAN_PKG::spdlog + CONAN_PKG::abseil + CONAN_PKG::openssl + CONAN_PKG::zlib + CONAN_PKG::libssh2 + pthread + dl) target_precompile_headers(centreon_connector_ssh PRIVATE precomp_inc/precomp.hh) -# Installation path. -if (WITH_PREFIX) - set(CMAKE_INSTALL_PREFIX "${WITH_PREFIX}") -endif () -if (WITH_PREFIX_BINARY) +if(WITH_PREFIX_BINARY) set(PREFIX_BINARY "${WITH_PREFIX_BINARY}") -else () - set(PREFIX_BINARY "${CMAKE_INSTALL_PREFIX}/bin") -endif () +else() + set(PREFIX_BINARY ${PREFIX_CONNECTORS}) +endif() # Install rules. install(TARGETS centreon_connector_ssh RUNTIME DESTINATION ${PREFIX_BINARY}) # Code coverage on unit tests option(WITH_COVERAGE "Add code coverage on unit tests." OFF) -if (WITH_COVERAGE) + +if(WITH_COVERAGE) set(WITH_TESTING ON) set(CMAKE_BUILD_TYPE "Debug") include(CodeCoverage.cmake) - APPEND_COVERAGE_COMPILER_FLAGS() -endif () + append_coverage_compiler_flags() +endif() diff --git a/centreon-engine/.gitignore b/centreon-engine/.gitignore index a6ae72d23d6..e69de29bb2d 100644 --- a/centreon-engine/.gitignore +++ b/centreon-engine/.gitignore @@ -1,26 +0,0 @@ -*.swp -**/.idea/* -**/.vscode/* -**/build/* -conf/centengine.cfg -conf/objects/*.cfg -conf/resource.cfg -doc/_build -inc/com/centreon/engine/version.hh -inc/compatibility/common.h -inc/compatibility/locations.h -scripts/centengine.pc -scripts/centengine.sh -src/simumod/neb.cc -tags -gtest.cbp -**/CMakeFiles/* -cmake-build-debug/* -modules/bench/passive/paths.hh -enginerpc/engine.*pb.cc -enginerpc/engine.*pb.h -**/__pycache__/* -**/engine_pb2*.py -benchmark/centreon-engine/* -benchmark/log/* -benchmark/lib/* diff --git a/centreon-engine/CMakeLists.txt b/centreon-engine/CMakeLists.txt index 28716ff6dc2..fc1f95c121f 100644 --- a/centreon-engine/CMakeLists.txt +++ b/centreon-engine/CMakeLists.txt @@ -1,100 +1,84 @@ -## -## Copyright 2011-2021 Centreon -## -## This file is part of Centreon Engine. -## -## Centreon Engine is free software: you can redistribute it and/or -## modify it under the terms of the GNU General Public License version 2 -## as published by the Free Software Foundation. -## -## Centreon Engine is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Centreon Engine. If not, see -## . -## +# +# Copyright 2011-2022 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 +# # # Global settings. # # Set necessary settings. -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.16) project("Centreon Engine" C CXX) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") +add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1") +set(CMAKE_CXX_STANDARD 14) # set -latomic if OS is Raspbian. -if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm") +if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic") -endif () +endif() # With libasan -option(WITH_ASAN "Add the libasan to check memory leaks and other memory issues." OFF) -if (WITH_ASAN) +option(WITH_ASAN + "Add the libasan to check memory leaks and other memory issues." OFF) + +if(WITH_ASAN) set(CMAKE_BUILD_TYPE Debug) - set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") - set (CMAKE_LINKER_FLAGS_DEBUG - "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") -endif () + set(CMAKE_CXX_FLAGS_DEBUG + "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") + set(CMAKE_LINKER_FLAGS_DEBUG + "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") +endif() -add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1") set(INC_DIR "${PROJECT_SOURCE_DIR}/inc") set(SCRIPT_DIR "${PROJECT_SOURCE_DIR}/scripts") set(SRC_DIR "${PROJECT_SOURCE_DIR}/src") include_directories("${INC_DIR}") include_directories("${INC_DIR}/compatibility") -include(${CMAKE_BINARY_DIR}/conan_paths.cmake) - -set(protobuf_MODULE_COMPATIBLE True) -find_package(Protobuf REQUIRED) -find_package(gRPC REQUIRED) -find_package(re2 REQUIRED) -find_package(c-ares REQUIRED) -find_package(ZLIB REQUIRED) -find_package(nlohmann_json REQUIRED) -find_package(fmt REQUIRED) -find_package(spdlog REQUIRED) - -include_directories(${gRPC_INCLUDE_DIRS}) -include_directories(${absl_INCLUDE_DIRS}) -include_directories(${protobuf_INCLUDE_DIRS}) -include_directories(${nlohmann_json_INCLUDE_DIRS}) -include_directories(${fmt_INCLUDE_DIRS}) - -link_directories(${protobuf_LIB_DIRS}) -link_directories(${gRPC_LIB_DIRS}) -link_directories(${OpenSSL_LIB_DIRS}) -link_directories(${c-ares_LIB_DIRS}) -link_directories(${ZLIB_LIB_DIRS}) -link_directories(${nlohmann_json_LIB_DIRS}) -link_directories(${CMAKE_SOURCE_DIR}/build/centreon-clib/) +link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) # Version. set(VERSION "$ENV{VERSION}") -if ("${VERSION}" STREQUAL "") + +if("${VERSION}" STREQUAL "") set(CENTREON_ENGINE_MAJOR ${COLLECT_MAJOR}) set(CENTREON_ENGINE_MINOR ${COLLECT_MINOR}) set(CENTREON_ENGINE_PATCH ${COLLECT_PATCH}) -else () +else() string(REGEX MATCHALL "([0-9]*)\\.([0-9]*)\\.([0-9]*)" _ "${VERSION}") - # Version. + # Version. set(CENTREON_ENGINE_MAJOR ${CMAKE_MATCH_1}) set(CENTREON_ENGINE_MINOR ${CMAKE_MATCH_2}) set(CENTREON_ENGINE_PATCH ${CMAKE_MATCH_3}) -endif () -if (CENTREON_ENGINE_PRERELEASE) - set(CENTREON_ENGINE_VERSION "${CENTREON_ENGINE_MAJOR}.${CENTREON_ENGINE_MINOR}.${CENTREON_ENGINE_PATCH}-${CENTREON_ENGINE_PRERELEASE}") -else () - set(CENTREON_ENGINE_VERSION "${CENTREON_ENGINE_MAJOR}.${CENTREON_ENGINE_MINOR}.${CENTREON_ENGINE_PATCH}") endif() + +if(CENTREON_ENGINE_PRERELEASE) + set(CENTREON_ENGINE_VERSION + "${CENTREON_ENGINE_MAJOR}.${CENTREON_ENGINE_MINOR}.${CENTREON_ENGINE_PATCH}-${CENTREON_ENGINE_PRERELEASE}" + ) +else() + set(CENTREON_ENGINE_VERSION + "${CENTREON_ENGINE_MAJOR}.${CENTREON_ENGINE_MINOR}.${CENTREON_ENGINE_PATCH}" + ) +endif() + message(STATUS "Generating version header (${CENTREON_ENGINE_VERSION}).") configure_file("${INC_DIR}/com/centreon/engine/version.hh.in" - "${INC_DIR}/com/centreon/engine/version.hh") + "${INC_DIR}/com/centreon/engine/version.hh") # # Check and/or find required components. @@ -104,74 +88,36 @@ configure_file("${INC_DIR}/com/centreon/engine/version.hh.in" include(CheckLibraryExists) message(STATUS "Checking for libm.") check_library_exists("m" "ceil" "${CMAKE_LIBRARY_PATH}" MATH_LIB_FOUND) -if (MATH_LIB_FOUND) + +if(MATH_LIB_FOUND) set(MATH_LIBRARIES "m") -endif () +endif() + message(STATUS "Checking for libnsl.") -check_library_exists("nsl" "getservbyname" "${CMAKE_LIBRARY_PATH}" NSL_LIB_FOUND) -if (NSL_LIB_FOUND) +check_library_exists("nsl" "getservbyname" "${CMAKE_LIBRARY_PATH}" + NSL_LIB_FOUND) + +if(NSL_LIB_FOUND) set(NSL_LIBRARIES "nsl") -endif () +endif() + message(STATUS "Checking for libsocket.") -check_library_exists("socket" "connect" "${CMAKE_LIBRARY_PATH}" SOCKET_LIB_FOUND) -if (SOCKET_LIB_FOUND) +check_library_exists("socket" "connect" "${CMAKE_LIBRARY_PATH}" + SOCKET_LIB_FOUND) + +if(SOCKET_LIB_FOUND) set(SOCKET_LIBRARIES "socket") -endif () +endif() # Find pthreads. set(CMAKE_THREAD_PREFER_PTHREAD TRUE) include(FindThreads) -if (NOT CMAKE_USE_PTHREADS_INIT) + +if(NOT CMAKE_USE_PTHREADS_INIT) message(FATAL_ERROR "Could not find pthread's library.") -endif () -set(PTHREAD_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}") +endif() -# Find Centreon Clib's headers. -if (WITH_CENTREON_CLIB_INCLUDE_DIR) - find_file( - CLIB_HEADER_FOUND - "com/centreon/clib/version.hh" - PATHS "${WITH_CENTREON_CLIB_INCLUDE_DIR}" - NO_DEFAULT_PATH) - if (NOT CLIB_HEADER_FOUND) - message(FATAL_ERROR "Could not find Centreon Clib's headers in ${WITH_CENTREON_CLIB_INCLUDE_DIR}.") - endif () - include_directories("${WITH_CENTREON_CLIB_INCLUDE_DIR}") - set(CLIB_INCLUDE_DIR "${WITH_CENTREON_CLIB_INCLUDE_DIR}") -elseif (CLIB_FOUND) # Was Centreon Clib detected with pkg-config ? - if (CMAKE_CXX_FLAGS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLIB_CFLAGS}") - else () - set(CMAKE_CXX_FLAGS "${CLIB_CFLAGS}") - endif () -else () - find_path(CLIB_INCLUDE_DIR "com/centreon/clib/version.hh" PATH_SUFFIXES "centreon-clib") - if (NOT CLIB_INCLUDE_DIR) - message(FATAL_ERROR "Could not find Centreon Clib's headers (try WITH_CENTREON_CLIB_INCLUDE_DIR).") - endif () - include_directories("${CLIB_INCLUDE_DIR}") -endif () - -# Find Centreon Clib's library. -if (WITH_CENTREON_CLIB_LIBRARIES) - set(CLIB_LIBRARIES "${WITH_CENTREON_CLIB_LIBRARIES}") -elseif (WITH_CENTREON_CLIB_LIBRARY_DIR) - find_library( - CLIB_LIBRARIES - "centreon_clib" - PATHS "${WITH_CENTREON_CLIB_LIBRARY_DIR}" - NO_DEFAULT_PATH) - if (NOT CLIB_LIBRARIES) - message(FATAL_ERROR "Could not find Centreon Clib's library in ${WITH_CENTREON_CLIB_LIBRARY_DIR}.") - endif () -elseif (CLIB_FOUND) # Was Centreon Clib detected with pkg-config ? - set(CLIB_LIBRARIES "${CLIB_LDFLAGS}") -else () - find_library(CLIB_LIBRARIES "centreon_clib") - if (NOT CLIB_LIBRARIES) - message(FATAL_ERROR "Could not find Centreon Clib's library (try WITH_CENTREON_CLIB_LIBRARY_DIR or WITH_CENTREON_CLIB_LIBRARIES).") - endif () -endif () +set(PTHREAD_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}") # Check functions. include(CheckIncludeFileCXX) @@ -180,21 +126,26 @@ include(CheckStructHasMember) message(STATUS "Checking for tm_zone member in tm struct.") check_struct_has_member("tm" "tm_zone" "time.h" HAVE_TM_ZONE) -if (HAVE_TM_ZONE) + +if(HAVE_TM_ZONE) add_definitions(-DHAVE_TM_ZONE) -endif () +endif() + include(CheckSymbolExists) message(STATUS "Checking for symbol tzname.") check_symbol_exists("tzname" "time.h" HAVE_TZNAME) -if (HAVE_TZNAME) + +if(HAVE_TZNAME) add_definitions(-DHAVE_TZNAME) -endif () +endif() + message(STATUS "Checking for function getopt_long.") check_include_file_cxx("getopt.h" HAVE_GETOPT_H) check_function_exists("getopt_long" HAVE_GETOPT_LONG) -if (HAVE_GETOPT_H AND HAVE_GETOPT_LONG) + +if(HAVE_GETOPT_H AND HAVE_GETOPT_LONG) add_definitions(-DHAVE_GETOPT_H) -endif () +endif() # # Options. @@ -207,147 +158,147 @@ option(BUILD_OFFLINE "Build offline" OFF) option(WITH_CREATE_FILES "Create centreon-engine files." ON) set(CREATE_FILES "${WITH_CREATE_FILES}") -# Main directory. -if (WITH_PREFIX) - set(CMAKE_INSTALL_PREFIX "${WITH_PREFIX}") -endif () - # Executable directory. -if (WITH_PREFIX_BIN) +if(WITH_PREFIX_BIN) set(PREFIX_BIN "${WITH_PREFIX_BIN}") -else () - set(PREFIX_BIN "${CMAKE_INSTALL_PREFIX}/bin") -endif () +else() + set(PREFIX_BIN "${CMAKE_INSTALL_PREFIX}/sbin") +endif() # Configuration directory. -if (WITH_PREFIX_CONF_ENGINE) +if(WITH_PREFIX_CONF_ENGINE) set(PREFIX_CONF "${WITH_PREFIX_CONF_ENGINE}") -else () - set(PREFIX_CONF "${CMAKE_INSTALL_PREFIX}/etc") -endif () +else() + set(PREFIX_CONF "/etc/centreon-engine") +endif() # Library directory. -if (WITH_PREFIX_LIB_ENGINE) +if(WITH_PREFIX_LIB_ENGINE) set(PREFIX_LIB "${WITH_PREFIX_LIB_ENGINE}") -else () +else() set(PREFIX_LIB "${CMAKE_INSTALL_PREFIX}/lib/centreon-engine") -endif () +endif() # Development headers directory. -if (WITH_PREFIX_INC) +if(WITH_PREFIX_INC) set(PREFIX_INC "${WITH_PREFIX_INC}") -else () +else() set(PREFIX_INC "${CMAKE_INSTALL_PREFIX}/include/centreon-engine") -endif () +endif() # pkg-config directory. option(WITH_PKGCONFIG_SCRIPT "Generate and install pkg-config script." ON) -if (WITH_PKGCONFIG_SCRIPT) + +if(WITH_PKGCONFIG_SCRIPT) # Generate pkg-config file. message(STATUS "Generating pkg-config file.") - configure_file( - "${SCRIPT_DIR}/centengine.pc.in" - "${SCRIPT_DIR}/centengine.pc" - @ONLY) + configure_file("${SCRIPT_DIR}/centengine.pc.in" "${SCRIPT_DIR}/centengine.pc" + @ONLY) # pkg-config file install directory. - if (WITH_PKGCONFIG_DIR) + if(WITH_PKGCONFIG_DIR) set(PKGCONFIG_DIR "${WITH_PKGCONFIG_DIR}") - else () + else() set(PKGCONFIG_DIR "${PREFIX_LIB}/pkgconfig") - endif () + endif() # Install rule. - install(FILES "${SCRIPT_DIR}/centengine.pc" + install( + FILES "${SCRIPT_DIR}/centengine.pc" DESTINATION "${PKGCONFIG_DIR}" COMPONENT "runtime") -endif () +endif() # var directory. -if (WITH_VAR_DIR) +if(WITH_VAR_DIR) set(VAR_DIR "${WITH_VAR_DIR}") -else () - set(VAR_DIR "${CMAKE_INSTALL_PREFIX}/var") -endif () +else() + set(VAR_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-engine") +endif() # Log archive dir. -if (WITH_LOG_ARCHIVE_DIR) +if(WITH_LOG_ARCHIVE_DIR) set(LOG_ARCHIVE_DIR "${WITH_LOG_ARCHIVE_DIR}") -else () +else() set(LOG_ARCHIVE_DIR "${VAR_DIR}/archives") -endif () +endif() # RW dir. -if (WITH_RW_DIR) +if(WITH_RW_DIR) set(RW_DIR "${WITH_RW_DIR}") -else () +else() set(RW_DIR "${VAR_DIR}/rw") -endif () +endif() # User used to run Centreon Engine. -if (WITH_USER_ENGINE) +if(WITH_USER_ENGINE) set(USER "${WITH_USER_ENGINE}") -else () +else() set(USER "root") -endif () +endif() # Group used to run Centreon Engine. -if (WITH_GROUP_ENGINE) +if(WITH_GROUP_ENGINE) set(GROUP "${WITH_GROUP_ENGINE}") -else () +else() set(GROUP "root") -endif () +endif() # Check OS distributor. -if (CMAKE_SYSTEM_NAME STREQUAL "Linux") +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") message(STATUS "Attempting to determine OS distributor.") - execute_process(COMMAND "lsb_release" "--short" "--id" + execute_process( + COMMAND "lsb_release" "--short" "--id" RESULT_VARIABLE RETCODE OUTPUT_VARIABLE OS_DISTRIBUTOR ERROR_QUIET) - if (RETCODE EQUAL 0) + + if(RETCODE EQUAL 0) string(REGEX REPLACE "\n$" "" OS_DISTRIBUTOR "${OS_DISTRIBUTOR}") - else () + else() set(OS_DISTRIBUTOR "${CMAKE_SYSTEM_NAME}") - endif () -elseif () + endif() +elseif() set(OS_DISTRIBUTOR "${CMAKE_SYSTEM_NAME}") -endif () +endif() # Set startup script to auto if not define. -if (NOT WITH_STARTUP_SCRIPT) +if(NOT WITH_STARTUP_SCRIPT) set(WITH_STARTUP_SCRIPT "auto") -endif () +endif() # Check which startup script to use. -if (WITH_STARTUP_SCRIPT STREQUAL "auto") - if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - if (OS_DISTRIBUTOR STREQUAL "Ubuntu") +if(WITH_STARTUP_SCRIPT STREQUAL "auto") + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + if(OS_DISTRIBUTOR STREQUAL "Ubuntu") set(WITH_STARTUP_SCRIPT "upstart") - else () + else() set(WITH_STARTUP_SCRIPT "sysv") - endif () - else () - message(STATUS "Centreon Engine does not provide startup script for ${CMAKE_SYSTEM_NAME}.") - endif () -endif () + endif() + else() + message( + STATUS + "Centreon Engine does not provide startup script for ${CMAKE_SYSTEM_NAME}." + ) + endif() +endif() # Create upstart file. -if (WITH_STARTUP_SCRIPT STREQUAL "upstart") +if(WITH_STARTUP_SCRIPT STREQUAL "upstart") # Generate Upstart script. message(STATUS "Generating upstart script.") - configure_file("${SCRIPT_DIR}/upstart.conf.in" - "${SCRIPT_DIR}/upstart.conf") + configure_file("${SCRIPT_DIR}/upstart.conf.in" "${SCRIPT_DIR}/upstart.conf") # Startup dir. - if (WITH_STARTUP_DIR) + if(WITH_STARTUP_DIR) set(STARTUP_DIR "${WITH_STARTUP_DIR}") - else () + else() set(STARTUP_DIR "/etc/init") - endif () + endif() # Script install rule. - install(FILES "${SCRIPT_DIR}/upstart.conf" + install( + FILES "${SCRIPT_DIR}/upstart.conf" DESTINATION "${STARTUP_DIR}" COMPONENT "runtime" RENAME "centengine.conf") @@ -355,44 +306,46 @@ if (WITH_STARTUP_SCRIPT STREQUAL "upstart") # String printed in summary. set(STARTUP_SCRIPT "Upstart configuration file") -# Create SysV start script. -elseif (WITH_STARTUP_SCRIPT STREQUAL "sysv") + # Create SysV start script. +elseif(WITH_STARTUP_SCRIPT STREQUAL "sysv") # Lock file. - if (WITH_LOCK_FILE) + if(WITH_LOCK_FILE) set(LOCK_FILE "${WITH_LOCK_FILE}") - else () - if (OS_DISTRIBUTOR STREQUAL "Ubuntu" - OR OS_DISTRIBUTOR STREQUAL "Debian" - OR OS_DISTRIBUTOR STREQUAL "SUSE LINUX") + else() + if(OS_DISTRIBUTOR STREQUAL "Ubuntu" + OR OS_DISTRIBUTOR STREQUAL "Debian" + OR OS_DISTRIBUTOR STREQUAL "SUSE LINUX") set(LOCK_FILE "/var/lock/centengine.lock") - else () + else() set(LOCK_FILE "/var/lock/subsys/centengine.lock") - endif () - endif () + endif() + endif() + string(REGEX REPLACE "/[^/]*$" "" LOCK_DIR "${LOCK_FILE}") # PID file. - if (WITH_PID_FILE) + if(WITH_PID_FILE) set(PID_FILE "${WITH_PID_FILE}") - else () + else() set(PID_FILE "/var/run/centengine.pid") - endif () + endif() + string(REGEX REPLACE "/[^/]*$" "" PID_DIR "${PID_FILE}") # Generate SysV script. message(STATUS "Generating generic startup script.") - configure_file("${SCRIPT_DIR}/centengine.sh.in" - "${SCRIPT_DIR}/centengine.sh") + configure_file("${SCRIPT_DIR}/centengine.sh.in" "${SCRIPT_DIR}/centengine.sh") # Startup dir. - if (WITH_STARTUP_DIR) + if(WITH_STARTUP_DIR) set(STARTUP_DIR "${WITH_STARTUP_DIR}") - else () + else() set(STARTUP_DIR "/etc/init.d") - endif () + endif() # Script install rule. - install(PROGRAMS "${SCRIPT_DIR}/centengine.sh" + install( + PROGRAMS "${SCRIPT_DIR}/centengine.sh" DESTINATION "${STARTUP_DIR}" COMPONENT "runtime" RENAME "centengine") @@ -400,105 +353,115 @@ elseif (WITH_STARTUP_SCRIPT STREQUAL "sysv") # String printed in summary. set(STARTUP_SCRIPT "SysV-style script") -# Create Systemd start script. -elseif (WITH_STARTUP_SCRIPT STREQUAL "systemd") + # Create Systemd start script. +elseif(WITH_STARTUP_SCRIPT STREQUAL "systemd") # Generate Systemd script. message(STATUS "Generating systemd startup script.") configure_file("${SCRIPT_DIR}/centengine.service.in" - "${SCRIPT_DIR}/centengine.service") + "${SCRIPT_DIR}/centengine.service") # Startup dir. - if (WITH_STARTUP_DIR) + if(WITH_STARTUP_DIR) set(STARTUP_DIR "${WITH_STARTUP_DIR}") - else () + else() set(STARTUP_DIR "/etc/systemd/system") - endif () + endif() # Script install rule. - install(PROGRAMS "${SCRIPT_DIR}/centengine.service" + install( + PROGRAMS "${SCRIPT_DIR}/centengine.service" DESTINATION "${STARTUP_DIR}" COMPONENT "runtime") # String printed in summary. set(STARTUP_SCRIPT "Systemd script") -else () +else() # Default. - message(STATUS "Invalid value for option WITH_STARTUP_SCRIPT (must be one of 'auto', 'sysv' or 'upstart').") + message( + STATUS + "Invalid value for option WITH_STARTUP_SCRIPT (must be one of 'auto', 'sysv' or 'upstart')." + ) set(STARTUP_SCRIPT "disabled") -endif () +endif() # logrotate directory. -option(WITH_LOGROTATE_SCRIPT "Generate and install logrotate script." OFF) -if (WITH_LOGROTATE_SCRIPT) +option(WITH_ENGINE_LOGROTATE_SCRIPT "Generate and install logrotate script." + OFF) + +if(WITH_ENGINE_LOGROTATE_SCRIPT) # Generate logrotate file. message(STATUS "Generating logrorate file.") - if (WITH_STARTUP_SCRIPT STREQUAL "upstart") - configure_file( - "${SCRIPT_DIR}/logrotate_upstart.conf.in" - "${SCRIPT_DIR}/logrotate.conf" - @ONLY) - elseif (WITH_STARTUP_SCRIPT STREQUAL "systemd") - configure_file( - "${SCRIPT_DIR}/logrotate_systemd.conf.in" - "${SCRIPT_DIR}/logrotate.conf" - @ONLY) - else () - configure_file( - "${SCRIPT_DIR}/logrotate_sysv.conf.in" - "${SCRIPT_DIR}/logrotate.conf" - @ONLY) - endif () + + if(WITH_STARTUP_SCRIPT STREQUAL "upstart") + configure_file("${SCRIPT_DIR}/logrotate_upstart.conf.in" + "${SCRIPT_DIR}/logrotate.conf" @ONLY) + elseif(WITH_STARTUP_SCRIPT STREQUAL "systemd") + configure_file("${SCRIPT_DIR}/logrotate_systemd.conf.in" + "${SCRIPT_DIR}/logrotate.conf" @ONLY) + else() + configure_file("${SCRIPT_DIR}/logrotate_sysv.conf.in" + "${SCRIPT_DIR}/logrotate.conf" @ONLY) + endif() # logrotate file install directory. - if (WITH_LOGROTATE_DIR) + if(WITH_LOGROTATE_DIR) set(LOGROTATE_DIR "${WITH_LOGROTATE_DIR}") - else () + else() set(LOGROTATE_DIR "/etc/logrotate.d") - endif () + endif() # Install rule. install( FILES "${SCRIPT_DIR}/logrotate.conf" DESTINATION "${LOGROTATE_DIR}" COMPONENT "runtime" - RENAME "centengine" - ) -endif () + RENAME "centengine") +endif() -option(WITH_SHARED_LIB "Define if the core library is to be build as a shared object or a static library." OFF) -if (WITH_SHARED_LIB) +option( + WITH_SHARED_LIB + "Define if the core library is to be build as a shared object or a static library." + OFF) + +if(WITH_SHARED_LIB) set(LIBRARY_TYPE SHARED) -else () +else() set(LIBRARY_TYPE STATIC) -endif () +endif() # Code coverage on unit tests option(WITH_COVERAGE "Add code coverage on unit tests." OFF) -if (WITH_TESTING AND WITH_COVERAGE) + +if(WITH_TESTING AND WITH_COVERAGE) set(CMAKE_BUILD_TYPE "Debug") include(cmake/CodeCoverage.cmake) - APPEND_COVERAGE_COMPILER_FLAGS() + append_coverage_compiler_flags() endif() # Simumod module to simulate cbmod and catch its output -option(WITH_SIMU "Add a module only used for tests to see data that cbmod should receive" OFF) -if (WITH_SIMU) +option(WITH_SIMU + "Add a module only used for tests to see data that cbmod should receive" + OFF) + +if(WITH_SIMU) set(CMAKE_BUILD_TYPE "Debug") add_subdirectory(src/simumod) -endif () +endif() # DEBUG_CONFIG enables checks on configuration. Those checks are not free and -# may slow down engine reloads. But it provides a way to check bugs in -# the configuration system. -option(WITH_DEBUG_CONFIG "Enables checks on configuration. This is an option for developers." OFF) -if (WITH_DEBUG_CONFIG) +# may slow down engine reloads. But it provides a way to check bugs in the +# configuration system. +option(WITH_DEBUG_CONFIG + "Enables checks on configuration. This is an option for developers." OFF) + +if(WITH_DEBUG_CONFIG) add_definitions(-DDEBUG_CONFIG) -endif () +endif() # Configure files. configure_file("${INC_DIR}/compatibility/common.h.in" - "${INC_DIR}/compatibility/common.h") + "${INC_DIR}/compatibility/common.h") # Locations definitions add_definitions(-DDEFAULT_STATUS_FILE="${VAR_DIR}/status.dat") @@ -510,113 +473,108 @@ add_definitions(-DDEFAULT_COMMAND_FILE="${RW_DIR}/centengine.cmd") add_definitions(-DDEFAULT_CONFIG_FILE="${PREFIX_CONF}/centengine.cfg") # Add specific linker flags for Mac OS to build correctly shared libraries. -if (APPLE) +if(APPLE) set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-undefined -Wl,dynamic_lookup") -endif () +endif() # # Targets. # - -set( - FILES - - # Sources. - "${SRC_DIR}/anomalydetection.cc" - "${SRC_DIR}/broker.cc" - "${SRC_DIR}/checkable.cc" - "${SRC_DIR}/check_result.cc" - "${SRC_DIR}/command_manager.cc" - "${SRC_DIR}/comment.cc" - "${SRC_DIR}/config.cc" - "${SRC_DIR}/contact.cc" - "${SRC_DIR}/contactgroup.cc" - "${SRC_DIR}/customvariable.cc" - "${SRC_DIR}/daterange.cc" - "${SRC_DIR}/dependency.cc" - "${SRC_DIR}/diagnostic.cc" - "${SRC_DIR}/exceptions/error.cc" - "${SRC_DIR}/flapping.cc" - "${SRC_DIR}/escalation.cc" - "${SRC_DIR}/globals.cc" - "${SRC_DIR}/host.cc" - "${SRC_DIR}/hostdependency.cc" - "${SRC_DIR}/hostescalation.cc" - "${SRC_DIR}/hostgroup.cc" - "${SRC_DIR}/macros.cc" - "${SRC_DIR}/nebmods.cc" - "${SRC_DIR}/notification.cc" - "${SRC_DIR}/notifier.cc" - "${SRC_DIR}/sehandlers.cc" - "${SRC_DIR}/service.cc" - "${SRC_DIR}/servicedependency.cc" - "${SRC_DIR}/serviceescalation.cc" - "${SRC_DIR}/servicegroup.cc" - "${SRC_DIR}/shared.cc" - "${SRC_DIR}/statistics.cc" - "${SRC_DIR}/statusdata.cc" - "${SRC_DIR}/string.cc" - "${SRC_DIR}/timeperiod.cc" - "${SRC_DIR}/timerange.cc" - "${SRC_DIR}/timezone_locker.cc" - "${SRC_DIR}/timezone_manager.cc" - "${SRC_DIR}/utils.cc" - "${SRC_DIR}/xpddefault.cc" - "${SRC_DIR}/xsddefault.cc" - - # Headers. - "${INC_DIR}/com/centreon/engine/anomalydetection.hh" - "${INC_DIR}/com/centreon/engine/broker.hh" - "${INC_DIR}/com/centreon/engine/checkable.hh" - "${INC_DIR}/com/centreon/engine/check_result.hh" - "${INC_DIR}/com/centreon/engine/circular_buffer.hh" - "${INC_DIR}/com/centreon/engine/command_manager.hh" - "${INC_DIR}/com/centreon/engine/comment.hh" - "${INC_DIR}/com/centreon/engine/common.hh" - "${INC_DIR}/com/centreon/engine/config.hh" - "${INC_DIR}/com/centreon/engine/contact.hh" - "${INC_DIR}/com/centreon/engine/contactgroup.hh" - "${INC_DIR}/com/centreon/engine/customvariable.hh" - "${INC_DIR}/com/centreon/engine/daterange.hh" - "${INC_DIR}/com/centreon/engine/dependency.hh" - "${INC_DIR}/com/centreon/engine/diagnostic.hh" - "${INC_DIR}/com/centreon/engine/exceptions/error.hh" - "${INC_DIR}/com/centreon/engine/escalation.hh" - "${INC_DIR}/com/centreon/engine/flapping.hh" - "${INC_DIR}/com/centreon/engine/globals.hh" - "${INC_DIR}/com/centreon/engine/host.hh" - "${INC_DIR}/com/centreon/engine/hostdependency.hh" - "${INC_DIR}/com/centreon/engine/hostescalation.hh" - "${INC_DIR}/com/centreon/engine/hostgroup.hh" - "${INC_DIR}/com/centreon/engine/logging.hh" - "${INC_DIR}/com/centreon/engine/macros.hh" - "${INC_DIR}/com/centreon/engine/nebcallbacks.hh" - "${INC_DIR}/com/centreon/engine/neberrors.hh" - "${INC_DIR}/com/centreon/engine/nebmods.hh" - "${INC_DIR}/com/centreon/engine/nebmodules.hh" - "${INC_DIR}/com/centreon/engine/nebstructs.hh" - "${INC_DIR}/com/centreon/engine/notification.hh" - "${INC_DIR}/com/centreon/engine/notifier.hh" - "${INC_DIR}/com/centreon/engine/objects.hh" - "${INC_DIR}/com/centreon/engine/opt.hh" - "${INC_DIR}/com/centreon/engine/sehandlers.hh" - "${INC_DIR}/com/centreon/engine/service.hh" - "${INC_DIR}/com/centreon/engine/servicedependency.hh" - "${INC_DIR}/com/centreon/engine/serviceescalation.hh" - "${INC_DIR}/com/centreon/engine/servicegroup.hh" - "${INC_DIR}/com/centreon/engine/shared.hh" - "${INC_DIR}/com/centreon/engine/statistics.hh" - "${INC_DIR}/com/centreon/engine/statusdata.hh" - "${INC_DIR}/com/centreon/engine/string.hh" - "${INC_DIR}/com/centreon/engine/timeperiod.hh" - "${INC_DIR}/com/centreon/engine/timerange.hh" - "${INC_DIR}/com/centreon/engine/timezone_locker.hh" - "${INC_DIR}/com/centreon/engine/timezone_manager.hh" - "${INC_DIR}/com/centreon/engine/utils.hh" - "${INC_DIR}/com/centreon/engine/version.hh" - "${INC_DIR}/com/centreon/engine/xpddefault.hh" - "${INC_DIR}/com/centreon/engine/xsddefault.hh" -) +set(FILES + # Sources. + "${SRC_DIR}/anomalydetection.cc" + "${SRC_DIR}/broker.cc" + "${SRC_DIR}/checkable.cc" + "${SRC_DIR}/check_result.cc" + "${SRC_DIR}/command_manager.cc" + "${SRC_DIR}/comment.cc" + "${SRC_DIR}/config.cc" + "${SRC_DIR}/contact.cc" + "${SRC_DIR}/contactgroup.cc" + "${SRC_DIR}/customvariable.cc" + "${SRC_DIR}/daterange.cc" + "${SRC_DIR}/dependency.cc" + "${SRC_DIR}/diagnostic.cc" + "${SRC_DIR}/exceptions/error.cc" + "${SRC_DIR}/flapping.cc" + "${SRC_DIR}/escalation.cc" + "${SRC_DIR}/globals.cc" + "${SRC_DIR}/host.cc" + "${SRC_DIR}/hostdependency.cc" + "${SRC_DIR}/hostescalation.cc" + "${SRC_DIR}/hostgroup.cc" + "${SRC_DIR}/macros.cc" + "${SRC_DIR}/nebmods.cc" + "${SRC_DIR}/notification.cc" + "${SRC_DIR}/notifier.cc" + "${SRC_DIR}/sehandlers.cc" + "${SRC_DIR}/service.cc" + "${SRC_DIR}/servicedependency.cc" + "${SRC_DIR}/serviceescalation.cc" + "${SRC_DIR}/servicegroup.cc" + "${SRC_DIR}/shared.cc" + "${SRC_DIR}/statistics.cc" + "${SRC_DIR}/statusdata.cc" + "${SRC_DIR}/string.cc" + "${SRC_DIR}/timeperiod.cc" + "${SRC_DIR}/timerange.cc" + "${SRC_DIR}/timezone_locker.cc" + "${SRC_DIR}/timezone_manager.cc" + "${SRC_DIR}/utils.cc" + "${SRC_DIR}/xpddefault.cc" + "${SRC_DIR}/xsddefault.cc" + # Headers. + "${INC_DIR}/com/centreon/engine/anomalydetection.hh" + "${INC_DIR}/com/centreon/engine/broker.hh" + "${INC_DIR}/com/centreon/engine/checkable.hh" + "${INC_DIR}/com/centreon/engine/check_result.hh" + "${INC_DIR}/com/centreon/engine/circular_buffer.hh" + "${INC_DIR}/com/centreon/engine/command_manager.hh" + "${INC_DIR}/com/centreon/engine/comment.hh" + "${INC_DIR}/com/centreon/engine/common.hh" + "${INC_DIR}/com/centreon/engine/config.hh" + "${INC_DIR}/com/centreon/engine/contact.hh" + "${INC_DIR}/com/centreon/engine/contactgroup.hh" + "${INC_DIR}/com/centreon/engine/customvariable.hh" + "${INC_DIR}/com/centreon/engine/daterange.hh" + "${INC_DIR}/com/centreon/engine/dependency.hh" + "${INC_DIR}/com/centreon/engine/diagnostic.hh" + "${INC_DIR}/com/centreon/engine/exceptions/error.hh" + "${INC_DIR}/com/centreon/engine/escalation.hh" + "${INC_DIR}/com/centreon/engine/flapping.hh" + "${INC_DIR}/com/centreon/engine/globals.hh" + "${INC_DIR}/com/centreon/engine/host.hh" + "${INC_DIR}/com/centreon/engine/hostdependency.hh" + "${INC_DIR}/com/centreon/engine/hostescalation.hh" + "${INC_DIR}/com/centreon/engine/hostgroup.hh" + "${INC_DIR}/com/centreon/engine/logging.hh" + "${INC_DIR}/com/centreon/engine/macros.hh" + "${INC_DIR}/com/centreon/engine/nebcallbacks.hh" + "${INC_DIR}/com/centreon/engine/neberrors.hh" + "${INC_DIR}/com/centreon/engine/nebmods.hh" + "${INC_DIR}/com/centreon/engine/nebmodules.hh" + "${INC_DIR}/com/centreon/engine/nebstructs.hh" + "${INC_DIR}/com/centreon/engine/notification.hh" + "${INC_DIR}/com/centreon/engine/notifier.hh" + "${INC_DIR}/com/centreon/engine/objects.hh" + "${INC_DIR}/com/centreon/engine/opt.hh" + "${INC_DIR}/com/centreon/engine/sehandlers.hh" + "${INC_DIR}/com/centreon/engine/service.hh" + "${INC_DIR}/com/centreon/engine/servicedependency.hh" + "${INC_DIR}/com/centreon/engine/serviceescalation.hh" + "${INC_DIR}/com/centreon/engine/servicegroup.hh" + "${INC_DIR}/com/centreon/engine/shared.hh" + "${INC_DIR}/com/centreon/engine/statistics.hh" + "${INC_DIR}/com/centreon/engine/statusdata.hh" + "${INC_DIR}/com/centreon/engine/string.hh" + "${INC_DIR}/com/centreon/engine/timeperiod.hh" + "${INC_DIR}/com/centreon/engine/timerange.hh" + "${INC_DIR}/com/centreon/engine/timezone_locker.hh" + "${INC_DIR}/com/centreon/engine/timezone_manager.hh" + "${INC_DIR}/com/centreon/engine/utils.hh" + "${INC_DIR}/com/centreon/engine/version.hh" + "${INC_DIR}/com/centreon/engine/xpddefault.hh" + "${INC_DIR}/com/centreon/engine/xsddefault.hh") # Subdirectories with core features. add_subdirectory(src/broker) @@ -638,31 +596,40 @@ include_directories(enginerpc) # Library engine target. add_library(cce_core ${LIBRARY_TYPE} ${FILES}) add_dependencies(cce_core engine_rpc) -add_dependencies(cce_core centreon_clib_shared) +add_dependencies(cce_core centreon_clib) # Link target with required libraries. -target_link_libraries(cce_core ${nlohmann_json_LIBS} +target_link_libraries( + cce_core + CONAN_PKG::nlohmann_json ${MATH_LIBRARIES} ${PTHREAD_LIBRARIES} ${SOCKET_LIBRARIES} centreon_clib - ${fmt_LIBRARIES} -) + CONAN_PKG::spdlog) # centengine target. add_executable("centengine" "${SRC_DIR}/main.cc") set_property(TARGET "centengine" PROPERTY ENABLE_EXPORTS "1") -add_dependencies(centengine centreon_clib_shared) -get_property(CENTENGINE_BINARY TARGET "centengine" PROPERTY LOCATION) +add_dependencies(centengine centreon_clib) # Link centengine with required libraries. -target_link_libraries(centengine centreon_clib "-Wl,-whole-archive" enginerpc cce_core "-Wl,-no-whole-archive" ${gRPC_LIBS} ${re2_LIBS} ${absl_LIBS} ${OpenSSL_LIBS} ${c-ares_LIBS} ${ZLIB_LIBS} dl) +target_link_libraries( + centengine + centreon_clib + "-Wl,-whole-archive" + enginerpc + cce_core + "-Wl,-no-whole-archive" + CONAN_PKG::grpc + CONAN_PKG::openssl + CONAN_PKG::zlib + dl) # centenginestats target. add_executable("centenginestats" "${SRC_DIR}/centenginestats.cc") -add_dependencies("centenginestats" centreon_clib_shared) +add_dependencies("centenginestats" centreon_clib) target_link_libraries("centenginestats" centreon_clib) -get_property(CENTENGINESTATS_BINARY TARGET "centenginestats" PROPERTY LOCATION) # Unit tests. add_subdirectory(tests) @@ -672,13 +639,15 @@ add_subdirectory(tests) # # Install rules. -install(TARGETS "centengine" "centenginestats" +install( + TARGETS "centengine" "centenginestats" DESTINATION "${PREFIX_BIN}" COMPONENT "runtime") -## Create directories. -if (CREATE_FILES) - install(CODE " +# # Create directories. +if(CREATE_FILES) + install( + CODE " function(mkdir_chown user group path) if (APPLE OR (UNIX AND NOT CYGWIN)) if (NOT EXISTS \"\$ENV{DESTDIR}\${path}\") @@ -722,26 +691,25 @@ if (CREATE_FILES) touch_chown(\"${USER}\" \"${GROUP}\" \"${VAR_DIR}/centengine.debug\") touch_chown(\"${USER}\" \"${GROUP}\" \"${VAR_DIR}/retention.dat\") ") -endif () +endif() # Install header files for development. -install(DIRECTORY "${INC_DIR}/" +install( + DIRECTORY "${INC_DIR}/" DESTINATION "${PREFIX_INC}" COMPONENT "development" - FILES_MATCHING PATTERN "*.hh" - PATTERN "${INC_DIR}/compatibility/" EXCLUDE -) + FILES_MATCHING + PATTERN "*.hh" + PATTERN "${INC_DIR}/compatibility/" EXCLUDE) # # Packaging. # - include(cmake/package.cmake) # # Print summary. # - message(STATUS "") message(STATUS "") message(STATUS "Configuration Summary") @@ -757,34 +725,44 @@ message(STATUS " - Version ${CMAKE_SYSTEM_VERSION}") message(STATUS " - Processor ${CMAKE_SYSTEM_PROCESSOR}") message(STATUS "") message(STATUS " Build") -message(STATUS " - Compiler ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_ID})") +message( + STATUS + " - Compiler ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_ID})" +) message(STATUS " - Extra compilation flags ${CMAKE_CXX_FLAGS}") -if (WITH_SHARED_LIB) + +if(WITH_SHARED_LIB) message(STATUS " - Build static core library no") -else () +else() message(STATUS " - Build static core library yes") -endif () +endif() + message(STATUS " - External commands module enabled") -if (WITH_TESTING) + +if(WITH_TESTING) message(STATUS " - Unit tests enabled") - if (WITH_COVERAGE) + + if(WITH_COVERAGE) message(STATUS " - Code coverage enabled") - else () + else() message(STATUS " - Code coverage disabled") - endif () -else () + endif() +else() message(STATUS " - Unit tests disabled") -endif () -if (WITH_PKGCONFIG_SCRIPT) +endif() + +if(WITH_PKGCONFIG_SCRIPT) message(STATUS " - pkg-config script enabled") -else () +else() message(STATUS " - pkg-config script disabled") -endif () -if (WITH_LOGROTATE_SCRIPT) +endif() + +if(WITH_ENGINE_LOGROTATE_SCRIPT) message(STATUS " - logrotate script enabled") -else () +else() message(STATUS " - logrotate script disabled") -endif () +endif() + message(STATUS " - Startup script ${STARTUP_SCRIPT}") message(STATUS "") message(STATUS " Install") @@ -796,18 +774,23 @@ message(STATUS " - Include prefix ${PREFIX_INC}") message(STATUS " - var directory ${VAR_DIR}") message(STATUS " - Log archive directory ${LOG_ARCHIVE_DIR}") message(STATUS " - RW directory ${RW_DIR}") -if (LOCK_FILE) + +if(LOCK_FILE) message(STATUS " - Lock prefix ${LOCK_FILE}") -endif () -if (WITH_PKGCONFIG_SCRIPT) +endif() + +if(WITH_PKGCONFIG_SCRIPT) message(STATUS " - pkg-config directory ${PKGCONFIG_DIR}") -endif () -if (WITH_LOGROTATE_SCRIPT) +endif() + +if(WITH_ENGINE_LOGROTATE_SCRIPT) message(STATUS " - logrotate directory ${LOGROTATE_DIR}") -endif () -if (STARTUP_DIR) +endif() + +if(STARTUP_DIR) message(STATUS " - Startup directory ${STARTUP_DIR}") -endif () +endif() + message(STATUS " - User ${USER}") message(STATUS " - Group ${GROUP}") message(STATUS " - Package ${PACKAGE_LIST}") diff --git a/centreon-engine/enginerpc/CMakeLists.txt b/centreon-engine/enginerpc/CMakeLists.txt index e2bd9a2359b..214195dd6aa 100644 --- a/centreon-engine/enginerpc/CMakeLists.txt +++ b/centreon-engine/enginerpc/CMakeLists.txt @@ -1,45 +1,36 @@ -## -## Copyright 2019-2021 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 -## -## +# +# Copyright 2019-2021 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 +# # Set directories. set(ENGINERPC_DIR "${PROJECT_SOURCE_DIR}/enginerpc") -set(ENGINERPC_DIR "${PROJECT_SOURCE_DIR}/enginerpc" PARENT_SCOPE) +set(ENGINERPC_DIR + "${PROJECT_SOURCE_DIR}/enginerpc" + PARENT_SCOPE) set(INC_DIR "../inc/com/centreon/engine/") set(ENGINERPC enginerpc) -set(ENGINERPC enginerpc PARENT_SCOPE) +set(ENGINERPC + enginerpc + PARENT_SCOPE) # Include directories. -include_directories( - ${ENGINERPC_DIR} -) - +include_directories(${ENGINERPC_DIR}) set(protobuf_MODULE_COMPATIBLE True) -find_package(Protobuf REQUIRED) -find_package(gRPC REQUIRED) - -include_directories(${gRPC_INCLUDE_DIRS}) -include_directories(${absl_INCLUDE_DIRS}) -include_directories(${protobuf_INCLUDE_DIRS}) - -link_directories(${protobuf_LIB_DIRS}) -link_directories(${gRPC_LIB_DIRS}) set(PROTOBUF_PREFIX "${protobuf_LIB_DIRS}/..") message(STATUS "${PROTOBUF_PREFIX}/bin/protoc") @@ -49,47 +40,39 @@ add_custom_command( DEPENDS ${ENGINERPC_DIR}/engine.proto COMMENT "Generating interface files of the proto file (grpc)" OUTPUT ${ENGINERPC_DIR}/engine.grpc.pb.cc ${ENGINERPC_DIR}/engine.grpc.pb.h - COMMAND ${PROTOBUF_PREFIX}/bin/protoc - ARGS --plugin=protoc-gen-grpc=${GRPC_PREFIX}/bin/grpc_cpp_plugin --proto_path=${ENGINERPC_DIR} --grpc_out="${ENGINERPC_DIR}" ${ENGINERPC_DIR}/engine.proto - + COMMAND + ${Protobuf_PROTOC_EXECUTABLE} ARGS + --plugin=protoc-gen-grpc=${CONAN_BIN_DIRS_GRPC}/grpc_cpp_plugin + --proto_path=${ENGINERPC_DIR} --grpc_out="${ENGINERPC_DIR}" + ${ENGINERPC_DIR}/engine.proto DEPENDS ${ENGINERPC_DIR}/engine.proto COMMENT "Generating interface files of the proto file (protobuf)" OUTPUT ${ENGINERPC_DIR}/engine.pb.cc ${ENGINERPC_DIR}/engine.pb.h - COMMAND ${PROTOBUF_PREFIX}/bin/protoc - ARGS --cpp_out="${ENGINERPC_DIR}" --proto_path=${ENGINERPC_DIR} ${ENGINERPC_DIR}/engine.proto -) + COMMAND ${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out="${ENGINERPC_DIR}" + --proto_path=${ENGINERPC_DIR} ${ENGINERPC_DIR}/engine.proto) -add_custom_target(engine_rpc DEPENDS - ${ENGINERPC_DIR}/engine.grpc.pb.cc - ${ENGINERPC_DIR}/engine.pb.cc - ${ENGINERPC_DIR}/engine.grpc.pb.h - ${ENGINERPC_DIR}/engine.pb.h) +add_custom_target( + engine_rpc + DEPENDS ${ENGINERPC_DIR}/engine.grpc.pb.cc ${ENGINERPC_DIR}/engine.pb.cc + ${ENGINERPC_DIR}/engine.grpc.pb.h ${ENGINERPC_DIR}/engine.pb.h) add_library( - cerpc - STATIC - - ${ENGINERPC_DIR}/engine.grpc.pb.cc - ${ENGINERPC_DIR}/engine.pb.cc - ${ENGINERPC_DIR}/engine.grpc.pb.h - ${ENGINERPC_DIR}/engine.pb.h) -target_link_libraries(cerpc ${protobuf_LIBS}) + cerpc STATIC ${ENGINERPC_DIR}/engine.grpc.pb.cc ${ENGINERPC_DIR}/engine.pb.cc + ${ENGINERPC_DIR}/engine.grpc.pb.h ${ENGINERPC_DIR}/engine.pb.h) +target_link_libraries(cerpc CONAN_PKG::protobuf) # mod_enginerpc target. add_library( - ${ENGINERPC} - STATIC - + ${ENGINERPC} STATIC # Sources. - engine_impl.cc - enginerpc.cc - + engine_impl.cc enginerpc.cc # Headers. - "${INC_DIR}/engine_impl.hh" - "${INC_DIR}/enginerpc.hh" -) + "${INC_DIR}/engine_impl.hh" "${INC_DIR}/enginerpc.hh") # Prettier name. -set_property(TARGET ${ENGINERPC} PROPERTY PREFIX "" PROPERTY POSITION_INDEPENDENT_CODE ON) +set_property( + TARGET ${ENGINERPC} + PROPERTY PREFIX "" + PROPERTY POSITION_INDEPENDENT_CODE ON) # Link target with libraries. target_link_libraries(${ENGINERPC} cerpc) diff --git a/centreon-engine/modules/bench/CMakeLists.txt b/centreon-engine/modules/bench/CMakeLists.txt index 6d147cfd127..0996f3987eb 100644 --- a/centreon-engine/modules/bench/CMakeLists.txt +++ b/centreon-engine/modules/bench/CMakeLists.txt @@ -1,24 +1,22 @@ -## -## Copyright 2015-2016 Centreon -## -## This file is part of Centreon Engine. -## -## Centreon Engine is free software: you can redistribute it and/or -## modify it under the terms of the GNU General Public License version 2 -## as published by the Free Software Foundation. -## -## Centreon Engine is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Centreon Engine. If not, see -## . -## +# +# Copyright 2015-2016 Centreon +# +# This file is part of Centreon Engine. +# +# Centreon Engine is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 as published by +# the Free Software Foundation. +# +# Centreon Engine is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# Centreon Engine. If not, see . +# option(WITH_BENCH "Build benchmarking tools." OFF) -if (WITH_BENCH) +if(WITH_BENCH) # Set directories. set(SRC_DIR "${PROJECT_SOURCE_DIR}/modules/bench") include_directories("${SRC_DIR}/passive") @@ -27,21 +25,20 @@ if (WITH_BENCH) link_directories(${CMAKE_SOURCE_DIR}/build/) # Passive checks benchmarking module. - add_library("bench_passive_module" SHARED - "${SRC_DIR}/passive/module.cc") - set_target_properties("bench_passive_module" - PROPERTIES PREFIX "") - install(TARGETS "bench_passive_module" + add_library("bench_passive_module" SHARED "${SRC_DIR}/passive/module.cc") + set_target_properties("bench_passive_module" PROPERTIES PREFIX "") + install( + TARGETS "bench_passive_module" DESTINATION "${PREFIX_LIB}" COMPONENT "bench") # Passive checks benchmarking command line tool. - add_executable("centengine_bench_passive" - "${SRC_DIR}/passive/engine_cfg.cc" - "${SRC_DIR}/passive/main.cc") -add_dependencies("centengine_bench_passive" centreon_clib_shared) + add_executable("centengine_bench_passive" "${SRC_DIR}/passive/engine_cfg.cc" + "${SRC_DIR}/passive/main.cc") + add_dependencies("centengine_bench_passive" centreon_clib) target_link_libraries("centengine_bench_passive" centreon_clib) - install(TARGETS "centengine_bench_passive" + install( + TARGETS "centengine_bench_passive" DESTINATION "${PREFIX_BIN}" COMPONENT "bench") -endif () +endif() diff --git a/centreon-engine/modules/external_commands/CMakeLists.txt b/centreon-engine/modules/external_commands/CMakeLists.txt index 21958dcbcca..a1d015a5a39 100644 --- a/centreon-engine/modules/external_commands/CMakeLists.txt +++ b/centreon-engine/modules/external_commands/CMakeLists.txt @@ -1,21 +1,19 @@ -## -## Copyright 2011-2013 Merethis -## -## This file is part of Centreon Engine. -## -## Centreon Engine is free software: you can redistribute it and/or -## modify it under the terms of the GNU General Public License version 2 -## as published by the Free Software Foundation. -## -## Centreon Engine is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Centreon Engine. If not, see -## . -## +# +# 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 : contact@centreon.com +# # Set directories. set(MODULE_DIR "${PROJECT_SOURCE_DIR}/modules/external_commands") @@ -24,38 +22,35 @@ set(INC_DIR "${MODULE_DIR}/inc/com/centreon/engine/modules/external_commands") # Include directories. include_directories("${MODULE_DIR}/inc") -link_directories(${CMAKE_SOURCE_DIR}/build/centreon-clib/) +link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) # mod_externalcmd target. add_library( - externalcmd - SHARED - + externalcmd SHARED # Sources. "${SRC_DIR}/commands.cc" "${SRC_DIR}/internal.cc" "${SRC_DIR}/main.cc" "${SRC_DIR}/processing.cc" "${SRC_DIR}/utils.cc" - # Headers. "${INC_DIR}/commands.hh" "${INC_DIR}/internal.hh" "${INC_DIR}/processing.hh" - "${INC_DIR}/utils.hh" -) + "${INC_DIR}/utils.hh") + # Prettier name. set_property(TARGET "externalcmd" PROPERTY PREFIX "") + # Location. -get_property( - EXTERNALCMD_MODULE - TARGET "externalcmd" - PROPERTY LOCATION) -set(EXTERNALCMD_MODULE "${EXTERNALCMD_MODULE}" PARENT_SCOPE) -add_dependencies(externalcmd centreon_clib_shared) +set(EXTERNALCMD_MODULE + "${EXTERNALCMD_MODULE}" + PARENT_SCOPE) +add_dependencies(externalcmd centreon_clib) target_link_libraries(externalcmd centreon_clib) # Install rule. -install(TARGETS "externalcmd" +install( + TARGETS "externalcmd" DESTINATION "${PREFIX_LIB}" COMPONENT "runtime") diff --git a/centreon-engine/src/simumod/CMakeLists.txt b/centreon-engine/src/simumod/CMakeLists.txt index 9a16d620e18..75a84bddc04 100644 --- a/centreon-engine/src/simumod/CMakeLists.txt +++ b/centreon-engine/src/simumod/CMakeLists.txt @@ -1,20 +1,19 @@ -## -## 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 -## +# +# 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 +# # Global options. set(SRC_DIR "${SRC_DIR}/simumod") @@ -27,22 +26,25 @@ set(SIMUMOD "simumod") add_custom_command( OUTPUT ${SRC_DIR}/neb.cc COMMAND ${SRC_DIR}/coder.pl > ${SRC_DIR}/neb.cc - DEPENDS ${SRC_DIR}/coder.pl -) -add_library("${SIMUMOD}" SHARED + DEPENDS ${SRC_DIR}/coder.pl) +add_library( + "${SIMUMOD}" SHARED # Sources. - "${SRC_DIR}/neb.cc" - # Headers. + "${SRC_DIR}/neb.cc" # Headers. ) + # Prettier name. set_target_properties("${SIMUMOD}" PROPERTIES PREFIX "") -link_directories(${CMAKE_SOURCE_DIR}/build/centreon-clib/) +link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) # Location -get_property(SIMUMOD_MODULE +get_property( + SIMUMOD_MODULE TARGET "${SIMUMOD}" PROPERTY LOCATION) -set(SIMUMOD_MODULE "${SIMUMOD_MODULE}" PARENT_SCOPE) -add_dependencies("${SIMUMOD}" centreon_clib_shared) +set(SIMUMOD_MODULE + "${SIMUMOD_MODULE}" + PARENT_SCOPE) +add_dependencies("${SIMUMOD}" centreon_clib) target_link_libraries("${SIMUMOD}" centreon_clib) diff --git a/centreon-engine/test/commands/CMakeLists.txt b/centreon-engine/test/commands/CMakeLists.txt index 0ec4f277833..50800ca26b5 100644 --- a/centreon-engine/test/commands/CMakeLists.txt +++ b/centreon-engine/test/commands/CMakeLists.txt @@ -1,33 +1,31 @@ -## -## Copyright 2011-2013 Merethis -## -## This file is part of Centreon Scheduler. -## -## Centreon Scheduler is free software: you can redistribute it and/or -## modify it under the terms of the GNU General Public License version 2 -## as published by the Free Software Foundation. -## -## Centreon Scheduler is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Centreon Scheduler. If not, see -## . -## +# +# Copyright 2011-2022 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 +# # Set directories. set(TEST_DIR "${TEST_DIR}/commands") -link_directories(${CMAKE_SOURCE_DIR}/build/centreon-clib/) +link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) # Test binary. add_executable("bin_connector_test_run" "${TEST_DIR}/bin_connector_test_run.cc") -add_dependencies("bin_connector_test_run" centreon_clib_shared) +add_dependencies("bin_connector_test_run" centreon_clib) target_link_libraries("bin_connector_test_run" centreon_clib) add_executable("bin_test_run" "${TEST_DIR}/bin_test_run.cc") -add_dependencies("bin_test_run" centreon_clib_shared) +add_dependencies("bin_test_run" centreon_clib) target_link_libraries("bin_test_run" centreon_clib) # Test connector. @@ -43,11 +41,8 @@ add_executable("connector_run_sync" "${TEST_DIR}/connector_run_sync.cc") target_link_libraries("connector_run_sync" "cce_core") add_test("connector_run_sync" "connector_run_sync") -add_executable( - "connector_run_async" - "${TEST_DIR}/connector_run_async.cc" - "${TEST_DIR}/wait_process.hh" -) +add_executable("connector_run_async" "${TEST_DIR}/connector_run_async.cc" + "${TEST_DIR}/wait_process.hh") target_link_libraries("connector_run_async" "cce_core") add_test("connector_run_async" "connector_run_async") @@ -55,11 +50,8 @@ add_executable("connector_get" "${TEST_DIR}/connector_get.cc") target_link_libraries("connector_get" "cce_core") add_test("connector_get" "connector_get") -add_executable( - "connector_restart" - "${TEST_DIR}/connector_restart.cc" - "${TEST_DIR}/wait_process.hh" -) +add_executable("connector_restart" "${TEST_DIR}/connector_restart.cc" + "${TEST_DIR}/wait_process.hh") target_link_libraries("connector_restart" "cce_core") add_test("connector_restart" "connector_restart") @@ -106,11 +98,8 @@ add_executable("raw_run_sync" "${TEST_DIR}/raw_run_sync.cc") target_link_libraries("raw_run_sync" "cce_core") add_test("raw_run_sync" "raw_run_sync") -add_executable( - "raw_run_async" - "${TEST_DIR}/raw_run_async.cc" - "${TEST_DIR}/wait_process.hh" -) +add_executable("raw_run_async" "${TEST_DIR}/raw_run_async.cc" + "${TEST_DIR}/wait_process.hh") target_link_libraries("raw_run_async" "cce_core") add_test("raw_run_async" "raw_run_async") diff --git a/centreon-engine/tests/CMakeLists.txt b/centreon-engine/tests/CMakeLists.txt index 0573e9c1547..dbf03e332bd 100755 --- a/centreon-engine/tests/CMakeLists.txt +++ b/centreon-engine/tests/CMakeLists.txt @@ -1,146 +1,169 @@ -## -## Copyright 2016, 2020-2021 Centreon -## - -## This file is part of Centreon Engine. -## -## Centreon Engine is free software : you can redistribute it and / or -## modify it under the terms of the GNU General Public License version 2 -## as published by the Free Software Foundation. -## -## Centreon Engine is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Centreon Engine. If not, see -## . -## +# +# Copyright 2016, 2020-2022 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 +# # Enable unit tests or not . option(WITH_TESTING "Build unit tests." OFF) -if (WITH_TESTING) +if(WITH_TESTING) find_package(GTest REQUIRED) include_directories(${GTest_INCLUDE_DIRS}) link_directories(${GTest_LIB_DIRS}) -# Tests directory. - # Add root inclusion direction. + # Tests directory. Add root inclusion direction. set(MODULE_DIR "${PROJECT_SOURCE_DIR}/modules/external_commands") set(INC_DIR "${MODULE_DIR}/inc/com/centreon/engine/modules/external_commands") include_directories(${PROJECT_SOURCE_DIR} ${MODULE_DIR}/inc) -#Set directory. + # Set directory. set(TESTS_DIR "${PROJECT_SOURCE_DIR}/tests") include_directories(${PROJECT_SOURCE_DIR}/enginerpc) add_definitions(-DENGINERPC_TESTS_PATH="${TESTS_DIR}/enginerpc") - add_executable(rpc_client_engine - ${TESTS_DIR}/enginerpc/client.cc) + add_executable(rpc_client_engine ${TESTS_DIR}/enginerpc/client.cc) - target_link_libraries(rpc_client_engine cerpc ${gRPC_LIBS} ${re2_LIBS} ${absl_LIBS} ${OpenSSL_LIBS} ${c-ares_LIBS} ${ZLIB_LIBS} dl pthread) + target_link_libraries( + rpc_client_engine + cerpc + CONAN_PKG::grpc + CONAN_PKG::openssl + CONAN_PKG::zlib + dl + pthread) add_executable("bin_connector_test_run" - "${TESTS_DIR}/commands/bin_connector_test_run.cc") + "${TESTS_DIR}/commands/bin_connector_test_run.cc") target_link_libraries(bin_connector_test_run cce_core pthread) set(ut_sources - # Sources. - "${PROJECT_SOURCE_DIR}/modules/external_commands/src/commands.cc" - "${PROJECT_SOURCE_DIR}/modules/external_commands/src/internal.cc" - "${PROJECT_SOURCE_DIR}/modules/external_commands/src/processing.cc" - "${TESTS_DIR}/parse-check-output.cc" - "${TESTS_DIR}/checks/service_check.cc" - "${TESTS_DIR}/checks/service_retention.cc" - "${TESTS_DIR}/checks/anomalydetection.cc" - "${TESTS_DIR}/commands/simple-command.cc" - "${TESTS_DIR}/commands/connector.cc" - "${TESTS_DIR}/configuration/applier/applier-anomalydetection.cc" - "${TESTS_DIR}/configuration/applier/applier-command.cc" - "${TESTS_DIR}/configuration/applier/applier-connector.cc" - "${TESTS_DIR}/configuration/applier/applier-contact.cc" - "${TESTS_DIR}/configuration/applier/applier-contactgroup.cc" - "${TESTS_DIR}/configuration/applier/applier-global.cc" - "${TESTS_DIR}/configuration/applier/applier-host.cc" - "${TESTS_DIR}/configuration/applier/applier-hostescalation.cc" - "${TESTS_DIR}/configuration/applier/applier-hostdependency.cc" - "${TESTS_DIR}/configuration/applier/applier-hostgroup.cc" - "${TESTS_DIR}/configuration/applier/applier-service.cc" - "${TESTS_DIR}/configuration/applier/applier-serviceescalation.cc" - "${TESTS_DIR}/configuration/applier/applier-servicegroup.cc" - "${TESTS_DIR}/configuration/contact.cc" - "${TESTS_DIR}/configuration/host.cc" - "${TESTS_DIR}/configuration/object.cc" - "${TESTS_DIR}/configuration/service.cc" - "${TESTS_DIR}/configuration/timeperiod-test.cc" - "${TESTS_DIR}/contacts/contactgroup-config.cc" - "${TESTS_DIR}/contacts/simple-contactgroup.cc" - "${TESTS_DIR}/custom_vars/extcmd.cc" - "${TESTS_DIR}/downtimes/downtime.cc" - "${TESTS_DIR}/downtimes/downtime_finder.cc" - "${TESTS_DIR}/enginerpc/enginerpc.cc" - "${TESTS_DIR}/helper.cc" - "${TESTS_DIR}/macros/macro.cc" - "${TESTS_DIR}/macros/macro_hostname.cc" - "${TESTS_DIR}/macros/macro_service.cc" - "${TESTS_DIR}/external_commands/anomalydetection.cc" - "${TESTS_DIR}/external_commands/host.cc" - "${TESTS_DIR}/external_commands/service.cc" - "${TESTS_DIR}/main.cc" - "${TESTS_DIR}/loop/loop.cc" - "${TESTS_DIR}/notifications/host_downtime_notification.cc" - "${TESTS_DIR}/notifications/host_flapping_notification.cc" - "${TESTS_DIR}/notifications/host_normal_notification.cc" - "${TESTS_DIR}/notifications/host_recovery_notification.cc" - "${TESTS_DIR}/notifications/service_normal_notification.cc" - "${TESTS_DIR}/notifications/service_timeperiod_notification.cc" - "${TESTS_DIR}/notifications/service_flapping_notification.cc" - "${TESTS_DIR}/notifications/service_downtime_notification_test.cc" - "${TESTS_DIR}/perfdata/perfdata.cc" - "${TESTS_DIR}/retention/host.cc" - "${TESTS_DIR}/retention/service.cc" - "${TESTS_DIR}/string/string.cc" - "${TESTS_DIR}/test_engine.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/between_two_years.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/calendar_date.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/dst_backward.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/dst_forward.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/earliest_daterange_first.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/exclusion.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/exceptions_test.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/generic_month_date.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/normal_weekday.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/offset_weekday_of_generic_month.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/offset_weekday_of_specific_month.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/precedence.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/skip_interval.cc" - "${TESTS_DIR}/timeperiod/get_next_valid_time/specific_month_date.cc" - "${TESTS_DIR}/timeperiod/utils.cc" -# # Headers. - "${TESTS_DIR}/test_engine.hh" - "${TESTS_DIR}/timeperiod/utils.hh" - ) + # Sources. + "${PROJECT_SOURCE_DIR}/modules/external_commands/src/commands.cc" + "${PROJECT_SOURCE_DIR}/modules/external_commands/src/internal.cc" + "${PROJECT_SOURCE_DIR}/modules/external_commands/src/processing.cc" + "${TESTS_DIR}/parse-check-output.cc" + "${TESTS_DIR}/checks/service_check.cc" + "${TESTS_DIR}/checks/service_retention.cc" + "${TESTS_DIR}/checks/anomalydetection.cc" + "${TESTS_DIR}/commands/simple-command.cc" + "${TESTS_DIR}/commands/connector.cc" + "${TESTS_DIR}/configuration/applier/applier-anomalydetection.cc" + "${TESTS_DIR}/configuration/applier/applier-command.cc" + "${TESTS_DIR}/configuration/applier/applier-connector.cc" + "${TESTS_DIR}/configuration/applier/applier-contact.cc" + "${TESTS_DIR}/configuration/applier/applier-contactgroup.cc" + "${TESTS_DIR}/configuration/applier/applier-global.cc" + "${TESTS_DIR}/configuration/applier/applier-host.cc" + "${TESTS_DIR}/configuration/applier/applier-hostescalation.cc" + "${TESTS_DIR}/configuration/applier/applier-hostdependency.cc" + "${TESTS_DIR}/configuration/applier/applier-hostgroup.cc" + "${TESTS_DIR}/configuration/applier/applier-service.cc" + "${TESTS_DIR}/configuration/applier/applier-serviceescalation.cc" + "${TESTS_DIR}/configuration/applier/applier-servicegroup.cc" + "${TESTS_DIR}/configuration/contact.cc" + "${TESTS_DIR}/configuration/host.cc" + "${TESTS_DIR}/configuration/object.cc" + "${TESTS_DIR}/configuration/service.cc" + "${TESTS_DIR}/configuration/timeperiod-test.cc" + "${TESTS_DIR}/contacts/contactgroup-config.cc" + "${TESTS_DIR}/contacts/simple-contactgroup.cc" + "${TESTS_DIR}/custom_vars/extcmd.cc" + "${TESTS_DIR}/downtimes/downtime.cc" + "${TESTS_DIR}/downtimes/downtime_finder.cc" + "${TESTS_DIR}/enginerpc/enginerpc.cc" + "${TESTS_DIR}/helper.cc" + "${TESTS_DIR}/macros/macro.cc" + "${TESTS_DIR}/macros/macro_hostname.cc" + "${TESTS_DIR}/macros/macro_service.cc" + "${TESTS_DIR}/external_commands/anomalydetection.cc" + "${TESTS_DIR}/external_commands/host.cc" + "${TESTS_DIR}/external_commands/service.cc" + "${TESTS_DIR}/main.cc" + "${TESTS_DIR}/loop/loop.cc" + "${TESTS_DIR}/notifications/host_downtime_notification.cc" + "${TESTS_DIR}/notifications/host_flapping_notification.cc" + "${TESTS_DIR}/notifications/host_normal_notification.cc" + "${TESTS_DIR}/notifications/host_recovery_notification.cc" + "${TESTS_DIR}/notifications/service_normal_notification.cc" + "${TESTS_DIR}/notifications/service_timeperiod_notification.cc" + "${TESTS_DIR}/notifications/service_flapping_notification.cc" + "${TESTS_DIR}/notifications/service_downtime_notification_test.cc" + "${TESTS_DIR}/perfdata/perfdata.cc" + "${TESTS_DIR}/retention/host.cc" + "${TESTS_DIR}/retention/service.cc" + "${TESTS_DIR}/string/string.cc" + "${TESTS_DIR}/test_engine.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/between_two_years.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/calendar_date.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/dst_backward.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/dst_forward.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/earliest_daterange_first.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/exclusion.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/exceptions_test.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/generic_month_date.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/normal_weekday.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/offset_weekday_of_generic_month.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/offset_weekday_of_specific_month.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/precedence.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/skip_interval.cc" + "${TESTS_DIR}/timeperiod/get_next_valid_time/specific_month_date.cc" + "${TESTS_DIR}/timeperiod/utils.cc" + # # Headers. + "${TESTS_DIR}/test_engine.hh" + "${TESTS_DIR}/timeperiod/utils.hh") # Unit test executable. include_directories(${TESTS_DIR}) add_executable(ut_engine ${ut_sources}) - #file used by timeperiod-test.cc - file(COPY ${TESTS_DIR}/configuration/timeperiods.cfg DESTINATION ${CMAKE_BINARY_DIR}/centreon-engine/tests/ ) + + set_target_properties( + ut_engine rpc_client_engine bin_connector_test_run + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/tests + RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/tests) + + # file used by timeperiod-test.cc + file(COPY ${TESTS_DIR}/configuration/timeperiods.cfg + DESTINATION ${CMAKE_BINARY_DIR}/tests/) add_test(NAME tests COMMAND ut_engine) - if (WITH_COVERAGE) - set(COVERAGE_EXCLUDES '${PROJECT_BINARY_DIR}/*' '${PROJECT_SOURCE_DIR}/tests/*' '/usr/include/* ') - SETUP_TARGET_FOR_COVERAGE( - NAME test-coverage - EXECUTABLE ut_engine - DEPENDENCIES ut_engine - ) + if(WITH_COVERAGE) + set(COVERAGE_EXCLUDES '${PROJECT_BINARY_DIR}/*' + '${PROJECT_SOURCE_DIR}/tests/*' '/usr/include/* ') + setup_target_for_coverage(NAME test-coverage EXECUTABLE ut_engine + DEPENDENCIES ut_engine) set(GCOV gcov) - endif () - target_link_libraries(ut_engine ${ENGINERPC} cce_core pthread ${GCOV} ${GTest_LIBS} ${gRPC_LIBS} ${re2_LIBS} ${absl_LIBS} ${OpenSSL_LIBS} ${c-ares_LIBS} ${ZLIB_LIBS} ${fmt_LIBS} dl) + endif() + + target_link_libraries( + ut_engine + ${ENGINERPC} + cce_core + pthread + ${GCOV} + CONAN_PKG::gtest + CONAN_PKG::grpc + CONAN_PKG::openssl + CONAN_PKG::zlib + CONAN_PKG::spdlog + dl) -endif () + set_target_properties( + ut_engine bin_connector_test_run rpc_client_engine + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests) +endif() diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile deleted file mode 100644 index 5ab4817403d..00000000000 --- a/ci/Jenkinsfile +++ /dev/null @@ -1,42 +0,0 @@ -/* -** Pipeline code. -*/ - -stage('Dependencies containers creation') { - parallel 'centos7 dependencies': { - node { - dir('centreon-collect-centos7') { - checkout scm - dir ('ci/docker') { - sh 'cp ../../conanfile.txt .' - sh 'docker build --no-cache . -f Dockerfile.collect-centos7-dependencies -t registry.centreon.com/centreon-collect-centos7-dependencies:21.10' - sh 'docker push registry.centreon.com/centreon-collect-centos7-dependencies:21.10' - } - } - } - }, - 'debian dependencies': { - node { - dir('centreon-collect-debian') { - checkout scm - dir ('ci/docker') { - sh 'cp ../../conanfile.txt .' - sh 'docker build --no-cache . -f Dockerfile.collect-debian-dependencies -t registry.centreon.com/centreon-collect-debian-dependencies:21.10' - sh 'docker push registry.centreon.com/centreon-collect-debian-dependencies:21.10' - } - } - } - }, - 'centos8 dependencies': { - node { - dir('centreon-collect-alma8') { - checkout scm - dir ('ci/docker') { - sh 'cp ../../conanfile.txt .' - sh 'docker build --no-cache . -f Dockerfile.collect-alma8-dependencies -t registry.centreon.com/centreon-collect-alma8-dependencies:21.10' - sh 'docker push registry.centreon.com/centreon-collect-alma8-dependencies:21.10' - } - } - } - } -} diff --git a/ci/debian-collect/centreon-broker-cbmod.install b/ci/debian-collect/centreon-broker-cbmod.install new file mode 100644 index 00000000000..4b541fd5598 --- /dev/null +++ b/ci/debian-collect/centreon-broker-cbmod.install @@ -0,0 +1,2 @@ +debian/tmp-centreon-collect/usr/lib64/nagios/cbmod.so usr/lib64/nagios +debian/tmp-centreon-collect/usr/etc/central-module.json etc/centreon-broker diff --git a/ci/debian-collect/centreon-broker-cbmod.postinst b/ci/debian-collect/centreon-broker-cbmod.postinst new file mode 100644 index 00000000000..2bdb6f8ab3f --- /dev/null +++ b/ci/debian-collect/centreon-broker-cbmod.postinst @@ -0,0 +1,12 @@ +#!/bin/sh + +if [ "$1" = "configure" ] ; then + if [ "$(getent passwd centreon-engine)" ]; then + usermod -a -G centreon-broker centreon-engine + fi + if [ "$(getent passwd centreon-broker)" ]; then + usermod -a -G centreon-engine centreon-broker + fi +fi + +exit 0 diff --git a/ci/debian-collect/centreon-broker-core.dirs b/ci/debian-collect/centreon-broker-core.dirs new file mode 100644 index 00000000000..7374bcdecf9 --- /dev/null +++ b/ci/debian-collect/centreon-broker-core.dirs @@ -0,0 +1 @@ +usr/share/centreon-broker/lua diff --git a/ci/debian-collect/centreon-broker-core.install b/ci/debian-collect/centreon-broker-core.install new file mode 100644 index 00000000000..982f7552074 --- /dev/null +++ b/ci/debian-collect/centreon-broker-core.install @@ -0,0 +1,7 @@ +debian/tmp-centreon-collect/usr/lib/centreon-broker/10-neb.so usr/share/centreon/lib/centreon-broker +debian/tmp-centreon-collect/usr/lib/centreon-broker/15-stats.so usr/share/centreon/lib/centreon-broker +debian/tmp-centreon-collect/usr/lib/centreon-broker/20-bam.so usr/share/centreon/lib/centreon-broker +debian/tmp-centreon-collect/usr/lib/centreon-broker/50-tcp.so usr/share/centreon/lib/centreon-broker +debian/tmp-centreon-collect/usr/lib/centreon-broker/60-tls.so usr/share/centreon/lib/centreon-broker +debian/tmp-centreon-collect/usr/lib/centreon-broker/70-lua.so usr/share/centreon/lib/centreon-broker +debian/tmp-centreon-collect/usr/lib/centreon-broker/80-sql.so usr/share/centreon/lib/centreon-broker diff --git a/ci/debian-collect/centreon-broker-dev.install b/ci/debian-collect/centreon-broker-dev.install new file mode 100644 index 00000000000..b33234c7917 --- /dev/null +++ b/ci/debian-collect/centreon-broker-dev.install @@ -0,0 +1 @@ +debian/tmp-centreon-collect/usr/include/centreon-broker/com/centreon/broker/* usr/include/centreon-broker/com/centreon/broker diff --git a/ci/debian-collect/centreon-broker-graphite.install b/ci/debian-collect/centreon-broker-graphite.install new file mode 100644 index 00000000000..eec81a14100 --- /dev/null +++ b/ci/debian-collect/centreon-broker-graphite.install @@ -0,0 +1 @@ +debian/tmp-centreon-collect/usr/lib/centreon-broker/70-graphite.so usr/share/centreon/lib/centreon-broker diff --git a/ci/debian-collect/centreon-broker-influxdb.install b/ci/debian-collect/centreon-broker-influxdb.install new file mode 100644 index 00000000000..7e1a61a4ebe --- /dev/null +++ b/ci/debian-collect/centreon-broker-influxdb.install @@ -0,0 +1 @@ +debian/tmp-centreon-collect/usr/lib/centreon-broker/70-influxdb.so usr/share/centreon/lib/centreon-broker diff --git a/ci/debian-collect/centreon-broker-storage.install b/ci/debian-collect/centreon-broker-storage.install new file mode 100644 index 00000000000..6fb06ed5554 --- /dev/null +++ b/ci/debian-collect/centreon-broker-storage.install @@ -0,0 +1,2 @@ +debian/tmp-centreon-collect/usr/lib/centreon-broker/20-storage.so usr/share/centreon/lib/centreon-broker +debian/tmp-centreon-collect/usr/lib/centreon-broker/70-rrd.so usr/share/centreon/lib/centreon-broker diff --git a/ci/debian-collect/centreon-broker.dirs b/ci/debian-collect/centreon-broker.dirs new file mode 100644 index 00000000000..009f208b6cb --- /dev/null +++ b/ci/debian-collect/centreon-broker.dirs @@ -0,0 +1,3 @@ +etc/centreon-broker +var/lib/centreon-broker +var/log/centreon-broker diff --git a/ci/debian-collect/centreon-broker.install b/ci/debian-collect/centreon-broker.install new file mode 100644 index 00000000000..dd58de27501 --- /dev/null +++ b/ci/debian-collect/centreon-broker.install @@ -0,0 +1,6 @@ +debian/extra/centreon-broker/cbd.service lib/systemd/system +debian/tmp-centreon-collect/usr/bin/cbd usr/sbin +debian/tmp-centreon-collect/usr/bin/cbwd usr/sbin +debian/tmp-centreon-collect/usr/etc/central-broker.json etc/centreon-broker +debian/tmp-centreon-collect/usr/etc/central-rrd.json etc/centreon-broker +debian/tmp-centreon-collect/usr/etc/watchdog.json etc/centreon-broker diff --git a/ci/debian-collect/centreon-broker.logrotate b/ci/debian-collect/centreon-broker.logrotate new file mode 100644 index 00000000000..1fcddd9f925 --- /dev/null +++ b/ci/debian-collect/centreon-broker.logrotate @@ -0,0 +1,10 @@ +/var/log/centreon-broker/*log { + copytruncate + weekly + rotate 52 + compress + delaycompress + notifempty + missingok + su root root +} diff --git a/ci/debian-collect/centreon-broker.postinst b/ci/debian-collect/centreon-broker.postinst new file mode 100644 index 00000000000..4d2f80ae8ad --- /dev/null +++ b/ci/debian-collect/centreon-broker.postinst @@ -0,0 +1,21 @@ +#!/bin/sh + +if [ "$1" = "configure" ] ; then + if [ ! "$(getent passwd centreon-broker)" ]; then + adduser --system --group --home /var/lib/centreon-broker --no-create-home centreon-broker + fi + if [ "$(getent passwd centreon)" ]; then + usermod -a -G centreon-broker centreon + usermod -a -G centreon centreon-broker + fi + chown -vR centreon-broker:centreon-broker \ + /etc/centreon-broker \ + /var/lib/centreon-broker \ + /var/log/centreon-broker + chmod -vR g+w \ + /etc/centreon-broker \ + /var/lib/centreon-broker \ + /var/log/centreon-broker +fi + +exit 0 diff --git a/ci/debian-collect/centreon-broker.postrm b/ci/debian-collect/centreon-broker.postrm new file mode 100644 index 00000000000..242ca3cd6e5 --- /dev/null +++ b/ci/debian-collect/centreon-broker.postrm @@ -0,0 +1,7 @@ +#!/bin/sh + +deluser centreon centreon-broker || true +deluser centreon-broker || true +delgroup centreon-broker || true + +#DEBHELPER# diff --git a/ci/debian-collect/centreon-clib-dev.install b/ci/debian-collect/centreon-clib-dev.install new file mode 100644 index 00000000000..4fa79187fdc --- /dev/null +++ b/ci/debian-collect/centreon-clib-dev.install @@ -0,0 +1 @@ +debian/tmp-centreon-collect/usr/include/centreon-clib/com/centreon/* usr/include/com/centreon diff --git a/ci/debian-collect/centreon-clib.install b/ci/debian-collect/centreon-clib.install new file mode 100644 index 00000000000..ba0a5b57601 --- /dev/null +++ b/ci/debian-collect/centreon-clib.install @@ -0,0 +1 @@ +debian/tmp-centreon-collect/usr/lib/libcentreon_clib.so usr/lib diff --git a/ci/debian-collect/centreon-connector-perl.install b/ci/debian-collect/centreon-connector-perl.install new file mode 100644 index 00000000000..11cceab2207 --- /dev/null +++ b/ci/debian-collect/centreon-connector-perl.install @@ -0,0 +1 @@ +debian/tmp-centreon-collect/usr/lib64/centreon-connector/centreon_connector_perl usr/lib/centreon-connector diff --git a/ci/debian-collect/centreon-connector-ssh.install b/ci/debian-collect/centreon-connector-ssh.install new file mode 100644 index 00000000000..2191335946d --- /dev/null +++ b/ci/debian-collect/centreon-connector-ssh.install @@ -0,0 +1 @@ +debian/tmp-centreon-collect/usr/lib64/centreon-connector/centreon_connector_ssh usr/lib64/centreon-connector diff --git a/ci/debian-collect/centreon-engine-bench.install b/ci/debian-collect/centreon-engine-bench.install new file mode 100644 index 00000000000..c20d7faaed6 --- /dev/null +++ b/ci/debian-collect/centreon-engine-bench.install @@ -0,0 +1,2 @@ +debian/tmp-centreon-collect/usr/lib64/centreon-engine/bench_passive_module.so usr/lib64/centreon-engine +debian/tmp-centreon-collect/usr/sbin/centengine_bench_passive usr/sbin diff --git a/ci/debian-collect/centreon-engine-dev.install b/ci/debian-collect/centreon-engine-dev.install new file mode 100644 index 00000000000..9b9fb023e58 --- /dev/null +++ b/ci/debian-collect/centreon-engine-dev.install @@ -0,0 +1 @@ +debian/tmp-centreon-collect/usr/include/centreon-engine/com/centreon/engine/* usr/include/centreon-engine/com/centreon/engine diff --git a/ci/debian-collect/centreon-engine-extcommands.dirs b/ci/debian-collect/centreon-engine-extcommands.dirs new file mode 100644 index 00000000000..df508b3a82b --- /dev/null +++ b/ci/debian-collect/centreon-engine-extcommands.dirs @@ -0,0 +1 @@ +var/lib/centreon-engine/rw diff --git a/ci/debian-collect/centreon-engine-extcommands.install b/ci/debian-collect/centreon-engine-extcommands.install new file mode 100644 index 00000000000..9bdec9b2baa --- /dev/null +++ b/ci/debian-collect/centreon-engine-extcommands.install @@ -0,0 +1 @@ +debian/tmp-centreon-collect/usr/lib/centreon-engine/externalcmd.so usr/lib64/centreon-engine diff --git a/ci/debian-collect/centreon-engine.dirs b/ci/debian-collect/centreon-engine.dirs new file mode 100644 index 00000000000..bdb5d530835 --- /dev/null +++ b/ci/debian-collect/centreon-engine.dirs @@ -0,0 +1,2 @@ +var/lib/centreon-engine +var/log/centreon-engine diff --git a/ci/debian-collect/centreon-engine.install b/ci/debian-collect/centreon-engine.install new file mode 100644 index 00000000000..3212210b2e9 --- /dev/null +++ b/ci/debian-collect/centreon-engine.install @@ -0,0 +1,5 @@ +debian/extra/centreon-engine/centengine.service lib/systemd/system +debian/tmp-centreon-collect/etc/centreon-engine/* etc/centreon-engine +debian/tmp-centreon-collect/usr/sbin/centengine usr/sbin +debian/tmp-centreon-collect/usr/sbin/centenginestats usr/sbin +packaging/rpm/centreonengine_integrate_centreon_engine2centreon.sh usr/share/centreon-engine/extra diff --git a/ci/debian-collect/centreon-engine.logrotate b/ci/debian-collect/centreon-engine.logrotate new file mode 100644 index 00000000000..69f94bdeb59 --- /dev/null +++ b/ci/debian-collect/centreon-engine.logrotate @@ -0,0 +1,25 @@ +/var/log/centreon-engine/centengine.log { + compress + create 640 centreon-engine centreon-engine + daily + delaycompress + missingok + olddir /var/log/centreon-engine/archives + rotate 365 + postrotate + systemctl reload centengine + endscript +} + +/var/log/centreon-engine/centengine.debug { + compress + create 640 centreon-engine centreon-engine + delaycompress + missingok + olddir /var/log/centreon-engine/archives + rotate 5 + size 1G + postrotate + systemctl reload centengine + endscript +} diff --git a/ci/debian-collect/centreon-engine.postinst b/ci/debian-collect/centreon-engine.postinst new file mode 100644 index 00000000000..b717efd54bc --- /dev/null +++ b/ci/debian-collect/centreon-engine.postinst @@ -0,0 +1,38 @@ +#!/bin/sh + +if [ "$1" = "configure" ] ; then + if [ ! "$(getent passwd centreon-engine)" ]; then + adduser --system --group --home /var/lib/centreon-engine --shell /bin/bash --no-create-home centreon-engine + fi + if [ "$(getent passwd centreon)" ]; then + usermod -a -G centreon-engine centreon + usermod -a -G centreon centreon-engine + fi + if [ "$(getent passwd centreon-broker)" ]; then + usermod -a -G centreon-engine centreon-broker + fi + if [ "$(getent passwd centreon-gorgone)" ]; then + usermod -a -G centreon-engine centreon-gorgone + usermod -a -G centreon-gorgone centreon-engine + fi + if [ "$(getent passwd www-data)" ]; then + usermod -a -G centreon-engine www-data + fi + if [ "$(getent passwd nagios)" ]; then + usermod -a -G centreon-engine nagios + fi + chown -vR centreon-engine:centreon-engine \ + /etc/centreon-engine \ + /var/lib/centreon-engine \ + /var/log/centreon-engine + chmod -vR g+w \ + /etc/centreon-engine \ + /var/lib/centreon-engine \ + /var/log/centreon-engine + + mv /usr/share/centreon-engine/extra/centreonengine_integrate_centreon_engine2centreon.sh /usr/share/centreon-engine/extra/integrate_centreon_engine2centreon.sh + chmod 0755 /usr/share/centreon-engine/extra/integrate_centreon_engine2centreon.sh + chown root:root /usr/share/centreon-engine/extra/integrate_centreon_engine2centreon.sh +fi + +exit 0 diff --git a/ci/debian-collect/centreon-engine.postrm b/ci/debian-collect/centreon-engine.postrm new file mode 100644 index 00000000000..c0388199228 --- /dev/null +++ b/ci/debian-collect/centreon-engine.postrm @@ -0,0 +1,14 @@ +#!/bin/sh + +set -e + +case "$1" in + remove) + deluser centreon centreon-engine || true + deluser centreon-engine || true + delgroup centreon-engine || true + ;; + +esac + +exit 0 diff --git a/ci/debian-collect/control b/ci/debian-collect/control new file mode 100644 index 00000000000..ea84d1357c7 --- /dev/null +++ b/ci/debian-collect/control @@ -0,0 +1,171 @@ +Source: centreon-collect +Section: net +Priority: optional +Maintainer: Luiz Costa +Build-Depends: debhelper-compat (=12), + gcc, + g++, + cmake, + pkg-config, + libmariadb3, + librrd-dev, + libgnutls28-dev, + ninja-build, + liblua5.3-dev, + python3, + python3-pip, + libperl-dev, + libgcrypt20-dev +Standards-Version: 4.5.0 +Homepage: https://wwww.centreon.com + +Package: centreon-clib +Architecture: any +Depends: ${misc:Depends}, ${shlibs:Depends} +Description: Centreon Clib is a common library for all Centreon products + written in C/C++. + +Package: centreon-clib-dev +Architecture: any +Depends: + centreon-clib (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: Centreon Clib is a common library for all Centreon products + written in C/C++. + +Package: centreon-engine +Architecture: any +Depends: + centreon-clib (>= ${centreon:version}~), + centreon-common (>= ${centreon:version}~), + centreon-engine-extcommands (>= ${centreon:version}~), + monitoring-plugins-basic, + ${misc:Depends}, + ${shlibs:Depends} +Description: Centreon Engine is a monitoring engine, compatible with Nagios + configuration, designed to monitor hosts and services on your network. + +Package: centreon-engine-dev +Architecture: any +Depends: + centreon-clib-dev (>= ${centreon:version}~), + centreon-common (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: Centreon Engine devel provide include files to develop Centreon Engine + Modules or Centreon Engine Connector. + +Package: centreon-engine-extcommands +Architecture: any +Depends: + centreon-common (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: Centreon Engine External Commands allow to other applications to send + command into the daemon. External applications can submit commands by + writing to the command file, which is periodically processed by the + engine daemon. + +Package: centreon-connector-perl +Architecture: any +Depends: + centreon-engine (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: Centreon Connector Perl provide embedded perl for Centreon Engine + a monitoring engine. + +Package: centreon-connector-ssh +Architecture: any +Depends: + centreon-engine (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: Centreon Connector SSH provide persistante connection between checks. + +Package: centreon-connector +Architecture: any +Depends: + centreon-connector-perl (>= ${centreon:version}~), + centreon-connector-ssh (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: Centreon Connector provide a monitoring tools, compatible with + Centreon-Engine configuration, designed to monitor and manage system. + +Package: centreon-broker +Architecture: any +Depends: + centreon-clib (>= ${centreon:version}~), + centreon-engine (>= ${centreon:version}~), + centreon-broker-core (>= ${centreon:version}~), + centreon-broker-cbmod (>= ${centreon:version}~), + centreon-broker-storage (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: Centreon Broker is a Centreon Engine/Nagios module that report events in + one or multiple databases. + +Package: centreon-broker-core +Architecture: any +Depends: + centreon-broker (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: core holds Centreon Broker's default modules. + +Package: centreon-broker-cbmod +Architecture: any +Depends: + centreon-engine (>= ${centreon:version}~), + centreon-broker-core (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: This module can be loaded by Centreon Engine. + +Package: centreon-broker-dev +Architecture: any +Depends: + centreon-broker-core (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: Centreon Broker development files. + Include files needed to develop a module for Centreon Broker. + +Package: centreon-broker-storage +Architecture: any +Depends: + centreon-broker-core (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: Storage holds Centreon Broker's prefdata storage. + +Package: centreon-broker-influxdb +Architecture: any +Depends: + centreon-broker-core (>= ${centreon:version}~), + centreon-broker-storage (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: This module of Centreon Broker allows you to write performance data + generated by plugins (run themselves by Centreon Engine) to an InfluxDB database. + +Package: centreon-broker-graphite +Architecture: any +Depends: + centreon-broker-core (>= ${centreon:version}~), + centreon-broker-storage (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: This module of Centreon Broker allows you to write performance data + generated by plugins (run themselves by Centreon Engine) to a Graphite database. + +Package: centreon-collect-client +Architecture: any +Depends: + centreon-broker (>= ${centreon:version}~), + centreon-engine (>= ${centreon:version}~), + ${misc:Depends}, + ${shlibs:Depends} +Description: gRPC client to connect to Centreon Broker or Centreon Engine. diff --git a/ci/debian-collect/copyright b/ci/debian-collect/copyright new file mode 100644 index 00000000000..4f3f1140e99 --- /dev/null +++ b/ci/debian-collect/copyright @@ -0,0 +1,29 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: centreon-collect +Upstream-Contact: Luiz Costa +Source: https://www.centreon.com + +Files: * +Copyright: 2021 Centreon +License: Apache-2.0 + +Files: debian/* +Copyright: 2021 Centreon +License: Apache-2.0 + +License: Apache-2.0 + 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 + . + https://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. + . + On Debian systems, the complete text of the Apache version 2.0 license + can be found in "/usr/share/common-licenses/Apache-2.0". + diff --git a/ci/debian-collect/extra/centreon-broker/cbd.service b/ci/debian-collect/extra/centreon-broker/cbd.service new file mode 100644 index 00000000000..e737acfc843 --- /dev/null +++ b/ci/debian-collect/extra/centreon-broker/cbd.service @@ -0,0 +1,34 @@ +## +## Copyright 2015-2021 Centreon +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## +## For more information : contact@centreon.com +## + +[Unit] +Description=Centreon Broker watchdog +PartOf=centreon.service +After=centreon.service +ReloadPropagatedFrom=centreon.service +After=mariadb.service + +[Service] +ExecStart=/usr/sbin/cbwd /etc/centreon-broker/watchdog.json +ExecReload=/bin/kill -HUP $MAINPID +Type=simple +User=centreon-broker +UMask=0002 + +[Install] +WantedBy=centreon.service diff --git a/ci/debian-collect/extra/centreon-engine/centengine.service b/ci/debian-collect/extra/centreon-engine/centengine.service new file mode 100644 index 00000000000..682db099f6c --- /dev/null +++ b/ci/debian-collect/extra/centreon-engine/centengine.service @@ -0,0 +1,33 @@ +## +## Copyright 2021 Centreon +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## +## For more information : contact@centreon.com +## + +[Unit] +Description=Centreon Engine +PartOf=centreon.service +After=centreon.service +ReloadPropagatedFrom=centreon.service +After=cbd.service + +[Service] +ExecStart=/usr/sbin/centengine /etc/centreon-engine/centengine.cfg +ExecReload=/bin/kill -HUP $MAINPID +Type=simple +User=centreon-engine + +[Install] +WantedBy=centreon.service diff --git a/ci/debian-collect/rules b/ci/debian-collect/rules new file mode 100644 index 00000000000..c38b55893bf --- /dev/null +++ b/ci/debian-collect/rules @@ -0,0 +1,31 @@ +#!/usr/bin/make -f + +%: + dh $@ + +override_dh_gencontrol: + dh_gencontrol -- -Tdebian/substvars + +override_dh_auto_configure: + mkdir build + cd build && \ + conan install .. -s compiler.cppstd=14 -s compiler.libcxx=libstdc++11 --build=missing && \ + CXXFLAGS="-Wall -Wextra" cmake \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=On \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DWITH_TESTING=0 \ + -DWITH_MODULE_SIMU=On \ + -DWITH_BENCH=On \ + -DWITH_CREATE_FILES=OFF \ + -DWITH_CONFIG_FILES=y \ + -DWITH_DAEMONS=y \ + .. + +override_dh_auto_build: + cd build && \ + make -j9 + +override_dh_auto_install: + cd build && \ + make -j9 install DESTDIR=../debian/tmp-centreon-collect diff --git a/ci/debian-collect/source/format b/ci/debian-collect/source/format new file mode 100644 index 00000000000..163aaf8d82b --- /dev/null +++ b/ci/debian-collect/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/ci/debian-collect/source/include-binaries b/ci/debian-collect/source/include-binaries new file mode 100644 index 00000000000..13a56642228 --- /dev/null +++ b/ci/debian-collect/source/include-binaries @@ -0,0 +1,7 @@ +debian/tmp-centreon-collect/usr/lib64/centreon-connector/centreon_connector_ssh +debian/tmp-centreon-collect/usr/lib64/centreon-connector/centreon_connector_perl +debian/tmp-centreon-collect/usr/sbin/centengine +debian/tmp-centreon-collect/usr/sbin/cbwd +debian/tmp-centreon-collect/usr/sbin/centenginestats +debian/tmp-centreon-collect/usr/sbin/centengine_bench_passive +debian/tmp-centreon-collect/usr/sbin/cbd diff --git a/ci/debian-collect/source/local-options b/ci/debian-collect/source/local-options new file mode 100644 index 00000000000..00131ee8c41 --- /dev/null +++ b/ci/debian-collect/source/local-options @@ -0,0 +1,2 @@ +#abort-on-upstream-changes +#unapply-patches diff --git a/ci/debian-collect/substvars b/ci/debian-collect/substvars new file mode 100644 index 00000000000..259ab2cfb00 --- /dev/null +++ b/ci/debian-collect/substvars @@ -0,0 +1 @@ +centreon:version=22.10.0 diff --git a/ci/debian-gorgone/centreon-gorgone.dirs b/ci/debian-gorgone/centreon-gorgone.dirs new file mode 100644 index 00000000000..326d08ce2ea --- /dev/null +++ b/ci/debian-gorgone/centreon-gorgone.dirs @@ -0,0 +1,6 @@ +etc/centreon-gorgone/config.d +etc/centreon-gorgone/config.d/cron.d +var/cache/centreon-gorgone +var/cache/centreon-gorgone/autodiscovery +var/lib/centreon-gorgone +var/log/centreon-gorgone diff --git a/ci/debian-gorgone/centreon-gorgone.install b/ci/debian-gorgone/centreon-gorgone.install new file mode 100644 index 00000000000..664fd3010ed --- /dev/null +++ b/ci/debian-gorgone/centreon-gorgone.install @@ -0,0 +1,12 @@ +gorgoned usr/bin +contrib/* usr/local/bin +packaging/config.yaml etc/centreon-gorgone +packaging/centreon.yaml etc/centreon-gorgone/config.d +packaging/centreon-api.yaml etc/centreon-gorgone/config.d +packaging/centreon-audit.yaml etc/centreon-gorgone/config.d +packaging/sudoers.d/centreon-gorgone etc/sudoers.d +debian/extra/gorgoned.service lib/systemd/system +debian/extra/gorgoned etc/default +gorgone/class/* usr/share/perl5/gorgone/class +gorgone/modules/* usr/share/perl5/gorgone/modules +gorgone/standard/* usr/share/perl5/gorgone/standard diff --git a/ci/debian-gorgone/centreon-gorgone.logrotate b/ci/debian-gorgone/centreon-gorgone.logrotate new file mode 100644 index 00000000000..e6f56b7475f --- /dev/null +++ b/ci/debian-gorgone/centreon-gorgone.logrotate @@ -0,0 +1,10 @@ +/var/log/centreon-gorgone/gorgoned.log { + copytruncate + weekly + rotate 52 + compress + delaycompress + notifempty + missingok + su root root +} diff --git a/ci/debian-gorgone/centreon-gorgone.postinst b/ci/debian-gorgone/centreon-gorgone.postinst new file mode 100644 index 00000000000..69e8fd4bc53 --- /dev/null +++ b/ci/debian-gorgone/centreon-gorgone.postinst @@ -0,0 +1,67 @@ +#!/bin/sh + +if [ "$1" = "configure" ] ; then + + if [ ! "$(getent passwd centreon-gorgone)" ]; then + adduser --system --group --home /var/lib/centreon-gorgone --no-create-home centreon-gorgone + fi + + if [ "$(getent passwd centreon)" ]; then + usermod -a -G centreon-gorgone centreon + usermod -a -G centreon centreon-gorgone + fi + + if [ "$(getent passwd centreon-engine)" ]; then + usermod -a -G centreon-gorgone centreon-engine + fi + + if [ "$(getent passwd centreon-broker)" ]; then + usermod -a -G centreon-gorgone centreon-broker + fi + + chown -vR centreon-gorgone:centreon-gorgone \ + /etc/centreon-gorgone \ + /var/cache/centreon-gorgone \ + /var/cache/centreon-gorgone/autodiscovery \ + /var/lib/centreon-gorgone \ + /var/log/centreon-gorgone + chmod -vR g+w \ + /etc/centreon-gorgone \ + /var/cache/centreon-gorgone \ + /var/cache/centreon-gorgone/autodiscovery \ + /var/lib/centreon-gorgone \ + /var/log/centreon-gorgone + + chown root:root \ + /usr/local/bin/gorgone_config_init.pl \ + /usr/local/bin/gorgone_audit.pl \ + /usr/local/bin/gorgone_install_plugins.pl + + chmod 0755 \ + /usr/local/bin/gorgone_config_init.pl \ + /usr/local/bin/gorgone_audit.pl + + chmod 0750 \ + /usr/local/bin/gorgone_install_plugins.pl + + if [ ! -d /var/lib/centreon-gorgone/.ssh -a -d /var/spool/centreon/.ssh ] ; then + /usr/bin/cp -r /var/spool/centreon/.ssh /var/lib/centreon-gorgone/.ssh + /usr/bin/chown -R centreon-gorgone:centreon-gorgone /var/lib/centreon-gorgone/.ssh + /usr/bin/chmod 600 /var/lib/centreon-gorgone/.ssh/id_rsa + fi + + # rename files to priority + if [ ! -e /etc/centreon-gorgone/config.d/30-centreon.yaml ] && [ -e /etc/centreon-gorgone/config.d/centreon.yaml ]; then + mv /etc/centreon-gorgone/config.d/centreon.yaml /etc/centreon-gorgone/config.d/30-centreon.yaml + fi + if [ ! -e /etc/centreon-gorgone/config.d/31-centreon-api.yaml ] && [ -e /etc/centreon-gorgone/config.d/centreon-api.yaml ]; then + mv /etc/centreon-gorgone/config.d/centreon-api.yaml /etc/centreon-gorgone/config.d/31-centreon-api.yaml + fi + if [ ! -e /etc/centreon-gorgone/config.d/50-centreon-audit.yaml ] && [ -e /etc/centreon-gorgone/config.d/centreon-audit.yaml ]; then + mv /etc/centreon-gorgone/config.d/centreon-audit.yaml /etc/centreon-gorgone/config.d/50-centreon-audit.yaml + fi + + systemctl preset gorgoned.service || : >/dev/null 2>&1 || : + +fi +exit 0 diff --git a/ci/debian-gorgone/control b/ci/debian-gorgone/control new file mode 100644 index 00000000000..47f0700cf2f --- /dev/null +++ b/ci/debian-gorgone/control @@ -0,0 +1,59 @@ +Source: centreon-gorgone +Section: net +Priority: optional +Maintainer: Luiz Costa +Build-Depends: + debhelper-compat (=12), + lsb-base, + perl:native, + libdigest-md5-file-perl, + libjson-pp-perl, + libjson-xs-perl, + libyaml-libyaml-perl, + libdbi-perl, + libdbd-sqlite3-perl, + libdbd-mysql-perl, + libhttp-daemon-perl, + libhttp-daemon-ssl-perl, + libnetaddr-ip-perl, + libschedule-cron-perl, + libhash-merge-perl, + libcryptx-perl, + libzmq-constants-perl, + zmq-libzmq4-perl +Standards-Version: 4.5.0 +Homepage: https://wwww.centreon.com + +Package: centreon-gorgone +Architecture: any +Depends: + centreon-common (>= ${centreon:version}~), + libdatetime-perl, + libtry-tiny-perl, + libxml-simple-perl, + libxml-libxml-simple-perl, + libdigest-md5-file-perl, + libjson-pp-perl, + libjson-xs-perl, + libyaml-libyaml-perl, + libdbi-perl, + libdbd-sqlite3-perl, + libdbd-mysql-perl, + libhttp-daemon-perl, + libhttp-daemon-ssl-perl, + libnetaddr-ip-perl, + libschedule-cron-perl, + libhash-merge-perl, + libcryptx-perl, + libmojolicious-perl, + libauthen-simple-perl, + libauthen-simple-net-perl, + libnet-curl-perl, + libssh-session-perl, + libzmq-constants-perl, + libzmq5, + zmq-libzmq4-perl, + sudo, + ${shlibs:Depends}, + ${misc:Depends} +Description: Centreon Gorgone. diff --git a/ci/debian-gorgone/copyright b/ci/debian-gorgone/copyright new file mode 100644 index 00000000000..9331ebebd3d --- /dev/null +++ b/ci/debian-gorgone/copyright @@ -0,0 +1,29 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: centreon-gorgone +Upstream-Contact: Luiz Costa +Source: https://www.centreon.com + +Files: * +Copyright: 2022 Centreon +License: Apache-2.0 + +Files: debian/* +Copyright: 2022 Centreon +License: Apache-2.0 + +License: Apache-2.0 + 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 + . + https://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. + . + On Debian systems, the complete text of the Apache version 2.0 license + can be found in "/usr/share/common-licenses/Apache-2.0". + diff --git a/ci/debian-gorgone/extra/gorgoned b/ci/debian-gorgone/extra/gorgoned new file mode 100644 index 00000000000..d6fb7a6ebe2 --- /dev/null +++ b/ci/debian-gorgone/extra/gorgoned @@ -0,0 +1,6 @@ +# Configuration file for Centreon Gorgone. + +# OPTIONS for the daemon launch +CONFIG="/etc/centreon-gorgone/config.yaml" +LOGFILE="/var/log/centreon-gorgone/gorgoned.log" +SEVERITY="info" diff --git a/ci/debian-gorgone/extra/gorgoned.service b/ci/debian-gorgone/extra/gorgoned.service new file mode 100644 index 00000000000..a226b0256c4 --- /dev/null +++ b/ci/debian-gorgone/extra/gorgoned.service @@ -0,0 +1,33 @@ +## +## Copyright 2019-2021 Centreon +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## +## For more information : contact@centreon.com +## + +[Unit] +Description=Centreon Gorgone +PartOf=centreon.service +After=centreon.service +ReloadPropagatedFrom=centreon.service + +[Service] +EnvironmentFile=/etc/default/gorgoned +ExecStart=/usr/bin/perl /usr/bin/gorgoned --config=${CONFIG} --logfile=${LOGFILE} --severity=${SEVERITY} +Type=simple +User=centreon-gorgone + +[Install] +WantedBy=multi-user.target +WantedBy=centreon.service diff --git a/ci/debian-gorgone/rules b/ci/debian-gorgone/rules new file mode 100644 index 00000000000..95af63e770c --- /dev/null +++ b/ci/debian-gorgone/rules @@ -0,0 +1,11 @@ +#!/usr/bin/make -f + +export DEB_BUILD_MAINT_OPTIONS = hardening=+all + +%: + dh $@ + +override_dh_gencontrol: + dh_gencontrol -- -Tdebian/substvars + +override_dh_usrlocal: diff --git a/ci/debian-gorgone/source/format b/ci/debian-gorgone/source/format new file mode 100644 index 00000000000..163aaf8d82b --- /dev/null +++ b/ci/debian-gorgone/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/ci/debian-gorgone/substvars b/ci/debian-gorgone/substvars new file mode 100644 index 00000000000..929c65b6607 --- /dev/null +++ b/ci/debian-gorgone/substvars @@ -0,0 +1 @@ +centreon:version= diff --git a/ci/docker/Dockerfile.collect-alma8-dependencies b/ci/docker/Dockerfile.collect-alma8 similarity index 89% rename from ci/docker/Dockerfile.collect-alma8-dependencies rename to ci/docker/Dockerfile.collect-alma8 index 8875d156605..793428839d0 100644 --- a/ci/docker/Dockerfile.collect-alma8-dependencies +++ b/ci/docker/Dockerfile.collect-alma8 @@ -1,4 +1,4 @@ -FROM registry.centreon.com/almalinux:8.5 +FROM almalinux:8.5 RUN dnf clean all @@ -24,7 +24,6 @@ RUN dnf clean all && dnf install -y cmake \ make \ maven \ perl-ExtUtils-Embed.noarch \ - libssh2-devel \ python38 \ python38-pip \ perl-Thread-Queue \ @@ -41,6 +40,6 @@ RUN pip3 install conan --prefix=/usr --upgrade RUN rm -rf ~/.conan/profiles/default COPY conanfile.txt . RUN cat conanfile.txt -RUN conan install . -s compiler.libcxx=libstdc++11 --build='*' - +RUN conan install . -s compiler.cppstd=14 -s compiler.libcxx=libstdc++11 --build='*' + WORKDIR /src diff --git a/ci/docker/Dockerfile.collect-centos7-dependencies b/ci/docker/Dockerfile.collect-centos7 similarity index 95% rename from ci/docker/Dockerfile.collect-centos7-dependencies rename to ci/docker/Dockerfile.collect-centos7 index 5cd6cf47657..ea06641e271 100644 --- a/ci/docker/Dockerfile.collect-centos7-dependencies +++ b/ci/docker/Dockerfile.collect-centos7 @@ -14,8 +14,6 @@ RUN yum -y upgrade && yum -y update && \ openssh-server \ epel-release \ centos-release-scl \ - python3 \ - python3-pip \ ninja-build \ gnutls-devel \ lua-devel \ @@ -24,7 +22,6 @@ RUN yum -y upgrade && yum -y update && \ perl-Data-Dumper \ perl-ExtUtils-MakeMaker \ perl-ExtUtils-Embed.noarch \ - libssh2-devel \ redhat-lsb \ libgcrypt-devel \ galera*.rpm \ @@ -32,11 +29,9 @@ RUN yum -y upgrade && yum -y update && \ yum clean all RUN yum-config-manager --enable rhel-server-rhscl-7-rpms RUN yum -y install devtoolset-9 \ - rh-python38 \ MariaDB*.rpm \ + rh-python38 \ cmake3 \ - gcc \ - gcc-c++ \ perl-Ext* \ perl-App-FatPacker \ perl-File-Copy-Recursive \ @@ -50,9 +45,9 @@ RUN yum -y install devtoolset-9 \ RUN ln -s /usr/bin/cmake3 /usr/bin/cmake COPY conanfile.txt . RUN cat conanfile.txt -RUN source /opt/rh/devtoolset-9/enable && source /opt/rh/rh-python38/enable &&\ +RUN source /opt/rh/devtoolset-9/enable && source /opt/rh/rh-python38/enable && \ pip3 install conan --upgrade &&\ - conan install . -s compiler.libcxx=libstdc++11 --build='*' + /opt/rh/rh-python38/root/usr/local/bin/conan install . -s compiler.cppstd=14 -s compiler.libcxx=libstdc++11 --build='*' RUN unzip -q sonar-scanner-cli-4.7.0.2747-linux.zip RUN rm -rf sonar-scanner-cli-4.7.0.2747-linux.zip diff --git a/ci/docker/Dockerfile.collect-debian-bullseye b/ci/docker/Dockerfile.collect-debian-bullseye new file mode 100644 index 00000000000..6132883ee1d --- /dev/null +++ b/ci/docker/Dockerfile.collect-debian-bullseye @@ -0,0 +1,38 @@ +FROM debian:bullseye +RUN apt-get -y update && \ + apt-get -y install cmake \ + curl \ + gcc \ + g++ \ + pkg-config \ + ninja-build \ + libmariadb3 \ + librrd-dev \ + libgnutls28-dev \ + ninja-build \ + liblua5.3-dev \ + python3 \ + python3-pip \ + libperl-dev \ + libgcrypt20-dev \ + dh-make \ + aptitude \ + lintian \ + pbuilder \ + quilt \ + git-buildpackage \ + debmake \ + devscripts \ + fakeroot \ + locales && \ + rm -rf /var/lib/apt/lists/* && \ + localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 +RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py +RUN python3 get-pip.py +RUN pip3 install conan +RUN ln -s /usr/local/bin/conan /usr/bin/conan +RUN rm -rf ~/.conan/profiles/default +COPY conanfile.txt . +RUN cat conanfile.txt +RUN conan install . -s compiler.cppstd=14 -s compiler.libcxx=libstdc++11 --build='missing' +WORKDIR /src diff --git a/ci/docker/Dockerfile.collect-debian-dependencies b/ci/docker/Dockerfile.collect-debian-dependencies deleted file mode 100644 index 2880bd38f8b..00000000000 --- a/ci/docker/Dockerfile.collect-debian-dependencies +++ /dev/null @@ -1,34 +0,0 @@ -FROM debian:buster -RUN apt-get -y update && \ - apt-get -y install curl -RUN curl http://ftp.fr.debian.org/debian/pool/main/c/cmake/cmake_3.18.4-2+deb11u1~bpo10+1_amd64.deb --output cmake_3.18.4-2+deb11u1~bpo10+1_amd64.deb -RUN curl http://ftp.fr.debian.org/debian/pool/main/c/cmake/cmake-data_3.18.4-2+deb11u1~bpo10+1_all.deb --output cmake-data_3.18.4-2+deb11u1~bpo10+1_all.deb -RUN curl http://ftp.fr.debian.org/debian/pool/main/d/dwz/dwz_0.13-5~bpo10+1_amd64.deb --output dwz_0.13-5~bpo10+1_amd64.deb -RUN apt-get -y update && \ - apt-get -y install cmake \ - gcc \ - g++ \ - pkg-config \ - ninja-build \ - libmariadb3 \ - librrd-dev \ - libgnutls28-dev \ - ninja-build \ - liblua5.3-dev \ - python3 \ - python3-pip \ - libperl-dev \ - libssh2-1-dev \ - libgcrypt20-dev -RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py -RUN dpkg -i cmake_3.18.4-2+deb11u1~bpo10+1_amd64.deb cmake-data_3.18.4-2+deb11u1~bpo10+1_all.deb -RUN python3 get-pip.py -RUN pip3 install conan -RUN ln -s /usr/local/bin/conan /usr/bin/conan -RUN rm -rf ~/.conan/profiles/default -COPY conanfile.txt . -RUN cat conanfile.txt -RUN conan install . -s compiler.libcxx=libstdc++11 --build='missing' -WORKDIR /src - - diff --git a/ci/docker/Dockerfile.gorgone-alma8 b/ci/docker/Dockerfile.gorgone-alma8 new file mode 100644 index 00000000000..f3bd7f4352f --- /dev/null +++ b/ci/docker/Dockerfile.gorgone-alma8 @@ -0,0 +1,21 @@ +FROM almalinux:8.5 + +RUN dnf clean all +# fix locale +RUN echo 'http_caching=none' >> /etc/yum.conf && \ + echo 'assumeyes=1' >> /etc/yum.conf && \ + sed -i 's/best=True/best=False/g' /etc/dnf/dnf.conf && \ + dnf install -y dnf-plugins-core +RUN dnf config-manager --set-enabled powertools +RUN dnf clean all && dnf install -y perl-ExtUtils-Embed.noarch \ + python38 \ + python38-pip \ + perl-Thread-Queue \ + redhat-lsb \ + yum-utils \ + perl \ + rpm-build +RUN dnf update libarchive + + +WORKDIR /src diff --git a/ci/docker/Dockerfile.gorgone-centos7 b/ci/docker/Dockerfile.gorgone-centos7 new file mode 100644 index 00000000000..721da1fc189 --- /dev/null +++ b/ci/docker/Dockerfile.gorgone-centos7 @@ -0,0 +1,23 @@ +FROM centos:7 + +# fix locale +RUN yum -y upgrade && yum -y update && \ + yum -y install perl-Thread-Queue \ + perl-devel \ + perl-Data-Dumper \ + perl-ExtUtils-MakeMaker \ + perl-ExtUtils-Embed.noarch \ + redhat-lsb \ + rh-python38 \ + perl-Ext* \ + perl-App-FatPacker \ + perl-File-Copy-Recursive \ + perl-JSON \ + gettext \ + expect \ + perl-XML-SAX \ + rpm-build \ + unzip \ + ShellCheck + +WORKDIR /src diff --git a/ci/docker/Dockerfile.gorgone-debian-bullseye b/ci/docker/Dockerfile.gorgone-debian-bullseye new file mode 100644 index 00000000000..587d3c37610 --- /dev/null +++ b/ci/docker/Dockerfile.gorgone-debian-bullseye @@ -0,0 +1,30 @@ +FROM debian:bullseye + +# fix locale +RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \ +&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 +ENV LANG en_US.utf8 + +RUN apt-get update && apt-get install -y \ +dh-make \ +dh-make-perl \ +libtest-simple-perl \ +libmodule-install-perl \ +libnet-ldap-perl \ +libauthen-simple-passwd-perl \ +libmojolicious-perl \ +aptitude \ +lintian \ +pbuilder \ +quilt \ +git-buildpackage \ +debmake \ +devscripts \ +fakeroot \ +curl \ +python3 \ +python3-pip \ +&& pip3 install conan \ +&& ln -s /usr/local/bin/conan /usr/bin/conan + +WORKDIR /src diff --git a/ci/release/Jenkinsfile b/ci/release/Jenkinsfile deleted file mode 100644 index 6dec05eb0e8..00000000000 --- a/ci/release/Jenkinsfile +++ /dev/null @@ -1,21 +0,0 @@ -@Library("centreon-shared-library") _ - -pipeline { - agent { label 'C++' } - stages { - stage('Release Collect') { - input { - message "what verion and release number the release should have ?" - parameters { - string(name: 'VERSION', defaultValue: '', description: 'Version to be released') - string(name: 'RELEASE', defaultValue: '', description: 'Release number') - } - } - steps { - echo 'Releasing Centreon Collect' - loadCommonScripts() - sh './ci/release/collect-release.sh' - } - } - } -} diff --git a/ci/release/collect-release.sh b/ci/release/collect-release.sh index 2e9fb92ba3c..eb5ef26da08 100755 --- a/ci/release/collect-release.sh +++ b/ci/release/collect-release.sh @@ -16,15 +16,14 @@ MAJOR=`echo $VERSION | cut -d . -f 1,2` ssh -o StrictHostKeyChecking=no ubuntu@srvi-repo.int.centreon.com cp -r "/srv/sources/standard/testing/centreon-collect/centreon-collect-$VERSION-$RELEASE" "/srv/sources/standard/stable/" # Put sources online. -upload_tarball_for_download "centreon-collect" "$VERSION" "/srv/sources/standard/stable/centreon-collect-$VERSION-$RELEASE/centreon-collect-$VERSION-$RELEASE.tar.gz" "s3://centreon-download/public/centreon-collect/centreon-collect-$VERSION.tar.gz" +upload_tarball_for_download "centreon-collect" "$VERSION" "/srv/sources/standard/stable/centreon-collect-$VERSION-$RELEASE/centreon-collect-$VERSION-$RELEASE.tar.gz" "s3://centreon-download/public/centreon-collect/centreon-collect-$VERSION.tar.gz" "$1" # Move RPMs to the stable repository. promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el7" "x86_64" "broker" "centreon-broker-$VERSION-$RELEASE" -promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el7" "x86_64" "engine" "centreon-engine-$VERSION-$RELEASE" -promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el7" "x86_64" "clib" "centreon-clib-$VERSION-$RELEASE" -promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el7" "x86_64" "connector" "centreon-connector-$VERSION-$RELEASE" - promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el8" "x86_64" "broker" "centreon-broker-$VERSION-$RELEASE" +promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el7" "x86_64" "engine" "centreon-engine-$VERSION-$RELEASE" promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el8" "x86_64" "engine" "centreon-engine-$VERSION-$RELEASE" +promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el7" "x86_64" "clib" "centreon-clib-$VERSION-$RELEASE" promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el8" "x86_64" "clib" "centreon-clib-$VERSION-$RELEASE" +promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el7" "x86_64" "connector" "centreon-connector-$VERSION-$RELEASE" promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el8" "x86_64" "connector" "centreon-connector-$VERSION-$RELEASE" diff --git a/ci/scripts/collect-deb-package.sh b/ci/scripts/collect-deb-package.sh new file mode 100755 index 00000000000..d6602c718c4 --- /dev/null +++ b/ci/scripts/collect-deb-package.sh @@ -0,0 +1,32 @@ +#!/bin/sh +set -e + +if [ -z "$ROOT" ] ; then + ROOT=centreon-collect +fi + +if [ -z "$VERSION" -o -z "$RELEASE" -o -z "$DISTRIB" ] ; then + echo "You need to specify VERSION / RELEASE variables" + exit 1 +fi + +echo "############################# PACKAGING COLLECT ################################" + +AUTHOR="Luiz Costa" +AUTHOR_EMAIL="me@luizgustavo.pro.br" + +# fix version to debian format accept +VERSION="$(echo $VERSION | sed 's/-/./g')" + +if [ -d "$ROOT/build" ] ; then + rm -rf "$ROOT/build" +fi +rm -rf "$ROOT/gorgone" +tar --exclude={".git","build"} -czpf centreon-collect-$VERSION.tar.gz "$ROOT" +cd "$ROOT" +cp -rf ci/debian-collect debian +sed -i "s/^centreon:version=.*$/centreon:version=$(echo $VERSION-$RELEASE)/" debian/substvars +#sed -i "s/^centreon:version=.*$/centreon:version=$(echo $VERSION | egrep -o '^[0-9][0-9].[0-9][0-9]')/" debian/substvars +debmake -f "${AUTHOR}" -e "${AUTHOR_EMAIL}" -u "$VERSION" -r "$DISTRIB" +debuild-pbuilder +cd ../ diff --git a/ci/scripts/collect-release.sh b/ci/scripts/collect-release.sh deleted file mode 100755 index 819905f1da2..00000000000 --- a/ci/scripts/collect-release.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -set -e -set -x - -source common.sh - -# Check arguments -if [ -z "$VERSION" -o -z "$RELEASE" ] ; then - echo "You need to specify VERSION / RELEASE variables" - exit 1 -fi - -MAJOR=`echo $VERSION | cut -d . -f 1,2` - -# Move sources to the stable directory. -ssh -o StrictHostKeyChecking=no ubuntu@srvi-repo.int.centreon.com cp -r "/srv/sources/standard/testing/centreon-collect/centreon-collect-$VERSION-$RELEASE" "/srv/sources/standard/stable/" - -# Put sources online. -upload_tarball_for_download "centreon-collect" "$VERSION" "/srv/sources/standard/stable/centreon-collect-$VERSION-$RELEASE/centreon-collect-$VERSION-$RELEASE.tar.gz" "s3://centreon-download/public/centreon-collect/centreon-collect-$VERSION.tar.gz" - -# Move RPMs to the stable repository. -promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el7" "x86_64" "broker" "centreon-broker-$VERSION-$RELEASE" -promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el7" "x86_64" "engine" "centreon-engine-$VERSION-$RELEASE" -promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el7" "x86_64" "clib" "centreon-clib-$VERSION-$RELEASE" -promote_rpms_from_testing_to_stable "standard" "$MAJOR" "el7" "x86_64" "connector" "centreon-connector-$VERSION-$RELEASE" diff --git a/ci/scripts/collect-rpm-delivery.sh b/ci/scripts/collect-rpm-delivery.sh index a9f2e5490e7..46967a02f91 100755 --- a/ci/scripts/collect-rpm-delivery.sh +++ b/ci/scripts/collect-rpm-delivery.sh @@ -11,24 +11,27 @@ if [ -z "$VERSION" -o -z "$RELEASE" ] ; then fi MAJOR=`echo $VERSION | cut -d . -f 1,2` +COLLECTEL7RPMS=`echo output/*collect*.el7.*.rpm` +COLLECTEL8RPMS=`echo output/*collect*.el8.*.rpm` ENGINEEL7RPMS=`echo output/*engine*.el7.*.rpm` -BROKEREL7RPMS=`echo output/*broker*.el7.*.rpm` -CLIBEL7RPMS=`echo output/*clib*.el7.*.rpm` -CONNECTOREL7RPMS=`echo output/*connector*.el7.*.rpm` - ENGINEEL8RPMS=`echo output/*engine*.el8.*.rpm` +BROKEREL7RPMS=`echo output/*broker*.el7.*.rpm` BROKEREL8RPMS=`echo output/*broker*.el8.*.rpm` +CLIBEL7RPMS=`echo output/*clib*.el7.*.rpm` CLIBEL8RPMS=`echo output/*clib*.el8.*.rpm` +CONNECTOREL7RPMS=`echo output/*connector*.el7.*.rpm` CONNECTOREL8RPMS=`echo output/*connector*.el8.*.rpm` # Publish RPMs if [ "$BUILD" '=' 'QA' ] then + put_rpms "standard" "$MAJOR" "el7" "unstable" "x86_64" "collect" "centreon-collect-$VERSION-$RELEASE" $COLLECTEL7RPMS put_rpms "standard" "$MAJOR" "el7" "unstable" "x86_64" "engine" "centreon-engine-$VERSION-$RELEASE" $ENGINEEL7RPMS put_rpms "standard" "$MAJOR" "el7" "unstable" "x86_64" "broker" "centreon-broker-$VERSION-$RELEASE" $BROKEREL7RPMS put_rpms "standard" "$MAJOR" "el7" "unstable" "x86_64" "connector" "centreon-connector-$VERSION-$RELEASE" $CONNECTOREL7RPMS put_rpms "standard" "$MAJOR" "el7" "unstable" "x86_64" "clib" "centreon-clib-$VERSION-$RELEASE" $CLIBEL7RPMS - + + put_rpms "standard" "$MAJOR" "el8" "unstable" "x86_64" "collect" "centreon-collect-$VERSION-$RELEASE" $COLLECTEL8RPMS put_rpms "standard" "$MAJOR" "el8" "unstable" "x86_64" "engine" "centreon-engine-$VERSION-$RELEASE" $ENGINEEL8RPMS put_rpms "standard" "$MAJOR" "el8" "unstable" "x86_64" "broker" "centreon-broker-$VERSION-$RELEASE" $BROKEREL8RPMS put_rpms "standard" "$MAJOR" "el8" "unstable" "x86_64" "connector" "centreon-connector-$VERSION-$RELEASE" $CONNECTOREL8RPMS @@ -36,23 +39,28 @@ then elif [ "$BUILD" '=' 'RELEASE' ] then copy_internal_source_to_testing "standard" "centreon-collect" "centreon-collect-$VERSION-$RELEASE" + put_rpms "standard" "$MAJOR" "el7" "testing" "x86_64" "collect" "centreon-collect-$VERSION-$RELEASE" $COLLECTEL7RPMS put_rpms "standard" "$MAJOR" "el7" "testing" "x86_64" "engine" "centreon-engine-$VERSION-$RELEASE" $ENGINEEL7RPMS put_rpms "standard" "$MAJOR" "el7" "testing" "x86_64" "broker" "centreon-broker-$VERSION-$RELEASE" $BROKEREL7RPMS put_rpms "standard" "$MAJOR" "el7" "testing" "x86_64" "connector" "centreon-connector-$VERSION-$RELEASE" $CONNECTOREL7RPMS put_rpms "standard" "$MAJOR" "el7" "testing" "x86_64" "clib" "centreon-clib-$VERSION-$RELEASE" $CLIBEL7RPMS + put_rpms "standard" "$MAJOR" "el8" "testing" "x86_64" "collect" "centreon-collect-$VERSION-$RELEASE" $COLLECTEL8RPMS put_rpms "standard" "$MAJOR" "el8" "testing" "x86_64" "engine" "centreon-engine-$VERSION-$RELEASE" $ENGINEEL8RPMS put_rpms "standard" "$MAJOR" "el8" "testing" "x86_64" "broker" "centreon-broker-$VERSION-$RELEASE" $BROKEREL8RPMS put_rpms "standard" "$MAJOR" "el8" "testing" "x86_64" "connector" "centreon-connector-$VERSION-$RELEASE" $CONNECTOREL8RPMS put_rpms "standard" "$MAJOR" "el8" "testing" "x86_64" "clib" "centreon-clib-$VERSION-$RELEASE" $CLIBEL8RPMS + else + put_rpms "standard" "$MAJOR" "el7" "canary" "x86_64" "collect" "centreon-collect-$VERSION-$RELEASE" $COLLECTEL7RPMS put_rpms "standard" "$MAJOR" "el7" "canary" "x86_64" "engine" "centreon-engine-$VERSION-$RELEASE" $ENGINEEL7RPMS put_rpms "standard" "$MAJOR" "el7" "canary" "x86_64" "broker" "centreon-broker-$VERSION-$RELEASE" $BROKEREL7RPMS put_rpms "standard" "$MAJOR" "el7" "canary" "x86_64" "connector" "centreon-connector-$VERSION-$RELEASE" $CONNECTOREL7RPMS put_rpms "standard" "$MAJOR" "el7" "canary" "x86_64" "clib" "centreon-clib-$VERSION-$RELEASE" $CLIBEL7RPMS + put_rpms "standard" "$MAJOR" "el8" "canary" "x86_64" "collect" "centreon-collect-$VERSION-$RELEASE" $COLLECTEL8RPMS put_rpms "standard" "$MAJOR" "el8" "canary" "x86_64" "engine" "centreon-engine-$VERSION-$RELEASE" $ENGINEEL8RPMS put_rpms "standard" "$MAJOR" "el8" "canary" "x86_64" "broker" "centreon-broker-$VERSION-$RELEASE" $BROKEREL8RPMS put_rpms "standard" "$MAJOR" "el8" "canary" "x86_64" "connector" "centreon-connector-$VERSION-$RELEASE" $CONNECTOREL8RPMS - put_rpms "standard" "$MAJOR" "el8" "canary" "x86_64" "clib" "centreon-clib-$VERSION-$RELEASE" $CLIBEL8RPMS + put_rpms "standard" "$MAJOR" "el8" "canary" "x86_64" "clib" "centreon-clib-$VERSION-$RELEASE" $CLIBEL8RPMS fi diff --git a/ci/scripts/collect-rpm-package.sh b/ci/scripts/collect-rpm-package.sh index aad51826d93..60acd3e8e66 100755 --- a/ci/scripts/collect-rpm-package.sh +++ b/ci/scripts/collect-rpm-package.sh @@ -2,74 +2,32 @@ set -e if [ -z "$VERSION" -o -z "$RELEASE" -o -z "$DISTRIB" ] ; then - echo "You need to specify VERSION / RELEASE variables" + echo "You need to specify VERSION / RELEASE / DISTRIB variables" exit 1 fi -echo "################################################## BUILDING BROKER ##################################################" +echo "########################### BUILDING COLLECT ############################" + # generate rpm broker if [ ! -d /root/rpmbuild/SOURCES ] ; then mkdir -p /root/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} fi -mkdir centreon-broker-$VERSION -cp -r centreon-broker/* centreon-broker-$VERSION -cp -r resources centreon-broker-$VERSION -cp conanfile.txt centreon-broker-$VERSION -tar -czf centreon-broker-$VERSION.tar.gz centreon-broker-$VERSION cmake.sh -mv centreon-broker-$VERSION.tar.gz /root/rpmbuild/SOURCES/ -rm -rf centreon-broker-$VERSION -rpmbuild -ba centreon-broker/packaging/rpm/centreon-broker.spectemplate -D "VERSION $VERSION" -D "RELEASE $RELEASE" - - -# echo "################################################## BUILDING CLIB ##################################################" - -# generate rpm clib -mkdir centreon-clib-$VERSION -cp -r centreon-clib/* centreon-clib-$VERSION -cp conanfile.txt centreon-clib-$VERSION -tar -czf centreon-clib-$VERSION.tar.gz centreon-clib-$VERSION cmake.sh -mv centreon-clib-$VERSION.tar.gz /root/rpmbuild/SOURCES/ -rm -rf centreon-clib-$VERSION -rpmbuild -ba centreon-clib/packaging/rpm/centreon-clib.spectemplate -D "VERSION $VERSION" -D "RELEASE $RELEASE" - -# echo "################################################## INSTALL CLIB ##################################################" - -if [ "$DISTRIB" = "el7" ] ; then - rpm -i /root/rpmbuild/RPMS/x86_64/centreon-clib-$VERSION-$RELEASE.el7.x86_64.rpm - rpm -i /root/rpmbuild/RPMS/x86_64/centreon-clib-debuginfo-$VERSION-$RELEASE.el7.x86_64.rpm - rpm -i /root/rpmbuild/RPMS/x86_64/centreon-clib-devel-$VERSION-$RELEASE.el7.x86_64.rpm -else - rpm -i /root/rpmbuild/RPMS/x86_64/centreon-clib-$VERSION-$RELEASE.el8.x86_64.rpm - rpm -i /root/rpmbuild/RPMS/x86_64/centreon-clib-debuginfo-$VERSION-$RELEASE.el8.x86_64.rpm - rpm -i /root/rpmbuild/RPMS/x86_64/centreon-clib-devel-$VERSION-$RELEASE.el8.x86_64.rpm -fi - -# echo "################################################## BUILDING ENGINE ##################################################" - -# generate rpm engine -mkdir centreon-engine-$VERSION -cp -r centreon-engine/* centreon-engine-$VERSION -cp conanfile.txt centreon-engine-$VERSION -tar -czf centreon-engine-$VERSION.tar.gz centreon-engine-$VERSION cmake.sh -mv centreon-engine-$VERSION.tar.gz /root/rpmbuild/SOURCES/ -rm -rf centreon-engine-$VERSION - -cp centreon-engine/packaging/rpm/centreonengine_integrate_centreon_engine2centreon.sh /root/rpmbuild/SOURCES/ -rpmbuild -ba centreon-engine/packaging/rpm/centreon-engine.spectemplate -D "VERSION $VERSION" -D "RELEASE $RELEASE" +tar czf /root/rpmbuild/SOURCES/centreon-collect-$VERSION.tar.gz \ + --exclude './build' \ + --exclude './.git' \ + --transform "s,^\.,centreon-collect-$VERSION," . +cp packaging/rpm/centreonengine_integrate_centreon_engine2centreon.sh /root/rpmbuild/SOURCES/ -# echo "################################################## BUILDING CONNECTOR ##################################################" +DISTRIB=$(lsb_release -rs | cut -f1 -d.) +if [ "$DISTRIB" = "7" ] ; then + source /opt/rh/devtoolset-9/enable +fi -# generate rpm connector -mkdir centreon-connector-$VERSION -cp -r centreon-connector/* centreon-connector-$VERSION -cp conanfile.txt centreon-connector-$VERSION -tar -czf centreon-connector-$VERSION.tar.gz centreon-connector-$VERSION cmake.sh -mv centreon-connector-$VERSION.tar.gz /root/rpmbuild/SOURCES/ -rm -rf centreon-connector-$VERSION +echo -e "%_topdir %(echo $HOME)/rpmbuild\n%_smp_mflags -j9\n" > $HOME/rpmbuild/.rpmmacros -rpmbuild -ba centreon-connector/packaging/rpm/centreon-connector.spectemplate -D "VERSION $VERSION" -D "RELEASE $RELEASE" +rpmbuild -ba packaging/rpm/centreon-collect.spec -D "VERSION $VERSION" -D "RELEASE $RELEASE" # cleaning and according permissions to slave to delivery rpms rm -rf *.rpm diff --git a/ci/scripts/collect-sonar-scanner-common.sh b/ci/scripts/collect-sonar-scanner-common.sh deleted file mode 100755 index e9560f937a8..00000000000 --- a/ci/scripts/collect-sonar-scanner-common.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash - -set -e - -source common.sh -CACHE_REFERENCE="$2" -# Check arguments. -if [ -z "$VERSION" ]; then - echo "ERROR: You need to specify VERSION environment variable." - exit 1 -fi - -if [ -z "$PROJECT" ]; then - echo "WARNING: PROJECT was not set as environment variable." - PROJECT="centreon-collect" -fi - -if [ -n "$CHANGE_TARGET" ]; then - TARGET="$CHANGE_TARGET" -else - TARGET="$BRANCH_NAME" -fi - -get_cache() { - echo "INFO: Cleaning before pulling tarball ..." - rm -f "$PROJECT-SQ-cache-$TARGET.tar.gz" - - TAR_NAME="$PROJECT-SQ-cache-$TARGET.tar.gz" - CACHE_URL="http://srvi-repo.int.centreon.com/sources/internal/SQ-cache/$PROJECT/$TAR_NAME" - if validate_file_exists "$CACHE_URL"; then - echo "INFO: Pulling tarball ..." - wget -q "$CACHE_URL" - else - TAR_NAME="$PROJECT-SQ-cache-$CACHE_REFERENCE.tar.gz" - CACHE_URL="http://srvi-repo.int.centreon.com/sources/internal/SQ-cache/$PROJECT/$TAR_NAME" - if validate_file_exists "$CACHE_URL"; then - echo "INFO: Pulling tarball $CACHE_REFERENCE ..." - wget -q "$CACHE_URL" - else - echo "WARNING: File not found. Skipping $TARGET's cache on $CACHE_REFERENCE" - if [ ! -d build ] ; then - mkdir build - fi - return 0 - fi - fi - tar xzf "$TAR_NAME" - if [ ! -d build ] ; then - mkdir build - fi - mv cache build/ - rm -rf "$TAR_NAME" -} - -set_cache() { - cd tmp - if [ -z "$TARGET" ]; then - echo "ERROR: Target's name is empty. Skipping $VERSION's cache" - exit - fi - - if [ -f "$PROJECT-SQ-cache-$TARGET.tar.gz" ]; then - echo "INFO: Saving cache's tarball $PROJECT-SQ-cache-$TARGET.tar.gz ..." - put_internal_source "SQ-cache" "$PROJECT" "$PROJECT-SQ-cache-$TARGET.tar.gz" - else - echo "WARNING: Tarball to save not found. Skipping $TARGET's cache" - fi -} - -validate_file_exists() { - wget --spider -q "$1" - return $? -} - -# case load -if [ -n "$1" ]; then - if [ "get" == "$1" ]; then - get_cache - elif [ "set" == "$1" ]; then - set_cache - fi -fi diff --git a/ci/scripts/collect-sources-analysis.sh b/ci/scripts/collect-sources-analysis.sh deleted file mode 100755 index 5f25a81b25c..00000000000 --- a/ci/scripts/collect-sources-analysis.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -set -e - -#Cmake -cd /src/build/ - -# Variables -PROC_NBR=$( nproc ) -PROJECT="centreon-collect" -MODE="$1" -AUTH_TOKEN="$2" -URL="$3" -VERSION="$4" -TARGET="$5" -if [[ "$MODE" == "PR" && -n "$6" && -n "$7" ]]; then - PR_BRANCH="$6" - PR_KEY="$7" -fi - -# Get distrib -DISTRIB=$( lsb_release -rs | cut -f1 -d. ) -if [[ "$DISTRIB" = "7" ]] ; then - source /opt/rh/devtoolset-9/enable - source /opt/rh/rh-python38/enable -fi - -# Prepare compilation -conan install .. -s compiler.libcxx=libstdc++11 --build=missing -if [ $(cat /etc/issue | awk '{print $1}') = "Debian" ] ; then - CXXFLAGS="-Wall -Wextra" cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DWITH_CENTREON_CLIB_INCLUDE_DIR=../centreon-clib/inc/ -DWITH_CENTREON_CLIB_LIBRARIES=centreon-clib/libcentreon_clib.so -DCMAKE_BUILD_TYPE=Debug -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF_BROKER=/etc/centreon-broker -DWITH_PREFIX_LIB_BROKER=/usr/lib64/nagios -DWITH_PREFIX_CONF_ENGINE=/etc/centreon-engine -DWITH_PREFIX_LIB_ENGINE=/usr/lib64/centreon-engine -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_RW_DIR=/var/lib/centreon-engine/rw -DWITH_VAR_DIR=/var/log/centreon-engine -DWITH_MODULE_SIMU=On .. -else - CXXFLAGS="-Wall -Wextra" cmake3 -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DWITH_CENTREON_CLIB_INCLUDE_DIR=../centreon-clib/inc/ -DWITH_CENTREON_CLIB_LIBRARIES=centreon-clib/libcentreon_clib.so -DCMAKE_BUILD_TYPE=Debug -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF_BROKER=/etc/centreon-broker -DWITH_PREFIX_LIB_BROKER=/usr/lib64/nagios -DWITH_PREFIX_CONF_ENGINE=/etc/centreon-engine -DWITH_PREFIX_LIB_ENGINE=/usr/lib64/centreon-engine -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_RW_DIR=/var/lib/centreon-engine/rw -DWITH_VAR_DIR=/var/log/centreon-engine -DWITH_MODULE_SIMU=On .. -fi -cd .. - -# Delete default SQ configuration file to override -rm -f /sonar-scanner/conf/sonar-scanner.properties - -# Run SQ with or without reference branch -if [[ "PR" == "$MODE" ]] ; then - - echo "INFO: Running SQ in PR mode ..." - cd /src - /sonar-scanner/bin/sonar-scanner -Dsonar.scm.forceReloadAll=true -Dsonar.cfamily.threads="$PROC_NBR" -Dsonar.scm.provider=git -Dsonar.login="$AUTH_TOKEN" -Dsonar.host.url="$URL" -Dsonar.projectVersion="$VERSION" -Dsonar.pullrequest.base="$TARGET" -Dsonar.pullrequest.branch="$PR_BRANCH" -Dsonar.pullrequest.key="$PR_KEY" -else - echo "INFO: Running SQ in branch mode ..." - cd /src - /sonar-scanner/bin/sonar-scanner -Dsonar.scm.forceReloadAll=true -Dsonar.cfamily.threads="$PROC_NBR" -Dsonar.scm.provider=git -Dsonar.login="$AUTH_TOKEN" -Dsonar.host.url="$URL" -Dsonar.projectVersion="$VERSION" -Dsonar.branch.name="$TARGET" -fi - -mkdir tmp -cd /src/tmp - -echo "INFO: Creating cache tarball named $PROJECT-SQ-cache-$TARGET.tar.gz..." -mv /src/.scannerwork . -mv /src/build/cache . -tar czf "$PROJECT-SQ-cache-$TARGET.tar.gz" cache .scannerwork - diff --git a/ci/scripts/collect-test-robot.sh b/ci/scripts/collect-test-robot.sh index 1169c612f97..e9656c0a080 100755 --- a/ci/scripts/collect-test-robot.sh +++ b/ci/scripts/collect-test-robot.sh @@ -1,43 +1,34 @@ #!/bin/bash set -e +set -x export RUN_ENV=docker -USERNAME="$1" -TOKENJENKINS="$2" -BRANCH="$3" - - -echo "########################### configure and start sshd ############################" -ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key +echo "########################### Configure and start sshd ###########################" +ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -P "" +ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -P "" +ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -P "" /usr/sbin/sshd > /dev/null 2>&1 & -echo "########################### start mariadb ############################" +echo "########################### Start MariaDB ######################################" mariadbd --user=root > /dev/null 2>&1 & sleep 5 -echo "########################### init centreon database ############################" +echo "########################### Init centreon database ############################" -mysql -e "CREATE USER IF NOT EXISTS 'centreon'@'localhost' IDENTIFIED BY 'centreon'" +mysql -e "CREATE USER IF NOT EXISTS 'centreon'@'localhost' IDENTIFIED BY 'centreon';" -mysql -e "GRANT SELECT,UPDATE,DELETE,INSERT,CREATE,DROP,INDEX,ALTER,LOCK TABLES,CREATE TEMPORARY TABLES, EVENT,CREATE VIEW ON *.* TO 'centreon'@'localhost'" +mysql -e "GRANT SELECT,UPDATE,DELETE,INSERT,CREATE,DROP,INDEX,ALTER,LOCK TABLES,CREATE TEMPORARY TABLES, EVENT,CREATE VIEW ON *.* TO 'centreon'@'localhost';" mysql -u centreon -pcentreon < resources/centreon_storage.sql mysql -u centreon -pcentreon < resources/centreon.sql -echo "########################### download and install centreon collect ############################" - -curl https://$USERNAME:$TOKENJENKINS@jenkins.int.centreon.com/job/centreon-collect/job/$BRANCH/lastSuccessfulBuild/artifact/*zip*/myfile.zip --output artifact.zip -unzip artifact.zip -yum install -y https://yum.centreon.com/standard/21.10/el7/stable/noarch/RPMS/centreon-release-21.10-5.el7.centos.noarch.rpm -yum install -y centreon-common -cd artifacts -rpm -i centreon*.el7.x86_64.rpm +echo "########################## Install centreon collect ###########################" +echo "Installation..." +/usr/bin/rpm -Uvvh --force --nodeps *.rpm -echo "########################### install robot framework ############################" +echo "########################### Install Robot Framework ###########################" cd /src/tests/ pip3 install -U robotframework robotframework-databaselibrary pymysql python-dateutil @@ -47,6 +38,11 @@ pip3 install grpcio==1.33.2 grpcio_tools==1.33.2 ./init-proto.sh -echo "########################### run centreon collect test robot ############################" +echo "####################### Run Centreon Collect Robot Tests #######################" cd /src/tests/ robot --nostatusrc . + +echo "########################### Generate Folder Report #############################" +mkdir reports +cp log.html output.xml report.html reports + diff --git a/ci/scripts/collect-unit-tests.sh b/ci/scripts/collect-unit-tests.sh index 4ef2c0a3f86..e99c2c3449b 100755 --- a/ci/scripts/collect-unit-tests.sh +++ b/ci/scripts/collect-unit-tests.sh @@ -10,11 +10,11 @@ if [ "$DISTRIB" = "7" ] ; then source /opt/rh/devtoolset-9/enable source /opt/rh/rh-python38/enable fi -conan install .. -s compiler.libcxx=libstdc++11 --build=missing +conan install .. -s compiler.cppstd=14 -s compiler.libcxx=libstdc++11 --build=missing if [ $(cat /etc/issue | awk '{print $1}') = "Debian" ] ; then - CXXFLAGS="-Wall -Wextra" cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DWITH_CENTREON_CLIB_INCLUDE_DIR=../centreon-clib/inc/ -DWITH_CENTREON_CLIB_LIBRARIES=centreon-clib/libcentreon_clib.so -DCMAKE_BUILD_TYPE=Debug -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF_BROKER=/etc/centreon-broker -DWITH_PREFIX_LIB_BROKER=/usr/lib64/nagios -DWITH_PREFIX_CONF_ENGINE=/etc/centreon-engine -DWITH_PREFIX_LIB_ENGINE=/usr/lib64/centreon-engine -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_RW_DIR=/var/lib/centreon-engine/rw -DWITH_VAR_DIR=/var/log/centreon-engine -DWITH_MODULE_SIMU=On .. + CXXFLAGS="-Wall -Wextra" cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DWITH_CENTREON_CLIB_INCLUDE_DIR=../clib/inc/ -DWITH_CENTREON_CLIB_LIBRARIES=centreon-clib/libcentreon_clib.so -DCMAKE_BUILD_TYPE=Debug -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF_BROKER=/etc/centreon-broker -DWITH_PREFIX_LIB_BROKER=/usr/lib64/nagios -DWITH_PREFIX_CONF_ENGINE=/etc/centreon-engine -DWITH_PREFIX_LIB_ENGINE=/usr/lib64/centreon-engine -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_RW_DIR=/var/lib/centreon-engine/rw -DWITH_VAR_DIR=/var/log/centreon-engine -DWITH_MODULE_SIMU=On .. else - CXXFLAGS="-Wall -Wextra" cmake3 -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DWITH_CENTREON_CLIB_INCLUDE_DIR=../centreon-clib/inc/ -DWITH_CENTREON_CLIB_LIBRARIES=centreon-clib/libcentreon_clib.so -DCMAKE_BUILD_TYPE=Debug -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF_BROKER=/etc/centreon-broker -DWITH_PREFIX_LIB_BROKER=/usr/lib64/nagios -DWITH_PREFIX_CONF_ENGINE=/etc/centreon-engine -DWITH_PREFIX_LIB_ENGINE=/usr/lib64/centreon-engine -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_RW_DIR=/var/lib/centreon-engine/rw -DWITH_VAR_DIR=/var/log/centreon-engine -DWITH_MODULE_SIMU=On .. + CXXFLAGS="-Wall -Wextra" cmake3 -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DWITH_CENTREON_CLIB_INCLUDE_DIR=../clib/inc/ -DWITH_CENTREON_CLIB_LIBRARIES=centreon-clib/libcentreon_clib.so -DCMAKE_BUILD_TYPE=Debug -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF_BROKER=/etc/centreon-broker -DWITH_PREFIX_LIB_BROKER=/usr/lib64/nagios -DWITH_PREFIX_CONF_ENGINE=/etc/centreon-engine -DWITH_PREFIX_LIB_ENGINE=/usr/lib64/centreon-engine -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_RW_DIR=/var/lib/centreon-engine/rw -DWITH_VAR_DIR=/var/log/centreon-engine -DWITH_MODULE_SIMU=On .. fi #Build @@ -23,18 +23,8 @@ make -j9 install #Test -cd centreon-broker -test/ut --gtest_output=xml:broker-ut.xml -cd .. -cd centreon-engine -tests/ut_engine --gtest_output=xml:engine-ut.xml -cd .. -cd centreon-clib -test/ut-clib --gtest_output=xml:/src/clib-ut.xml -cd .. -# cd centreon-connector -# ./ut_connector --gtest_output=xml:/src/connector-ut.xml -# cd .. - - - +tests/ut_broker --gtest_output=xml:ut_broker.xml +tests/ut_engine --gtest_output=xml:ut_engine.xml +tests/ut_clib --gtest_output=xml:ut_clib.xml +tests/ut_connector --gtest_output=xml:ut_connector.xml +echo "---------------------------------------------------------- end of ut tests ------------------------------------------------" diff --git a/ci/scripts/gorgone-deb-package.sh b/ci/scripts/gorgone-deb-package.sh new file mode 100755 index 00000000000..27a27742e5b --- /dev/null +++ b/ci/scripts/gorgone-deb-package.sh @@ -0,0 +1,69 @@ +#!/bin/sh +set -ex + +if [ -z "$VERSION" -o -z "$RELEASE" -o -z "$DISTRIB" ] ; then + echo "You need to specify VERSION / RELEASE / DISTRIB variables" + exit 1 +fi + +echo "################################################## PACKAGING GORGONE ##################################################" + +AUTHOR="Luiz Costa" +AUTHOR_EMAIL="me@luizgustavo.pro.br" + +echo `pwd` + +if [ -d /build ]; then + rm -rf /build +fi +mkdir -p /build + +mkdir -p /build/tmp +cd /build/tmp +apt-cache dumpavail | dpkg --merge-avail + +yes | dh-make-perl make --build --version "0.11.3-${DISTRIB}" --cpan Mojolicious::Plugin::BasicAuthPlus +dpkg -i libmojolicious-plugin-basicauthplus-perl_0.11.3-${DISTRIB}_all.deb + +yes | dh-make-perl make --build --revision ${DISTRIB} --cpan ZMQ::Constants +dpkg -i libzmq-constants-perl_1.04-${DISTRIB}_all.deb + +git clone https://github.com/centreon-lab/zmq-libzmq4-perl.git zmq-libzmq4-perl-0.02 +mkdir zmq-libzmq4-perl +mv -v zmq-libzmq4-perl-0.02 zmq-libzmq4-perl/ +cd zmq-libzmq4-perl/ +tar czpvf zmq-libzmq4-perl-0.02.tar.gz zmq-libzmq4-perl-0.02 +cd zmq-libzmq4-perl-0.02 +rm -rf debian/changelog +debmake -f "${AUTHOR}" -e "${AUTHOR_EMAIL}" -b ":perl" -r ${DISTRIB} -y +debuild-pbuilder -uc -us +cd .. +dpkg -i zmq-libzmq4-perl_0.02-${DISTRIB}_all.deb +cd /build + +# fix version to debian format accept +VERSION="$(echo $VERSION | sed 's/-/./g')" + +mkdir -p /build/centreon-gorgone +mv /src/centreon-collect/gorgone /src/centreon-collect/centreon-gorgone +(cd /src/centreon-collect && tar czvpf - centreon-gorgone) | dd of=centreon-gorgone-$VERSION.tar.gz +cp -rv /src/centreon-collect/centreon-gorgone /build/ +cp -rv /src/centreon-collect/ci/debian-gorgone /build/centreon-gorgone/debian +sed -i "s/^centreon:version=.*$/centreon:version=$(echo $VERSION | egrep -o '^[0-9][0-9].[0-9][0-9]')/" /build/centreon-gorgone/debian/substvars + +cd /build/centreon-gorgone +debmake -f "${AUTHOR}" -e "${AUTHOR_EMAIL}" -u "$VERSION" -b ":perl" -y -r "${DISTRIB}" +debuild-pbuilder + +cd /build + +if [ -d "$DISTRIB" ] ; then + rm -rf "$DISTRIB" +fi +mkdir $DISTRIB +mv /build/tmp/libmojolicious-plugin-basicauthplus-perl_0.11.3-${DISTRIB}_all.deb $DISTRIB/ +mv /build/tmp/zmq-libzmq4-perl/zmq-libzmq4-perl_0.02-${DISTRIB}_all.deb $DISTRIB/ +mv /build/tmp/libzmq-constants-perl_1.04-${DISTRIB}_all.deb $DISTRIB/ +mv /build/*.deb $DISTRIB/ +mkdir /src/$DISTRIB +mv /build/$DISTRIB/*.deb /src/$DISTRIB diff --git a/ci/scripts/gorgone-rpm-package.sh b/ci/scripts/gorgone-rpm-package.sh new file mode 100755 index 00000000000..fd23c427b5f --- /dev/null +++ b/ci/scripts/gorgone-rpm-package.sh @@ -0,0 +1,27 @@ +#!/bin/sh +set -ex + +if [ -z "$VERSION" -o -z "$RELEASE" ] ; then + echo "You need to specify VERSION / RELEASE / DISTRIB variables" + exit 1 +fi + +echo "################################################## PACKAGING GORGONE ##################################################" + + +# generate rpm broker +if [ ! -d /root/rpmbuild/SOURCES ] ; then + mkdir -p /root/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} +fi +cd /src/gorgone + +tar czvpf /root/rpmbuild/SOURCES/centreon-gorgone-$VERSION.tar.gz \ + --transform "s,^\.,centreon-gorgone-$VERSION," . + +rpmbuild -ba /src/gorgone/packaging/centreon-gorgone.spectemplate -D "VERSION $VERSION" -D "REL $RELEASE" + +# cleaning and according permissions to slave to delivery rpms +cd /src +rm -rf *.rpm +cp -r /root/rpmbuild/RPMS/noarch/*.rpm . +chmod 777 *.rpm \ No newline at end of file diff --git a/cmake.sh b/cmake.sh index 269cfad2d43..aede0320c16 100755 --- a/cmake.sh +++ b/cmake.sh @@ -15,7 +15,7 @@ EOF BUILD_TYPE="Debug" CONAN_REBUILD="0" for i in $(cat conanfile.txt) ; do - if [[ $i =~ / ]] ; then + if [[ "$i" =~ / ]] ; then if [ ! -d ~/.conan/data/$i ] ; then echo "The package '$i' is missing" CONAN_REBUILD="1" @@ -24,19 +24,25 @@ for i in $(cat conanfile.txt) ; do fi done +STD=14 + for i in "$@" do - case $i in + case "$i" in -f|--force) + echo "Forced rebuild" force=1 shift ;; -r|--release) + echo "Release build" BUILD_TYPE="Release" shift ;; -fcr|--force-conan-rebuild) + echo "Forced conan rebuild" CONAN_REBUILD="1" + shift ;; -h|--help) show_help @@ -51,15 +57,19 @@ done # Am I root? my_id=$(id -u) -if [ -r /etc/centos-release ] ; then - maj="centos$(cat /etc/centos-release | awk '{print $4}' | cut -f1 -d'.')" +if [ -r /etc/centos-release -o -r /etc/almalinux-release ] ; then + if [ -r /etc/centos-release ] ; then + maj="centos$(cat /etc/centos-release | awk '{print $4}' | cut -f1 -d'.')" + else + maj="centos$(cat /etc/almalinux-release | awk '{print $3}' | cut -f1 -d'.')" + fi v=$(cmake --version) - if [[ $v =~ "version 3" ]] ; then + if [[ "$v" =~ "version 3" ]] ; then cmake='cmake' else if rpm -q cmake3 ; then cmake='cmake3' - elif [ $maj = "centos7" ] ; then + elif [[ "$maj" == "centos7" ]] ; then yum -y install epel-release cmake3 cmake='cmake3' else @@ -67,7 +77,7 @@ if [ -r /etc/centos-release ] ; then cmake='cmake' fi fi - if [ $maj = "centos7" ] ; then + if [[ "$maj" == "centos7" ]] ; then if [[ ! -x /opt/rh/rh-python38 ]] ; then yum -y install centos-release-scl yum -y install rh-python38 @@ -76,6 +86,7 @@ if [ -r /etc/centos-release ] ; then echo "python38 already installed" fi else + yum -y install gcc-c++ if [[ ! -x /usr/bin/python3 ]] ; then yum -y install python3 else @@ -99,6 +110,7 @@ if [ -r /etc/centos-release ] ; then fi pkgs=( + gcc-c++ ninja-build rrdtool-devel gnutls-devel @@ -107,30 +119,31 @@ if [ -r /etc/centos-release ] ; then perl-devel perl-ExtUtils-Embed perl-srpm-macros - libssh2-devel libgcrypt-devel ) for i in "${pkgs[@]}"; do if ! rpm -q $i ; then - if [ $maj = 'centos7' ] ; then + if [[ "$maj" == 'centos7' ]] ; then yum install -y $i - else + elif [[ "$maj" == 'centos8' ]] ; then dnf -y --enablerepo=PowerTools install $i + else + dnf -y install $i fi fi done elif [ -r /etc/issue ] ; then - maj=$(cat /etc/issue | awk '{print $1}') - version=$(cat /etc/issue | awk '{print $3}') - if [ $version = "9" ] ; then + maj=$(head -1 /etc/issue | awk '{print $1}') + version=$(head -1 /etc/issue | awk '{print $3}') + if [[ "$version" == "9" ]] ; then dpkg="dpkg" else dpkg="dpkg --no-pager" fi v=$(cmake --version) - if [[ $v =~ "version 3" ]] ; then + if [[ "$v" =~ "version 3" ]] ; then cmake='cmake' - elif [ $maj = "Debian" ] || [ "$maj" = "Ubuntu" ]; then + elif [[ "$maj" == "Debian" ]] || [[ "$maj" == "Ubuntu" ]]; then if $dpkg -l cmake ; then echo "Bad version of cmake..." exit 1 @@ -138,7 +151,7 @@ elif [ -r /etc/issue ] ; then echo -e "cmake is not installed, you could enter, as root:\n\tapt install -y cmake\n\n" cmake='cmake' fi - elif [ $maj = "Raspbian" ] ; then + elif [[ "$maj" == "Raspbian" ]] ; then if $dpkg -l cmake ; then echo "Bad version of cmake..." exit 1 @@ -151,12 +164,11 @@ elif [ -r /etc/issue ] ; then exit 1 fi - if [ $maj = "Debian" ] || [ "$maj" = "Ubuntu" ]; then + if [[ "$maj" == "Debian" ]] || [[ "$maj" == "Ubuntu" ]]; then pkgs=( gcc g++ pkg-config - libmariadb3 librrd-dev libgnutls28-dev ninja-build @@ -164,12 +176,11 @@ elif [ -r /etc/issue ] ; then python3 python3-pip libperl-dev - libssh2-1-dev libgcrypt20-dev ) for i in "${pkgs[@]}"; do if ! $dpkg -l $i | grep "^ii" ; then - if [ $my_id -eq 0 ] ; then + if [[ "$my_id" == 0 ]] ; then apt install -y $i else echo -e "The package \"$i\" is not installed, you can install it, as root, with the command:\n\tapt install -y $i\n\n" @@ -177,7 +188,7 @@ elif [ -r /etc/issue ] ; then fi fi done - elif [ $maj = "Raspbian" ] ; then + elif [[ "$maj" == "Raspbian" ]] ; then pkgs=( gcc g++ @@ -190,12 +201,11 @@ elif [ -r /etc/issue ] ; then python3 python3-pip libperl-dev - libssh2-1-dev libgcrypt20-dev ) for i in "${pkgs[@]}"; do if ! $dpkg -l $i | grep "^ii" ; then - if [ $my_id -eq 0 ] ; then + if [[ "$my_id" == 0 ]] ; then apt install -y $i else echo -e "The package \"$i\" is not installed, you can install it, as root, with the command:\n\tapt install -y $i\n\n" @@ -205,7 +215,7 @@ elif [ -r /etc/issue ] ; then done fi if [[ ! -x /usr/bin/python3 ]] ; then - if [ $my_id -eq 0 ] ; then + if [[ "$my_id" == 0 ]] ; then apt install -y python3 else echo -e "python3 is not installed, you can enter, as root:\n\tapt install -y python3\n\n" @@ -215,7 +225,7 @@ elif [ -r /etc/issue ] ; then echo "python3 already installed" fi if ! $dpkg -l python3-pip ; then - if [ $my_id -eq 0 ] ; then + if [[ "$my_id" == 0 ]] ; then apt install -y python3-pip else echo -e "python3-pip is not installed, you can enter, as root:\n\tapt install -y python3-pip\n\n" @@ -228,9 +238,7 @@ fi pip3 install conan --upgrade -if [ $my_id -eq 0 ] ; then - conan='/usr/local/bin/conan' -elif which conan ; then +if which conan ; then conan=$(which conan) else conan="$HOME/.local/bin/conan" @@ -247,21 +255,21 @@ if [ "$force" = "1" ] ; then mkdir build fi cd build -if [ $maj = "centos7" ] ; then +if [[ "$maj" == "centos7" ]] ; then rm -rf ~/.conan/profiles/default - if [ "$CONAN_REBUILD" = "1" ] ; then - $conan install .. -s compiler.libcxx=libstdc++11 --build="*" + if [[ "$CONAN_REBUILD" == "1" ]] ; then + $conan install .. -s compiler.cppstd=$STD -s compiler.libcxx=libstdc++11 --build="*" else - $conan install .. -s compiler.libcxx=libstdc++11 --build=missing + $conan install .. -s compiler.cppstd=$STD -s compiler.libcxx=libstdc++11 --build=missing fi else - $conan install .. -s compiler.libcxx=libstdc++11 --build=missing + $conan install .. -s compiler.cppstd=$STD -s compiler.libcxx=libstdc++11 --build=missing fi if [ $maj = "Raspbian" ] ; then - CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CENTREON_CLIB_INCLUDE_DIR=../centreon-clib/inc/ -DWITH_CENTREON_CLIB_LIBRARIES=centreon-clib/libcentreon_clib.so -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF_BROKER=/etc/centreon-broker -DWITH_PREFIX_LIB_BROKER=/usr/lib64/nagios -DWITH_PREFIX_CONF_ENGINE=/etc/centreon-engine -DWITH_PREFIX_LIB_ENGINE=/usr/lib64/centreon-engine -DWITH_PREFIX_LIB_CLIB=/usr/lib/ -DWITH_RW_DIR=/var/lib/centreon-engine/rw -DWITH_VAR_DIR=/var/log/centreon-engine -DWITH_MODULE_SIMU=On $* .. + CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF_BROKER=/etc/centreon-broker -DWITH_PREFIX_LIB_BROKER=/usr/lib64/nagios -DWITH_PREFIX_CONF_ENGINE=/etc/centreon-engine -DWITH_PREFIX_LIB_ENGINE=/usr/lib64/centreon-engine -DWITH_PREFIX_LIB_CLIB=/usr/lib/ -DWITH_RW_DIR=/var/lib/centreon-engine/rw -DWITH_VAR_DIR=/var/log/centreon-engine -DWITH_MODULE_SIMU=On $* .. elif [ $maj = "Debian" ] ; then - CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CENTREON_CLIB_INCLUDE_DIR=../centreon-clib/inc/ -DWITH_CENTREON_CLIB_LIBRARIES=centreon-clib/libcentreon_clib.so -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF_BROKER=/etc/centreon-broker -DWITH_PREFIX_LIB_BROKER=/usr/lib64/nagios -DWITH_PREFIX_CONF_ENGINE=/etc/centreon-engine -DWITH_PREFIX_LIB_ENGINE=/usr/lib64/centreon-engine -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_RW_DIR=/var/lib/centreon-engine/rw -DWITH_VAR_DIR=/var/log/centreon-engine -DWITH_MODULE_SIMU=On $* .. + CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF_BROKER=/etc/centreon-broker -DWITH_PREFIX_LIB_BROKER=/usr/lib64/nagios -DWITH_PREFIX_CONF_ENGINE=/etc/centreon-engine -DWITH_PREFIX_LIB_ENGINE=/usr/lib64/centreon-engine -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_RW_DIR=/var/lib/centreon-engine/rw -DWITH_VAR_DIR=/var/log/centreon-engine -DWITH_MODULE_SIMU=On $* .. else - CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CENTREON_CLIB_INCLUDE_DIR=../centreon-clib/inc/ -DWITH_CENTREON_CLIB_LIBRARIES=centreon-clib/libcentreon_clib.so -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF_BROKER=/etc/centreon-broker -DWITH_PREFIX_LIB_BROKER=/usr/lib64/nagios -DWITH_PREFIX_CONF_ENGINE=/etc/centreon-engine -DWITH_PREFIX_LIB_ENGINE=/usr/lib64/centreon-engine -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_RW_DIR=/var/lib/centreon-engine/rw -DWITH_VAR_DIR=/var/log/centreon-engine -DWITH_MODULE_SIMU=On $* .. + CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF_BROKER=/etc/centreon-broker -DWITH_PREFIX_LIB_BROKER=/usr/lib64/nagios -DWITH_PREFIX_CONF_ENGINE=/etc/centreon-engine -DWITH_PREFIX_LIB_ENGINE=/usr/lib64/centreon-engine -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_RW_DIR=/var/lib/centreon-engine/rw -DWITH_VAR_DIR=/var/log/centreon-engine -DWITH_MODULE_SIMU=On $* .. fi diff --git a/conanfile.txt b/conanfile.txt index cb4b243c6a0..dfe44ce4f76 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,22 +1,27 @@ [requires] gtest/cci.20210126 -asio/1.21.0 -fmt/7.1.3 -spdlog/1.8.5 -nlohmann_json/3.9.1 -openssl/1.1.1m -grpc/1.43.0 +asio/1.24.0 +fmt/8.1.1 +spdlog/1.11.0 +nlohmann_json/3.11.2 +openssl/1.1.1s +grpc/1.50.0 mariadb-connector-c/3.1.12 -zlib/1.2.11 -boost/1.78.0 +zlib/1.2.13 +boost/1.80.0 libssh2/1.10.0 [generators] -cmake_paths -cmake_find_package +cmake [options] -grpc:secure=True boost:header_only=True +grpc:secure=True +grpc:csharp_ext=False +grpc:csharp_plugin=False +grpc:node_plugin=False +grpc:objective_c_plugin=False +grpc:php_plugin=False +grpc:python_plugin=True +grpc:ruby_plugin=False libssh2:shared=False - diff --git a/packaging/rpm/centreon-collect.spec b/packaging/rpm/centreon-collect.spec new file mode 100644 index 00000000000..a35162e88d6 --- /dev/null +++ b/packaging/rpm/centreon-collect.spec @@ -0,0 +1,473 @@ +## +## Copyright 2021 Centreon +## + +Summary: Centreon collect's softwares collection +Name: centreon-collect +Version: %{VERSION} +Release: %{RELEASE}%{?dist} +License: ASL 2.0 +Source: %{name}-%{version}.tar.gz +Source1: centreonengine_integrate_centreon_engine2centreon.sh + +%define thismajor 21.10.0 +%define nextmajor 21.11.0 + +Group: Applications/Communications +URL: https://github.com/centreon/centreon-collect.git +Packager: David Boucher +Vendor: Centreon Entreprise Server (CES) Repository, http://yum.centreon.com/standard/ + +%description +Centreon Collect is a software collection containing centreon-broker, +centreon-engine, centreon-clib and centreon-connectors. + +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root + +BuildRequires: cmake3 >= 3.15 +BuildRequires: gcc +BuildRequires: gcc-c++ +BuildRequires: gnutls-devel >= 3.3.29 +BuildRequires: libgcrypt-devel +BuildRequires: lua-devel +BuildRequires: make +BuildRequires: perl +BuildRequires: perl-ExtUtils-Embed +BuildRequires: perl-devel +BuildRequires: rrdtool-devel +BuildRequires: systemd +Requires: centreon-clib = %{version}-%{release} +Requires: centreon-broker-core = %{version}-%{release} +Requires: centreon-engine = %{version}-%{release} +Requires: centreon-connector = %{version}-%{release} + +%package -n centreon-clib +Summary: Centreon core library. +Group: Development/Libraries + +%description -n centreon-clib +Centreon Clib is a common library for all Centreon +products written in C/C++. + +%package -n centreon-clib-devel +Summary: Provide include files for Centreon Clib. +Group: Development/Libraries + +%description -n centreon-clib-devel +Centreon Clib devel provide include files to build +Centreon products written in C/C++. + + +%package -n centreon-engine +Summary: Centreon Engine monitoring core. +Group: Applications/System +Requires: centreon-engine-daemon = %{version}-%{release} +Requires: centreon-engine-extcommands = %{version}-%{release} + +%description -n centreon-engine +Centreon Engine is a monitoring engine, compatible with Nagios +configuration, designed to monitor hosts and services on your network. + + +%package -n centreon-engine-daemon +Summary: Centreon Engine Daemon is the daemon to schedule checks. +Group: Application/System +Requires: centreon-clib = %{version}-%{release} +%{?systemd_requires} + +%description -n centreon-engine-daemon +Centreon Engine is a monitoring engine that schedule checks on your +network services and hosts. + + +%package -n centreon-engine-extcommands +Summary: Centreon Engine External Commands allow to other applications to send command into the daemon. +Group: Application/System +Requires: centreon-engine-daemon = %{version}-%{release} + +%description -n centreon-engine-extcommands +Centreon Engine External Commands allow to other applications to send +command into the daemon. External applications can submit commands by +writing to the command file, which is periodically processed by the +engine daemon. + + +%package -n centreon-engine-devel +Summary: Provide include files for Centreon Engine. +Group: Application/System +Requires: centreon-clib-devel = %{version}-%{release} + +%description -n centreon-engine-devel +Centreon Engine devel provide include files to develop Centreon Engine +Modules or Centreon Engine Connector. + + +%package -n centreon-engine-bench +Summary: Centreon Engine benchmarking tools. +Group: Application/System +Requires: centreon-clib = %{version}-%{release} + +%description -n centreon-engine-bench +Some Centreon Engine benchmarking tools. + + +%package -n centreon-connector +Summary: Centreon Connector provide some tools for Centreon Engine to monitoring and management system. +Group: Application/System +Requires: centreon-connector-perl = %{version}-%{release} +Requires: centreon-connector-ssh = %{version}-%{release} + +%description -n centreon-connector +Centreon Connector provide a monitoring tools, compatible with +Centreon-Engine configuration, designed to monitor and manage system. + + +%package -n centreon-connector-perl +Summary: Centreon Connector Perl provide embedded perl for Centreon-Engine. +Group: Application/System +Requires: centreon-clib = %{version}-%{release} +Requires: perl + +%description -n centreon-connector-perl +Centreon Connector Perl provide embedded perl for Centreon Engine +a monitoring engine. + + +%package -n centreon-connector-ssh +Summary: Centreon Connector SSH provide persistante connection between checks. +Group: Application/System +Requires: centreon-clib = %{version}-%{release} +Requires: libgcrypt + +%description -n centreon-connector-ssh +Centreon Connector SSH provide persistante connection between checks. + + +%package -n centreon-broker +Summary: Store Centreon Engine/Nagios events in a database. +Group: Applications/Communications +Requires: centreon-common >= %{thismajor} +Requires: centreon-common < %{nextmajor} +Requires: coreutils + +%description -n centreon-broker +Centreon Broker is a Centreon Engine/Nagios module that report events in +one or multiple databases. + + +%package -n centreon-broker-core +Summary: Centreon Broker's shared library. +Group: Applications/Communications +Requires: gnutls >= 3.3.29 +Requires: lua +Requires: centreon-broker = %{version}-%{release} +Requires: centreon-broker-storage = %{version}-%{release} + +%description -n centreon-broker-core +Centreon core holds Centreon Broker's default modules; + + +%package -n centreon-broker-storage +Summary: Centreon Broker's shared library for prefdata storage. +Group: Applications/Communications +Requires: centreon-broker-core = %{version}-%{release} + +%description -n centreon-broker-storage +storage holds Centreon Broker's prefdata storage. + + +%package -n centreon-broker-graphite +Summary: Write Centreon performance data to Graphite. +Group: Applications/Communications +Requires: centreon-broker-core = %{version}-%{release} + +%description -n centreon-broker-graphite +This module of Centreon Broker allows you to write performance data +generated by plugins (run themselves by Centreon Engine) to a Graphite +database. + + +%package -n centreon-broker-influxdb +Summary: Write Centreon performance data to InfluxDB. +Group: Applications/Communications +Requires: centreon-broker-core = %{version}-%{release} + +%description -n centreon-broker-influxdb +This module of Centreon Broker allows you to write performance data +generated by plugins (run themselves by Centreon Engine) to a Graphite +database. + + +%package -n centreon-broker-cbd +Summary: Centreon Broker daemon. +Group: System Environment/Daemons +Requires: centreon-broker-core = %{version}-%{release} +%{?systemd_requires} + +%description -n centreon-broker-cbd +The Centreon Broker daemon can aggregates output of multiple cbmod and store +events in a DB from a single point. + +%package -n centreon-broker-cbmod +Summary: Centreon Broker as Centreon Engine 2 module. +Group: Applications/Communications +Requires: centreon-broker-core = %{version}-%{release} +Requires: centreon-engine = %{version}-%{release} + +%description -n centreon-broker-cbmod +This module can be loaded by Centreon Engine. + + +%package -n centreon-broker-devel +Summary: Centreon Broker devel libraries. +Group: Applications/Communications + +%description -n centreon-broker-devel +Include files needed to develop a module Centreon Broker. + +%prep +%setup -q -n %{name}-%{version} + +%build +pip3 install conan --upgrade +conan install . -s compiler.cppstd=14 -s compiler.libcxx=libstdc++11 --build=missing + +cmake3 \ + -DWITH_TESTING=0 \ + -DWITH_BENCH=1 \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DWITH_PREFIX_BIN=%{_sbindir} \ + -DWITH_PREFIX_CONF_ENGINE=%{_sysconfdir}/centreon-engine \ + -DWITH_PREFIX_LIB_ENGINE=%{_libdir}/centreon-engine \ + -DWITH_PREFIX_MODULES=%{_datadir}/centreon/lib/centreon-broker \ + -DWITH_PREFIX_LIB_CLIB=%{_libdir} \ + -DWITH_VAR_DIR=%{_localstatedir}/log/centreon-engine \ + -DWITH_ENGINE_LOGROTATE_SCRIPT=1 \ + -DWITH_STARTUP_DIR=%{_unitdir} \ + -DWITH_DAEMONS='central-rrd;central-broker' \ + -DWITH_PREFIX_CONF_BROKER=%{_sysconfdir}/centreon-broker \ + -DWITH_STARTUP_SCRIPT=systemd \ + -DWITH_USER_BROKER=centreon-broker \ + -DWITH_GROUP_BROKER=centreon-broker \ + -DWITH_USER_ENGINE=centreon-engine \ + -DWITH_GROUP_ENGINE=centreon-engine \ + -DWITH_PKGCONFIG_SCRIPT=0 \ + -DWITH_CONFIG_FILES=y \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + . +%{__make} %{?_smp_mflags} + +%install +%{__rm} -rf $RPM_BUILD_ROOT +%{__install} -d $RPM_BUILD_ROOT%{_sbindir} +%{__install} -d -m 0775 $RPM_BUILD_ROOT%{_localstatedir}/log/centreon-broker +%{__install} -d -m 0775 $RPM_BUILD_ROOT%{_localstatedir}/lib/centreon-broker +%{__install} -d -m 0775 $RPM_BUILD_ROOT%{_sysconfdir}/centreon-broker +%{__install} -d $RPM_BUILD_ROOT%{_unitdir} +%{__install} -d $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d +%{__install} -d $RPM_BUILD_ROOT%{_sysconfdir}/centreon-engine/conf.d +%{__install} -d $RPM_BUILD_ROOT%{_datadir}/doc/centreon-broker +%{__install} -d $RPM_BUILD_ROOT%{_datadir}/centreon-broker/lua +%{__install} -m 644 centreon-broker/script/centreon-broker.logrotate $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/cbd +%{__install} -d $RPM_BUILD_ROOT%{_localstatedir}/log/centreon-engine +%{__install} -d $RPM_BUILD_ROOT%{_localstatedir}/log/centreon-engine/archives +%{__install} -d $RPM_BUILD_ROOT%{_localstatedir}/lib/centreon-engine +%{__install} -d $RPM_BUILD_ROOT%{_localstatedir}/lib/centreon-engine/rw +touch $RPM_BUILD_ROOT%{_localstatedir}/log/centreon-engine/centengine.debug +touch $RPM_BUILD_ROOT%{_localstatedir}/log/centreon-engine/centengine.log +touch $RPM_BUILD_ROOT%{_localstatedir}/log/centreon-engine/retention.dat +touch $RPM_BUILD_ROOT%{_localstatedir}/log/centreon-engine/status.dat +%{__install} -d $RPM_BUILD_ROOT%{_datadir}/centreon-engine/extra +%{__cp} %SOURCE1 $RPM_BUILD_ROOT%{_datadir}/centreon-engine/extra/integrate_centreon_engine2centreon.sh +%{__make} install DESTDIR="$RPM_BUILD_ROOT" + +%clean +%{__rm} -rf $RPM_BUILD_ROOT + +%pre -n centreon-broker +%{_bindir}/getent group centreon-broker &>/dev/null || %{_sbindir}/groupadd -r centreon-broker 2> /dev/null || : +%{_bindir}/getent passwd centreon-broker &>/dev/null || %{_sbindir}/useradd -m -g centreon-broker -d %{_localstatedir}/lib/centreon-broker -r centreon-broker 2> /dev/null || : +if id centreon &>/dev/null; then + %{_sbindir}/usermod -a -G centreon-broker centreon +fi +if id centreon-gorgone &>/dev/null; then + %{_sbindir}/usermod -a -G centreon-gorgone centreon-broker +fi +if id centreon-engine &>/dev/null; then + %{_sbindir}/usermod -a -G centreon-broker centreon-engine + %{_sbindir}/usermod -a -G centreon-engine centreon-broker +fi +if id nagios &>/dev/null; then + %{_sbindir}/usermod -a -G centreon-broker nagios +fi + +%pre -n centreon-engine-daemon +if ! id centreon-engine &>/dev/null; then + %{_sbindir}/useradd -d %{_localstatedir}/lib/centreon-engine -r centreon-engine &>/dev/null +fi +if id centreon-broker &>/dev/null; then + %{_sbindir}/usermod -a -G centreon-engine centreon-broker +fi +if id centreon-gorgone &>/dev/null; then + %{_sbindir}/usermod -a -G centreon-gorgone centreon-engine +fi +%define httpgroup apache +if id -g %{httpgroup} &>/dev/null; then + %{_sbindir}/usermod -a -G centreon-engine %{httpgroup} +fi +if id -g nagios &>/dev/null; then + %{_sbindir}/usermod -a -G centreon-engine nagios +fi + +%post -n centreon-engine-daemon +%systemd_post centengine.service || : + +%preun -n centreon-engine-daemon +%systemd_preun centengine.service || : + + +%post -n centreon-broker +chown -R centreon-broker:centreon-broker /var/lib/centreon-broker +chmod -R g+w /var/lib/centreon-broker +chown -R centreon-broker:centreon-broker /var/log/centreon-broker +chmod -R g+w /var/log/centreon-broker + +%post -n centreon-broker-cbd +%systemd_post cbd.service || : + +%pre -n centreon-broker-cbd +# Stop cbd daemons for compatibility +if [ -f /etc/init.d/cbd-central-broker ]; then + /etc/init.d/cbd-central-broker stop &>/dev/null || : +fi + +%preun -n centreon-broker-cbd +%systemd_preun cbd.service || : + +%files -n centreon-clib +%defattr(-,root,root,-) +%{_libdir}/libcentreon_clib.so +%doc centreon-clib/LICENSE + +%files -n centreon-clib-devel +%defattr(-,root,root,-) +%{_includedir}/centreon-clib +%doc centreon-clib/LICENSE + +%files -n centreon-engine + +%files -n centreon-engine-daemon +%defattr(-,centreon-engine,centreon-engine,-) +%attr(0664,centreon-engine,centreon-engine) %config(noreplace) %{_sysconfdir}/centreon-engine/centengine.cfg +%attr(0664,centreon-engine,centreon-engine) %config(noreplace) %{_sysconfdir}/centreon-engine/resource.cfg +%attr(0664,centreon-engine,centreon-engine) %config(noreplace) %{_sysconfdir}/centreon-engine/objects/*.cfg + +%defattr(-,root,root,-) +%config(noreplace) %{_sysconfdir}/logrotate.d/centengine +%attr(755, root, root) %{_unitdir}/centengine.service +%{_sbindir}/centengine +%{_sbindir}/centenginestats +%attr(0775,root,root) %{_datadir}/centreon-engine/extra/integrate_centreon_engine2centreon.sh +%attr(0755,centreon-engine,centreon-engine) %{_localstatedir}/log/centreon-engine/ +%attr(0755,centreon-engine,centreon-engine) %dir %{_localstatedir}/lib/centreon-engine/ +%doc centreon-engine/license.txt + +%files -n centreon-engine-extcommands +%defattr(-,root,root,-) +%{_libdir}/centreon-engine/externalcmd.so +%attr(0775,centreon-engine,centreon-engine) %{_localstatedir}/lib/centreon-engine/rw +%doc centreon-engine/license.txt + +%files -n centreon-engine-devel +%defattr(-,root,root,-) +%{_includedir}/centreon-engine +%doc centreon-engine/license.txt + +%files -n centreon-engine-bench +%defattr(-,root,root,-) +%{_libdir}/centreon-engine/bench_passive_module.so +%{_sbindir}/centengine_bench_passive + +%files -n centreon-connector + +%files -n centreon-connector-perl +%attr(0775,root,root) %{_libdir}/centreon-connector/centreon_connector_perl + +%files -n centreon-connector-ssh +%attr(0775,root,root) %{_libdir}/centreon-connector/centreon_connector_ssh + +%files -n centreon-broker +%defattr(-,centreon-broker,centreon-broker,-) +%{_localstatedir}/log/centreon-broker +%{_localstatedir}/lib/centreon-broker +%dir %{_sysconfdir}/centreon-broker + +%files -n centreon-broker-storage +%defattr(-,root,root,-) +%{_datadir}/centreon/lib/centreon-broker/20-storage.so +%{_datadir}/centreon/lib/centreon-broker/70-rrd.so + +%files -n centreon-broker-graphite +%defattr(-,root,root,-) +%{_datadir}/centreon/lib/centreon-broker/70-graphite.so + +%files -n centreon-broker-influxdb +%defattr(-,root,root,-) +%{_datadir}/centreon/lib/centreon-broker/70-influxdb.so + +%files -n centreon-broker-cbd +%defattr(-,centreon-broker,centreon-broker,-) +%attr(0664,centreon-broker,centreon-broker) %config(noreplace) %{_sysconfdir}/centreon-broker/central-broker.json +%attr(0664,centreon-broker,centreon-broker) %config(noreplace) %{_sysconfdir}/centreon-broker/central-rrd.json +%attr(0664,centreon-broker,centreon-broker) %config(noreplace) %{_sysconfdir}/centreon-broker/watchdog.json +%defattr(-,root,root,-) +%{_sbindir}/cbd +%{_sbindir}/cbwd + +%defattr(-,root,root,-) +%{_datadir}/doc/centreon-broker/ + +%attr(755, root, root) %{_unitdir}/cbd.service + +%files -n centreon-broker-core +%defattr(-,root,root,-) +%{_datadir}/centreon/lib/centreon-broker/10-neb.so +%{_datadir}/centreon/lib/centreon-broker/15-stats.so +%{_datadir}/centreon/lib/centreon-broker/20-bam.so +%{_datadir}/centreon/lib/centreon-broker/50-tcp.so +%{_datadir}/centreon/lib/centreon-broker/60-tls.so +%{_datadir}/centreon/lib/centreon-broker/70-lua.so +%{_datadir}/centreon/lib/centreon-broker/80-sql.so +%{_sysconfdir}/logrotate.d/cbd +%defattr(0775,centreon-broker,centreon-broker,-) +%{_datadir}/centreon-broker +%{_datadir}/centreon-broker/lua + +%files -n centreon-broker-cbmod +%defattr(-,centreon-broker,centreon-broker,-) +%attr(0664,centreon-broker,centreon-broker) %config(noreplace) %{_sysconfdir}/centreon-broker/central-module.json +%defattr(-,root,root,-) +%{_libdir}/nagios/cbmod.so + +%post -n centreon-broker-cbmod +%{_bindir}/getent passwd centreon-engine &>/dev/null && %{_sbindir}/usermod -a -G centreon-broker centreon-engine +%{_bindir}/getent group centreon-engine &>/dev/null && %{_sbindir}/usermod -a -G centreon-engine centreon-broker + +%files -n centreon-broker-devel +%defattr(-,root,root,-) +%{_prefix}/include/centreon-broker +%doc centreon-broker/LICENSE +%{_includedir}/centreon-broker + +%files +%{_exec_prefix}/lib/systemd/system/cbd.service +%{_exec_prefix}/lib/systemd/system/centengine.service +%{_localstatedir}/log/centreon-engine/centengine.debug +%{_localstatedir}/log/centreon-engine/centengine.log +%{_localstatedir}/log/centreon-engine/retention.dat +%{_localstatedir}/log/centreon-engine/status.dat + + +%changelog +* Thu Nov 3 2022 jcr 21.10.3 +- import spec file from 22.04. diff --git a/packaging/rpm/centreonengine_integrate_centreon_engine2centreon.sh b/packaging/rpm/centreonengine_integrate_centreon_engine2centreon.sh new file mode 100755 index 00000000000..b1ba511a541 --- /dev/null +++ b/packaging/rpm/centreonengine_integrate_centreon_engine2centreon.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +USE_CENTREON=0 + +## +# Help function +## +function help_usage +{ + echo "Usage: $(basename $0) [-c] [-h]" + echo " -h This help" + echo " -c Add right for centreon user and configuration (Requires Centreon RPMs)" +} + +# Parse options +while [ $# -gt 0 ]; do + if [ "$1" = "-h" ]; then + help_usage + exit 0 + elif [ "$1" = "-c" ]; then + USE_CENTREON=1 + else + echo "Bad arguments" >&2 + help_usage + exit 1 + fi + shift +done + +# +# Variables +# +RES_COL="60" +MOVE_TO_COL="\\033[${RES_COL}G" +SETCOLOR_SUCCESS="\\033[1;32m" +SETCOLOR_FAILURE="\\033[1;31m" +SETCOLOR_NORMAL="\\033[0;39m" + +## +# Print a status +# +# $1 the code if equal 0 Ok , else nok +## +function print_status +{ + if [ $1 -eq 0 ]; then + echo -e "${MOVE_TO_COL}[${SETCOLOR_SUCCESS}OK${SETCOLOR_NORMAL}]" + else + echo -e "${MOVE_TO_COL}[${SETCOLOR_FAILURE}NOK${SETCOLOR_NORMAL}]" + fi +} + + +if id apache &>/dev/null; then + RESTART_APACHE=0 + echo "Add groups to apache user" + id apache | grep "(centreon-engine)" &>/dev/null + if [ $? -ne 0 ]; then + echo -n "* Add group centreon-engine" + usermod -aG centreon-engine apache + print_status $? + RESTART_APACHE=1 + fi + id apache | grep "(centreon)" &>/dev/null + if getent group centreon &>/dev/null; then + if [ $? -ne 0 ]; then + echo -n "* Add group centreon" + usermod -aG centreon apache + print_status $? + RESTART_APACHE=1 + fi + fi + if [ ${RESTART_APACHE} -eq 1 ]; then + service httpd restart + fi +fi + +echo "Add group to user centreon-engine" +id centreon-engine | grep "(nagios)" &>/dev/null +if [ $? -ne 0 ]; then + if getent group nagios &>/dev/null; then + echo -n "* Add group nagios" + usermod -aG nagios centreon-engine + print_status $? + fi +fi +id centreon-engine | grep "(centreon)" &>/dev/null +if [ $? -ne 0 ]; then + if getent group centreon &>/dev/null; then + echo -n "* Add group centreon" + usermod -aG centreon centreon-engine + print_status $? + fi +fi + +if [ ${USE_CENTREON} -eq 1 ]; then + echo -n "Create symlinks for nagios.cfg" + if [ -f "/etc/centreon-engine/centengine.cfg" ] ; then + mv /etc/centreon-engine/centengine.cfg /etc/centreon-engine/centengine.cfg.old + fi + ln -s /etc/centreon-engine/nagios.cfg /etc/centreon-engine/centengine.cfg + print_status $? +fi + +grep User_Alias /etc/sudoers | grep "centreon-engine" &>/dev/null +if [ $? -ne 0 ]; then + echo "Add configuration for Centreon Engine in sudo" + echo -n "* Add user alias" + sed -i "s/^User_Alias\(.*\)$/User_Alias\1, centreon-engine/g" /etc/sudoers + print_status $? + + echo -n "* Add commands" + cat <> /etc/sudoers + +# Centreon Engine Restart +CENTREON ALL = NOPASSWD: /etc/init.d/centengine restart +# Centreon Engine stop +CENTREON ALL = NOPASSWD: /etc/init.d/centengine start +# Centreon Engine stop +CENTREON ALL = NOPASSWD: /etc/init.d/centengine stop +# Centreon Engine reload +CENTREON ALL = NOPASSWD: /etc/init.d/centengine reload +# Centreon Engine test config +CENTREON ALL = NOPASSWD: /usr/sbin/centengine -v * +# Centreon Engine test for optim config +CENTREON ALL = NOPASSWD: /usr/sbin/centengine -s * +EOF + print_status $? +fi + diff --git a/packaging/script/rpmbuild.sh b/packaging/script/rpmbuild.sh new file mode 100755 index 00000000000..96fb610f74a --- /dev/null +++ b/packaging/script/rpmbuild.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +show_help() { +cat << EOF +Usage: ${0##*/} version release + +This program build Centreon-collect +EOF +exit 2 +} + +VERSION=$1 +RELEASE=$2 + +if [ -z $VERSION ] || [ -z $RELEASE ] ; then + echo "Some or all of the parameters are empty"; + echo "$VERSION"; + echo "$RELEASE"; + show_help +fi + +# root dir of the new centreon collect +if [ ! -d /root/rpmbuild/SOURCES ] ; then + mkdir -p /root/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} +fi + +cd ../.. + +tar czf "/root/rpmbuild/SOURCES/centreon-collect-$VERSION.tar.gz" \ + --exclude './build' \ + --exclude './.git' \ + --transform "s,^\.,centreon-collect-$VERSION," . + +cp packaging/rpm/centreonengine_integrate_centreon_engine2centreon.sh /root/rpmbuild/SOURCES/ + +echo -e "%_topdir %(echo $HOME)/rpmbuild\n%_smp_mflags -j5\n" > $HOME/rpmbuild/.rpmmacros + +cd .. + +rpmbuild -ba centreon-collect/packaging/rpm/centreon-collect.spec -D "VERSION $VERSION" -D "RELEASE $RELEASE" + diff --git a/resources/centreon.sql b/resources/centreon.sql index b334bfe384c..7be6f2d0ed1 100644 --- a/resources/centreon.sql +++ b/resources/centreon.sql @@ -1,7 +1,6 @@ -CREATE DATABASE IF NOT EXISTS `centreon`; +CREATE DATABASE IF NOT EXISTS `DBNameConf`; - -USE centreon; +USE DBNameConf; SET FOREIGN_KEY_CHECKS=0; diff --git a/tests/Jenkinsfile b/tests/Jenkinsfile deleted file mode 100644 index dd68ea70965..00000000000 --- a/tests/Jenkinsfile +++ /dev/null @@ -1,25 +0,0 @@ -@Library('centreon-shared-library') _ - -pipeline { - agent none - triggers { - cron('0 0 * * *') - } - stages { - stage('Launch Centreon Tests') { - agent any - when { anyOf { branch 'dev-21.10.x'; branch '21.10.x'} } - environment { - JENKINS_USERNAME = "Service-Account-CI" - JENKINS_TOKEN = sh ( - script: 'aws ssm get-parameter --name service-account-ci-token --output text --query Parameter.Value --region eu-west-1', - returnStdout: true) - } - steps { - sh 'docker run -i --entrypoint /src/ci/scripts/collect-test-robot.sh -v "$PWD:/src" registry.centreon.com/centreon-collect-centos7-dependencies:21.10 $JENKINS_USERNAME $JENKINS_TOKEN $GIT_BRANCH' - robot outputPath: 'tests', logFileName: 'log.html', outputFileName: 'output.xml', reportFileName: 'report.html', passThreshold: 100, unstableThreshold: 75.0 - } - post { always { cleanWs() }} - } - } -} \ No newline at end of file diff --git a/tests/broker-engine/hostgroups.robot b/tests/broker-engine/hostgroups.robot index 050d6b7df09..7686ecbcfe0 100644 --- a/tests/broker-engine/hostgroups.robot +++ b/tests/broker-engine/hostgroups.robot @@ -90,3 +90,59 @@ EBNHG4 Stop Engine Kindly Stop Broker + + +EBNHG5 + [Documentation] New host group with several pollers and connections to DB with broker and delete this hostgroup + [Tags] Broker Engine hostgroup + Config Engine ${3} + Config Broker rrd + Config Broker central + Config Broker module ${3} + + Broker Config Log central sql info + Broker Config Output Set central central-broker-master-sql connections_count 5 + Broker Config Output Set central central-broker-master-perfdata connections_count 5 + ${start}= Get Current Date + Start Broker + Start Engine + Sleep 3s + Add Host Group ${0} ${1} ["host_1", "host_2", "host_3"] + + Reload Broker + Reload Engine + + ${content}= Create List enabling membership of host 3 to host group 1 on instance 1 enabling membership of host 2 to host group 1 + + ${result}= Find In Log With Timeout ${centralLog} ${start} ${content} 45 + Should Be True ${result} msg=One of the new host groups not found in logs. + + Sleep 10s + ${start}= Get Current Date + + Config Engine ${3} + Reload Broker + Reload Engine + + Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort} + Sleep 5s + FOR ${index} IN RANGE 10 + Log To Console SELECT count(*) FROM hosts_hostgroups + ${output}= Query SELECT count(*) FROM hosts_hostgroups + Log To Console ${output} + Sleep 1s + EXIT FOR LOOP IF "${output}" == "((0,),)" + END + Should Be Equal As Strings ${output} ((0,),) + + FOR ${index} IN RANGE 60 + Log To Console SELECT count(*) FROM hostgroups + ${output}= Query SELECT count(*) FROM hostgroups + Log To Console ${output} + Sleep 1s + EXIT FOR LOOP IF "${output}" == "((0,),)" + END + Should Be Equal As Strings ${output} ((0,),) + + Stop Engine + Kindly Stop Broker diff --git a/tests/broker-engine/hosts-with-notes-and-actions.robot b/tests/broker-engine/hosts-with-notes-and-actions.robot index a62ab66a998..b8ed7507a78 100644 --- a/tests/broker-engine/hosts-with-notes-and-actions.robot +++ b/tests/broker-engine/hosts-with-notes-and-actions.robot @@ -26,7 +26,6 @@ EBSNU1 Broker Config Add Item central bbdo_version 3.0.0 Broker Config Add Item rrd bbdo_version 3.0.0 Broker Config Log central sql debug - Config Broker Sql Output central unified_sql ${nu}= Evaluate 2000*"X" Engine Config set value in hosts 0 host_1 notes_url ${nu} Clear Retention @@ -54,7 +53,6 @@ EBSAU2 Broker Config Add Item central bbdo_version 3.0.0 Broker Config Add Item rrd bbdo_version 3.0.0 Broker Config Log central sql debug - Config Broker Sql Output central unified_sql ${au}= Evaluate 2000*"Y" Engine Config set value in hosts 0 host_2 action_url ${au} Clear Retention @@ -82,7 +80,6 @@ EBSN3 Broker Config Add Item central bbdo_version 3.0.0 Broker Config Add Item rrd bbdo_version 3.0.0 Broker Config Log central sql debug - Config Broker Sql Output central unified_sql ${n}= Evaluate 500*"Z" Engine Config set value in hosts 0 host_3 notes ${n} Clear Retention diff --git a/tests/broker-engine/scheduler.robot b/tests/broker-engine/scheduler.robot deleted file mode 100644 index 8a9c4cfb99c..00000000000 --- a/tests/broker-engine/scheduler.robot +++ /dev/null @@ -1,45 +0,0 @@ -*** Settings *** -Resource ../resources/resources.robot -Suite Setup Clean Before Suite -Suite Teardown Clean After Suite -Test Setup Stop Processes - -Documentation Centreon Broker and Engine log_v2 -Library DatabaseLibrary -Library Process -Library OperatingSystem -Library DateTime -Library Collections -Library ../resources/Engine.py -Library ../resources/Broker.py -Library ../resources/Common.py - -*** Test Cases *** -ENRSCHE1 - [Documentation] check next check of reschedule is last_check+interval_check - [Tags] Broker Engine scheduler - Config Engine ${1} - Config Broker rrd - Config Broker central - Config Broker module - Engine Config Set Value ${0} log_legacy_enabled ${0} - Engine Config Set Value ${0} log_v2_enabled ${1} - Engine Config Set Value ${0} log_level_checks debug - - ${start}= Get Current Date exclude_millis=yes - Sleep 1s - - Start Broker - Start Engine - ${result}= Check Connections - Should Be True ${result} msg=Engine and Broker not connected - - ${pid}= Get Process Id e0 - ${content}= Set Variable [checks] [debug] [${pid}] Rescheduling next check of host: host_14 - - ${log}= Catenate SEPARATOR= ${ENGINE_LOG} /config0/centengine.log - ${result1} ${result2}= check reschedule with timeout ${log} ${start} ${content} 240 - Should Be True ${result1} msg=the delta of last_check and next_check is not equal to 60. - Should Be True ${result2} msg=the delta of last_check and next_check is not equal to 300. - Stop Engine - Stop Broker diff --git a/tests/broker-engine/services-increased.robot b/tests/broker-engine/services-increased.robot deleted file mode 100644 index fa4a2e0191a..00000000000 --- a/tests/broker-engine/services-increased.robot +++ /dev/null @@ -1,48 +0,0 @@ -*** Settings *** -Resource ../resources/resources.robot -Suite Setup Clean Before Suite -Suite Teardown Clean After Suite -Test Setup Stop Processes - -Documentation Centreon Broker and Engine progressively add services -Library Process -Library OperatingSystem -Library DateTime -Library Collections -Library ../resources/Engine.py -Library ../resources/Broker.py -Library ../resources/Common.py - -*** Test Cases *** -EBNSVC1 - [Documentation] New services with several pollers - [Tags] Broker Engine services protobuf - Config Engine ${3} ${50} ${20} - Config Broker rrd - Config Broker central - Config Broker module ${3} - Broker Config Log central sql debug - Clear Retention - ${start}= Get Current Date - Start Broker - Start Engine - FOR ${i} IN RANGE ${3} - Sleep 10s - ${srv_by_host}= Evaluate 20 + 4 * $i - log to console ${srv_by_host} services by host with 50 hosts among 3 pollers. - Config Engine ${3} ${50} ${srv_by_host} - Reload Engine - Reload Broker - ${nb_srv}= Evaluate 17 * (20 + 4 * $i) - ${nb_res}= Evaluate $nb_srv + 17 - ${result}= Check Number Of Resources Monitored by Poller is ${1} ${nb_res} 30 - Should Be True ${result} msg=Poller 1 should monitor ${nb_srv} services and 17 hosts. - ${result}= Check Number Of Resources Monitored by Poller is ${2} ${nb_res} 30 - Should Be True ${result} msg=Poller 2 should monitor ${nb_srv} services and 17 hosts. - ${nb_srv}= Evaluate 16 * (20 + 4 * $i) - ${nb_res}= Evaluate $nb_srv + 16 - ${result}= Check Number Of Resources Monitored by Poller is ${3} ${nb_res} 30 - Should Be True ${result} msg=Poller 3 should monitor ${nb_srv} services and 16 hosts. - END - Stop Engine - Kindly Stop Broker diff --git a/tests/broker-engine/services-with-notes-and-actions.robot b/tests/broker-engine/services-with-notes-and-actions.robot index 21ff75fe935..2b5468ff2d2 100644 --- a/tests/broker-engine/services-with-notes-and-actions.robot +++ b/tests/broker-engine/services-with-notes-and-actions.robot @@ -26,7 +26,6 @@ EBSNU1 Broker Config Add Item central bbdo_version 3.0.0 Broker Config Add Item rrd bbdo_version 3.0.0 Broker Config Log central sql debug - Config Broker Sql Output central unified_sql ${nu}= Evaluate 2000*"X" Engine Config set value in services 0 service_1 notes_url ${nu} Clear Retention @@ -54,7 +53,6 @@ EBSAU2 Broker Config Add Item central bbdo_version 3.0.0 Broker Config Add Item rrd bbdo_version 3.0.0 Broker Config Log central sql debug - Config Broker Sql Output central unified_sql ${au}= Evaluate 2000*"Y" Engine Config set value in services 0 service_2 action_url ${au} Clear Retention @@ -82,7 +80,6 @@ EBSN3 Broker Config Add Item central bbdo_version 3.0.0 Broker Config Add Item rrd bbdo_version 3.0.0 Broker Config Log central sql debug - Config Broker Sql Output central unified_sql ${n}= Evaluate 500*"Z" Engine Config set value in services 0 service_3 notes ${n} Clear Retention diff --git a/tests/broker/sql.robot b/tests/broker/sql.robot index 8c72962adda..d3b35333d9c 100644 --- a/tests/broker/sql.robot +++ b/tests/broker/sql.robot @@ -222,32 +222,6 @@ BEDB3 Stop Broker Stop Engine -BEDB4 - [Documentation] start broker/engine, then stop MariaDB and then start it again. The gRPC API should give informations about SQL connections. - [Tags] Broker sql start-stop grpc - Config Broker central - Config Broker rrd - Config Broker module - Config Engine ${1} - ${start}= Get Current Date - Stop Mysql - Start Broker - Start Engine - FOR ${t} IN RANGE 60 - ${result}= Check All Sql connections Down with grpc 51001 - Exit For Loop If ${result} - END - Should Be True ${result} msg=Connections are not all down. - - Start Mysql - FOR ${t} IN RANGE 60 - ${result}= Check Sql connections count with grpc 51001 ${3} - Exit For Loop If ${result} - END - Should Be True ${result} msg=gRPC does not return 3 connections as expected - Stop Broker - Stop Engine - BDBM1 [Documentation] start broker/engine and then start MariaDB => connection is established [Tags] Broker sql start-stop diff --git a/tests/engine/start-stop.robot b/tests/engine/start-stop.robot index 1463ed53bca..78cf25286e7 100644 --- a/tests/engine/start-stop.robot +++ b/tests/engine/start-stop.robot @@ -8,6 +8,7 @@ Documentation Centreon Engine only start/stop tests Library Process Library OperatingSystem Library ../resources/Engine.py +Library ../resources/Broker.py *** Test Cases *** ESS1 @@ -26,12 +27,14 @@ ESS3 [Documentation] Start-Stop (0s between start/stop) 5 times three instances of engine and no coredump [Tags] Engine start-stop Config Engine ${3} + Config Broker module ${3} Repeat Keyword 5 times Start Stop Instances 300ms ESS4 [Documentation] Start-Stop (300ms between start/stop) 5 times three instances of engine and no coredump [Tags] Engine start-stop Config Engine ${3} + Config Broker module ${3} Repeat Keyword 5 times Start Stop Instances 300ms *** Keywords *** diff --git a/tests/init-sql.sh b/tests/init-sql.sh index f22037423d8..400dce9accc 100755 --- a/tests/init-sql.sh +++ b/tests/init-sql.sh @@ -1,7 +1,8 @@ #!/bin/bash - DBUserRoot=$(awk '($1=="${DBUserRoot}") {print $2}' resources/db_variables.robot) DBPassRoot=$(awk '($1=="${DBPassRoot}") {print $2}' resources/db_variables.robot) +DBStorage=$(awk '($1=="${DBName}") {print $2}' resources/db_variables.robot) +DBConf=$(awk '($1=="${DBNameConf}") {print $2}' resources/db_variables.robot) if [ -z $DBUserRoot ] ; then DBUserRoot="root" @@ -11,6 +12,18 @@ if [ -z $DBPassRoot ] ; then DBPassRoot="centreon" fi -mysql --user="$DBUserRoot" --password="$DBPassRoot" -e "drop database centreon" -mysql --user="$DBUserRoot" --password="$DBPassRoot" < ../resources/centreon.sql -mysql --user="$DBUserRoot" --password="$DBPassRoot" < ../resources/centreon_storage.sql + + +mysql --user="$DBUserRoot" --password="$DBPassRoot" -e "drop database ${DBConf}" +cat ../resources/centreon.sql | sed "s/DBNameConf/${DBConf}/g" > /tmp/centreon.sql + +mysql --user="$DBUserRoot" --password="$DBPassRoot" < /tmp/centreon.sql + +if [ $DBStorage != 'centreon_storage' ] +then + \rm /tmp/centreon_storage.sql + cat ../resources/centreon_storage.sql | sed "s/centreon_storage/${DBStorage}/g" > /tmp/centreon_storage.sql + mysql --user="$DBUserRoot" --password="$DBPassRoot" < /tmp/centreon_storage.sql +else + mysql --user="$DBUserRoot" --password="$DBPassRoot" < ../resources/centreon_storage.sql +fi \ No newline at end of file diff --git a/tests/resources/Broker.py b/tests/resources/Broker.py index eefe85ae5dc..44560e0fce6 100755 --- a/tests/resources/Broker.py +++ b/tests/resources/Broker.py @@ -14,8 +14,6 @@ import glob import os.path import grpc -import broker_pb2 -import broker_pb2_grpc from google.protobuf import empty_pb2 from robot.libraries.BuiltIn import BuiltIn @@ -289,8 +287,7 @@ "tcp": "error", "tls": "error", "lua": "error", - "bam": "error", - "grpc": "error" + "bam": "error" }} }}, "input": [ @@ -441,7 +438,8 @@ def config_broker(name, poller_inst: int = 1): f.close() else: f = open("/etc/centreon-broker/{}".format(filename), "w") - f.write(config[name].format(broker_id, broker_name, DB_HOST, DB_PORT, DB_USER, DB_PASS, DB_NAME_STORAGE)) + f.write(config[name].format(broker_id, broker_name, + DB_HOST, DB_PORT, DB_USER, DB_PASS, DB_NAME_STORAGE)) f.close() diff --git a/tests/resources/Engine.py b/tests/resources/Engine.py index cab79b08ba2..1b83bca717f 100755 --- a/tests/resources/Engine.py +++ b/tests/resources/Engine.py @@ -10,8 +10,6 @@ import stat import grpc -import engine_pb2 -import engine_pb2_grpc CONF_DIR = "/etc/centreon-engine" @@ -657,94 +655,58 @@ def process_service_check_result(hst: str, svc: str, state: int, output: str, co f.close() -def change_normal_svc_check_interval(use_grpc: int, hst: str, svc: str, check_interval: int): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.ChangeServiceObjectIntVar(engine_pb2.ChangeObjectInt( - host_name=hst, service_desc=svc, mode=engine_pb2.ChangeObjectInt.Mode.NORMAL_CHECK_INTERVAL, dval=check_interval)) - else: - now = int(time.time()) - cmd = "[{}] CHANGE_NORMAL_SVC_CHECK_INTERVAL;{};{};{}\n".format( - now, hst, svc, check_interval) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def change_normal_svc_check_interval(hst: str, svc: str, check_interval: int): + now = int(time.time()) + cmd = "[{}] CHANGE_NORMAL_SVC_CHECK_INTERVAL;{};{};{}\n".format( + now, hst, svc, check_interval) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def change_normal_host_check_interval(use_grpc: int, hst: str, check_interval: int): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.ChangeHostObjectIntVar(engine_pb2.ChangeObjectInt( - host_name=hst, mode=engine_pb2.ChangeObjectInt.Mode.NORMAL_CHECK_INTERVAL, dval=check_interval)) - else: - now = int(time.time()) - cmd = "[{}] CHANGE_NORMAL_HOST_CHECK_INTERVAL;{};{}\n".format( - now, hst, check_interval) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def change_normal_host_check_interval(hst: str, check_interval: int): + now = int(time.time()) + cmd = "[{}] CHANGE_NORMAL_HOST_CHECK_INTERVAL;{};{}\n".format( + now, hst, check_interval) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def change_retry_svc_check_interval(use_grpc: int, hst: str, svc: str, retry_interval: int): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.ChangeServiceObjectIntVar(engine_pb2.ChangeObjectInt( - host_name=hst, service_desc=svc, mode=engine_pb2.ChangeObjectInt.Mode.RETRY_CHECK_INTERVAL, dval=retry_interval)) - else: - now = int(time.time()) - cmd = "[{}] CHANGE_RETRY_SVC_CHECK_INTERVAL;{};{};{}\n".format( - now, hst, svc, retry_interval) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def change_retry_svc_check_interval(hst: str, svc: str, retry_interval: int): + now = int(time.time()) + cmd = "[{}] CHANGE_RETRY_SVC_CHECK_INTERVAL;{};{};{}\n".format( + now, hst, svc, retry_interval) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def change_retry_host_check_interval(use_grpc: int, hst: str, retry_interval: int): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.ChangeHostObjectIntVar(engine_pb2.ChangeObjectInt( - host_name=hst, mode=engine_pb2.ChangeObjectInt.Mode.RETRY_CHECK_INTERVAL, dval=retry_interval)) - else: - now = int(time.time()) - cmd = "[{}] CHANGE_RETRY_HOST_CHECK_INTERVAL;{};{}\n".format( - now, hst, retry_interval) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def change_retry_host_check_interval(hst: str, retry_interval: int): + now = int(time.time()) + cmd = "[{}] CHANGE_RETRY_HOST_CHECK_INTERVAL;{};{}\n".format( + now, hst, retry_interval) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def change_max_svc_check_attempts(use_grpc: int, hst: str, svc: str, max_check_attempts: int): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.ChangeServiceObjectIntVar(engine_pb2.ChangeObjectInt( - host_name=hst, service_desc=svc, mode=engine_pb2.ChangeObjectInt.Mode.MAX_ATTEMPTS, intval=max_check_attempts)) - else: - now = int(time.time()) - cmd = "[{}] CHANGE_MAX_SVC_CHECK_ATTEMPTS;{};{};{}\n".format( - now, hst, svc, max_check_attempts) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def change_max_svc_check_attempts(hst: str, svc: str, max_check_attempts: int): + now = int(time.time()) + cmd = "[{}] CHANGE_MAX_SVC_CHECK_ATTEMPTS;{};{};{}\n".format( + now, hst, svc, max_check_attempts) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def change_max_host_check_attempts(use_grpc: int, hst: str, max_check_attempts: int): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.ChangeHostObjectIntVar(engine_pb2.ChangeObjectInt( - host_name=hst, mode=engine_pb2.ChangeObjectInt.Mode.MAX_ATTEMPTS, intval=max_check_attempts)) - else: - now = int(time.time()) - cmd = "[{}] CHANGE_MAX_HOST_CHECK_ATTEMPTS;{};{}\n".format( - now, hst, max_check_attempts) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def change_max_host_check_attempts(hst: str, max_check_attempts: int): + now = int(time.time()) + cmd = "[{}] CHANGE_MAX_HOST_CHECK_ATTEMPTS;{};{}\n".format( + now, hst, max_check_attempts) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() def change_host_check_command(hst: str, Check_Command: str): @@ -756,304 +718,238 @@ def change_host_check_command(hst: str, Check_Command: str): f.close() -def change_host_check_timeperiod(use_grpc: int, hst: str, check_timeperiod: str): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.ChangeHostObjectCharVar(engine_pb2.ChangeObjectChar( - host_name=hst, mode=engine_pb2.ChangeObjectChar.Mode.CHANGE_CHECK_TIMEPERIOD, charval=check_timeperiod)) - else: - now = int(time.time()) - cmd = "[{}] CHANGE_HOST_CHECK_TIMEPERIOD;{};{}\n".format( - now, hst, check_timeperiod) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def change_host_check_timeperiod(hst: str, check_timeperiod: str): + now = int(time.time()) + cmd = "[{}] CHANGE_HOST_CHECK_TIMEPERIOD;{};{}\n".format( + now, hst, check_timeperiod) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def change_host_notification_timeperiod(use_grpc: int, hst: str, notification_timeperiod: str): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.ChangeHostObjectCharVar(engine_pb2.ChangeObjectChar( - host_name=hst, mode=engine_pb2.ChangeObjectChar.Mode.CHANGE_NOTIFICATION_TIMEPERIOD, charval=notification_timeperiod)) - else: - now = int(time.time()) - cmd = "[{}] CHANGE_HOST_NOTIFICATION_TIMEPERIOD;{};{}\n".format( - now, hst, notification_timeperiod) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def change_host_notification_timeperiod(hst: str, notification_timeperiod: str): + now = int(time.time()) + cmd = "[{}] CHANGE_HOST_NOTIFICATION_TIMEPERIOD;{};{}\n".format( + now, hst, notification_timeperiod) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def change_svc_check_timeperiod(use_grpc: int, hst: str, svc: str, check_timeperiod: str): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.ChangeServiceObjectCharVar(engine_pb2.ChangeObjectChar( - host_name=hst, service_desc=svc, mode=engine_pb2.ChangeObjectChar.Mode.CHANGE_CHECK_TIMEPERIOD, charval=check_timeperiod)) - else: - now = int(time.time()) - cmd = "[{}] CHANGE_SVC_CHECK_TIMEPERIOD;{};{};{}\n".format( - now, hst, svc, check_timeperiod) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def change_svc_check_timeperiod(hst: str, svc: str, check_timeperiod: str): + now = int(time.time()) + cmd = "[{}] CHANGE_SVC_CHECK_TIMEPERIOD;{};{};{}\n".format( + now, hst, svc, check_timeperiod) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def change_svc_notification_timeperiod(use_grpc: int, hst: str, svc: str, notification_timeperiod: str): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.ChangeServiceObjectCharVar(engine_pb2.ChangeObjectChar( - host_name=hst, service_desc=svc, mode=engine_pb2.ChangeObjectChar.Mode.CHANGE_NOTIFICATION_TIMEPERIOD, charval=notification_timeperiod)) - else: - now = int(time.time()) - cmd = "[{}] CHANGE_SVC_NOTIFICATION_TIMEPERIOD;{};{};{}\n".format( - now, hst, svc, notification_timeperiod) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def change_svc_notification_timeperiod(hst: str, svc: str, notification_timeperiod: str): + now = int(time.time()) + cmd = "[{}] CHANGE_SVC_NOTIFICATION_TIMEPERIOD;{};{};{}\n".format( + now, hst, svc, notification_timeperiod) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def disable_host_and_child_notifications(use_grpc: int, hst: str): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.DisableHostAndChildNotifications( - engine_pb2.HostIdentifier(name=hst)) - else: - now = int(time.time()) - cmd = "[{}] DISABLE_HOST_AND_CHILD_NOTIFICATIONS;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def disable_host_and_child_notifications(hst: str): + now = int(time.time()) + cmd = "[{}] DISABLE_HOST_AND_CHILD_NOTIFICATIONS;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def enable_host_and_child_notifications(use_grpc: int, hst: str): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.EnableHostAndChildNotifications( - engine_pb2.HostIdentifier(name=hst)) - else: - now = int(time.time()) - cmd = "[{}] ENABLE_HOST_AND_CHILD_NOTIFICATIONS;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def enable_host_and_child_notifications(hst: str): + now = int(time.time()) + cmd = "[{}] ENABLE_HOST_AND_CHILD_NOTIFICATIONS;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def disable_host_check(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] DISABLE_HOST_CHECK;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def disable_host_check(hst: str): + now = int(time.time()) + cmd = "[{}] DISABLE_HOST_CHECK;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def enable_host_check(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] ENABLE_HOST_CHECK;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def enable_host_check(hst: str): + now = int(time.time()) + cmd = "[{}] ENABLE_HOST_CHECK;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def disable_host_event_handler(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] DISABLE_HOST_EVENT_HANDLER;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def disable_host_event_handler(hst: str): + now = int(time.time()) + cmd = "[{}] DISABLE_HOST_EVENT_HANDLER;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def enable_host_event_handler(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] ENABLE_HOST_EVENT_HANDLER;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def enable_host_event_handler(hst: str): + now = int(time.time()) + cmd = "[{}] ENABLE_HOST_EVENT_HANDLER;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def disable_host_flap_detection(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] DISABLE_HOST_FLAP_DETECTION;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def disable_host_flap_detection(hst: str): + now = int(time.time()) + cmd = "[{}] DISABLE_HOST_FLAP_DETECTION;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def enable_host_flap_detection(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] ENABLE_HOST_FLAP_DETECTION;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def enable_host_flap_detection(hst: str): + now = int(time.time()) + cmd = "[{}] ENABLE_HOST_FLAP_DETECTION;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def disable_host_notifications(use_grpc: int, hst: str): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.DisableHostNotifications( - engine_pb2.HostIdentifier(name=hst)) - else: - now = int(time.time()) - cmd = "[{}] DISABLE_HOST_NOTIFICATIONS;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def disable_host_notifications(hst: str): + now = int(time.time()) + cmd = "[{}] DISABLE_HOST_NOTIFICATIONS;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def enable_host_notifications(use_grpc: int, hst: str): - if use_grpc > 0: - with grpc.insecure_channel("127.0.0.1:50001") as channel: - stub = engine_pb2_grpc.EngineStub(channel) - stub.EnableHostNotifications( - engine_pb2.HostIdentifier(name=hst)) - else: - now = int(time.time()) - cmd = "[{}] ENABLE_HOST_NOTIFICATIONS;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def enable_host_notifications(hst: str): + now = int(time.time()) + cmd = "[{}] ENABLE_HOST_NOTIFICATIONS;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def disable_host_svc_checks(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] DISABLE_HOST_SVC_CHECKS;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def disable_host_svc_checks(hst: str): + now = int(time.time()) + cmd = "[{}] DISABLE_HOST_SVC_CHECKS;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def enable_host_svc_checks(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] ENABLE_HOST_SVC_CHECKS;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def enable_host_svc_checks(hst: str): + now = int(time.time()) + cmd = "[{}] ENABLE_HOST_SVC_CHECKS;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def disable_host_svc_notifications(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] DISABLE_HOST_SVC_NOTIFICATIONS;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def disable_host_svc_notifications(hst: str): + now = int(time.time()) + cmd = "[{}] DISABLE_HOST_SVC_NOTIFICATIONS;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def enable_host_svc_notifications(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] ENABLE_HOST_SVC_NOTIFICATIONS;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def enable_host_svc_notifications(hst: str): + now = int(time.time()) + cmd = "[{}] ENABLE_HOST_SVC_NOTIFICATIONS;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def disable_passive_host_checks(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] DISABLE_PASSIVE_HOST_CHECKS;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def disable_passive_host_checks(hst: str): + now = int(time.time()) + cmd = "[{}] DISABLE_PASSIVE_HOST_CHECKS;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def enable_passive_host_checks(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] ENABLE_PASSIVE_HOST_CHECKS;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def enable_passive_host_checks(hst: str): + now = int(time.time()) + cmd = "[{}] ENABLE_PASSIVE_HOST_CHECKS;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def disable_passive_svc_checks(use_grpc: int, hst: str, svc: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] DISABLE_PASSIVE_SVC_CHECKS;{};{}\n".format( - now, hst, svc) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def disable_passive_svc_checks(hst: str, svc: str): + now = int(time.time()) + cmd = "[{}] DISABLE_PASSIVE_SVC_CHECKS;{};{}\n".format( + now, hst, svc) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def enable_passive_svc_checks(use_grpc: int, hst: str, svc: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] ENABLE_PASSIVE_SVC_CHECKS;{};{}\n".format( - now, hst, svc) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def enable_passive_svc_checks(hst: str, svc: str): + now = int(time.time()) + cmd = "[{}] ENABLE_PASSIVE_SVC_CHECKS;{};{}\n".format( + now, hst, svc) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def start_obsessing_over_host(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] START_OBSESSING_OVER_HOST;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def start_obsessing_over_host(hst: str): + now = int(time.time()) + cmd = "[{}] START_OBSESSING_OVER_HOST;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def stop_obsessing_over_host(use_grpc: int, hst: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] STOP_OBSESSING_OVER_HOST;{}\n".format( - now, hst) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def stop_obsessing_over_host(hst: str): + now = int(time.time()) + cmd = "[{}] STOP_OBSESSING_OVER_HOST;{}\n".format( + now, hst) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def start_obsessing_over_svc(use_grpc: int, hst: str, svc: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] START_OBSESSING_OVER_SVC;{};{}\n".format( - now, hst, svc) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def start_obsessing_over_svc(hst: str, svc: str): + now = int(time.time()) + cmd = "[{}] START_OBSESSING_OVER_SVC;{};{}\n".format( + now, hst, svc) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() -def stop_obsessing_over_svc(use_grpc: int, hst: str, svc: str): - if use_grpc == 0: - now = int(time.time()) - cmd = "[{}] STOP_OBSESSING_OVER_SVC;{};{}\n".format( - now, hst, svc) - f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") - f.write(cmd) - f.close() +def stop_obsessing_over_svc(hst: str, svc: str): + now = int(time.time()) + cmd = "[{}] STOP_OBSESSING_OVER_SVC;{};{}\n".format( + now, hst, svc) + f = open("/var/lib/centreon-engine/config0/rw/centengine.cmd", "w") + f.write(cmd) + f.close() def service_ext_commands(hst: str, svc: str, state: int, output: str): @@ -1082,6 +978,7 @@ def schedule_service_downtime(hst: str, svc: str, duration: int): f.write(cmd) f.close() + def schedule_host_downtime(poller: int, hst: str, duration: int): now = int(time.time()) cmd1 = "[{1}] SCHEDULE_HOST_DOWNTIME;{0};{1};{2};1;0;{3};admin;Downtime set by admin\n".format( @@ -1093,6 +990,7 @@ def schedule_host_downtime(poller: int, hst: str, duration: int): f.write(cmd2) f.close() + def delete_host_downtimes(poller: int, hst: str): now = int(time.time()) cmd = "[{}] DEL_HOST_DOWNTIME_FULL;{};;;;;;;;\n".format(now, hst) diff --git a/tests/resources/db_variables.robot b/tests/resources/db_variables.robot index 6aa17e4f969..dee7cea9af5 100644 --- a/tests/resources/db_variables.robot +++ b/tests/resources/db_variables.robot @@ -1,9 +1,12 @@ *** Variables *** -${DBName} centreon_storage -${DBNameConf} centreon -${DBHost} localhost +${EtcRoot} /tmp/etc +${VarRoot} /tmp/var +${DBName} centreon_storage_test +${DBNameConf} centreon_test +${DBHost} 127.0.0.1 ${DBUser} centreon -${DBPass} Fa@V@?L9@4Wfh70u +${DBPass} centreon ${DBPort} 3306 -${DBUserRoot} root -${DBPassRoot} Af58MwnP@zJ*@6!5 \ No newline at end of file +${DBUserRoot} centreon_test +${DBPassRoot} centreon +