Skip to content
Snippets Groups Projects
Commit a8cebf5e authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Replace the "partno" argument with "diskno partno" to match the

current lysrdiff.  Also adjust for new status files with double
dashes.  List both failed and stale backups, if there is space for it.
parent dd577a93
No related branches found
No related tags found
No related merge requests found
...@@ -8,14 +8,14 @@ activity=26 ...@@ -8,14 +8,14 @@ activity=26
stale=40 stale=40
usage () { usage () {
echo $0: usage: $0 '[ opt ] partno' >&2 echo $0: usage: $0 '[ opt ] diskno partno' >&2
echo options: >&2 echo options: >&2
echo ' --activty N Warn if no backup completed in the last N hours.' >&2 echo ' --activty N Warn if no backup completed in the last N hours.' >&2
echo ' --stale N Critical if oldest backup is more than N hours old.' >&2 echo ' --stale N Critical if oldest backup is more than N hours old.' >&2
exit 3 exit 3
} }
while [ $# -gt 1 ] while [ $# -gt 2 ]
do do
case "x$1" in case "x$1" in
x--activity) x--activity)
...@@ -33,23 +33,25 @@ do ...@@ -33,23 +33,25 @@ do
esac esac
done done
if [ $# != 1 ] if [ $# != 2 ]
then then
usage usage
fi fi
partno=$1 disk=$1
BASE=/lysrdiff/$partno/perm part=$2
BASE=/lysrdiff/$disk/perm/$part
if [ ! -f $BASE/lysrdiff.id ] if [ ! -f $BASE/lysrdiff.id ]
then then
echo CRITICAL - $BASE: no such file echo CRITICAL - $BASE/lysrdiff.id: no such file
exit 2 exit 2
fi fi
if [ "`cat $BASE/lysrdiff.id`" != "$partno perm" ] if [ "`cat $BASE/lysrdiff.id`" != "$disk perm $part" ]
then then
echo CRITICAL - found `cat $BASE/lysrdiff.id` instead of $lysrdiff >&2 echo CRITICAL - found `cat $BASE/lysrdiff.id` instead of $disk perm $part \
>&2
exit 2 exit 2
fi fi
...@@ -57,14 +59,14 @@ acttime=`date '+%Y-%m-%d %H:%M:%S' -d "$activity hours ago"` ...@@ -57,14 +59,14 @@ acttime=`date '+%Y-%m-%d %H:%M:%S' -d "$activity hours ago"`
staletime=`date '+%Y-%m-%d %H:%M:%S' -d "$stale hours ago"` staletime=`date '+%Y-%m-%d %H:%M:%S' -d "$stale hours ago"`
statecache=/tmp/lysrdiff-nagios-state statecache=/tmp/lysrdiff-nagios-state
state=$statecache-$partno state=$statecache-$disk-$part
find $BASE/lysrdiff/state -type f \ find $BASE/lysrdiff/state -type f \
-printf "%TY-%Tm-%Td %TH:%TM:%TS %P\n" \ -printf "%TY-%Tm-%Td %TH:%TM:%TS %P\n" \
| sort > $statecache.$partno.$$ | sort > $statecache.$disk.$part.$$
mv -f $statecache.$partno.$$ $state || { mv -f $statecache.$disk.$part.$$ $state || {
echo UNKNOWN - mv failed echo UNKNOWN - mv failed
rm $statecache.$partno.$$ rm $statecache.$disk.$part.$$
exit 3 exit 3
} }
rm -f $state-stale $state-active || { rm -f $state-stale $state-active || {
...@@ -75,21 +77,21 @@ rm -f $state-stale $state-active || { ...@@ -75,21 +77,21 @@ rm -f $state-stale $state-active || {
echo $staletime MARKER \ echo $staletime MARKER \
| sort $state - \ | sort $state - \
| grep -- '-start$\|MARKER' \ | grep -- '--start$\|MARKER' \
| sed -e '/MARKER$/,$d' \ | sed -e '/MARKER$/,$d' \
> $state-stale > $state-stale
echo $acttime MARKER \ echo $acttime MARKER \
| sort $state - \ | sort $state - \
| grep -- '-end$\|MARKER' \ | grep -- '--end$\|MARKER' \
| sed -e '0,/MARKER$/d' \ | sed -e '0,/MARKER$/d' \
> $state-active > $state-active
FAILED=`grep -c -- '-fail$' $state` FAILED=`grep -c -- '--fail$' $state`
STALE=`wc -l < $state-stale` STALE=`wc -l < $state-stale`
ACTIVITY=`wc -l < $state-active` ACTIVITY=`wc -l < $state-active`
if [ $FAILED -gt 0 ] if [ $FAILED -gt 10 ]
then then
echo -n "CRITICAL - $FAILED failed backups" echo -n "CRITICAL - $FAILED failed backups"
if [ $STALE -gt 0 ] if [ $STALE -gt 0 ]
...@@ -97,7 +99,7 @@ then ...@@ -97,7 +99,7 @@ then
echo -n " (also $STALE stale)" echo -n " (also $STALE stale)"
fi fi
echo -n ": " echo -n ": "
sed -n 's/-fail$//p' $state \ sed -n 's/--fail$//p' $state \
|awk 'BEGIN { sz = 0 } |awk 'BEGIN { sz = 0 }
NR > 1 && sz < 198 { printf ", "; sz += 2 } NR > 1 && sz < 198 { printf ", "; sz += 2 }
sz < 200 { printf "%s", $3; sz += length($3) } sz < 200 { printf "%s", $3; sz += length($3) }
...@@ -105,14 +107,51 @@ then ...@@ -105,14 +107,51 @@ then
|sed s'/, \([^,]*\)$/ and \1/' |sed s'/, \([^,]*\)$/ and \1/'
echo '. | activity='$ACTIVITY stale=$STALE failed=$FAILED echo '. | activity='$ACTIVITY stale=$STALE failed=$FAILED
rm $state $state-stale $state-active rm $state $state-stale $state-active
exit 2
fi
if [ $STALE -gt 10 ]
then
echo -n "CRITICAL - $STALE stale backups"
if [ $FAILED -gt 0 ]
then
echo -n " (also $FAILED failed)"
fi
( sed -n 's/--fail$//p' $state; sed 's/--start$//' $state-stale; ) \
|awk 'BEGIN { sz = 0 }
NR > 1 && sz < 198 { printf ", "; sz += 2 }
sz < 200 { printf "%s", $3; sz += length($3) }
END { if (sz >= 200) printf ", others" } ' \
|sed s'/, \([^,]*\)$/ and \1/'
echo '. | activity='$ACTIVITY stale=$STALE failed=$FAILED
rm $state $state-stale $state-active
exit 2 exit 2
fi fi
if [ $FAILED -gt 0 ]
then
echo -n "WARNING - $FAILED failed backups"
if [ $STALE -gt 0 ]
then
echo -n " (also $STALE stale)"
fi
echo -n ": "
sed -n 's/--fail$//p' $state \
|awk 'BEGIN { sz = 0 }
NR > 1 && sz < 198 { printf ", "; sz += 2 }
sz < 200 { printf "%s", $3; sz += length($3) }
END { if (sz >= 200) printf ", others" } ' \
|sed s'/, \([^,]*\)$/ and \1/'
echo '. | activity='$ACTIVITY stale=$STALE failed=$FAILED
rm $state $state-stale $state-active
exit 1
fi
if [ $STALE -gt 0 ] if [ $STALE -gt 0 ]
then then
echo -n "CRITICAL - $STALE stale backups: " echo -n "WARNING - $STALE stale backups: "
sed 's/-start$//' $state-stale \ sed 's/--start$//' $state-stale \
|awk 'BEGIN { sz = 0 } |awk 'BEGIN { sz = 0 }
NR > 1 && sz < 198 { printf ", "; sz += 2 } NR > 1 && sz < 198 { printf ", "; sz += 2 }
sz < 200 { printf "%s", $3; sz += length($3) } sz < 200 { printf "%s", $3; sz += length($3) }
...@@ -120,7 +159,7 @@ then ...@@ -120,7 +159,7 @@ then
|sed s'/, \([^,]*\)$/ and \1/' |sed s'/, \([^,]*\)$/ and \1/'
echo '. | activity='$ACTIVITY stale=$STALE failed=0 echo '. | activity='$ACTIVITY stale=$STALE failed=0
rm $state $state-stale $state-active rm $state $state-stale $state-active
exit 2 exit 1
fi fi
if [ $ACTIVITY = 0 ] if [ $ACTIVITY = 0 ]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment