Introduce pre-commit hooks

This commit is contained in:
Benjamin Renard 2024-04-18 11:16:47 +02:00
parent 28d084da36
commit 675bb089d8
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
3 changed files with 32 additions and 7 deletions

25
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,25 @@
# Pre-commit hooks to run tests and ensure code is cleaned.
# See https://pre-commit.com for more information
---
repos:
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
args:
- --ignore-words-list=exten
- --skip="./.*,*.csv,*.json,*.ini,*.subject,*.txt,*.html,*.log,*.conf"
- --quiet-level=2
- --ignore-regex=.*codespell-ignore$
#- --write-changes # Uncomment to write changes
exclude_types: [csv, json]
- repo: https://github.com/adrienverge/yamllint
rev: v1.32.0
hooks:
- id: yamllint
ignore: .github/
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
args: ["--print-width", "100"]

View file

@ -7,7 +7,7 @@ Checks are done by running Icinga/Nagios compatible check plugins inside contain
- `/usr/lib/nagios/plugins/check_apt`: for Debian based image, provide by the `monitoring-plugins-basic` debian package
- `/usr/lib/nagios/plugins/check_apk`: for Alpine based image, see [project](https://gitea.zionetrix.net/bn8/check_apk) for install instructions
__Note:__ The first plugin detected as installed will be used.
**Note:** The first plugin detected as installed will be used.
## Installation

View file

@ -139,7 +139,7 @@ fi
EXIT_CODE=0
declare -A CONTAINER_STATUS_FILE
declare -A CONTAINER_PID
declare -A UPTODATE
declare -A UP_TO_DATE
declare -A ERRORS
declare -A UNKNOWNS
CHECKED_CONTAINERS=( )
@ -232,7 +232,7 @@ do
rm -f ${CONTAINER_STATUS_FILE[$container]}
if [ $ex -eq 0 ]
then
UPTODATE+=( ["$container"]=$STATUS )
UP_TO_DATE+=( ["$container"]=$STATUS )
else
ERRORS+=( ["$container"]=$STATUS )
[ $ex -ge 3 ] && UNKNOWNS+=( "$container" )
@ -266,7 +266,7 @@ debug "Not found containers (${#NOTFOUNDS[@]}): $( implode ", " "${NOTFOUNDS[@]}
# Compute performance data
let CONTAINER_COUNTS=${#CHECKED_CONTAINERS[@]}+${#NOTFOUNDS[@]}
PERF_DATA=(
"uptodate_containers=${#UPTODATE[@]};;;0;$CONTAINER_COUNTS"
"uptodate_containers=${#UP_TO_DATE[@]};;;0;$CONTAINER_COUNTS"
"containers_with_errors=${#ERRORS[@]};1;;0;$CONTAINER_COUNTS"
"unknown_state_containers=${#UNKNOWNS[@]};;;0;$CONTAINER_COUNTS"
)
@ -274,7 +274,7 @@ PERF_DATA=(
# Display check result message
case $EXIT_CODE in
0)
echo -n "OK - All ${#UPTODATE[@]} container(s) are uptodate"
echo -n "OK - All ${#UP_TO_DATE[@]} container(s) are up-to-date"
;;
1)
echo -n "WARNING - ${#ERRORS[@]} container(s) need to be updated"
@ -296,9 +296,9 @@ do
echo ${container} - ${ERRORS[${container}]}
done
for container in ${!UPTODATE[@]}
for container in ${!UP_TO_DATE[@]}
do
echo ${container} - ${UPTODATE[${container}]}
echo ${container} - ${UP_TO_DATE[${container}]}
done
exit $EXIT_CODE