#!/bin/sh

monitoring=/var/tmp/zfs-auto-snapshot.status
crit_days=1

uptime=$(cut -d. -f1 /proc/uptime)
if [ "$uptime" -lt 3600 ]
then
    echo 'OK - The system has just booted'
    exit 0
fi

now=$(date +%s)
timestamp=$(cat "$monitoring")

if [ -z "$timestamp" ]
then
    echo 'UNKNOWN - No status info found'
    exit 3
fi

if [ "$timestamp" = 0 ]
then
    echo 'OK - Snapshots disabled'
    exit 0
elif [ $(( now - timestamp )) -gt $(( 60 * 60 * 24 * crit_days )) ]
then
    echo "CRITICAL - Status file indicates age greater than $crit_days day(s)"
    exit 2
else
    echo 'OK'
    exit 0
fi
