X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Fprivate%2Fmonitoring%2Fplugins%2Fcheck_backup_age;fp=modules%2Fprivate%2Fmonitoring%2Fplugins%2Fcheck_backup_age;h=0000000000000000000000000000000000000000;hb=1a64deeb894dc95e2645a75771732c6cc53a79ad;hp=d873bdc4ea1814bddc4ecc72cd120afad4d0295e;hpb=fa25ffd4583cc362075cd5e1b4130f33306103f0;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/private/monitoring/plugins/check_backup_age b/modules/private/monitoring/plugins/check_backup_age deleted file mode 100755 index d873bdc..0000000 --- a/modules/private/monitoring/plugins/check_backup_age +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -source $SECRETS_PATH -export HOME=$(mktemp -d) - -trap "rm -rf $HOME" EXIT -folder=$1 - -parse_date() { - d=$1 - echo $d | sed -e "s/^\(....\)\(..\)\(..\)T\(..\)\(..\)\(..\)/\1-\2-\3T\4:\5:\6/" -} - -output=$(duplicity collection-status --log-fd 2 "$BASE_URL$folder" 2>&1 > /dev/null) - -output=$(echo "$output" | grep -v "^\.") - -last_full=$(parse_date "$(echo "$output" | grep "^ full " | cut -d' ' -f3 | sort | tail -n1)") -last_bkp=$(parse_date "$(echo "$output" | grep -E "^ (full|inc) " | cut -d' ' -f3 | sort | tail -n1)") -orphaned_sets=$(echo "$output" | grep "^orphaned-sets-num" | cut -d' ' -f2) -incomplete_sets=$(echo "$output" | grep "^incomplete-sets-num" | cut -d' ' -f2) - -if [[ -z "$last_full" || -z "$last_bkp" || -z "$orphaned_sets" || -z "$incomplete_sets" ]]; then - echo "duply-backup $folder UNKNOWN - impossible to parse result" - exit 3 -fi - -last_full_age=$(( ($(date "+%s") - $(date -d "$last_full" "+%s")) / (60*60*24) )) -last_bkp_age=$(( ($(date "+%s") - $(date -d "$last_bkp" "+%s")) / (60*60) )) - -PERFS="orphan=$orphaned_sets;1;;0; incomplete=$incomplete_sets;1;;0; age=${last_bkp_age}h;30;48;0; full_age=${last_full_age}d;35;45;0;" - - -WARNINGS="" -ERRORS="" -if [[ "$incomplete_sets" -gt 0 ]]; then - WARNINGS="$WARNINGS - Incomplete sets is $incomplete_sets" -fi - -if [[ "$orphaned_sets" -gt 0 ]]; then - WARNINGS="$WARNINGS - Orphaned sets is $orphaned_sets" -fi - -if [[ "$last_full_age" -gt 45 ]]; then - ERRORS="$ERRORS - Last full backup is too old $last_full" -elif [[ "$last_full_age" -gt 35 ]]; then - WARNINGS="$WARNINGS - Last full backup is getting old $last_full" -fi - -if [[ "$last_bkp_age" -gt 48 ]]; then - ERRORS="$ERRORS - Last backup is too old $last_bkp" -elif [[ "$last_bkp_age" -gt 30 ]]; then - WARNINGS="$WARNINGS - Last backup is getting old $last_bkp" -fi - -if [[ -n "$ERRORS" ]]; then - echo "duply-backup $folder CRITICAL$ERRORS$WARNINGS | $PERFS" - exit 2 -elif [[ -n "$WARNINGS" ]]; then - echo "duply-backup $folder WARNING$WARNINGS | $PERFS" - exit 1 -else - echo "duply-backup $folder OK | $PERFS" -fi