diff --git a/.github/actions/delivery/action.yml b/.github/actions/delivery/action.yml index ae50e008a75..d76a3c937e8 100644 --- a/.github/actions/delivery/action.yml +++ b/.github/actions/delivery/action.yml @@ -8,7 +8,7 @@ inputs: description: "The distribution used for packaging" required: true version: - description: "Centreon packaged version" + description: "Centreon packaged major version" required: true cache_key: description: "The cached package key" @@ -37,7 +37,7 @@ runs: - name: Build name for DEB shell: bash - if: ${{ inputs.distrib == 'bullseye' }} + if: ${{ contains(fromJSON('["bullseye", "bookworm", "jammy"]'), inputs.distrib) }} run: | echo "extfile=deb" >> $GITHUB_ENV @@ -59,25 +59,19 @@ runs: FILES="*.${{ env.extfile }}" - echo "[DEBUG] - Version: ${{ inputs.version }}" - echo "[DEBUG] - Distrib: ${{ inputs.distrib }}" - - if [ -z "${{ inputs.module_name }}" ]; then - echo "module name is required" - exit 1 - fi - - if [ -z "${{ inputs.distrib }}" ]; then - echo "distrib is required" - exit 1 - fi - # DEBUG echo "[DEBUG] - Version: ${{ inputs.version }}" echo "[DEBUG] - Distrib: ${{ inputs.distrib }}" echo "[DEBUG] - module_name: ${{ inputs.module_name }}" echo "[DEBUG] - release_cloud: ${{ inputs.release_cloud }}" echo "[DEBUG] - release_type: ${{ inputs.release_type }}" + echo "[DEBUG] - stability: ${{ inputs.stability }}" + + # Make sure all required inputs are NOT empty + if [[ -z "${{ inputs.module_name }}" || -z "${{ inputs.distrib }}" || -z ${{ inputs.stability }} || -z ${{ inputs.version }} || -z ${{ inputs.release_cloud }} || -z ${{ inputs.release_type }} ]]; then + echo "Some mandatory inputs are empty, please check the logs." + exit 1 + fi # Create ARCH dirs mkdir noarch x86_64 @@ -94,18 +88,31 @@ runs: done # Build upload target path based on release_cloud and release_type values - # if cloud, deliver to testing- - # if non-cloud, delivery to testing as usual + # if cloud + hotfix or cloud + release, deliver to internal testing- + # if cloud + develop, delivery to internal unstable + # if non-cloud, delivery to onprem testing or unstable + # CLOUD + HOTFIX + REPO STANDARD INTERNAL OR CLOUD + RELEASE + REPO STANDARD INTERNAL - if [[ ${{ inputs.release_cloud }} -eq 1 && ${{ inputs.release_type }} == "hotfix" ]] || [[ ${{ inputs.release_cloud }} -eq 1 && ${{ inputs.release_type }} == "release" ]]; then + if [[ ${{ inputs.release_cloud }} -eq 1 && ( ${{ inputs.release_type }} == "hotfix" || ${{ inputs.release_type }} == "release" ) ]]; then + echo "[DEBUG] : Release cloud + ${{ inputs.release_type }}, using rpm-standard-internal." + ROOT_REPO_PATHS="rpm-standard-internal" + UPLOAD_REPO_PATH="${{ inputs.version }}/${{ inputs.distrib }}/${{ inputs.stability }}-${{ inputs.release_type }}/$ARCH/${{ inputs.module_name }}/" + + # CLOUD + NOT HOTFIX OR CLOUD + NOT RELEASE + REPO STANDARD INTERNAL + elif [[ ${{ inputs.release_cloud }} -eq 1 && ( ${{ inputs.release_type }} != "hotfix" && ${{ inputs.release_type }} != "release" ) ]]; then + echo "[DEBUG] : Release cloud + NOT ${{ inputs.release_type }}, using rpm-standard-internal." ROOT_REPO_PATHS="rpm-standard-internal" - UPLOAD_REPO_PATH="${{ inputs.version }}/${{ inputs.distrib }}/${{ inputs.stability }}-${{ inputs.release_type }}/$ARCH/RPMS/${{ inputs.module_name }}/" + UPLOAD_REPO_PATH="${{ inputs.version }}/${{ inputs.distrib }}/${{ inputs.stability }}-${{ inputs.release_type }}/$ARCH/${{ inputs.module_name }}/" + # NON-CLOUD + (HOTFIX OR RELEASE) + REPO STANDARD elif [[ ${{ inputs.release_cloud }} -eq 0 ]]; then + echo "[DEBUG] : NOT Release cloud + ${{ inputs.release_type }}, using rpm-standard." ROOT_REPO_PATHS="rpm-standard" UPLOAD_REPO_PATH="${{ inputs.version }}/${{ inputs.distrib }}/${{ inputs.stability }}/$ARCH/${{ inputs.module_name }}/" + + # NOT VALID, DO NOT DELIVER else - echo "Invalid combination of release_type and release_cloud" + echo "::error:: Invalid combination of release_type [${{ inputs.release_type }}] and release_cloud [${{ inputs.release_cloud }}]" exit 1 fi @@ -115,8 +122,10 @@ runs: if [ "$(ls -A $ARCH)" ]; then if [ "${{ inputs.stability }}" == "stable" ]; then echo "[DEBUG] - Stability is ${{ inputs.stability }}, not delivering." - else + elif [ "${{ inputs.stability }}" == "testing" ]; then jf rt upload "$ARCH/*.rpm" "$ROOT_REPO_PATH/$UPLOAD_REPO_PATH" --sync-deletes="$ROOT_REPO_PATH/$UPLOAD_REPO_PATH" --flat + else + jf rt upload "$ARCH/*.rpm" "$ROOT_REPO_PATH/${{ inputs.version }}/${{ inputs.distrib }}/${{ inputs.stability }}/$ARCH/${{ inputs.module_name }}/" --sync-deletes="$ROOT_REPO_PATH/${{ inputs.version }}/${{ inputs.distrib }}/${{ inputs.stability }}/$ARCH/${{ inputs.module_name }}/" --flat fi fi done @@ -128,13 +137,17 @@ runs: run: | FILES="*.${{ env.extfile }}" - if [ -z "${{ inputs.module_name }}" ]; then - echo "module name is required" - exit 1 - fi + # DEBUG + echo "[DEBUG] - Version: ${{ inputs.version }}" + echo "[DEBUG] - Distrib: ${{ inputs.distrib }}" + echo "[DEBUG] - module_name: ${{ inputs.module_name }}" + echo "[DEBUG] - release_cloud: ${{ inputs.release_cloud }}" + echo "[DEBUG] - release_type: ${{ inputs.release_type }}" + echo "[DEBUG] - stability: ${{ inputs.stability }}" - if [ -z "${{ inputs.distrib }}" ]; then - echo "distrib is required" + # Make sure all required inputs are NOT empty + if [[ -z "${{ inputs.module_name }}" || -z "${{ inputs.distrib }}" || -z ${{ inputs.stability }} || -z ${{ inputs.version }} || -z ${{ inputs.release_cloud }} || -z ${{ inputs.release_type }} ]]; then + echo "Some mandatory inputs are empty, please check the logs." exit 1 fi @@ -147,6 +160,12 @@ runs: echo "[DEBUG] - Version: $VERSION" - jf rt upload "$FILE" "apt-standard-${{ inputs.version }}-${{ inputs.stability }}/pool/${{ inputs.module_name }}/" --deb "${{ inputs.distrib }}/main/$ARCH" + if [[ "${{ inputs.distrib }}" == "jammy" ]]; then + ROOT_REPO_PATH="ubuntu-standard-${{ inputs.version }}-${{ inputs.stability }}" + else + ROOT_REPO_PATH="apt-standard-${{ inputs.version }}-${{ inputs.stability }}" + fi + + jf rt upload "$FILE" "$ROOT_REPO_PATH/pool/${{ inputs.module_name }}/" --deb "${{ inputs.distrib }}/main/$ARCH" done shell: bash diff --git a/.github/actions/promote-to-stable/action.yml b/.github/actions/promote-to-stable/action.yml index 7d953df3807..0b7ce45c45b 100644 --- a/.github/actions/promote-to-stable/action.yml +++ b/.github/actions/promote-to-stable/action.yml @@ -19,9 +19,6 @@ inputs: stability: description: "The package stability (stable, testing, unstable)" required: true - repository_name: - description: "The repository name" - required: true github_ref_name: description: "Release base ref name for push event" required: true @@ -54,7 +51,7 @@ runs: # Cloud specific promote # delivery by default to onprem, override to internal if base branch is master - if [[ ${{ inputs.github_base_ref }} == "master" ]]; then + if [[ ${{ inputs.github_ref_name }} == "master" ]]; then ROOT_REPO_PATH="rpm-standard-internal" else ROOT_REPO_PATH="rpm-standard" @@ -94,8 +91,6 @@ runs: # Download candidates for promote echo "[DEBUG] - Promoting $ARCH testing artifacts to stable." for ARTIFACT in ${SRC_PATHS[@]}; do - echo "[DEBUG] - Promoting $ARTIFACT to stable on artifactory." - jf rt cp $ARTIFACT $TARGET_PATH --flat=true echo "[DEBUG] - Downloading $ARTIFACT from TESTING." jf rt download $ARTIFACT --flat done @@ -113,14 +108,21 @@ runs: shell: bash - name: Promote DEB packages to stable - if: ${{ startsWith(inputs.distrib, 'bullseye') }} + if: ${{ contains(fromJSON('["bullseye", "bookworm"]'), inputs.distrib) }} run: | + set -eux + echo "[DEBUG] - Major version: ${{ inputs.major_version }}" echo "[DEBUG] - Minor version: ${{ inputs.minor_version }}" echo "[DEBUG] - Distrib: ${{ inputs.distrib }}" + # Define ROOT_REPO_PATH for debian + # There is no cloud ROOT_REPO_PATH for debian, only onprem + # Should there be a need to deploy debian to cloud repositories, please use the same condition as RPM promotion + ROOT_REPO_PATH="apt-standard-${{ inputs.major_version }}" + echo "[DEBUG] - Get path of testing DEB packages to promote to stable." - SRC_PATHS=$(jf rt s --include-dirs apt-standard-${{ inputs.major_version }}-testing/pool/${{ inputs.module_name }}/*.deb | jq -r '.[].path') + SRC_PATHS=$(jf rt search --include-dirs "$ROOT_REPO_PATH-testing/pool/${{ inputs.module_name }}/*${{ inputs.distrib }}*.deb | jq -r '.[].path') if [[ ${SRC_PATHS[@]} ]]; then for SRC_PATH in ${SRC_PATHS[@]}; do @@ -132,7 +134,7 @@ runs: fi echo "[DEBUG] - Build target path." - TARGET_PATH="apt-standard-${{ inputs.major_version }}-${{ inputs.stability }}/pool/${{ inputs.module_name }}/" + TARGET_PATH="$ROOT_REPO_PATH-${{ inputs.stability }}/pool/${{ inputs.module_name }}/" echo "[DEBUG] - Target path: $TARGET_PATH" echo "[DEBUG] - Promoting DEB testing artifacts to stable." @@ -141,7 +143,7 @@ runs: jf rt download $ARTIFACT --flat done - for ARTIFACT_DL in $(dir|grep -E "*.deb"); do + for ARTIFACT_DL in $(dir -1|grep -E ".+${{ inputs.distrib }}.+\.deb"); do ARCH=$(echo $ARTIFACT_DL | cut -d '_' -f3 | cut -d '.' -f1) echo "[DEBUG] - Promoting (upload) $ARTIFACT_DL to stable $TARGET_PATH." jf rt upload "$ARTIFACT_DL" "$TARGET_PATH" --deb "${{ inputs.distrib }}/main/$ARCH" --flat diff --git a/.github/actions/release/action.yml b/.github/actions/release/action.yml index 3b1f84a66cf..f527522462f 100644 --- a/.github/actions/release/action.yml +++ b/.github/actions/release/action.yml @@ -38,14 +38,17 @@ runs: declare -a PREVIOUS_STABLE_TAGS=() SCOPE_VERSION="COLLECT" MINOR_VERSION_FILE_PATH=".version" + RELEASE_CLOUD=0 # Get current stable branch name # If MASTER, use root .version # Else use branch name if [[ "${{ inputs.github_ref_name }}" == "master" ]]; then CURRENT_STABLE_BRANCH_MAJOR_VERSION=$(grep -E "MAJOR" .version | cut -d '=' -f2) + RELEASE_CLOUD=1 else CURRENT_STABLE_BRANCH_MAJOR_VERSION=$(echo ${{ inputs.github_ref_name }} | cut -d '.' -f1,2) + RELEASE_CLOUD=0 fi echo "Current stable branch major version: $CURRENT_STABLE_BRANCH_MAJOR_VERSION" @@ -54,10 +57,15 @@ runs: MAJOR_VERSION=$(grep -E "MAJOR" .version | cut -d '=' -f2) MINOR_VERSION=$(grep -E "MINOR" .version | cut -d '=' -f2) # Previous stable tags array - PREVIOUS_STABLE_TAGS+=($(git tag -l --sort=-version:refname "$component-$CURRENT_STABLE_BRANCH_MAJOR_VERSION*" | head -n 1)) + if [[ $RELEASE_CLOUD -eq 1 ]]; then + PREVIOUS_STABLE_TAGS+=($(git tag -l --sort=-version:refname "$component-$CURRENT_STABLE_BRANCH_MAJOR_VERSION.*-*" | head -n 1)) + else + PREVIOUS_STABLE_TAGS+=($(git tag -l --sort=-version:refname "$component-$CURRENT_STABLE_BRANCH_MAJOR_VERSION.*" | grep -E "$component-$CURRENT_STABLE_BRANCH_MAJOR_VERSION.[0-9]+$" | head -n 1)) + fi # New stable tags array TMP_STABLE_TAGS+=("$component-$MAJOR_VERSION.$MINOR_VERSION") done + echo "Previous releases were: ${PREVIOUS_STABLE_TAGS[*]}" echo "Temporary new releases are: ${TMP_STABLE_TAGS[*]}" # Building final NEW_STABLE_TAGS with the new version tags only @@ -96,11 +104,6 @@ runs: git config --global user.email "release@centreon.com" git config --global user.name "Centreon" - # Rebuild NEW_STABLE_TAGS as an array - for i in ${NEW_RELEASE_TAGS[@]}; do - NEW_RELEASE_TAGS+=("$i") - done - # Create release tags on git for each release components # Abort if no tags or existing tag echo "Creating release tags." @@ -149,6 +152,7 @@ runs: else echo "::error::Release tag $TAG was empty, exiting." exit 1 + fi done shell: bash env: diff --git a/.github/workflows/centreon-collect.yml b/.github/workflows/centreon-collect.yml index e631745e800..bf2009f5ac2 100644 --- a/.github/workflows/centreon-collect.yml +++ b/.github/workflows/centreon-collect.yml @@ -21,6 +21,7 @@ on: - conanfile.txt - selinux/** - "!.veracode-exclusions" + - "!veracode.json" push: branches: - develop @@ -41,6 +42,7 @@ on: - conanfile.txt - selinux/** - "!.veracode-exclusions" + - "!veracode.json" jobs: get-version: @@ -180,7 +182,6 @@ jobs: major_version: ${{ needs.get-version.outputs.version }} minor_version: ${{ needs.get-version.outputs.patch }} stability: ${{ needs.get-version.outputs.stability }} - repository_name: standard github_ref_name: ${{ github.ref_name }} release_type: ${{ needs.get-version.outputs.release_type }} release_cloud: ${{ needs.get-version.outputs.release_cloud }} diff --git a/.github/workflows/libzmq.yml b/.github/workflows/libzmq.yml index bbaded08f75..34a651e66c8 100644 --- a/.github/workflows/libzmq.yml +++ b/.github/workflows/libzmq.yml @@ -209,7 +209,6 @@ jobs: major_version: ${{ needs.get-version.outputs.version }} minor_version: ${{ needs.get-version.outputs.patch }} stability: ${{ needs.get-version.outputs.stability }} - repository_name: standard github_ref_name: ${{ github.ref_name }} release_type: ${{ needs.get-version.outputs.release_type }} release_cloud: ${{ needs.get-version.outputs.release_cloud }} diff --git a/.version b/.version index 7edc6dec2c0..34efdaaa577 100644 --- a/.version +++ b/.version @@ -1,2 +1,2 @@ MAJOR=23.04 -MINOR=11 +MINOR=12 diff --git a/CMakeLists.txt b/CMakeLists.txt index 79d809443e6..cafcea94b08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,7 +116,7 @@ endif() # Version. set(COLLECT_MAJOR 23) set(COLLECT_MINOR 04) -set(COLLECT_PATCH 11) +set(COLLECT_PATCH 12) set(COLLECT_VERSION "${COLLECT_MAJOR}.${COLLECT_MINOR}.${COLLECT_PATCH}") add_definitions(-DCENTREON_CONNECTOR_VERSION=\"${COLLECT_VERSION}\") diff --git a/broker/bam/src/configuration/reader_v2.cc b/broker/bam/src/configuration/reader_v2.cc index e15c2b2d5db..a1aa63b6293 100644 --- a/broker/bam/src/configuration/reader_v2.cc +++ b/broker/bam/src/configuration/reader_v2.cc @@ -1,20 +1,20 @@ -/* -** Copyright 2014-2017, 2021 Centreon -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -** -** For more information : contact@centreon.com -*/ +/** + * Copyright 2014-2017, 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 + */ #include "com/centreon/broker/bam/configuration/reader_v2.hh" @@ -506,7 +506,15 @@ void reader_v2::_load_dimensions() { std::promise promise_ba_tp; std::future future_ba_tp = promise_ba_tp.get_future(); _mysql.run_query_and_get_result( - "SELECT ba_id, tp_id FROM mod_bam_relations_ba_timeperiods", + fmt::format( + "SELECT bt.ba_id, bt.tp_id FROM mod_bam_relations_ba_timeperiods bt" + " INNER JOIN mod_bam AS b" + " ON b.ba_id = bt.ba_id" + " INNER JOIN mod_bam_poller_relations AS pr" + " ON b.ba_id=pr.ba_id" + " WHERE b.activate='1'" + " AND pr.poller_id={}", + config::applier::state::instance().poller_id()), std::move(promise_ba_tp), 0); try { diff --git a/broker/bam/src/main.cc b/broker/bam/src/main.cc index 45f5190ee1b..ee9d9f2d77a 100644 --- a/broker/bam/src/main.cc +++ b/broker/bam/src/main.cc @@ -17,6 +17,7 @@ */ #include "bbdo/bam/ba_duration_event.hh" +#include "bbdo/bam/ba_event.hh" #include "bbdo/bam/ba_status.hh" #include "bbdo/bam/dimension_ba_bv_relation_event.hh" #include "bbdo/bam/dimension_ba_event.hh" @@ -109,6 +110,7 @@ void broker_module_init(void const* arg) { e.register_event(make_type(io::storage, storage::de_status), "status", &storage::status::operations, storage::status::entries); + register_bam_event(e, bam::de_ba_event, "ba_event"); register_bam_event(e, bam::de_ba_status, "ba_status"); register_bam_event(e, bam::de_kpi_status, "kpi_status"); register_bam_event(e, bam::de_kpi_event, "kpi_event"); diff --git a/engine/scripts/logrotate_systemd.conf.in b/engine/scripts/logrotate_systemd.conf.in index eab7d6965ac..2b86f7632c0 100644 --- a/engine/scripts/logrotate_systemd.conf.in +++ b/engine/scripts/logrotate_systemd.conf.in @@ -1,6 +1,6 @@ @ENGINE_VAR_LOG_DIR@/*.log { compress - create 640 @USER@ @GROUP@ + create 644 @USER@ @GROUP@ daily delaycompress missingok diff --git a/engine/scripts/logrotate_sysv.conf.in b/engine/scripts/logrotate_sysv.conf.in index 50f694b91d4..7ed01459d4e 100644 --- a/engine/scripts/logrotate_sysv.conf.in +++ b/engine/scripts/logrotate_sysv.conf.in @@ -1,6 +1,6 @@ @VAR_DIR@/centengine.log { compress - create 640 @USER@ @GROUP@ + create 644 @USER@ @GROUP@ daily delaycompress missingok @@ -14,7 +14,7 @@ @VAR_DIR@/centengine.debug { compress - create 640 @USER@ @GROUP@ + create 644 @USER@ @GROUP@ delaycompress missingok olddir @ENGINE_VAR_LOG_ARCHIVE_DIR@ diff --git a/engine/scripts/logrotate_upstart.conf.in b/engine/scripts/logrotate_upstart.conf.in index de02677d72d..f7c94a9de42 100644 --- a/engine/scripts/logrotate_upstart.conf.in +++ b/engine/scripts/logrotate_upstart.conf.in @@ -1,6 +1,6 @@ @VAR_DIR@/centengine.log { compress - create 640 @USER@ @GROUP@ + create 644 @USER@ @GROUP@ daily delaycompress missingok @@ -14,7 +14,7 @@ @VAR_DIR@/centengine.debug { compress - create 640 @USER@ @GROUP@ + create 644 @USER@ @GROUP@ delaycompress missingok olddir @ENGINE_VAR_LOG_ARCHIVE_DIR@ diff --git a/tests/bam/bam_pb.robot b/tests/bam/bam_pb.robot index 3c1fa016230..9eda36f3980 100644 --- a/tests/bam/bam_pb.robot +++ b/tests/bam/bam_pb.robot @@ -13,7 +13,7 @@ Library ../resources/Engine.py Suite Setup Ctn Clean Before Suite Suite Teardown Ctn Clean After Suite Test Setup Ctn BAM Setup -Test Teardown Ctn Save Logs If Failed +Test Teardown Ctn Stop Engine Broker And Save Logs *** Test Cases *** @@ -48,7 +48,13 @@ BAPBSTATUS Should Be True ${result} A message telling check_for_external_commands() should be available. # KPI set to critical - Repeat Keyword 3 times Ctn Process Service Check Result host_16 service_314 2 output critical for 314 + Repeat Keyword + ... 3 times + ... Ctn Process Service Check Result + ... host_16 + ... service_314 + ... 2 + ... output critical for 314 ${result} Ctn Check Service Status With Timeout host_16 service_314 2 60 HARD Should Be True ${result} The service (host_16,service_314) is not CRITICAL as expected @@ -64,14 +70,19 @@ BAPBSTATUS # Little check of the GetBa gRPC command ${result} Run Keyword And Return Status File Should Exist /tmp/output - Run Keyword If ${result} is True Remove File /tmp/output + IF ${result} is True Remove File /tmp/output Ctn Broker Get Ba 51001 1 /tmp/output Wait Until Created /tmp/output ${result} Grep File /tmp/output digraph Should Not Be Empty ${result} /tmp/output does not contain the word 'digraph' # check broker stats - ${res} Ctn Get Broker Stats central 1: 127.0.0.1:[0-9]+ 10 endpoint central-broker-master-input peers + ${res} Ctn Get Broker Stats + ... central + ... 1: 127.0.0.1:[0-9]+ + ... 10 + ... endpoint central-broker-master-input + ... peers Should Be True ${res} no central-broker-master-input.peers found in broker stat output ${res} Ctn Get Broker Stats central listening 10 endpoint central-broker-master-input state @@ -87,7 +98,12 @@ BAPBSTATUS Ctn Reload Broker # check broker stats - ${res} Ctn Get Broker Stats central 1: 127.0.0.1:[0-9]+ 10 endpoint central-broker-master-input peers + ${res} Ctn Get Broker Stats + ... central + ... 1: 127.0.0.1:[0-9]+ + ... 10 + ... endpoint central-broker-master-input + ... peers Should Be True ${res} no central-broker-master-input.peers found in broker stat output ${res} Ctn Get Broker Stats central listening 10 endpoint central-broker-master-input state @@ -99,7 +115,104 @@ BAPBSTATUS ${res} Ctn Get Broker Stats central connected 10 endpoint centreon-bam-reporting state Should Be True ${res} central-bam-reporting not connected - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker + # Little check of the GetBa gRPC command + ${result} Run Keyword And Return Status File Should Exist /tmp/output + IF ${result} is True Remove File /tmp/output + Ctn Broker Get Ba 51001 1 /tmp/output + Wait Until Created /tmp/output + ${result} Grep File /tmp/output digraph + Should Not Be Empty ${result} /tmp/output does not contain the word 'digraph' + +BAWORST2 + [Documentation] a worst ba with a boolean kpi and a ba kpi + [Tags] broker engine bam + Ctn BAM Init + + ${id_ba__sid} Ctn Create Ba test worst 100 100 + Ctn Add Boolean Kpi + ... ${id_ba__sid[0]} + ... {host_16 service_302} {IS} {OK} + ... False + ... 100 + + # ba kpi + @{svc} Set Variable ${{ [("host_16", "service_314")] }} + ${id_ba__sid__child} Ctn Create Ba With Services test_child worst ${svc} + Ctn Add Ba Kpi ${id_ba__sid__child[0]} ${id_ba__sid[0]} 1 2 3 + + Ctn Start Broker + ${start} Get Current Date + Ctn Start engine + # Let's wait for the external command check start + ${content} Create List check_for_external_commands() + ${result} Ctn Find In Log With Timeout ${engineLog0} ${start} ${content} 60 + Should Be True ${result} A message telling check_for_external_commands() should be available. + + ${result} Ctn Check Ba Status With Timeout test 0 60 + Ctn Dump Ba On Error ${result} ${id_ba__sid[0]} + Should Be True ${result} The BA test is not OK as expected + ${result} Ctn Check Ba Output With Timeout + ... test + ... Status is OK - All KPIs are in an OK state + ... 10 + Should Be True ${result} The BA test has not the expected output + + # boolean critical => ba test critical + Ctn Process Service Result Hard + ... host_16 + ... service_302 + ... 2 + ... output critical for service_302 + ${result} Ctn Check Service Status With Timeout host_16 service_302 2 60 HARD + Should Be True ${result} The service (host_16,service_302) is not CRITICAL as expected + Sleep 2s + ${result} Ctn Check Ba Status With Timeout test 2 60 + Ctn Dump Ba On Error ${result} ${id_ba__sid[0]} + Should Be True ${result} The BA test is not CRITICAL as expected + ${result} Ctn Check Ba Output With Timeout + ... test + ... Status is CRITICAL - At least one KPI is in a CRITICAL state: KPI Boolean rule bool test is in CRITICAL state + ... 10 + Should Be True ${result} The BA test has not the expected output + + # child ba critical + Ctn Process Service Result Hard + ... host_16 + ... service_314 + ... 2 + ... output critical for service_314 + ${result} Ctn Check Service Status With Timeout host_16 service_314 2 60 HARD + Should Be True ${result} The service (host_16,service_314) is not CRITICAL as expected + Sleep 2s + ${result} Ctn Check Ba Status With Timeout test_child 2 60 + Ctn Dump Ba On Error ${result} ${id_ba__sid[0]} + Should Be True ${result} The BA test_child is not CRITICAL as expected + ${result} Ctn Check Ba Status With Timeout test 2 60 + Ctn Dump Ba On Error ${result} ${id_ba__sid[0]} + Should Be True ${result} The BA test is not CRITICAL as expected + ${result} Ctn Check Ba Output With Timeout + ... test + ... Status is CRITICAL - At least one KPI is in a CRITICAL state: KPI Business Activity test_child is in CRITICAL state, KPI Boolean rule bool test is in CRITICAL state + ... 10 + Should Be True ${result} The BA test has not the expected output + + # boolean rule ok stay in critical + Ctn Process Service Result Hard + ... host_16 + ... service_302 + ... 0 + ... output OK + ${result} Ctn Check Service Status With Timeout host_16 service_302 0 60 HARD + Should Be True ${result} The service (host_16,service_302) is not OK as expected + Sleep 2s + ${result} Ctn Check Ba Status With Timeout test 2 60 + Ctn Dump Ba On Error ${result} ${id_ba__sid[0]} + Should Be True ${result} The BA test is not CRITICAL as expected + ${result} Ctn Check Ba Output With Timeout + ... test + ... Status is CRITICAL - At least one KPI is in a CRITICAL state: KPI Business Activity test_child is in CRITICAL state + ... 10 + Should Be True ${result} The BA test has not the expected output BABEST_SERVICE_CRITICAL [Documentation] With bbdo version 3.0.1, a BA of type 'best' with 2 serv, ba is critical only if the 2 services are critical @@ -133,7 +246,13 @@ BABEST_SERVICE_CRITICAL Should Be True ${result} A message telling check_for_external_commands() should be available. # KPI set to critical - Repeat Keyword 3 times Ctn Process Service Check Result host_16 service_314 2 output critical for 314 + Repeat Keyword + ... 3 times + ... Ctn Process Service Check Result + ... host_16 + ... service_314 + ... 2 + ... output critical for 314 ${result} Ctn Check Service Status With Timeout host_16 service_314 2 60 HARD Should Be True ${result} The service (host_16,service_314) is not CRITICAL as expected @@ -144,7 +263,13 @@ BABEST_SERVICE_CRITICAL Should Be True ${result} The BA ba_1 is not OK as expected # KPI set to critical - Repeat Keyword 3 times Ctn Process Service Check Result host_16 service_303 2 output critical for 314 + Repeat Keyword + ... 3 times + ... Ctn Process Service Check Result + ... host_16 + ... service_303 + ... 2 + ... output critical for 314 ${result} Ctn Check Service Status With Timeout host_16 service_303 2 60 HARD Should Be True ${result} The service (host_16,service_303) is not CRITICAL as expected @@ -163,8 +288,6 @@ BABEST_SERVICE_CRITICAL ${result} Ctn Check Ba Status With Timeout test 0 60 Should Be True ${result} The BA ba_1 is not OK as expected - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker - BA_IMPACT_2KPI_SERVICES [Documentation] With bbdo version 3.0.1, a BA of type 'impact' with 2 serv, ba is critical only if the 2 services are critical [Tags] broker engine bam @@ -267,8 +390,6 @@ BA_IMPACT_2KPI_SERVICES ${result} Ctn Check Ba Status With Timeout test 0 60 Should Be True ${result} The BA ba_1 is not OK as expected - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker - BA_RATIO_PERCENT_BA_SERVICE [Documentation] With bbdo version 3.0.1, a BA of type 'ratio percent' with 2 serv an 1 ba with one service [Tags] broker engine bam @@ -370,8 +491,6 @@ BA_RATIO_PERCENT_BA_SERVICE ${result} Ctn Check Ba Status With Timeout test 2 30 Should Be True ${result} The BA test is not CRITICAL as expected - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker - BA_RATIO_NUMBER_BA_SERVICE [Documentation] With bbdo version 3.0.1, a BA of type 'ratio number' with 2 services and one ba with 1 service [Tags] broker engine bam @@ -477,8 +596,6 @@ BA_RATIO_NUMBER_BA_SERVICE ${result} Ctn Check Ba Status With Timeout test 2 60 Should Be True ${result} The BA test is not CRITICAL as expected - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker - BA_BOOL_KPI [Documentation] With bbdo version 3.0.1, a BA of type 'worst' with 1 boolean kpi [Tags] broker engine bam @@ -539,8 +656,6 @@ BA_BOOL_KPI ${result} Ctn Check Ba Status With Timeout test 2 30 Should Be True ${result} The BA test is not CRITICAL as expected - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker - BEPB_DIMENSION_BV_EVENT [Documentation] bbdo_version 3 use pb_dimension_bv_event message. [Tags] broker engine protobuf bam bbdo @@ -579,7 +694,7 @@ BEPB_DIMENSION_BV_EVENT Should Not Be Empty ${grep_res} event not found - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker ${True} + [Teardown] Ctn Stop Engine Broker And Save Logs ${True} BEPB_DIMENSION_BA_EVENT [Documentation] bbdo_version 3 use pb_dimension_ba_event message. @@ -623,7 +738,7 @@ BEPB_DIMENSION_BA_EVENT Should Not Be Empty ${grep_res} event not found - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker ${True} + [Teardown] Ctn Stop Engine Broker And Save Logs ${True} BEPB_DIMENSION_BA_BV_RELATION_EVENT [Documentation] bbdo_version 3 use pb_dimension_ba_bv_relation_event message. @@ -714,7 +829,7 @@ BEPB_DIMENSION_TIMEPERIOD Should Not Be Empty ${grep_res} event not found - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker ${True} + [Teardown] Ctn Stop Engine Broker And Save Logs ${True} BEPB_DIMENSION_KPI_EVENT [Documentation] bbdo_version 3 use pb_dimension_kpi_event message. @@ -761,7 +876,7 @@ BEPB_DIMENSION_KPI_EVENT Should Be Equal As Strings ${output} ${expected} mod_bam_reporting_kpi not filled - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker ${True} + [Teardown] Ctn Stop Engine Broker And Save Logs ${True} BEPB_KPI_STATUS [Documentation] bbdo_version 3 use kpi_status message. @@ -792,7 +907,13 @@ BEPB_KPI_STATUS ${start} Get Current Date result_format=epoch # KPI set to critical - Repeat Keyword 3 times Ctn Process Service Check Result host_16 service_314 2 output critical for 314 + Repeat Keyword + ... 3 times + ... Ctn Process Service Check Result + ... host_16 + ... service_314 + ... 2 + ... output critical for 314 ${result} Ctn Check Service Status With Timeout host_16 service_314 2 60 HARD Should Be True ${result} The service (host_16,service_314) is not CRITICAL as expected @@ -811,7 +932,7 @@ BEPB_KPI_STATUS Should Be True (${output} + 0.999) >= ${start} - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker ${True} + [Teardown] Ctn Stop Engine Broker And Save Logs ${True} BEPB_BA_DURATION_EVENT [Documentation] use of pb_ba_duration_event message. @@ -849,7 +970,13 @@ BEPB_BA_DURATION_EVENT # KPI set to critical # as GetCurrent Date floor milliseconds to upper or lower integer, we substract 1s ${start_event} Ctn Get Round Current Date - Repeat Keyword 3 times Ctn Process Service Check Result host_16 service_314 2 output critical for 314 + Repeat Keyword + ... 3 times + ... Ctn Process Service Check Result + ... host_16 + ... service_314 + ... 2 + ... output critical for 314 ${result} Ctn Check Service Status With Timeout host_16 service_314 2 60 HARD Should Be True ${result} The service (host_16,service_314) is not CRITICAL as expected Sleep 2s @@ -872,7 +999,7 @@ BEPB_BA_DURATION_EVENT Should Be True ${output[0][0]} >= ${start_event} Should Be True ${output[0][1]} <= ${end_event} - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker ${True} + [Teardown] Ctn Stop Engine Broker And Save Logs ${True} BEPB_DIMENSION_BA_TIMEPERIOD_RELATION [Documentation] use of pb_dimension_ba_timeperiod_relation message. @@ -917,7 +1044,7 @@ BEPB_DIMENSION_BA_TIMEPERIOD_RELATION ... len("""${output}""") > 5 ... "centreon_storage.mod_bam_reporting_relations_ba_timeperiods not updated" - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker ${True} + [Teardown] Ctn Stop Engine Broker And Save Logs ${True} BEPB_DIMENSION_TRUNCATE_TABLE [Documentation] use of pb_dimension_timeperiod message. @@ -958,7 +1085,7 @@ BEPB_DIMENSION_TRUNCATE_TABLE ... "_type":393246, "category":6, "element":30, "update_started":false Should Not Be Empty ${grep_res} event not found - [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker ${True} + [Teardown] Ctn Stop Engine Broker And Save Logs ${True} BA_RATIO_NUMBER_BA_4_SERVICE [Documentation] With bbdo version 3.0.1, a BA of type 'ratio number' with 4 serv @@ -1112,12 +1239,11 @@ BA_RATIO_PERCENT_BA_4_SERVICE [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker - BA_CHANGED [Documentation] A BA of type worst is configured with one service kpi. - ... Then it is modified so that the service kpi is replaced - ... by a boolean rule kpi. When cbd is reloaded, the BA is - ... well updated. + ... Then it is modified so that the service kpi is replaced + ... by a boolean rule kpi. When cbd is reloaded, the BA is + ... well updated. [Tags] MON-34895 Ctn Bam Init @@ -1171,13 +1297,12 @@ BA_CHANGED Should Not Be Empty ${result} [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker - BA_IMPACT_IMPACT [Documentation] A BA of type impact is defined with two BAs of type impact - ... as children. The first child has an impact of 90 and the - ... second one of 10. When they are impacting both, the - ... parent should be critical. When they are not impacting, - ... the parent should be ok. + ... as children. The first child has an impact of 90 and the + ... second one of 10. When they are impacting both, the + ... parent should be critical. When they are not impacting, + ... the parent should be ok. [Tags] MON-34895 Ctn Bam Init @@ -1200,9 +1325,9 @@ BA_IMPACT_IMPACT Should Be True ${result} A message telling check_for_external_commands() should be available. FOR ${state} ${value} IN - ... OK 0 + ... OK 0 ... CRITICAL 2 - ... OK 0 + ... OK 0 ... CRITICAL 2 # Both services ${state} => The BA parent is ${state} Ctn Process Service Result Hard @@ -1210,7 +1335,7 @@ BA_IMPACT_IMPACT ... service_302 ... ${value} ... output ${state} for service 302 - + Ctn Process Service Result Hard ... host_16 ... service_303 @@ -1253,6 +1378,32 @@ BA_IMPACT_IMPACT [Teardown] Run Keywords Ctn Stop Engine AND Ctn Kindly Stop Broker +BA_DISABLED + [Documentation] create a disabled BA with timeperiods and reporting filter don't create error message + [Tags] broker engine bam MON-38396 + Ctn Bam Init + Ctn Create Ba test worst 100 100 ignore 0 + Ctn Add Relations Ba Timeperiods 1 1 + + ${start} Get Current Date + Ctn Start Broker + + ${content} Create List bam configuration loaded + ${result} Ctn Find In Log With Timeout ${centralLog} ${start} ${content} 60 + Should Be True ${result} A message telling 'bam configuration loaded' should be available. + + ${res} Grep File + ... ${centralLog} + ... could not insert relation of BA to timeperiod + Should Be Empty ${res} A mod_bam_reporting_relations_ba_timeperiods error had been found in log + + ${res} Grep File + ... ${centralLog} + ... The configured write filters for the endpoint 'centreon-bam-reporting' are too restrictive and will be ignored + Should Be Empty ${res} A filter error of centreon-bam-reporting had been found in log + + [Teardown] Ctn Stop Engine Broker And Save Logs ${True} + *** Keywords *** Ctn BAM Setup diff --git a/tests/init-sql-docker.sh b/tests/init-sql-docker.sh index fc7e90f44c5..42cd3013d97 100755 --- a/tests/init-sql-docker.sh +++ b/tests/init-sql-docker.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e ss -nl | grep "0.0.0.0:3306" while [ $? -ne 0 ] @@ -15,6 +16,8 @@ DBConf=$(awk '($1=="${DBNameConf}") {print $2}' /scripts/tests/resources/db_vari cd /scripts +apt update && apt install -y mysql-client + #create users mysql --user="$DBUserRoot" --password="$DBPassRoot" -h 127.0.0.1 -e "grant all privileges ON *.* to 'centreon'@'%' identified by 'centreon'" mysql --user="$DBUserRoot" --password="$DBPassRoot" -h 127.0.0.1 -e "grant all privileges ON *.* to 'root_centreon'@'%' identified by 'centreon'" diff --git a/tests/resources/Common.py b/tests/resources/Common.py index 25becde5a2e..7b2bc3f6935 100644 --- a/tests/resources/Common.py +++ b/tests/resources/Common.py @@ -749,6 +749,32 @@ def ctn_check_ba_status_with_timeout(ba_name: str, status: int, timeout: int): return False +def ctn_check_ba_output_with_timeout(ba_name: str, expected_output: str, timeout: int): + """ check if the expected is written in mod_bam.comment column + @param ba_name name of the ba + @param expected_output output that we should find in comment column + @param timeout timeout in second + """ + limit = time.time() + timeout + while time.time() < limit: + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_CONF, + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor) + with connection: + with connection.cursor() as cursor: + cursor.execute( + f"SELECT * FROM mod_bam WHERE name='{ba_name}'") + result = cursor.fetchall() + logger.console(f"ba: {result[0]}") + if result[0]['current_status'] is not None and result[0]['comment'] == expected_output: + return True + time.sleep(5) + return False + + def ctn_check_downtimes_with_timeout(nb: int, timeout: int): limit = time.time() + timeout while time.time() < limit: diff --git a/tests/resources/Engine.py b/tests/resources/Engine.py index a85e4d17109..d7d67d13f9d 100755 --- a/tests/resources/Engine.py +++ b/tests/resources/Engine.py @@ -1198,7 +1198,7 @@ def ctn_create_ba_with_services(name: str, typ: str, svc: list, dt_policy="inher return dbconf.ctn_create_ba_with_services(name, typ, svc, dt_policy) -def ctn_create_ba(name: str, typ: str, critical_impact: int, warning_impact: int, dt_policy="inherit"): +def ctn_create_ba(name: str, typ: str, critical_impact: int, warning_impact: int, dt_policy="inherit", activate:int = 1): """ Create a BA. @@ -1208,12 +1208,25 @@ def ctn_create_ba(name: str, typ: str, critical_impact: int, warning_impact: int critical_impact (int): Impact weight in the event of a Critical condition, in real-time monitoring warning_impact (int): Impact weight in the event of a Warning condition, in real-time monitoring. Ignored if indicator is a boolean rule dt_policy (str, optional): Defaults to "inherit": inherit, ignore, ignore_all + activate: 1 for enable, 0 for disable Returns: A tuple(BA ID, virtual service associated to the BA). """ global dbconf - return dbconf.ctn_create_ba(name, typ, critical_impact, warning_impact, dt_policy) + return dbconf.ctn_create_ba(name, typ, critical_impact, warning_impact, dt_policy, activate) + +def ctn_add_relations_ba_timeperiods(id_ba:int, id_time_period:int): + """ + add a line in mod_bam_relations_ba_timeperiods table + + Args: + id_ba: + id_time_period: + """ + + global dbconf + return dbconf.ctn_add_relations_ba_timeperiods(id_ba,id_time_period) def ctn_add_boolean_kpi(id_ba: int, expression: str, impact_if: bool, critical_impact: int): diff --git a/tests/resources/db_conf.py b/tests/resources/db_conf.py index 898d390b149..9b9ffd7a7e3 100755 --- a/tests/resources/db_conf.py +++ b/tests/resources/db_conf.py @@ -230,7 +230,18 @@ def ctn_create_ba_with_services(self, name: str, typ: str, svc: [(str, str)], dt connection.commit() return (id_ba, sid) - def ctn_create_ba(self, name: str, typ: str, critical_impact: int, warning_impact: int, dt_policy: str): + def ctn_create_ba(self, name: str, typ: str, critical_impact: int, warning_impact: int, dt_policy: str, activate:int = 1): + """ + create a ba in centreon db + + Args: + name: name of ba + typ: best, worst, ratro_percent, ratio_number, impact + critical_impact: critical impact level + warning_impact: warning impact level + dt_policy: Downtime policy: inherit, ignore + activate: 1 for enable, 0 for disable + """ connection = pymysql.connect(host=DB_HOST, user=DB_USER, password=DB_PASS, @@ -256,8 +267,7 @@ def ctn_create_ba(self, name: str, typ: str, critical_impact: int, warning_impac else: inherit_dt = 0 with connection.cursor() as cursor: - cursor.execute("INSERT INTO mod_bam (name, state_source, activate,id_reporting_period,level_w,level_c,id_notification_period,notifications_enabled,event_handler_enabled, inherit_kpi_downtimes) VALUES ('{}',{},'1',1, {}, {}, 1,'0', '0','{}')".format( - name, t, warning_impact, critical_impact, inherit_dt)) + cursor.execute(f"INSERT INTO mod_bam (name, state_source, activate,id_reporting_period,level_w,level_c,id_notification_period,notifications_enabled,event_handler_enabled, inherit_kpi_downtimes) VALUES ('{name}',{t},'{activate}',1, {warning_impact}, {critical_impact}, 1,'0', '0','{inherit_dt}')") id_ba = cursor.lastrowid sid = self.engine.create_bam_service("ba_{}".format( id_ba), name, "_Module_BAM_1", "centreon-bam-check!{}".format(id_ba)) @@ -346,3 +356,24 @@ def ctn_add_ba_kpi(self, id_ba_src: int, id_ba_dest: int, critical_impact: int, id_ba_src, id_ba_dest, warning_impact, critical_impact, unknown_impact)) connection.commit() + + def ctn_add_relations_ba_timeperiods(self, id_ba:int, id_time_period:int): + """ + add a line in mod_bam_relations_ba_timeperiods table + + Args: + id_ba: + id_time_period: + """ + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_CONF, + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor) + + with connection: + with connection.cursor() as cursor: + cursor.execute(f"INSERT INTO mod_bam_relations_ba_timeperiods (ba_id, tp_id) VALUES ({id_ba},{id_time_period})") + + connection.commit() diff --git a/veracode.json b/veracode.json new file mode 100644 index 00000000000..329f76f89be --- /dev/null +++ b/veracode.json @@ -0,0 +1,3 @@ +{ + "ignorethirdparty": "false" +} \ No newline at end of file