Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gorgone): when pushing engine conf, push centreon_vmware daemon configuration #1718

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
224 changes: 112 additions & 112 deletions .github/workflows/gorgone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,118 +130,118 @@ jobs:
rpm_gpg_signing_passphrase: ${{ secrets.RPM_GPG_SIGNING_PASSPHRASE }}
stability: ${{ needs.get-version.outputs.stability }}

# test-gorgone:
# needs: [get-version, package]

# strategy:
# fail-fast: false
# matrix:
# distrib: [el8, el9, bookworm, jammy]
# include:
# - package_extension: rpm
# image: gorgone-testing-alma8
# distrib: el8
# - package_extension: rpm
# image: gorgone-testing-alma9
# distrib: el9
# - package_extension: deb
# image: gorgone-testing-jammy
# distrib: jammy
# - package_extension: deb
# image: gorgone-testing-bookworm
# distrib: bookworm

# runs-on: ubuntu-22.04
# container:
# image: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/${{ matrix.image }}:${{ needs.get-version.outputs.gorgone_docker_version }}
# credentials:
# username: ${{ secrets.DOCKER_REGISTRY_ID }}
# password: ${{ secrets.DOCKER_REGISTRY_PASSWD }}

# services:
# mariadb:
# image: mariadb:latest
# ports:
# - 3306
# env:
# MYSQL_USER: centreon
# MYSQL_PASSWORD: password
# MYSQL_ROOT_PASSWORD: password

# steps:
# - name: Get linked branch of centreon repository
# id: centreon_repo_linked_branch
# run: |
# CENTREON_REPO_LINKED_BRANCH=$(git ls-remote -h https://github.com/centreon/centreon.git | grep -E "refs/heads/dev-${{ needs.get-version.outputs.major_version }}\.x$" >/dev/null 2>&1 && echo "dev-${{ needs.get-version.outputs.major_version }}.x" || echo develop)

# GIT_BRANCH_EXISTS=$(git ls-remote -h https://github.com/centreon/centreon.git | grep -E "refs/heads/${{ github.head_ref || github.ref_name }}$" >/dev/null 2>&1 && echo yes || echo no)
# if [[ "$GIT_BRANCH_EXISTS" == "yes" ]]; then
# CENTREON_REPO_LINKED_BRANCH="${{ github.head_ref || github.ref_name }}"
# fi

# echo "linked_branch=$CENTREON_REPO_LINKED_BRANCH" >> $GITHUB_OUTPUT
# shell: bash

# - name: Checkout sources
# uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

# - name: Checkout sources
# uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
# with:
# repository: centreon/centreon
# path: centreon
# ref: ${{ steps.centreon_repo_linked_branch.outputs.linked_branch }}
# sparse-checkout: |
# centreon/www/install/createTables.sql
# centreon/www/install/createTablesCentstorage.sql

# - name: get cached gorgone package
# uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
# with:
# path: ./*.${{ matrix.package_extension }}
# key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}
# fail-on-cache-miss: true

# - name: Parse distrib name
# id: parse-distrib
# uses: ./.github/actions/parse-distrib
# with:
# distrib: ${{ matrix.distrib }}

# - name: Install gorgone from just built package
# shell: bash
# run: |
# if [[ "${{ matrix.package_extension }}" == "deb" ]]; then
# apt update
# apt install -y ./centreon-gorgone*${{ steps.parse-distrib.outputs.package_distrib_name }}*
# else
# dnf install -y ./centreon-gorgone*${{ steps.parse-distrib.outputs.package_distrib_name }}* ./centreon-gorgone-centreon-config*${{ steps.parse-distrib.outputs.package_distrib_name }}*
# # in el8 at least, there is a package for the configuration and a package for the actual code.
# # this is not the case for debian, and for now I don't know why it was made any different between the 2 Os.
# fi

# - name: Create databases
# run: |
# mysql -h mariadb -u root -ppassword -e "CREATE DATABASE \`centreon\`"
# mysql -h mariadb -u root -ppassword -e "CREATE DATABASE \`centreon-storage\`"
# mysql -h mariadb -u root -ppassword -e "GRANT ALL PRIVILEGES ON centreon.* TO 'centreon'@'%'"
# mysql -h mariadb -u root -ppassword -e "GRANT ALL PRIVILEGES ON \`centreon-storage\`.* TO 'centreon'@'%'"
# mysql -h mariadb -u root -ppassword 'centreon' < centreon/centreon/www/install/createTables.sql
# mysql -h mariadb -u root -ppassword 'centreon-storage' < centreon/centreon/www/install/createTablesCentstorage.sql

# - name: Run tests
# run: robot -v 'DBHOST:mariadb' -v 'DBNAME:centreon' -v 'DBNAME_STORAGE:centreon-storage' -v 'DBUSER:centreon' gorgone/tests

# - name: Upload gorgone and robot debug artifacts
# if: failure()
# uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
# with:
# name: gorgone-debug-${{ matrix.distrib }}
# path: |
# log.html
# /var/log/centreon-gorgone
# /etc/centreon-gorgone
# retention-days: 1
test-gorgone:
needs: [get-version, package]

strategy:
fail-fast: false
matrix:
distrib: [el8, el9, bookworm, jammy]
include:
- package_extension: rpm
image: gorgone-testing-alma8
distrib: el8
- package_extension: rpm
image: gorgone-testing-alma9
distrib: el9
- package_extension: deb
image: gorgone-testing-jammy
distrib: jammy
- package_extension: deb
image: gorgone-testing-bookworm
distrib: bookworm

runs-on: ubuntu-22.04
container:
image: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/${{ matrix.image }}:${{ needs.get-version.outputs.gorgone_docker_version }}
credentials:
username: ${{ secrets.DOCKER_REGISTRY_ID }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWD }}

services:
mariadb:
image: mariadb:latest
ports:
- 3306
env:
MYSQL_USER: centreon
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password

steps:
- name: Get linked branch of centreon repository
id: centreon_repo_linked_branch
run: |
CENTREON_REPO_LINKED_BRANCH=$(git ls-remote -h https://github.com/centreon/centreon.git | grep -E "refs/heads/dev-${{ needs.get-version.outputs.major_version }}\.x$" >/dev/null 2>&1 && echo "dev-${{ needs.get-version.outputs.major_version }}.x" || echo develop)

GIT_BRANCH_EXISTS=$(git ls-remote -h https://github.com/centreon/centreon.git | grep -E "refs/heads/${{ github.head_ref || github.ref_name }}$" >/dev/null 2>&1 && echo yes || echo no)
if [[ "$GIT_BRANCH_EXISTS" == "yes" ]]; then
CENTREON_REPO_LINKED_BRANCH="${{ github.head_ref || github.ref_name }}"
fi

echo "linked_branch=$CENTREON_REPO_LINKED_BRANCH" >> $GITHUB_OUTPUT
shell: bash

- name: Checkout sources
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Checkout sources
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
repository: centreon/centreon
path: centreon
ref: ${{ steps.centreon_repo_linked_branch.outputs.linked_branch }}
sparse-checkout: |
centreon/www/install/createTables.sql
centreon/www/install/createTablesCentstorage.sql

- name: get cached gorgone package
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ./*.${{ matrix.package_extension }}
key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}
fail-on-cache-miss: true

- name: Parse distrib name
id: parse-distrib
uses: ./.github/actions/parse-distrib
with:
distrib: ${{ matrix.distrib }}

- name: Install gorgone from just built package
shell: bash
run: |
if [[ "${{ matrix.package_extension }}" == "deb" ]]; then
apt update
apt install -y ./centreon-gorgone*${{ steps.parse-distrib.outputs.package_distrib_name }}*
else
dnf install -y ./centreon-gorgone*${{ steps.parse-distrib.outputs.package_distrib_name }}* ./centreon-gorgone-centreon-config*${{ steps.parse-distrib.outputs.package_distrib_name }}*
# in el8 at least, there is a package for the configuration and a package for the actual code.
# this is not the case for debian, and for now I don't know why it was made any different between the 2 Os.
fi

- name: Create databases
run: |
mysql -h mariadb -u root -ppassword -e "CREATE DATABASE \`centreon\`"
mysql -h mariadb -u root -ppassword -e "CREATE DATABASE \`centreon-storage\`"
mysql -h mariadb -u root -ppassword -e "GRANT ALL PRIVILEGES ON centreon.* TO 'centreon'@'%'"
mysql -h mariadb -u root -ppassword -e "GRANT ALL PRIVILEGES ON \`centreon-storage\`.* TO 'centreon'@'%'"
mysql -h mariadb -u root -ppassword 'centreon' < centreon/centreon/www/install/createTables.sql
mysql -h mariadb -u root -ppassword 'centreon-storage' < centreon/centreon/www/install/createTablesCentstorage.sql

- name: Run tests
run: robot -v 'DBHOST:mariadb' -v 'DBNAME:centreon' -v 'DBNAME_STORAGE:centreon-storage' -v 'DBUSER:centreon' gorgone/tests

- name: Upload gorgone and robot debug artifacts
if: failure()
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
with:
name: gorgone-debug-${{ matrix.distrib }}
path: |
log.html
/var/log/centreon-gorgone
/etc/centreon-gorgone
retention-days: 1

deliver-sources:
runs-on: [self-hosted, common]
Expand Down
68 changes: 68 additions & 0 deletions gorgone/contrib/named_pipe_reader.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/perl
# Copyright 2024 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# 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.
#
use strict;
use warnings;
use Getopt::Long;
use POSIX qw(mkfifo);
use DateTime;
use File::Basename;
use File::Path qw(make_path);
# global variable for easier verb() usage, don't need to pass the verbose argument.
my $args = {};
sub main {

GetOptions("pipename=s" => \$args->{pipename},
"logfile=s" => \$args->{logfile}, # string
"verbose" => \$args->{verbose}) # flag
or die("Error in command line arguments\n");
make_path(basename($args->{pipename}));

verb("pipe to create is : " . $args->{pipename});
unlink($args->{pipename});
mkfifo($args->{pipename}, 0777) || die "can't mkfifo $args->{pipename} : $!";
open(my $fh_log, '>>', $args->{logfile}) or die "can't open log file $args->{logfile} : $!";
{
my $ofh = select $fh_log;
$| = 1; # work only on current filehandle, so we select our log fh and make it hot, and continue after.
select $ofh
}
while (1) {
open(my $fh_pipe, '<', $args->{pipename}) or die "can't open pipe $args->{pipename}";
my $val = <$fh_pipe>;
verb("pipe gave value : " . $val);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
my $date = sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$year+1900, $mon+1, $mday, $hour, $min, $sec
);
print $fh_log $date . " - " . $val;

close $fh_pipe;
sleep(0.1);
}

}
sub verb {
return if !$args->{verbose};
print DateTime->now() . " - ";
print shift ;
print "\n";
}
main;
Loading