-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalert.sh
More file actions
44 lines (42 loc) · 1.63 KB
/
alert.sh
File metadata and controls
44 lines (42 loc) · 1.63 KB
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
#!/bin/bash
# set alert level 90% is default
ALERT=90
# Exclude list of unwanted monitoring, if several partions then use "|" to separate the partitions.
EXCLUDE_LIST="/auto/ripper|loop"
LIST=( "example1@gmail.com" "example1@gmail.com" "example1@gmail.com" )
sender="example1@gmail.com"
gmpwd="smtp password goes here"
sub="Virtual Machine ran out of space"
#
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
main_prog() {
while read -r output;
do
#Get public ip of ur VM
publicip=`dig TXT +short o-o.myaddr.l.google.com @ns1.google.com`
usep=$(echo "$output" | awk '{ print $1}' | cut -d'%' -f1)
partition=$(echo "$output" | awk '{print $2}')
if [ $usep -ge $ALERT ] ; then
echo "Running out of space \"$partition ($usep%)\" on server $(hostname), $(date)\nPublic IP: $publicip" > "alert.txt"
body="Running out of space \"$partition ($usep%)\" on server $(hostname), $(date)\nPublic IP: $publicip"
for i in "${LIST[@]}"
do
receiver=$i
file=alert.txt
MIMEType=`file --mime-type "$file" | sed 's/.*: //'`
curl -s --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
--mail-from $sender \
--mail-rcpt $receiver\
--user $sender:$gmpwd \
-F '=(;type=multipart/mixed' -F "=$body;type=text/plain" -F "file=@$file;type=$MIMEType;encoder=base64" -F '=)' \
-H "Subject: $sub" -H "From: Alerts <$sender>" -H "To: $i"
done
fi
done
}
if [ "$EXCLUDE_LIST" != "" ] ; then
df -H | grep -vE "^Filesystem|tmpfs|cdrom|${EXCLUDE_LIST}" | awk '{print $5 " " $6}' | main_prog
else
df -H | grep -vE "^Filesystem|tmpfs|cdrom" | awk '{print $5 " " $6}' | main_prog
fi