diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 00000000000..56fac62d5ec --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,16 @@ +version = 1 + +[[analyzers]] +name = "shell" +enabled = true + +[[analyzers]] +name = "python" +enabled = true + + [analyzers.meta] + runtime_version = "3.x.x" + +[[analyzers]] +name = "cxx" +enabled = true \ No newline at end of file diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 7a1ce8313aa..a2a84022cac 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -15,10 +15,10 @@ Please include a short resume of the changes and what is the purpose of PR. Any ## Target serie -- [ ] 21.04.x - [ ] 21.10.x - [ ] 22.04.x -- [ ] 22.10.x (master) +- [ ] 22.10.x +- [ ] 23.04.x (master)

How this pull request can be tested ?

diff --git a/.github/actions/delivery/action.yml b/.github/actions/delivery/action.yml index 7b3ded223ee..86e4b70117a 100644 --- a/.github/actions/delivery/action.yml +++ b/.github/actions/delivery/action.yml @@ -1,21 +1,51 @@ name: "delivery" description: "RPM and DEB packages delivery Centreon" inputs: + module_name: + description: "The name of the module" + required: true + repository_name: + description: "The name of the repository" + required: true distrib: description: "The distribution used for packaging" required: true - repos_username: + nexus_username: description: "Artifact Manager technical username" required: true - repos_password: + nexus_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 + artifactory_token: + description: "The token for artifactory" + required: true runs: using: "composite" @@ -29,7 +59,7 @@ runs: - name: Build name for DEB shell: bash - if: ${{ inputs.distrib == 'buster' || inputs.distrib == 'bullseye' }} + if: ${{ inputs.distrib == 'bullseye' }} run: | echo "build=debbuild-centreon-collect" >> $GITHUB_ENV echo "extfile=deb" >> $GITHUB_ENV @@ -38,8 +68,15 @@ runs: 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 }} + key: ${{ inputs.cache_key }} + restore-keys: ${{ inputs.cache_key }} + + - 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: | @@ -52,35 +89,95 @@ runs: echo "[DEBUG] - Branch name: $BRANCHNAME" case "$BRANCHNAME" in develop | dev-[2-9][0-9].[0-9][0-9].x) - REPO="unstable" + SUBREPO="unstable" ;; release* | hotfix*) - REPO="testing" + SUBREPO="testing" ;; master | [2-9][0-9].[0-9][0-9].x) - REPO="stable" + SUBREPO="stable" ;; *) echo -n "[INFO] NO DELIVERY FOR THIS BRANCH" exit 0 ;; esac - FILES="*.${{ env.extfile }}"; - DISTRIB="${{ inputs.distrib }}"; - echo "[DEBUG] - Repo: $REPO" - echo "[DEBUG] - FILES: $FILES" - echo "[DEBUG] - DISTRIB: $DISTRIB" + + 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 "[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" + + if [[ "${{ env.extfile }}" == "deb" ]] && [[ "$SUBREPO" == "stable" ]]; then + curl --fail -u "${{ inputs.nexus_username }}":"${{ inputs.nexus_password }}" -H "Content-Type: multipart/form-data" --data-binary "@./$FILE" https://apt.centreon.com/repository/${{ inputs.version }}/ + curl --fail -v -H "Authorization: Bearer ${{ inputs.artifactory_token }}" -X PUT "https://centreon.jfrog.io/artifactory/apt-${{ inputs.version }}-$SUBREPO/pool/$FILE;deb.distribution=bullseye;deb.component=main;deb.architecture=amd64" -T "$FILE" + elif [[ "${{ env.extfile }}" == "deb" ]] && [[ "$SUBREPO" != "stable" ]]; then + curl --fail -u "${{ inputs.nexus_username }}":"${{ inputs.nexus_password }}" -H "Content-Type: multipart/form-data" --data-binary "@./$FILE" https://apt.centreon.com/repository/${{ inputs.version }}-$SUBREPO/ + curl --fail -v -H "Authorization: Bearer ${{ inputs.artifactory_token }}" -X PUT "https://centreon.jfrog.io/artifactory/apt-${{ inputs.version }}-$SUBREPO/pool/$FILE;deb.distribution=bullseye;deb.component=main;deb.architecture=amd64" -T "$FILE" else - echo "[DEBUG] - https://artifactory.apps.centreon.com/artifactory/rpm-$VERSION-$REPO/$DISTRIB/$REPO/x86_64/centreon-collect" - curl -v -u "${{ inputs.repos_username }}":"${{ inputs.repos_password }}" -X PUT "https://artifactory.apps.centreon.com/artifactory/rpm-$VERSION-$REPO/$DISTRIB/$REPO/x86_64/centreon-collect/$FILE" -T "./$FILE" + 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" + curl --fail -v -H "Authorization: Bearer ${{ inputs.artifactory_token }}" -X PUT "https://centreon.jfrog.io/artifactory/rpm/$PROJECT_PATH/$MAJOR/$DISTRIB/$SUBREPO/$ARCH/$FILE" -T "./$FILE" + 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" + curl --fail -v -H "Authorization: Bearer ${{ inputs.artifactory_token }}" -X PUT "https://centreon.jfrog.io/artifactory/rpm/$PROJECT_PATH/$MAJOR/$DISTRIB/$SUBREPO/$ARCH/$PROJECT/$FOLDER/$FILE" -T "./$FILE" + 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..ff3327071ff --- /dev/null +++ b/.github/actions/get-packages/action.yml @@ -0,0 +1,92 @@ +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="${{ inputs.release }}" + + echo "[DEBUG] - FULL_VERSION: $FULL_VERSION" + echo "[DEBUG] - RELEASE: $RELEASE" + + # Obtain latest version.patch-release + PKG_DIR_VERSION=$(curl -s "https://yum.centreon.com/standard/23.04/el7/unstable/x86_64/centreon-collect/" | sed -En 's/.*([2-9][0-9]\.[0-9][0-9]\.[[:digit:]]+-[[:digit:]]+\.[[a-z0-9]{7}).*/\1/p') + + echo "[DEBUG] - PKG_DIR_VERSION: $PKG_DIR_VERSION" + + # Fetch files from repo + 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://yum.centreon.com/standard/${{ inputs.version }}/${{ inputs.distrib }}/$REPO/x86_64/centreon-collect/$PKG_DIR_VERSION/$FILE-$PKG_DIR_VERSION.${{ inputs.distrib }}.x86_64.rpm" + curl -s -JO "https://yum.centreon.com/standard/${{ inputs.version }}/${{ inputs.distrib }}/$REPO/x86_64/centreon-collect/centreon-collect-$PKG_DIR_VERSION/$FILE-$PKG_DIR_VERSION.${{ 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..bdfb32c77a7 --- /dev/null +++ b/.github/actions/package-sign/action.yml @@ -0,0 +1,39 @@ +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 + registry_url: + description: Docker registry url + required: true + registry_username: + description: Docker registry username + required: true + registry_password: + description: Docker registry 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: ${{ inputs.registry_url }} + username: ${{ inputs.registry_username }} + password: ${{ inputs.registry_password }} + + - run: docker run -i -e TOKEN=${{ inputs.centreon_pat }} --entrypoint /src/.github/scripts/${{ inputs.script_name }}.sh -v "$PWD:/src" ${{ inputs.registry_url }}/${{ inputs.image_name }}:${{ inputs.image_version}} ${{ inputs.params }} + shell: bash \ No newline at end of file diff --git a/.github/actions/runner-docker/action.yml b/.github/actions/runner-docker/action.yml index f872079c8c6..8f943b43544 100644 --- a/.github/actions/runner-docker/action.yml +++ b/.github/actions/runner-docker/action.yml @@ -1,6 +1,9 @@ name: "runner docker Centreon" description: "runner docker Centreon" inputs: + registry_url: + description: Docker registry url + required: true script_name: description: "script name" required: true @@ -16,11 +19,9 @@ inputs: params: description: "params for script" required: false -env: - REGISTRY: registry-docker.centreon.com/docker-global 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 }} + - run: docker run -i --entrypoint ${{ inputs.script_name }}.sh -v "$PWD:/src" ${{ inputs.env_variable }} ${{ inputs.registry_url }}/${{ inputs.image_name }}:${{ inputs.image_version}} ${{ inputs.params }} 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 index 0da07173f63..bb82589b2ee 100644 --- a/.github/workflows/centreon-collect.yml +++ b/.github/workflows/centreon-collect.yml @@ -1,20 +1,14 @@ 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 + push: + branches: + - develop + - dev-[2-9][0-9].[0-9][0-9].x + - master + - "[2-9][0-9].[0-9][0-9].x" jobs: create-version: @@ -42,9 +36,10 @@ jobs: echo "release=$GITHUB_RUN_ATTEMPT" >> $GITHUB_OUTPUT ;; *) - echo "release=`date +%s`.${{ github.sha }}" >> $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 }}" @@ -66,23 +61,24 @@ jobs: strategy: matrix: - include: - - image: centos7 - - image: alma8 - - image: debian-buster - - image: debian-bullseye + image: [centos7, alma8, debian-bullseye] + name: unit test ${{ matrix.image }} + 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 }} + registry: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }} + username: ${{ secrets.DOCKER_REGISTRY_ID }} + password: ${{ secrets.DOCKER_REGISTRY_PASSWD }} + - name: Test ${{ matrix.image }} uses: ./.github/actions/runner-docker with: + registry_url: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }} script_name: /src/ci/scripts/collect-unit-tests image_name: centreon-collect-${{ matrix.image }} image_version: ${{ env.imgversion }} @@ -105,25 +101,37 @@ jobs: 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 }} + registry: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }} + username: ${{ secrets.DOCKER_REGISTRY_ID }} + password: ${{ secrets.DOCKER_REGISTRY_PASSWD }} - name: make rpm ${{ matrix.image }} uses: ./.github/actions/runner-docker with: + registry_url: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }} 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 + registry_url: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }} + registry_username: ${{ secrets.DOCKER_REGISTRY_ID }} + registry_password: ${{ secrets.DOCKER_REGISTRY_PASSWD }} + - name: Use cache RPM files uses: actions/cache@v3 env: - cache-name-rpmbuild: cache-${{ github.sha }}-${{ github.run_id }}-rpmbuild-centreon-collect-${{ matrix.distrib }} + cache-name-rpmbuild: cache-${{ github.sha }}-${{ github.run_id }}-rpmbuild-collect-${{ matrix.distrib }} with: path: ./*.rpm key: ${{ env.cache-name-rpmbuild }} @@ -139,8 +147,6 @@ jobs: strategy: matrix: include: - - image: debian-buster - distrib: buster - image: debian-bullseye distrib: bullseye steps: @@ -151,13 +157,14 @@ jobs: - name: Login to Registry uses: docker/login-action@v2 with: - registry: ${{ env.REGISTRY }} - username: ${{ secrets.REPOS_USERNAME }} - password: ${{ secrets.REPOS_PASSWORD }} + registry: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }} + username: ${{ secrets.DOCKER_REGISTRY_ID }} + password: ${{ secrets.DOCKER_REGISTRY_PASSWD }} - name: debmake ${{ matrix.image }} uses: ./centreon-collect/.github/actions/runner-docker with: + registry_url: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }} script_name: /src/centreon-collect/ci/scripts/collect-deb-package image_name: centreon-collect-${{ matrix.image }} image_version: ${{ env.imgversion }} @@ -179,7 +186,7 @@ jobs: name: Delivery strategy: matrix: - distrib: [buster, bullseye] + distrib: [bullseye] steps: - name: Checkout sources uses: actions/checkout@v3 @@ -188,9 +195,11 @@ jobs: uses: ./.github/actions/delivery with: distrib: ${{ matrix.distrib }} + repository_name: standard version: ${{ env.version }} - repos_username: ${{ secrets.REPOS_USERNAME }} - repos_password: ${{ secrets.REPOS_PASSWORD }} + nexus_username: ${{ secrets.NEXUS_USERNAME }} + nexus_password: ${{ secrets.NEXUS_PASSWORD }} + artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }} cache_key: cache-${{ github.sha }}-${{ github.run_id }} delivery-centos: @@ -211,6 +220,15 @@ jobs: 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 }} + minor_version: ${{ needs.create-version.outputs.patch }} + release: ${{ needs.create-version.outputs.release }} + module_name: centreon-collect + nexus_username: ${{ secrets.NEXUS_USERNAME }} + nexus_password: ${{ secrets.NEXUS_PASSWORD }} + artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }} + cache_key: cache-${{ github.sha }}-${{ github.run_id }}-rpmbuild-collect-${{ matrix.distrib }} + 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/centreon-gorgone.yml b/.github/workflows/centreon-gorgone.yml deleted file mode 100644 index 2085a0f2002..00000000000 --- a/.github/workflows/centreon-gorgone.yml +++ /dev/null @@ -1,196 +0,0 @@ -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/**' - -env: - version: 22.10 -jobs: - rpm-packaging: - runs-on: ubuntu-22.04 - strategy: - matrix: - include: - - image: centos7 - distrib: el7 - - image: alma8 - 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: ${{ env.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 - 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: ${{ env.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/.github/workflows/docker-builder.yml b/.github/workflows/docker-builder.yml index b1b58d3f16f..39fcfdf156b 100644 --- a/.github/workflows/docker-builder.yml +++ b/.github/workflows/docker-builder.yml @@ -1,23 +1,17 @@ name: Centreon collect build docker on: - pull_request_target: - types: - - closed + push: branches: - develop + - dev-[2-9][0-9].[0-9][0-9].x 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-version: runs-on: ubuntu-latest @@ -45,21 +39,10 @@ jobs: strategy: fail-fast: false matrix: + distrib: [centos7, alma8, debian-bullseye] include: - project: collect - distrib: centos7 - - project: collect - distrib: alma8 - - project: collect - distrib: debian-buster - - 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 @@ -67,13 +50,17 @@ jobs: - 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 }} + registry: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }} + username: ${{ secrets.DOCKER_REGISTRY_ID }} + password: ${{ secrets.DOCKER_REGISTRY_PASSWD }} - - name: push docker ${{ matrix.distrib }} - run: docker push $REGISTRY/centreon-${{ matrix.project }}-${{ matrix.distrib }}:${{ env.imgversion }} + - uses: docker/setup-buildx-action@v2 + - uses: docker/build-push-action@v3 + with: + file: ci/docker/Dockerfile.${{ matrix.project }}-${{ matrix.distrib }} + context: . + build-args: "REGISTRY_URL=${{ vars.DOCKER_PROXY_REGISTRY_URL }}" + pull: true + push: true + tags: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/centreon-${{ matrix.project }}-${{ matrix.distrib }}:${{ env.imgversion }} diff --git a/.github/workflows/release-collect.yml b/.github/workflows/release-collect.yml index 0b740b0f81d..cece445f5a1 100644 --- a/.github/workflows/release-collect.yml +++ b/.github/workflows/release-collect.yml @@ -11,7 +11,6 @@ on: - "!dev*" paths: - ".github/actions/release/action.yml" - - ".github/workflows/release-collect.yml" workflow_dispatch: jobs: diff --git a/.github/workflows/robot-nightly.yml b/.github/workflows/robot-nightly.yml index 570acdd6ab0..3f5ab8300cf 100644 --- a/.github/workflows/robot-nightly.yml +++ b/.github/workflows/robot-nightly.yml @@ -2,13 +2,9 @@ name: centreon collect nightly robot on: workflow_dispatch: - push: - branches: - - master - - develop - pull_request: - paths: - - '.github/workflows/robot-nightly.yml' + #pull_request: + # paths: + # - '.github/workflows/robot-nightly.yml' schedule: - cron: '0 0 * * *' @@ -20,25 +16,65 @@ jobs: # branch: [develop, master] include: - image: centreon-collect-centos7 + distrib: el7 + folder_report: tests/ + - image: centreon-collect-alma8 + distrib: el8 folder_report: tests/ steps: - name: Checkout sources uses: actions/checkout@v3 - - run: | - VERSION=$(awk '$1 ~ "COLLECT_MAJOR" {maj=substr($2, 1, length($2)-1)} $1 ~ "COLLECT_MINOR" {min=substr($2, 1, length($2)-1)} $1 ~ "COLLECT_PATCH" {patch=substr($2, 1, length($2) - 1) ; print maj "." min "." patch}' CMakeLists.txt) + - 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 - id: version - - run: | - echo "Version is ${{ env.version }}" + 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=`date +%s`.`echo ${{ github.sha }} | cut -c -7`" >> $GITHUB_OUTPUT + echo "release=`date +%s`.`echo ${{ github.sha }} | cut -c -7`" >> $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: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }} + username: ${{ secrets.DOCKER_REGISTRY_ID }} + password: ${{ secrets.DOCKER_REGISTRY_PASSWD }} - - name: Test robot centos7 + - name: Tests robot (Centos7, Alma8) uses: ./.github/actions/runner-docker with: + registry_url: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }} script_name: /src/ci/scripts/collect-test-robot image_name: ${{ matrix.image }} - image_version: ${{ env.version }} - params: ${{ matrix.branch }} + image_version: ${{ env.imgversion }} - name: Send report to commit uses: joonvena/robotframework-reporter-action@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aca3764ad8..86458323a75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ #### Broker +*Lua* +* Lua accepts repeated fields from Protobuf events. + #### Engine ### Enhancements diff --git a/CMakeLists.txt b/CMakeLists.txt index 99ff2742dbe..ad9d14f9e95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,8 @@ set(USER_ENGINE centreon-engine) 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}") diff --git a/README.md b/README.md index 5751ed69559..b96bbb21aac 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ apt install conan If it does not work, conan can be installed with pip3: ```shell -pip3 install conan +pip3 install conan==1.57.0 ``` > All the dependencies pulled by conan are located in conanfile.txt. If diff --git a/broker/lua/src/broker_event.cc b/broker/lua/src/broker_event.cc index 5916a2111a0..378bcbfecf5 100644 --- a/broker/lua/src/broker_event.cc +++ b/broker/lua/src/broker_event.cc @@ -28,6 +28,10 @@ using namespace com::centreon::broker; using namespace com::centreon::broker::lua; using namespace com::centreon::exceptions; +static void _write_item(lua_State* L, + const google::protobuf::Message* p, + const google::protobuf::FieldDescriptor* f); + /** * The Lua broker_event constructor * @@ -51,7 +55,7 @@ static void _message_to_table(lua_State* L, const google::protobuf::Descriptor* desc = p->GetDescriptor(); const google::protobuf::Reflection* refl = p->GetReflection(); for (int i = 0; i < desc->field_count(); i++) { - auto f = desc->field(i); + const google::protobuf::FieldDescriptor* f = desc->field(i); auto oof = f->containing_oneof(); if (oof) { @@ -60,51 +64,118 @@ static void _message_to_table(lua_State* L, } } + _write_item(L, p, f); + lua_rawset(L, -3); + } +} + +static void _write_item(lua_State* L, + const google::protobuf::Message* p, + const google::protobuf::FieldDescriptor* f) { + const google::protobuf::Reflection* refl = p->GetReflection(); + if (f) { const std::string& entry_name = f->name(); lua_pushlstring(L, entry_name.c_str(), entry_name.size()); - switch (f->type()) { - case google::protobuf::FieldDescriptor::TYPE_BOOL: - lua_pushboolean(L, refl->GetBool(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_DOUBLE: - lua_pushnumber(L, refl->GetDouble(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_INT32: - lua_pushinteger(L, refl->GetInt32(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_UINT32: - lua_pushinteger(L, refl->GetUInt32(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_INT64: - lua_pushinteger(L, refl->GetInt64(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_UINT64: - lua_pushinteger(L, refl->GetUInt64(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_ENUM: - lua_pushinteger(L, refl->GetEnumValue(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_STRING: { - const std::string& s = refl->GetString(*p, f); - lua_pushlstring(L, s.c_str(), s.size()); - } break; - case google::protobuf::FieldDescriptor::TYPE_MESSAGE: - if (f->is_repeated()) { - size_t s = refl->FieldSize(*p, f); - // const google::protobuf::Message& msg = refl->GetMessage(*p, f); - lua_newtable(L); + if (f->is_repeated()) { + size_t s = refl->FieldSize(*p, f); + lua_newtable(L); + switch (f->type()) { + case google::protobuf::FieldDescriptor::TYPE_BOOL: + for (size_t i = 0; i < s; i++) { + lua_pushboolean(L, refl->GetRepeatedBool(*p, f, i)); + lua_rawseti(L, -2, i + 1); + } + break; + case google::protobuf::FieldDescriptor::TYPE_DOUBLE: + for (size_t i = 0; i < s; i++) { + lua_pushnumber(L, refl->GetRepeatedDouble(*p, f, i)); + lua_rawseti(L, -2, i + 1); + } + break; + case google::protobuf::FieldDescriptor::TYPE_INT32: + for (size_t i = 0; i < s; i++) { + lua_pushinteger(L, refl->GetRepeatedInt32(*p, f, i)); + lua_rawseti(L, -2, i + 1); + } + break; + case google::protobuf::FieldDescriptor::TYPE_UINT32: + for (size_t i = 0; i < s; i++) { + lua_pushinteger(L, refl->GetRepeatedUInt32(*p, f, i)); + lua_rawseti(L, -2, i + 1); + } + break; + case google::protobuf::FieldDescriptor::TYPE_INT64: + for (size_t i = 0; i < s; i++) { + lua_pushinteger(L, refl->GetRepeatedInt64(*p, f, i)); + lua_rawseti(L, -2, i + 1); + } + break; + case google::protobuf::FieldDescriptor::TYPE_UINT64: + for (size_t i = 0; i < s; i++) { + lua_pushinteger(L, refl->GetRepeatedUInt64(*p, f, i)); + lua_rawseti(L, -2, i + 1); + } + break; + case google::protobuf::FieldDescriptor::TYPE_ENUM: + for (size_t i = 0; i < s; i++) { + lua_pushinteger(L, refl->GetRepeatedEnumValue(*p, f, i)); + lua_rawseti(L, -2, i + 1); + } + break; + case google::protobuf::FieldDescriptor::TYPE_STRING: { + for (size_t i = 0; i < s; i++) { + const std::string& s = refl->GetRepeatedString(*p, f, i); + lua_pushlstring(L, s.c_str(), s.size()); + lua_rawseti(L, -2, i + 1); + } + } break; + case google::protobuf::FieldDescriptor::TYPE_MESSAGE: { for (size_t i = 0; i < s; i++) { lua_newtable(L); _message_to_table(L, &refl->GetRepeatedMessage(*p, f, i)); lua_rawseti(L, -2, i + 1); } - } - break; - default: - lua_pushlstring(L, "not_implemented", 15); - break; + } break; + default: + lua_pushlstring(L, "not_implemented", 15); + break; + } + } else { + switch (f->type()) { + case google::protobuf::FieldDescriptor::TYPE_BOOL: + lua_pushboolean(L, refl->GetBool(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_DOUBLE: + lua_pushnumber(L, refl->GetDouble(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_INT32: + lua_pushinteger(L, refl->GetInt32(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_UINT32: + lua_pushinteger(L, refl->GetUInt32(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_INT64: + lua_pushinteger(L, refl->GetInt64(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_UINT64: + lua_pushinteger(L, refl->GetUInt64(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_ENUM: + lua_pushinteger(L, refl->GetEnumValue(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_STRING: { + const std::string& s = refl->GetString(*p, f); + lua_pushlstring(L, s.c_str(), s.size()); + } break; + case google::protobuf::FieldDescriptor::TYPE_MESSAGE: + lua_newtable(L); + _message_to_table(L, &refl->GetMessage(*p, f)); + break; + default: + lua_pushlstring(L, "not_implemented", 15); + break; + } } - lua_rawset(L, -3); } } @@ -480,43 +551,7 @@ static int l_broker_event_next(lua_State* L) { return 0; } } - - const std::string& entry_name = f->name(); - lua_pushlstring(L, entry_name.c_str(), entry_name.size()); - switch (f->type()) { - case google::protobuf::FieldDescriptor::TYPE_BOOL: - lua_pushboolean(L, refl->GetBool(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_DOUBLE: - lua_pushnumber(L, refl->GetDouble(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_INT32: - lua_pushinteger(L, refl->GetInt32(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_UINT32: - lua_pushinteger(L, refl->GetUInt32(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_INT64: - lua_pushinteger(L, refl->GetInt64(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_UINT64: - lua_pushinteger(L, refl->GetUInt64(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_ENUM: - lua_pushinteger(L, refl->GetEnumValue(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_STRING: { - const std::string& s = refl->GetString(*p, f); - lua_pushlstring(L, s.c_str(), s.size()); - } break; - case google::protobuf::FieldDescriptor::TYPE_MESSAGE: { - std::string s{"Protobuf message"}; - lua_pushlstring(L, s.c_str(), s.size()); - } break; - default: - lua_pushlstring(L, "not implemented", 15); - break; - } + _write_item(L, p, f); return 2; } } @@ -686,50 +721,8 @@ static int l_broker_event_index(lua_State* L) { if (!refl->GetOneofFieldDescriptor(*p, oof)) return 0; } - const std::string& entry_name = f->name(); - lua_pushlstring(L, entry_name.c_str(), entry_name.size()); - switch (f->type()) { - case google::protobuf::FieldDescriptor::TYPE_BOOL: - lua_pushboolean(L, refl->GetBool(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_DOUBLE: - lua_pushnumber(L, refl->GetDouble(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_INT32: - lua_pushinteger(L, refl->GetInt32(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_UINT32: - lua_pushinteger(L, refl->GetUInt32(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_INT64: - lua_pushinteger(L, refl->GetInt64(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_UINT64: - lua_pushinteger(L, refl->GetUInt64(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_ENUM: - lua_pushinteger(L, refl->GetEnumValue(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_STRING: { - const std::string& s = refl->GetString(*p, f); - lua_pushlstring(L, s.c_str(), s.size()); - } break; - case google::protobuf::FieldDescriptor::TYPE_MESSAGE: - if (f->is_repeated()) { - size_t s = refl->FieldSize(*p, f); - // const google::protobuf::Message& msg = refl->GetMessage(*p, f); - lua_newtable(L); - for (size_t i = 0; i < s; i++) { - lua_newtable(L); - _message_to_table(L, &refl->GetRepeatedMessage(*p, f, i)); - lua_rawseti(L, -2, i + 1); - } - } - break; - default: - lua_pushlstring(L, "not_implemented", 15); - break; - } + + _write_item(L, p, f); return 1; } } diff --git a/broker/lua/src/broker_utils.cc b/broker/lua/src/broker_utils.cc index ffc374521ee..b01023ba247 100644 --- a/broker/lua/src/broker_utils.cc +++ b/broker/lua/src/broker_utils.cc @@ -136,6 +136,7 @@ static void escape_str(const char* content, std::ostringstream& oss) { static void _message_to_json(std::ostringstream& oss, const google::protobuf::Message* p) { + std::string tmpl; const google::protobuf::Descriptor* desc = p->GetDescriptor(); const google::protobuf::Reflection* refl = p->GetReflection(); for (int i = 0; i < desc->field_count(); i++) { @@ -147,38 +148,86 @@ static void _message_to_json(std::ostringstream& oss, } } const std::string& entry_name = f->name(); - if (i > 0) - oss << ", "; - switch (f->type()) { - case google::protobuf::FieldDescriptor::TYPE_BOOL: - oss << fmt::format("\"{}\":{}", entry_name, refl->GetBool(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_DOUBLE: - oss << fmt::format("\"{}\":{}", entry_name, refl->GetDouble(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_INT32: - oss << fmt::format("\"{}\":{}", entry_name, refl->GetInt32(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_UINT32: - oss << fmt::format("\"{}\":{}", entry_name, refl->GetUInt32(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_INT64: - oss << fmt::format("\"{}\":{}", entry_name, refl->GetInt64(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_UINT64: - oss << fmt::format("\"{}\":{}", entry_name, refl->GetUInt64(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_ENUM: - oss << fmt::format("\"{}\":{}", entry_name, refl->GetEnumValue(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_STRING: - oss << fmt::format("\"{}\":\"{}\"", entry_name, refl->GetString(*p, f)); - break; - case google::protobuf::FieldDescriptor::TYPE_MESSAGE: - oss << fmt::format("\"{}\":", entry_name); - if (f->is_repeated()) { - oss << '['; - size_t s = refl->FieldSize(*p, f); + if (f->is_repeated()) { + size_t s = refl->FieldSize(*p, f); + if (i > 0) + oss << ", "; + switch (f->type()) { + case google::protobuf::FieldDescriptor::TYPE_BOOL: + oss << fmt::format("\"{}\":[", entry_name); + for (size_t j = 0; j < s; j++) { + if (j > 0) + oss << ","; + oss << refl->GetRepeatedBool(*p, f, j); + } + oss << ']'; + break; + case google::protobuf::FieldDescriptor::TYPE_DOUBLE: + oss << fmt::format("\"{}\":[", entry_name); + for (size_t j = 0; j < s; j++) { + if (j > 0) + oss << ","; + oss << refl->GetRepeatedDouble(*p, f, j); + } + oss << ']'; + break; + case google::protobuf::FieldDescriptor::TYPE_INT32: + oss << fmt::format("\"{}\":[", entry_name); + for (size_t j = 0; j < s; j++) { + if (j > 0) + oss << ","; + oss << refl->GetRepeatedInt32(*p, f, j); + } + oss << ']'; + break; + case google::protobuf::FieldDescriptor::TYPE_UINT32: + oss << fmt::format("\"{}\":[", entry_name); + for (size_t j = 0; j < s; j++) { + if (j > 0) + oss << ","; + oss << refl->GetRepeatedUInt32(*p, f, j); + } + oss << ']'; + break; + case google::protobuf::FieldDescriptor::TYPE_INT64: + oss << fmt::format("\"{}\":[", entry_name); + for (size_t j = 0; j < s; j++) { + if (j > 0) + oss << ","; + oss << refl->GetRepeatedInt64(*p, f, j); + } + oss << ']'; + break; + case google::protobuf::FieldDescriptor::TYPE_UINT64: + oss << fmt::format("\"{}\":[", entry_name); + for (size_t j = 0; j < s; j++) { + if (j > 0) + oss << ","; + oss << refl->GetRepeatedUInt64(*p, f, j); + } + oss << ']'; + break; + case google::protobuf::FieldDescriptor::TYPE_ENUM: + oss << fmt::format("\"{}\":[", entry_name); + for (size_t j = 0; j < s; j++) { + if (j > 0) + oss << ","; + oss << refl->GetRepeatedEnumValue(*p, f, j); + } + oss << ']'; + break; + case google::protobuf::FieldDescriptor::TYPE_STRING: + oss << fmt::format("\"{}\":[", entry_name); + for (size_t j = 0; j < s; j++) { + if (j > 0) + oss << ","; + oss << "\"" << refl->GetRepeatedStringReference(*p, f, j, &tmpl) + << "\""; + } + oss << ']'; + break; + case google::protobuf::FieldDescriptor::TYPE_MESSAGE: + oss << fmt::format("\"{}\":[", entry_name); for (size_t i = 0; i < s; i++) { if (i > 0) oss << ", "; @@ -187,12 +236,52 @@ static void _message_to_json(std::ostringstream& oss, oss << '}'; } oss << ']'; - } - break; - default: // Error, a type not handled - throw msg_fmt( - "protobuf {} type ID is not handled in the broker json converter", - f->type()); + break; + default: // Error, a type not handled + throw msg_fmt( + "protobuf {} type ID is not handled in the broker json converter", + f->type()); + } + } else { + if (i > 0) + oss << ", "; + switch (f->type()) { + case google::protobuf::FieldDescriptor::TYPE_BOOL: + oss << fmt::format("\"{}\":{}", entry_name, refl->GetBool(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_DOUBLE: + oss << fmt::format("\"{}\":{}", entry_name, refl->GetDouble(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_INT32: + oss << fmt::format("\"{}\":{}", entry_name, refl->GetInt32(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_UINT32: + oss << fmt::format("\"{}\":{}", entry_name, refl->GetUInt32(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_INT64: + oss << fmt::format("\"{}\":{}", entry_name, refl->GetInt64(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_UINT64: + oss << fmt::format("\"{}\":{}", entry_name, refl->GetUInt64(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_ENUM: + oss << fmt::format("\"{}\":{}", entry_name, + refl->GetEnumValue(*p, f)); + break; + case google::protobuf::FieldDescriptor::TYPE_STRING: + oss << fmt::format("\"{}\":\"{}\"", entry_name, + refl->GetStringReference(*p, f, &tmpl)); + break; + case google::protobuf::FieldDescriptor::TYPE_MESSAGE: + oss << fmt::format("\"{}\":{{", entry_name); + _message_to_json(oss, &refl->GetMessage(*p, f)); + oss << '}'; + break; + default: // Error, a type not handled + throw msg_fmt( + "protobuf {} type ID is not handled in the broker json converter", + f->type()); + } } } } diff --git a/broker/lua/test/lua.cc b/broker/lua/test/lua.cc index 23303aac54a..8b147e91c4c 100644 --- a/broker/lua/test/lua.cc +++ b/broker/lua/test/lua.cc @@ -23,6 +23,9 @@ #include #include "../../core/test/test_server.hh" +#include "bbdo/remove_graph_message.pb.h" +#include "bbdo/storage/index_mapping.hh" +#include "bbdo/storage/metric_mapping.hh" #include "bbdo/storage/status.hh" #include "com/centreon/broker/config/applier/init.hh" #include "com/centreon/broker/config/applier/modules.hh" @@ -1023,7 +1026,7 @@ TEST_F(LuaTest, IndexMetricCacheTest) { hst->host_id = 1; hst->host_name = "host1"; _cache->write(hst); - std::shared_ptr im(new storage::index_mapping); + auto im{std::make_shared()}; im->index_id = 7; im->service_id = 14; im->host_id = 1; @@ -1129,7 +1132,7 @@ TEST_F(LuaTest, InstanceNameCacheTest) { TEST_F(LuaTest, MetricMappingCacheTestV1) { std::map conf; std::string filename("/tmp/cache_test.lua"); - std::shared_ptr mm(new storage::metric_mapping); + auto mm{std::make_shared()}; mm->index_id = 19; mm->metric_id = 27; _cache->write(mm); @@ -1156,10 +1159,10 @@ TEST_F(LuaTest, MetricMappingCacheTestV1) { TEST_F(LuaTest, MetricMappingCacheTestV2) { config::applier::modules modules; - modules.load_file("./lib/20-storage.so"); + modules.load_file("./lib/20-unified_sql.so"); std::map conf; std::string filename("/tmp/cache_test.lua"); - std::shared_ptr mm(new storage::metric_mapping); + auto mm{std::make_shared()}; mm->index_id = 19; mm->metric_id = 27; _cache->write(mm); @@ -3274,6 +3277,8 @@ TEST_F(LuaTest, BrokerApi2PbServiceStatusWithNext) { obj.set_check_interval(7); obj.set_check_type(Service_CheckType_ACTIVE); obj.set_last_check(123459); + obj.set_internal_id(314159265); + obj.set_icon_id(358979); TagInfo* tag = obj.mutable_tags()->Add(); tag->set_id(24); tag->set_type(SERVICECATEGORY); @@ -3296,6 +3301,7 @@ TEST_F(LuaTest, BrokerApi2PbServiceStatusWithNext) { auto binding{std::make_unique(filename, conf, *_cache)}; binding->write(svc); std::string lst(ReadFile("/tmp/event_log")); + std::cout << lst << std::endl; ASSERT_NE(lst.find("description => foo bar"), std::string::npos); ASSERT_NE(lst.find("check_command => super command"), std::string::npos); ASSERT_NE(lst.find("output => cool"), std::string::npos); @@ -3305,7 +3311,9 @@ TEST_F(LuaTest, BrokerApi2PbServiceStatusWithNext) { ASSERT_NE(lst.find("service_id => 288"), std::string::npos); ASSERT_NE(lst.find("host_id => 1899"), std::string::npos); ASSERT_NE(lst.find("last_check => 123459"), std::string::npos); - ASSERT_NE(lst.find("tags => Protobuf message"), std::string::npos); + ASSERT_NE(lst.find("tags => table:"), std::string::npos); + ASSERT_NE(lst.find("internal_id => 314159265"), std::string::npos); + ASSERT_NE(lst.find("icon_id => 358979"), std::string::npos); RemoveFile(filename); RemoveFile("/tmp/event_log"); } @@ -4179,3 +4187,115 @@ TEST_F(LuaTest, HostStatusObjectMatchBetweenBbdoVersions) { RemoveFile(filename); RemoveFile("/tmp/log"); } + +using pb_remove_graph_message = + io::protobuf; + +TEST_F(LuaTest, PbRemoveGraphMessage) { + config::applier::modules modules; + modules.load_file("./lib/20-unified_sql.so"); + + std::map conf; + std::string filename("/tmp/test_remove_graph.lua"); + auto rm{std::make_shared()}; + rm->mut_obj().add_index_ids(2); + rm->mut_obj().add_index_ids(3); + rm->mut_obj().add_index_ids(5); + rm->mut_obj().add_metric_ids(7); + rm->mut_obj().add_metric_ids(11); + + CreateScript( + filename, + "broker_api_version = 1\n" + "function init(conf)\n" + " broker_log:set_parameters(3, '/tmp/log')\n" + "end\n\n" + "function write(d)\n" + " broker_log:info(1, 'remove_graph...' .. broker.json_encode(d))\n" + " return true\n" + "end\n"); + auto binding{std::make_unique(filename, conf, *_cache)}; + binding->write(rm); + std::string lst(ReadFile("/tmp/log")); + std::cout << lst << std::endl; + ASSERT_NE(lst.find("\"metric_ids\":[7,11]"), std::string::npos); + ASSERT_NE(lst.find("\"index_ids\":[2,3,5]"), std::string::npos); + RemoveFile(filename); + RemoveFile("/tmp/log"); +} + +TEST_F(LuaTest, PbRemoveGraphMessageV2) { + config::applier::modules modules; + modules.load_file("./lib/20-unified_sql.so"); + + std::map conf; + std::string filename("/tmp/test_remove_graph.lua"); + auto rm{std::make_shared()}; + rm->mut_obj().add_index_ids(2); + rm->mut_obj().add_index_ids(3); + rm->mut_obj().add_index_ids(5); + rm->mut_obj().add_metric_ids(7); + rm->mut_obj().add_metric_ids(11); + + CreateScript( + filename, + "broker_api_version = 2\n" + "function init(conf)\n" + " broker_log:set_parameters(3, '/tmp/log')\n" + "end\n\n" + "function write(d)\n" + " broker_log:info(1, 'remove_graph...' .. broker.json_encode(d))\n" + " return true\n" + "end\n"); + auto binding{std::make_unique(filename, conf, *_cache)}; + binding->write(rm); + std::string lst(ReadFile("/tmp/log")); + std::cout << lst << std::endl; + ASSERT_NE(lst.find("\"metric_ids\":[7,11]"), std::string::npos); + ASSERT_NE(lst.find("\"index_ids\":[2,3,5]"), std::string::npos); + RemoveFile(filename); + RemoveFile("/tmp/log"); +} + +TEST_F(LuaTest, BrokerApi2PbRemoveGraphMessageWithNext) { + config::applier::modules modules; + modules.load_file("./lib/20-unified_sql.so"); + std::map conf; + std::string filename("/tmp/test_remove_graph_with_next.lua"); + auto rm{std::make_shared()}; + rm->mut_obj().add_index_ids(2); + rm->mut_obj().add_index_ids(3); + rm->mut_obj().add_index_ids(5); + rm->mut_obj().add_metric_ids(7); + rm->mut_obj().add_metric_ids(11); + + CreateScript(filename, + "broker_api_version = 2\n" + "function init(conf)\n" + " broker_log:set_parameters(3, '/tmp/event_log')\n" + "end\n\n" + "function write(d)\n" + " for i,v in pairs(d) do\n" + " broker_log:info(0, i .. ' => ' .. tostring(v))\n" + " end\n" + " for i,v in pairs(d.index_ids) do\n" + " broker_log:info(0, ' ' .. i .. ' => ' .. tostring(v))\n" + " end\n" + " return true\n" + "end\n"); + auto binding{std::make_unique(filename, conf, *_cache)}; + binding->write(rm); + std::string lst(ReadFile("/tmp/event_log")); + std::cout << lst << std::endl; + ASSERT_NE(lst.find("_type => 196616"), std::string::npos); + ASSERT_NE(lst.find("category => 3"), std::string::npos); + ASSERT_NE(lst.find("element => 8"), std::string::npos); + ASSERT_NE(lst.find("index_ids => table:"), std::string::npos); + ASSERT_NE(lst.find("metric_ids => table:"), std::string::npos); + ASSERT_NE(lst.find(" 1 => 2"), std::string::npos); + ASSERT_NE(lst.find(" 2 => 3"), std::string::npos); + ASSERT_NE(lst.find(" 3 => 5"), std::string::npos); + RemoveFile(filename); + RemoveFile("/tmp/event_log"); +} diff --git a/ci/debian-collect/copyright b/ci/debian-collect/copyright index 4f3f1140e99..87bbe9a8c03 100644 --- a/ci/debian-collect/copyright +++ b/ci/debian-collect/copyright @@ -4,11 +4,11 @@ Upstream-Contact: Luiz Costa Source: https://www.centreon.com Files: * -Copyright: 2021 Centreon +Copyright: 2023 Centreon License: Apache-2.0 Files: debian/* -Copyright: 2021 Centreon +Copyright: 2023 Centreon License: Apache-2.0 License: Apache-2.0 diff --git a/ci/debian-gorgone/centreon-gorgone.dirs b/ci/debian-gorgone/centreon-gorgone.dirs deleted file mode 100644 index 326d08ce2ea..00000000000 --- a/ci/debian-gorgone/centreon-gorgone.dirs +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index 664fd3010ed..00000000000 --- a/ci/debian-gorgone/centreon-gorgone.install +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index e6f56b7475f..00000000000 --- a/ci/debian-gorgone/centreon-gorgone.logrotate +++ /dev/null @@ -1,10 +0,0 @@ -/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 deleted file mode 100644 index 69e8fd4bc53..00000000000 --- a/ci/debian-gorgone/centreon-gorgone.postinst +++ /dev/null @@ -1,67 +0,0 @@ -#!/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 deleted file mode 100644 index 47f0700cf2f..00000000000 --- a/ci/debian-gorgone/control +++ /dev/null @@ -1,59 +0,0 @@ -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 deleted file mode 100644 index 9331ebebd3d..00000000000 --- a/ci/debian-gorgone/copyright +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index d6fb7a6ebe2..00000000000 --- a/ci/debian-gorgone/extra/gorgoned +++ /dev/null @@ -1,6 +0,0 @@ -# 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 deleted file mode 100644 index a226b0256c4..00000000000 --- a/ci/debian-gorgone/extra/gorgoned.service +++ /dev/null @@ -1,33 +0,0 @@ -## -## 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 deleted file mode 100644 index 95af63e770c..00000000000 --- a/ci/debian-gorgone/rules +++ /dev/null @@ -1,11 +0,0 @@ -#!/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 deleted file mode 100644 index 163aaf8d82b..00000000000 --- a/ci/debian-gorgone/source/format +++ /dev/null @@ -1 +0,0 @@ -3.0 (quilt) diff --git a/ci/debian-gorgone/substvars b/ci/debian-gorgone/substvars deleted file mode 100644 index 929c65b6607..00000000000 --- a/ci/debian-gorgone/substvars +++ /dev/null @@ -1 +0,0 @@ -centreon:version= diff --git a/ci/docker/Dockerfile.collect-alma8 b/ci/docker/Dockerfile.collect-alma8 index 793428839d0..b5b91de789b 100644 --- a/ci/docker/Dockerfile.collect-alma8 +++ b/ci/docker/Dockerfile.collect-alma8 @@ -1,4 +1,6 @@ -FROM almalinux:8.5 +ARG REGISTRY_URL + +FROM ${REGISTRY_URL}/almalinux:8 RUN dnf clean all @@ -11,12 +13,18 @@ RUN dnf config-manager --set-enabled powertools RUN curl -o centreon-release.rpm "http://yum-1.centreon.com/standard/21.10/el8/stable/noarch/RPMS/centreon-release-21.10-1.el8.noarch.rpm" RUN dnf install --nogpgcheck centreon-release.rpm RUN dnf config-manager --set-enabled 'centreon-testing*' +RUN curl -LsS "https://r.mariadb.com/downloads/mariadb_repo_setup" | bash -s -- --os-type=rhel --os-version=8 --mariadb-server-version="mariadb-10.5" RUN dnf clean all && dnf install -y cmake \ gcc \ gcc-c++ \ gettext \ git \ MariaDB-devel \ + MariaDB-shared \ + MariaDB-client \ + MariaDB-compat \ + MariaDB-common \ + MariaDB-server \ gnutls-devel \ libgcrypt-devel \ libssh2-devel \ @@ -31,12 +39,11 @@ RUN dnf clean all && dnf install -y cmake \ rpm-build \ rrdtool-devel \ yum-utils \ - MariaDB-shared \ perl \ rpm-build RUN dnf update libarchive -RUN pip3 install conan --prefix=/usr --upgrade +RUN pip3 install conan==1.57.0 --prefix=/usr --upgrade RUN rm -rf ~/.conan/profiles/default COPY conanfile.txt . RUN cat conanfile.txt diff --git a/ci/docker/Dockerfile.collect-centos7 b/ci/docker/Dockerfile.collect-centos7 index ea06641e271..a3b777c1a55 100644 --- a/ci/docker/Dockerfile.collect-centos7 +++ b/ci/docker/Dockerfile.collect-centos7 @@ -1,4 +1,7 @@ -FROM centos:7 +ARG REGISTRY_URL + +FROM ${REGISTRY_URL}/centos:7 + RUN curl https://downloads.mariadb.com/MariaDB/mariadb-10.5.8/yum/centos7-amd64/rpms/MariaDB-shared-10.5.8-1.el7.centos.x86_64.rpm --output MariaDB-shared-10.5.8-1.el7.centos.x86_64.rpm && \ curl https://downloads.mariadb.com/MariaDB/mariadb-10.5.8/yum/centos7-amd64/rpms/MariaDB-common-10.5.8-1.el7.centos.x86_64.rpm --output MariaDB-common-10.5.8-1.el7.centos.x86_64.rpm && \ curl https://downloads.mariadb.com/MariaDB/mariadb-10.5.8/yum/centos7-amd64/rpms/MariaDB-compat-10.5.8-1.el7.centos.x86_64.rpm --output MariaDB-compat-10.5.8-1.el7.centos.x86_64.rpm && \ @@ -46,7 +49,7 @@ 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 && \ - pip3 install conan --upgrade &&\ + pip3 install conan==1.57.0 --upgrade &&\ /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 diff --git a/ci/docker/Dockerfile.collect-debian-bullseye b/ci/docker/Dockerfile.collect-debian-bullseye index a6227f8cd93..ffa52a01640 100644 --- a/ci/docker/Dockerfile.collect-debian-bullseye +++ b/ci/docker/Dockerfile.collect-debian-bullseye @@ -1,6 +1,9 @@ -FROM debian:bullseye +ARG REGISTRY_URL + +FROM ${REGISTRY_URL}/debian:bullseye + RUN apt-get -y update && \ - apt-get -y install cmake \ + apt-get -y install cmake \ curl \ gcc \ g++ \ @@ -29,12 +32,10 @@ RUN apt-get -y update && \ 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 pip3 install conan==1.57.0 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-buster b/ci/docker/Dockerfile.collect-debian-buster deleted file mode 100644 index eaebb6b6447..00000000000 --- a/ci/docker/Dockerfile.collect-debian-buster +++ /dev/null @@ -1,46 +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 \ - libgcrypt20-dev \ - dh-make \ - aptitude \ - lintian \ - pbuilder \ - quilt \ - git-buildpackage \ - debmake \ - devscripts \ - fakeroot \ - dwz \ - 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 dpkg -i cmake_3.18.4-2+deb11u1~bpo10+1_amd64.deb cmake-data_3.18.4-2+deb11u1~bpo10+1_all.deb -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.gorgone-alma8 b/ci/docker/Dockerfile.gorgone-alma8 deleted file mode 100644 index f3bd7f4352f..00000000000 --- a/ci/docker/Dockerfile.gorgone-alma8 +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index 721da1fc189..00000000000 --- a/ci/docker/Dockerfile.gorgone-centos7 +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 587d3c37610..00000000000 --- a/ci/docker/Dockerfile.gorgone-debian-bullseye +++ /dev/null @@ -1,30 +0,0 @@ -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/scripts/collect-deb-package.sh b/ci/scripts/collect-deb-package.sh index d6602c718c4..e7712db98b6 100755 --- a/ci/scripts/collect-deb-package.sh +++ b/ci/scripts/collect-deb-package.sh @@ -12,8 +12,8 @@ fi echo "############################# PACKAGING COLLECT ################################" -AUTHOR="Luiz Costa" -AUTHOR_EMAIL="me@luizgustavo.pro.br" +AUTHOR="Centreon" +AUTHOR_EMAIL="contact@centreon.com" # fix version to debian format accept VERSION="$(echo $VERSION | sed 's/-/./g')" @@ -26,7 +26,13 @@ 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" +echo "debmake begin" +debmake -f "${AUTHOR}" -e "${AUTHOR_EMAIL}" -u "$VERSION" -r "$RELEASE" +echo "version de dwz" +/usr/bin/dwz -v +echo "version de gcc" +gcc --version +echo "version de ld" +ld --version debuild-pbuilder cd ../ diff --git a/ci/scripts/collect-test-robot.sh b/ci/scripts/collect-test-robot.sh index dedcaa2bb49..e4b2d060fa2 100755 --- a/ci/scripts/collect-test-robot.sh +++ b/ci/scripts/collect-test-robot.sh @@ -1,21 +1,21 @@ #!/bin/bash set -e +set -x export RUN_ENV=docker -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 ############################" -cd /src/tests/ 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';" @@ -23,41 +23,43 @@ mysql -e "GRANT SELECT,UPDATE,DELETE,INSERT,CREATE,DROP,INDEX,ALTER,LOCK TABLES, mysql -u centreon -pcentreon < resources/centreon_storage.sql mysql -u centreon -pcentreon < resources/centreon.sql -echo "########################### build and install centreon collect ############################" - -rm -rf /src/build -mkdir /src/build -cd /src/build/ -DISTRIB=$(lsb_release -rs | cut -f1 -d.) -if [ "$DISTRIB" = "7" ] ; then - source /opt/rh/devtoolset-9/enable -fi -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_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF .. -else - CXXFLAGS="-Wall -Wextra" cmake3 -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF .. -fi +echo "########################## Install centreon collect ###########################" -#Build -make -j9 -make -j9 install +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 -yum install "Development Tools" python3-devel -y - -pip3 install grpcio==1.33.2 grpcio_tools==1.33.2 +yum groupinstall "Development Tools" -y +yum install python3-devel -y + +# Get OS version id +VERSION_ID=$(grep '^VERSION_ID' /etc/os-release | sed -En 's/^VERSION_ID="([[:digit:]])\.[[:digit:]]"/\1/p') + +# Force version for el7 only +if [ -f /etc/os-release ]; then + case "$VERSION_ID" in + 7) + pip3 install grpcio==1.33.2 grpcio_tools==1.33.2 + ;; + 8) + pip3 install grpcio grpcio_tools + ;; + *) + echo "OS Version is neither 7 or 8" + ;; + esac +fi ./init-proto.sh -echo "########################### run centreon collect test robot ############################" +echo "####################### Run Centreon Collect Robot Tests #######################" cd /src/tests/ robot --nostatusrc . -echo "########################### generate folder report ############################" +echo "########################### Generate Folder Report #############################" mkdir reports cp log.html output.xml report.html reports diff --git a/ci/scripts/gorgone-deb-package.sh b/ci/scripts/gorgone-deb-package.sh deleted file mode 100755 index 27a27742e5b..00000000000 --- a/ci/scripts/gorgone-deb-package.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/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 deleted file mode 100755 index fd23c427b5f..00000000000 --- a/ci/scripts/gorgone-rpm-package.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/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 d318889532c..2187d92b5c3 100755 --- a/cmake.sh +++ b/cmake.sh @@ -10,6 +10,7 @@ This program build Centreon-broker -r|--release : Build on release mode -fcr|--force-conan-rebuild : rebuild conan data -ng : C++17 standard + -clang : Compilation with clang++ -h|--help : help EOF } @@ -26,6 +27,10 @@ for i in $(cat conanfile.txt) ; do done STD=14 +COMPILER=gcc +LIBCXX=libstdc++11 +WITH_CLANG=OFF +EE= for i in "$@" do @@ -45,6 +50,13 @@ do BUILD_TYPE="Release" shift ;; + -clang) + COMPILER=clang + WITH_CLANG=ON + STD=14 + EE="-e CXX=/usr/bin/clang++ -e CC=/usr/bin/clang -e:b CXX=/usr/bin/clang++ -e:b CC=/usr/bin/clang" + shift + ;; -fcr|--force-conan-rebuild) echo "Forced conan rebuild" CONAN_REBUILD="1" @@ -242,12 +254,12 @@ elif [ -r /etc/issue ] ; then fi fi -pip3 install conan --upgrade +pip3 install conan==1.57.0 --upgrade -if [[ "$my_id" == 0 ]] ; then - conan='/usr/local/bin/conan' -elif which conan ; then +if which conan ; then conan=$(which conan) +elif [[ -x /usr/local/bin/conan ]] ; then + conan='/usr/local/bin/conan' else conan="$HOME/.local/bin/conan" fi @@ -266,12 +278,15 @@ cd build if [[ "$maj" == "centos7" ]] ; then rm -rf ~/.conan/profiles/default if [[ "$CONAN_REBUILD" == "1" ]] ; then - $conan install .. -s compiler.cppstd=$STD -s compiler.libcxx=libstdc++11 --build="*" + echo $conan install .. -pr:b=default -s compiler=$COMPILER -s compiler.cppstd=$STD -s compiler.libcxx=$LIBCXX $EE --build="*" + $conan install .. -pr:b=default -s compiler=$COMPILER -s compiler.cppstd=$STD -s compiler.libcxx=$LIBCXX $EE --build="*" else - $conan install .. -s compiler.cppstd=$STD -s compiler.libcxx=libstdc++11 --build=missing + echo $conan install .. -pr:b=default -s compiler=$COMPILER -s compiler.cppstd=$STD -s compiler.libcxx=$LIBCXX $EE --build=missing + $conan install .. -pr:b=default -s compiler=$COMPILER -s compiler.cppstd=$STD -s compiler.libcxx=$LIBCXX $EE --build=missing fi else - $conan install .. -s compiler.cppstd=$STD -s compiler.libcxx=libstdc++11 --build=missing + echo $conan install .. -pr:b=default -s compiler=$COMPILER -s compiler.libcxx=$LIBCXX -s compiler.cppstd=$STD $EE --build=missing + $conan install .. -pr:b=default -s compiler=$COMPILER -s compiler.libcxx=$LIBCXX -s compiler.cppstd=$STD $EE --build=missing fi if [[ $STD -eq 17 ]] ; then @@ -281,9 +296,9 @@ else fi if [[ "$maj" == "Raspbian" ]] ; then - CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF $NG $* .. + CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CLANG=$WITH_CLANG -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF $NG $* .. elif [[ "$maj" == "Debian" ]] ; then - CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -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_LIB_CLIB=/usr/lib64/ -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF $NG $* .. + CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CLANG=$WITH_CLANG -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -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_LIB_CLIB=/usr/lib64/ -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF $NG $* .. else - CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF -DWITH_CONF=OFF $NG $* .. + CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CLANG=$WITH_CLANG -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF -DWITH_CONF=OFF $NG $* .. fi diff --git a/packaging/rpm/centreon-collect.spec b/packaging/rpm/centreon-collect.spec index d8dc1c391a2..316f6e56274 100644 --- a/packaging/rpm/centreon-collect.spec +++ b/packaging/rpm/centreon-collect.spec @@ -1,17 +1,17 @@ ## -## Copyright 2021 Centreon +## Copyright 2023 Centreon ## Summary: Centreon collect's softwares collection Name: centreon-collect Version: %{VERSION} Release: %{RELEASE}%{?dist} -License: ASL 2.0 +License: Apache-2.0 Source: %{name}-%{version}.tar.gz Source1: centreonengine_integrate_centreon_engine2centreon.sh %define thismajor 22.10.0 -%define nextmajor 22.11.0 +%define nextmajor 23.04.0 Group: Applications/Communications URL: https://github.com/centreon/centreon-collect.git @@ -44,6 +44,7 @@ Requires: centreon-connector = %{version}-%{release} %package -n centreon-clib Summary: Centreon core library. Group: Development/Libraries +License: Apache-2.0 %description -n centreon-clib Centreon Clib is a common library for all Centreon @@ -52,6 +53,7 @@ products written in C/C++. %package -n centreon-clib-devel Summary: Provide include files for Centreon Clib. Group: Development/Libraries +License: Apache-2.0 %description -n centreon-clib-devel Centreon Clib devel provide include files to build @@ -61,6 +63,7 @@ Centreon products written in C/C++. %package -n centreon-engine Summary: Centreon Engine monitoring core. Group: Applications/System +License: Apache-2.0 Requires: centreon-engine-daemon = %{version}-%{release} Requires: centreon-engine-extcommands = %{version}-%{release} @@ -72,6 +75,7 @@ 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 +License: Apache-2.0 Requires: centreon-clib = %{version}-%{release} %{?systemd_requires} @@ -83,6 +87,7 @@ 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 +License: Apache-2.0 Requires: centreon-engine-daemon = %{version}-%{release} %description -n centreon-engine-extcommands @@ -95,6 +100,7 @@ engine daemon. %package -n centreon-engine-devel Summary: Provide include files for Centreon Engine. Group: Application/System +License: Apache-2.0 Requires: centreon-clib-devel = %{version}-%{release} %description -n centreon-engine-devel @@ -105,6 +111,7 @@ Modules or Centreon Engine Connector. %package -n centreon-engine-bench Summary: Centreon Engine benchmarking tools. Group: Application/System +License: Apache-2.0 Requires: centreon-clib = %{version}-%{release} %description -n centreon-engine-bench @@ -114,6 +121,7 @@ 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 +License: Apache-2.0 Requires: centreon-connector-perl = %{version}-%{release} Requires: centreon-connector-ssh = %{version}-%{release} @@ -125,6 +133,7 @@ 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 +License: Apache-2.0 Requires: centreon-clib = %{version}-%{release} Requires: perl @@ -136,6 +145,7 @@ a monitoring engine. %package -n centreon-connector-ssh Summary: Centreon Connector SSH provide persistante connection between checks. Group: Application/System +License: Apache-2.0 Requires: centreon-clib = %{version}-%{release} Requires: libgcrypt @@ -146,6 +156,7 @@ Centreon Connector SSH provide persistante connection between checks. %package -n centreon-broker Summary: Store Centreon Engine/Nagios events in a database. Group: Applications/Communications +License: Apache-2.0 Requires: centreon-common >= %{thismajor} Requires: centreon-common < %{nextmajor} Requires: coreutils @@ -158,6 +169,7 @@ one or multiple databases. %package -n centreon-broker-core Summary: Centreon Broker's shared library. Group: Applications/Communications +License: Apache-2.0 Requires: gnutls >= 3.3.29 Requires: lua Requires: centreon-broker = %{version}-%{release} @@ -170,6 +182,7 @@ 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 +License: Apache-2.0 Requires: centreon-broker-core = %{version}-%{release} %description -n centreon-broker-storage @@ -179,6 +192,7 @@ storage holds Centreon Broker's prefdata storage. %package -n centreon-broker-graphite Summary: Write Centreon performance data to Graphite. Group: Applications/Communications +License: Apache-2.0 Requires: centreon-broker-core = %{version}-%{release} %description -n centreon-broker-graphite @@ -190,6 +204,7 @@ database. %package -n centreon-broker-influxdb Summary: Write Centreon performance data to InfluxDB. Group: Applications/Communications +License: Apache-2.0 Requires: centreon-broker-core = %{version}-%{release} %description -n centreon-broker-influxdb @@ -201,6 +216,7 @@ database. %package -n centreon-broker-cbd Summary: Centreon Broker daemon. Group: System Environment/Daemons +License: Apache-2.0 Requires: centreon-broker-core = %{version}-%{release} %{?systemd_requires} @@ -211,6 +227,7 @@ events in a DB from a single point. %package -n centreon-broker-cbmod Summary: Centreon Broker as Centreon Engine 2 module. Group: Applications/Communications +License: Apache-2.0 Requires: centreon-broker-core = %{version}-%{release} Requires: centreon-engine = %{version}-%{release} @@ -221,6 +238,7 @@ This module can be loaded by Centreon Engine. %package -n centreon-broker-devel Summary: Centreon Broker devel libraries. Group: Applications/Communications +License: Apache-2.0 %description -n centreon-broker-devel Include files needed to develop a module Centreon Broker. @@ -229,6 +247,7 @@ Include files needed to develop a module Centreon Broker. %package -n centreon-collect-client Summary: Centreon Collect gRPC Client. It can be used to exchange with cbd or centengine Group: Applications/Communications +License: Apache-2.0 Requires: centreon-broker-core = %{version}-%{release} Requires: centreon-engine = %{version}-%{release} @@ -241,7 +260,7 @@ centengine. %setup -q -n %{name}-%{version} %build -pip3 install conan --upgrade +pip3 install conan==1.57.0 --upgrade conan install . -s compiler.cppstd=14 -s compiler.libcxx=libstdc++11 --build=missing cmake3 \ diff --git a/tests/resources/Broker.py b/tests/resources/Broker.py index adb8da003a5..41427d2ac7a 100755 --- a/tests/resources/Broker.py +++ b/tests/resources/Broker.py @@ -967,7 +967,7 @@ def check_broker_stats_exist(name, key1, key2, timeout=TIMEOUT): else: filename = "central-rrd-master-stats.json" retry = True - while retry: + while retry and time.time() < limit: retry = False f = open(VAR_ROOT + "/lib/centreon-broker/{}".format(filename), "r") buf = f.read() @@ -995,7 +995,7 @@ def get_broker_stats_size(name, key, timeout=TIMEOUT): else: filename = "central-rrd-master-stats.json" retry = True - while retry: + while retry and time.time() < limit: retry = False f = open(VAR_ROOT + "/lib/centreon-broker/{}".format(filename), "r") buf = f.read() diff --git a/tests/resources/Common.py b/tests/resources/Common.py index e3c763c8627..123ee45101f 100644 --- a/tests/resources/Common.py +++ b/tests/resources/Common.py @@ -1,5 +1,5 @@ from robot.api import logger -from subprocess import getoutput +from subprocess import getoutput, Popen, DEVNULL import re import os import time @@ -151,17 +151,24 @@ def run_env(): def start_mysql(): if not run_env(): + logger.console("Starting Mariadb with systemd") getoutput("systemctl start mysql") + logger.console("Mariadb started with systemd") else: - getoutput("mariadbd --user=root > /dev/null 2>&1 &") + logger.console("Starting Mariadb directly") + Popen(["mariadbd", "--user=root"], stdout=DEVNULL, stderr=DEVNULL) + logger.console("Mariadb directly started") def stop_mysql(): if not run_env(): + logger.console("Stopping Mariadb with systemd") getoutput("systemctl stop mysql") + logger.console("Mariadb stopped with systemd") else: - getoutput( - "kill -9 $(ps aux | grep 'mariadbd --user=root' | grep -v grep | awk '{print $2}')") + logger.console("Stopping directly MariaDB") + getoutput("kill -SIGTERM $(pidof mariadbd)") + logger.console("Mariadb directly stopped") def stop_rrdcached():