Add some pre-commit hooks

This commit is contained in:
Benjamin Renard 2024-10-07 12:03:29 +02:00
parent a18b4d6ae9
commit b477cb7a55
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
5 changed files with 59 additions and 28 deletions

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

@ -0,0 +1,29 @@
# 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/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
args: ["--print-width", "100"]
- repo: https://github.com/adrienverge/yamllint
rev: v1.32.0
hooks:
- id: yamllint
ignore: .github/
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck

View file

@ -1,25 +1,21 @@
Nagios/Icinga check plugins for BackupPC
========================================
# Nagios/Icinga check plugins for BackupPC
This repository compile some usefull Nagios/Icinga check plugins for BackupPC :
This repository compile some useful Nagios/Icinga check plugins for BackupPC :
* *check_backuppc\* :* Check the age of the last backup
* *check_backuppc_du :* Check disk space use by backups
- _check_backuppc\* :_ Check the age of the last backup
- _check_backuppc_du :_ Check disk space use by backups
\* This check plugins was fork from [_check_backuppc_](https://sourceforge.net/projects/n-backuppc/) (version 1.1.0) write by Seneca Cunningham <tetragon@users.sourceforge.net>.
Compatibility
-------------
## Compatibility
This check plugins have been successfully test with BackupPC 3 (3.2.1) and 4 (4.1.5).
Copyright
---------
## Copyright
Copyright (c) 2018 Easter-eggs
License
-------
## License
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.

View file

@ -82,7 +82,7 @@ $goodOpt = GetOptions(
@hostsDesired = () if $#hostsDesired < 0;
@hostsExcluded = () if $#hostsExcluded < 0;
# Always check disabled host if a named host is provided (when backup is trigerred by cron)
# Always check disabled host if a named host is provided (when backup is triggered by cron)
$forceCheckOnDisabledHosts = 1 if ( @hostsDesired && scalar(@hostsDesired) );
if ($opt_V)

View file

@ -105,7 +105,7 @@ my $hosts_infos = $server->HostInfoRead();
# undump the output... BackupPC uses Data::Dumper
eval $status_raw;
# Allow hostname separeted by comma
# Allow hostname separated by comma
@hostlist = split(/,/,join(',',@hostlist));
my $per_host_detail;

View file

@ -1,6 +1,10 @@
#!/bin/bash
cd /var/lib/backuppc/pc
[[ ! -d /var/lib/backuppc/pc ]] && echo "BackupPC directory not found (/var/lib/backuppc/pc)." && exit 1
if ! cd "/var/lib/backuppc/pc"; then
echo "Failed to enter in BackupPC directory (/var/lib/backuppc/pc)."
exit 1
fi
OUT="<table align=center>
<thead>
@ -15,18 +19,19 @@ OUT="<table align=center>
<tbody>"
t_v3=0
t_v4=0
for h in *
do
[ ! -d "$h" -o ! -e "$h/backups" ] && continue
vers=$( cat $h/backups|cut -f24 )
v3=$( echo -e "$vers"|grep -Ev '^4'|wc -l|cut -f1 )
let t_v3=t_v3+v3
[ $v3 -ne 0 ] && v3="<strong>$v3</strong>"
v4=$( echo -e "$vers"|grep -Ec '^4' )
let t_v4=t_v4+v4
for h in *; do
if [[ ! -d "$h" ]] || [[ ! -e "$h/backups" ]]; then
continue
fi
vers=$( cut -f24 < "$h/backups" )
v3=$( grep -Evc '^4' <<< "$vers" )
((t_v3=t_v3+v3))
[[ "$v3" -ne 0 ]] && v3="<strong>$v3</strong>"
v4=$( grep -Ec '^4' <<< "$vers" )
((t_v4=t_v4+v4))
OUT="$OUT<tr><td align=left>$h</td><td>$v3</td><td>$v4</td></tr>"
done
[ $t_v3 -gt 0 ] && t_v3="<strong>$t_v3</strong>"
[[ $t_v3 -gt 0 ]] && t_v3="<strong>$t_v3</strong>"
OUT="$OUT
</tbody>
<tfooter>
@ -37,4 +42,5 @@ OUT="$OUT
</tr>
</tfooter>
</table>"
echo $OUT|lynx -stdin
lynx -stdin <<< "$OUT"
# vim:set sw=4 ts=4 sts=4 ft=bash expandtab: