From b477cb7a55afa5e82e83c07ccf4fba5fa9932aac Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 7 Oct 2024 12:03:29 +0200 Subject: [PATCH] Add some pre-commit hooks --- .pre-commit-config.yaml | 29 +++++++++++++++++++++++++++++ README.md | 22 +++++++++------------- check_backuppc | 2 +- check_backuppc_du | 2 +- check_backuppc_nb_bkp_v3 | 32 +++++++++++++++++++------------- 5 files changed, 59 insertions(+), 28 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..b581460 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/README.md b/README.md index 9fa19d8..3a62e16 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,24 @@ -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 . -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. -This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. diff --git a/check_backuppc b/check_backuppc index 27969ec..13c6808 100755 --- a/check_backuppc +++ b/check_backuppc @@ -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) diff --git a/check_backuppc_du b/check_backuppc_du index 3e062d5..e753898 100755 --- a/check_backuppc_du +++ b/check_backuppc_du @@ -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; diff --git a/check_backuppc_nb_bkp_v3 b/check_backuppc_nb_bkp_v3 index 93b3615..bdb9df8 100755 --- a/check_backuppc_nb_bkp_v3 +++ b/check_backuppc_nb_bkp_v3 @@ -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=" @@ -15,18 +19,19 @@ OUT="
" 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="$v3" - v4=$( echo -e "$vers"|grep -Ec '^4' ) - let t_v4=t_v4+v4 - OUT="$OUT" +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="$v3" + v4=$( grep -Ec '^4' <<< "$vers" ) + ((t_v4=t_v4+v4)) + OUT="$OUT" done -[ $t_v3 -gt 0 ] && t_v3="$t_v3" +[[ $t_v3 -gt 0 ]] && t_v3="$t_v3" OUT="$OUT @@ -37,4 +42,5 @@ OUT="$OUT
$h$v3$v4
$h$v3$v4
" -echo $OUT|lynx -stdin +lynx -stdin <<< "$OUT" +# vim:set sw=4 ts=4 sts=4 ft=bash expandtab: