-
Notifications
You must be signed in to change notification settings - Fork 23
/
check_application_health.sh
executable file
·63 lines (57 loc) · 1.26 KB
/
check_application_health.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
#!/usr/bin/env bash
#
# Check application health
#
# Usage: check_application_health.sh [-w webroot] [-c command] [-t timeout]
# -w, --webroot Path to webroot
# -c, --command Healthcheck command
# -t, --timeout timeout, eg: 10s
# -h, --help Display this screen
#
# eg: check_application_health.sh \
# -w '/var/www/myapp.io/current' \
# -c 'php app/console monitor:health'
#
# (c) 2014, Benjamin Dos Santos <benjamin.dossantos@gmail.com>
# https://github.com/bdossantos/nagios-plugins
#
while [[ -n "$1" ]]; do
case $1 in
-w | --webroot)
webroot=$2
shift
;;
-c | --command)
command=$2
shift
;;
--help | -h)
sed -n '2,10p' "$0" | tr -d '#'
exit 3
;;
*)
echo "Unknown argument: $1"
exec "$0" --help
exit 3
;;
esac
shift
done
if [[ -z "$webroot" ]] || [[ -z "$command" ]]; then
echo "CRITICAL - undefined webroot or command"
exit 2
fi
if [[ ! -d "$webroot" ]]; then
echo "CRITICAL - webroot directory does not exist"
exit 2
fi
cd "$webroot"
health=$($command)
if [[ $? -ne 0 ]]; then
echo "CRITICAL - The application is sick, '${command}' return code != 0 !"
echo "$health"
exit 2
fi
echo "OK - The application is healthy"
echo "$health"
exit 0