Skip to content

Commit 6aacee7

Browse files
authored
Release 20251200 (#5894)
2 parents 0b47145 + 4afcd4a commit 6aacee7

File tree

107 files changed

+11150
-601
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+11150
-601
lines changed

.githooks/pre-commit

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
#!/usr/bin/env sh
22
set -eu
33

4-
# ensure gitleaks is available
5-
if ! command -v gitleaks >/dev/null 2>&1; then
6-
echo "Error: gitleaks is not installed or not in PATH." >&2
7-
echo "Install: https://github.com/gitleaks/gitleaks#install" >&2
4+
# Directory containing the scripts (relative to this script's location)
5+
DIR="$(dirname "$0")/pre-commit.d"
6+
7+
# Variable to keep track of the highest exit code
8+
max_exit_code=0
9+
10+
# Check if the directory exists
11+
if [ ! -d "$DIR" ]; then
12+
echo "Error: directory '$DIR' does not exist." >&2
813
exit 1
914
fi
1015

11-
# scan for secrets before commit
12-
gitleaks detect --no-git --verbose
16+
# Execute each .sh file in the directory
17+
for script in "$DIR"/*.sh; do
18+
# Skip if no .sh files are found
19+
[ -e "$script" ] || { echo "no pre-commit hook found, maybe check $DIR folder for executable .sh files" ; exit 1 ; }
20+
21+
echo "Running $script ..."
22+
/bin/bash "$script"
23+
exit_code=$?
24+
25+
# Update the highest exit code if necessary
26+
if [ "$exit_code" -gt "$max_exit_code" ]; then
27+
max_exit_code=$exit_code
28+
fi
29+
done
30+
31+
exit $max_exit_code
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
RED='\033[0;31m'
4+
GREEN='\033[0;32m'
5+
YELLOW='\033[1;33m'
6+
NC='\033[0m' # No Color
7+
8+
# global errors counter
9+
errors=0
10+
11+
function info() {
12+
echo -e "${GREEN}INFO${NC}: $*"
13+
}
14+
15+
function warning() {
16+
echo -e "${YELLOW}WARNING${NC}: $*"
17+
}
18+
19+
function error() {
20+
echo -e "${RED}ERROR${NC}: $*"
21+
: $((errors++))
22+
}
23+
24+
function fatal() {
25+
echo -e "${RED}FATAL${NC}: $*"
26+
exit 1
27+
}
28+
29+
function check_tabs() {
30+
local file="$1"
31+
info "--> Checking BASH indentation"
32+
grep -P '^\t' "$file" >/dev/null 2>&1 && warning "--> File $file contains leading tab character (suspected bad indentation)."
33+
}
34+
35+
jq=$(type -p jq) || fatal "Could not locate jq command"
36+
# Determining the robotidy command
37+
robotidy_path=$(type -p robocop) || robotidy_path=$(type -p robotidy) || fatal "Could not locate either robocop nor robotidy. Cannot check robot lint"
38+
robotidy_exe="${robotidy_path##*/}"
39+
info "Robot lint tool is $robotidy_exe"
40+
# Options depend on the use binary
41+
declare -A robotidy_opts=([robotidy]="-->-check --skip-keyword-call Examples:" [robocop]="check" )
42+
# Get list of committed files
43+
mapfile -t committed_files < <(git diff --cached --name-only --diff-filter=ACMR)
44+
info "Starting plugins pre-commit hooks for ${#committed_files[@]} files"
45+
for file in "${committed_files[@]}"; do
46+
info "--> $file:"
47+
file_extension="${file##*.}"
48+
case "$file_extension" in
49+
pm|pl)
50+
# check that the perl file compiles
51+
info "--> Checking that file compiles"
52+
PERL5LIB="$PERL5LIB:./src/" perl -c "$file" >/dev/null 2>&1 || error "File $file does not compile with perl -c"
53+
# check the copyright year
54+
info "--> Checking that file copyright is OK"
55+
grep "Copyright 20..-Present Centreon" "$file" >/dev/null || error "Copyright in $file does not contain \"Copyright $(date +%Y)-Present Centreon\""
56+
# check that no help is written as --warning-* --critical-*
57+
info "--> Checking there's no unsplitted '--warning-*' / '--critical-*'"
58+
grep -- '--warning-\*\|--critical-\*' "$file" >/dev/null && error "File $file contains help that is written as --warning-* or --critical-*"
59+
# check spelling
60+
info "--> Checking that spelling in file is OK"
61+
perl .github/scripts/pod_spell_check.t "$file" ./tests/resources/spellcheck/stopwords.txt >/dev/null 2>&1 || error "Spellcheck error on file $file"
62+
check_tabs "$file"
63+
;;
64+
txt)
65+
if [[ "${file##*/}" == "stopwords.txt" ]]; then
66+
# sort file and check if it makes a difference
67+
info "--> Checking that stopwords.txt is sorted "
68+
sort -ui "$file" >/tmp/sorted_stopwords
69+
diff "$file" /tmp/sorted_stopwords >/dev/null || error "stopwords.txt not sorted properly"
70+
fi
71+
;;
72+
robot)
73+
info "--> Checking robot lint"
74+
$robotidy_path ${robotidy_opts[$robotidy_exe]} "$file" >/dev/null 2>&1 || warning "--> Robot lint errors found in $file"
75+
check_tabs "$file"
76+
;;
77+
sh)
78+
check_tabs "$file"
79+
;;
80+
json)
81+
info "--> Checking JSON validity"
82+
jq '' "$file" >/dev/null 2>&1 || error "JSON file $file is not valid"
83+
check_tabs "$file"
84+
;;
85+
*)
86+
info "File extension '.${file_extension}' has no checks"
87+
;;
88+
esac
89+
done
90+
(( errors > 0 )) && fatal "$errors errors found in pre-commit checks"
91+
info "All plugins pre-commit checks passed"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
4+
# ensure gitleaks is available
5+
if ! command -v gitleaks >/dev/null 2>&1; then
6+
echo "Error: gitleaks is not installed or not in PATH." >&2
7+
echo "Install: https://github.com/gitleaks/gitleaks#install" >&2
8+
exit 1
9+
fi
10+
11+
# scan for secrets before commit
12+
gitleaks detect --no-git --verbose

.github/CODEOWNERS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ tests/** @centreon/owners-robot-e2e
2121
packaging/** @centreon/owners-perl
2222
selinux/** @centreon/owners-pipelines
2323
.github/scripts/pod_spell_check.t @centreon/owners-perl
24+
.githooks/** @centreon/owners-perl
2425

26+
.githooks/pre-commit.d/gitleaks.sh @centreon/owners-security
27+
.githooks/pre-commit @centreon/owners-security
2528
.gitleaks.toml @centreon/owners-security
2629
.gitleaksignore @centreon/owners-security
27-
**/security-checks.yml @centreon/owners-security
30+
**/secu-*.yml @centreon/owners-security

.github/actions/merge-artifacts/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ runs:
1818
using: 'composite'
1919
steps:
2020
- name: Download Artifacts
21-
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
21+
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
2222
with:
2323
pattern: ${{ inputs.source_name_pattern }}*
2424
path: ${{ inputs.target_name }}
2525
merge-multiple: true
2626

2727
- name: Upload the Regrouped Artifact
28-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
28+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
2929
with:
3030
name: ${{ inputs.target_name }}
3131
path: |

.github/actions/package-nfpm/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ runs:
130130
# Add to your PR the label upload-artifacts to get packages as artifacts
131131
- if: ${{ contains(github.event.pull_request.labels.*.name, 'upload-artifacts') }}
132132
name: Upload package artifacts
133-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
133+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
134134
with:
135135
name: packages-${{ inputs.distrib }}
136136
path: ./*.${{ inputs.package_extension}}

.github/actions/test-plugins/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ runs:
2727
fail-on-cache-miss: true
2828

2929
- name: Get the cached plugins.json
30-
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
30+
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
3131
with:
3232
path: ./plugins.json
3333
key: ${{ inputs.plugins-json-cache-key }}

.github/dependabot.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/scripts/plugins-source.container.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@
9494
'centreon/plugins/templates/counter.pm',
9595
'centreon/plugins/templates/hardware.pm'
9696
);
97+
if (grep 'snmp_standard/modes/listinterfaces.pm', @{$config->{files}}) {
98+
my %temp_map = map {$_ => 1 } (@{$config->{files}}, "snmp_standard/mode/resources/");
99+
@{$config->{files}} = sort keys %temp_map;
100+
}
97101
foreach my $file ((@common_files, @{$config->{files}})) {
98102
if (-f $file) {
99103
File::Copy::Recursive::fcopy($file, 'lib/' . $file);

.github/scripts/test-plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def remove_plugin(plugin, archi):
183183
print(f"{nb_plugins} plugins tested.\n there was {error_install} installation error, {error_tests} test "
184184
f"errors, and {error_purge} removal error list of error : {list_plugin_error}", )
185185

186-
command = "ps -ax | grep snmpsim-command-respond | cut -dp -f1 | xargs kill"
186+
command = "ps -ax | grep sn[m]psim-command-respond | awk '{print $1}' | xargs kill"
187187
subprocess.run(command, shell=True, check=False)
188188

189189
if error_install != 0 or error_tests != 0 or error_purge != 0:

0 commit comments

Comments
 (0)