-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.sh
77 lines (65 loc) · 1.9 KB
/
funcs.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
70
71
72
73
74
75
76
77
#!/bin/bash
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
send_mail(){
ruby "$SCRIPT_DIR/send_mail.rb" "$1"
}
website_running(){
name=$1
url=$2
if [[ -z $url ]]; then
url=$1
fi
result=$(curl -I https://$url 2> /dev/null | head -n 1 | grep -e "200" -e "401" -e "301" -e "302" )
if [[ -z $result ]]; then
printf "$name FAILED TO CONNECT\n"
send_mail "$name FAILED TO CONNECT"
else
printf "$name\n $result\n"
fi
sleep 3
}
disk_usage_percent(){
if [ -z "$1" ]; then
printf "first parameter must be full disk name e.g. /boot"
return -1
fi
# many spaces -> one
# column 6
# linenumber of line containing root
# just the line number, not the match
line=$(df -h | tr -s ' ' | cut -f6 -d \ | grep -n "^${1}$" | cut -d : -f1)
# take the value from column 5 in $line without %
usage=$(df -h | tr -s ' ' | cut -f5 -d \ | sed -n -e ${line}p | cut -d % -f1)
echo $usage
}
metric_check(){
name="$1"
test_command="$2"
test_type=$3
limit=$4
mail_text="$5"
number=$(eval $test_command)
if [ $number $test_type $limit ]; then
send_mail "$mail_text $limit ($number)"
fi
echo "$(date +"%Y-%m-%d %H:%M:%S"),$name,$number,$limit" >> "$SCRIPT_DIR/stats.csv"
}
application_status_check(){
test_command="$1"
running_output="$2"
start_command="$3"
failure_mail_text="$4"
output=$(eval $test_command)
if ! echo "$output" | grep -q "$running_output"; then
$start_command
sleep 10
output=$(eval $test_command)
if ! echo "$output" | grep -q "$running_output"; then
send_mail "$failure_mail_text - attempted to start WITH NO SUCCESS"
else
send_mail "$failure_mail_text - started it again successfully"
fi
else
echo "$test_command" good
fi
}