Skip to content

Instantly share code, notes, and snippets.

@ebirn
Created February 13, 2014 13:33
Show Gist options
  • Save ebirn/8975073 to your computer and use it in GitHub Desktop.
Save ebirn/8975073 to your computer and use it in GitHub Desktop.
Nagios check for zfs snapshot creation date, checks the age of the most recent snapshot
#!/bin/sh
FSNAME=$1
WARNAGE=$2
CRITAGE=$3
NOW=$(/bin/date +%s)
ZFS="sudo /sbin/zfs"
# get all snapshots of zfs filesystem and search for newest snapshot
CREATIONDATE=$($ZFS get creation -Hpr -t snapshot $FSNAME | /bin/awk 'BEGIN {max = 0} {if ($3>max) max=$3} END {print max}')
DIFF=$((NOW-CREATIONDATE))
if (( WARNAGE > CRITAGE )); then
echo "usage: $0 <fsname> <warntime> <crittime>"
echo " warning time must be smaller than crittime"
exit 3
fi
RETVAL=3 # UNKNOWN
MSG=""
if (( DIFF > CRITAGE )); then
RETVAL=2 # CRITICAL
MSG="CRITICAL:"
elif (( DIFF > WARNAGE )); then
RETVAL=1 # WARNING
MSG="WARNING:"
else
RETVAL=0 # OK
MSG="OK:"
fi
DATEFMT=$(date -d @$CREATIONDATE +"%Y-%m-%dT%H:%M:%SZ")
echo "$MSG snapshot $FSNAME created $DATEFMT"
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment