-
Notifications
You must be signed in to change notification settings - Fork 0
/
btrfs-monitor.sh
47 lines (40 loc) · 948 Bytes
/
btrfs-monitor.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
#!/bin/sh
# Import config
. /etc/conf.d/btrfs-monitor 2>/dev/null || >&2 echo "Could not source /etc/conf.d/btrfs-monitor"
STATUS_CMD="/bin/btrfs device stats"
send_email() {
printf "%s\n" \
"Subject: $1" \
"MIME-Version: 1.0" \
"Content-Type: text/html" \
"Content-Disposition: inline" \
"<html>" \
"<body>" \
"<pre style="font: monospace">" \
"$(date)" \
"$2" \
"</pre>" \
"</body>" \
"</html>" \
| sendmail "$MAILTO"
}
status=$($STATUS_CMD "$1")
if [ $? -ne 0 ]; then
echo "Error: Can't get device status"
exit 1
fi
echo "$status" | grep -qE '\s[^0]$'
error_found=$?
message="Status report for $1"
[ $error_found -eq 0 ] && message="Error found on $1"
echo "$message"
echo "$status"
if [ $error_found -eq 0 ] || [ "$ALWAYS_NOTIFY" == "true" ]; then
if [ -n "$MAILTO" ]; then
echo "Sending email to $MAILTO"
send_email "$message" "$status"
else
>&2 echo "Error: No email address given"
exit 1
fi
fi