-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpfsense_zfs_check.sh
69 lines (53 loc) · 1.58 KB
/
pfsense_zfs_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
#Modify this line if you want to change the allowed utilization for the pool
max_capacity=50
healthy_state="all pools are healthy"
_V=0
while getopts "v" OPTION
do
case $OPTION in
v) _V=1
;;
esac
done
#Check health status of drive
pool_status=`zpool status -x`
if [ $_V -eq 1 ]; then
echo "--------------------------"
echo "------ Pool Status -----"
echo "--------------------------"
zpool status
fi
if [ "$pool_status" = "$healthy_state" ]; then
echo "------ All pools are OK -"
echo ""
echo "------ Starting Scrubs -"
#Trigger Scrub again for drives
zpool list -H | while read line; do
pool=`echo "$line" | cut -f1`
echo "Triggering scrub for: $pool"
zpool scrub "$pool"
done
else
echo "!! There is an error with one of the pools !!"
#Send email warning
echo "$pool_status" | /usr/local/bin/php /usr/local/bin/mail.php -s"`hostname`: pfSense zpool warning - Error"
fi
echo ""
echo ""
if [ $_V -eq 1 ]; then
echo "--------------------------"
echo "------ Checking Space --"
echo "--------------------------"
fi
#Check space
/sbin/zpool list -H -o capacity | while read line; do
capacity=`echo "$line"| cut -d'%' -f1`
echo "Current capacity for pool is: $capacity"
if [ "$capacity" -ge "$max_capacity" ]; then
echo "Drive capacity greater than max"
echo "Drive capacity at: ${capacity}%"| /usr/local/bin/php /usr/local/bin/mail.php -s"`hostname`: pfSense zpool warning - Capacity reached"
else
echo "Drive capacity below max"
fi
done