#!/bin/bash 

CACHE_NAME=$1


/usr/local/emhttp/plugins/dynamix/scripts/notify -e "scrub_array" -s "Scrub Cache Drive" -d "Scrub of cache drive started" -i "normal"
btrfs scrub start -Bdr "/mnt/$CACHE_NAME" > /var/log/scrub_array.log
if [ $? -eq 0 ]
then
    /usr/local/emhttp/plugins/dynamix/scripts/notify -e "scrub_array" -s "Scrub $1 Cache Drive" -d "Scrub of cache drive finished" -i "normal"
else
    /usr/local/emhttp/plugins/dynamix/scripts/notify -e "scrub_array" -s "Scrub $1 Cache Drive" -d "Error in scrub of cache drive!" -i "alert"
fi

if mountpoint -q "/mnt/$CACHE_NAME"; then 
    btrfs dev stats -c "/mnt/$CACHE_NAME" 
    if [[ $? -ne 0 ]]; then 
        /usr/local/emhttp/webGui/scripts/notify -i warning -s "ERRORS in $CACHE_NAME cache pool"; 
    fi
fi



# if mountpoint -q /mnt/$CACHE_NAME; then 
#     btrfs dev stats -c /mnt/$CACHE_NAME 
#     if [[ $? -ne 0 ]]; then 
#         /usr/local/emhttp/webGui/scripts/notify -i warning -s "ERRORS on cache pool"; 
#     fi
# fi