#!/bin/bash LOG=/var/log/postgresql/postgresql-8.3-main.log WAL=/var/lib/postgresql/8.3/main/wal_archives WARN=5 CRIT=10 WARN_SIZE=500 CRIT_SIZE=1000 verb=0 [ "$1" == "-v" ] && verb=1 # Locale C last="`grep "restored log file" $LOG|tail -n 1|sed 's/.*restored log file "\([^"]*\)".*/\1/g'`" # Locale fr_FR #last=$( grep "restauration du journal de transactions" /data/prod/pg_log/postgresql-14.log|tail -n 1|sed 's/.*restauration du journal de transactions « \([^ ]*\) ».*/\1/g' ) [ $verb -eq 1 ] && echo "Last : $last" if [ ! -f $WAL/$last ] then echo "PG RESTORE UNKNOWN: The last restored file ($last) is not available" exit 3 fi nb=`find $WAL -type f -cnewer $WAL/$last|wc -l` [ $verb -eq 1 ] && echo "Nb files : $nb" nbtot=`find $WAL -type f |wc -l` [ $verb -eq 1 ] && echo "Nb total files : $nbtot" let 'nbnodel=nbtot-nb' [ $verb -eq 1 ] && echo "Nb not deleted files : $nbnodel" size=`du -sm $WAL|sed 's/\([0-9]*\).*/\1/g'` [ $verb -eq 1 ] && echo "Size : $size MB" STATE=OK EXIT=0 MSG="all files have been restored ($size MB - $nbnodel files not deleted)." PERF_DATA="size=${size}MB,not_deleted_files=$nbnodel,not_restored_files=$nb" if [ $nb -gt $CRIT -o $size -gt $CRIT_SIZE ] then STATE="CRITICAL" EXIT=2 MSG="$nb files not restored ($size MB - $nbnodel files not deleted)." else if [ $nb -gt $WARN -o $size -gt $WARN_SIZE ] then STATE="WARNING" EXIT=1 MSG="$nb files not restored ($size MB - $nbnodel files not deleted)." fi fi echo "PG RESTORE $STATE: $MSG | $PERF_DATA" exit $EXIT