Initial commit
Benjamin Renard

Benjamin Renard commited on 2009-10-15 17:26:07
Showing 1 changed files, with 47 additions and 0 deletions.

... ...
@@ -0,0 +1,47 @@
1
+#!/bin/bash
2
+
3
+LOG=/var/log/postgresql/postgresql-8.3-main.log
4
+WAL=/var/lib/postgresql/8.3/main/wal_archives
5
+WARN=5
6
+CRIT=10
7
+WARN_SIZE=500
8
+CRIT_SIZE=1000
9
+
10
+verb=0
11
+[ "$1" == "-v" ] && verb=1
12
+
13
+last="`grep "restored log file" $LOG|tail -n 1|sed 's/.*restored log file "\([^"]*\)".*/\1/g'`"
14
+[ $verb -eq 1 ] && echo "Last : $last"
15
+if [ ! -f $WAL/$last ]
16
+then
17
+	echo "PG RESTORE UNKNOWN: The last restored file ($last) is not available"
18
+	exit 3
19
+fi
20
+nb=`find $WAL -type f -cnewer $WAL/$last|wc -l`
21
+[ $verb -eq 1 ] && echo "Nb files : $nb"
22
+nbtot=`find $WAL -type f |wc -l`
23
+[ $verb -eq 1 ] && echo "Nb total files : $nbtot"
24
+let 'nbnodel=nbtot-nb'
25
+[ $verb -eq 1 ] && echo "Nb not deleted files : $nbnodel"
26
+size=`du -sm $WAL|sed 's/\([0-9]*\).*/\1/g'`
27
+[ $verb -eq 1 ] && echo "Size : $size MB"
28
+
29
+STATE=OK
30
+EXIT=0
31
+MSG="all files have been restored ($size MB - $nbnodel files not deleted)."
32
+if [ $nb -gt $CRIT -o $size -gt $CRIT_SIZE ]
33
+then
34
+	STATE="CRITICAL"
35
+	EXIT=2
36
+	MSG="$nb files not restored ($size MB - $nbnodel files not deleted)."
37
+else
38
+	if [ $nb -gt $WARN -o $size -gt $WARN_SIZE ]
39
+	then
40
+		STATE="WARNING"
41
+		EXIT=1
42
+		MSG="$nb files not restored ($size MB - $nbnodel files not deleted)."
43
+	fi
44
+fi
45
+
46
+echo "PG RESTORE $STATE: $MSG"
47
+exit $EXIT
0 48