-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_aspnetcore_healthcheck
70 lines (60 loc) · 1.55 KB
/
check_aspnetcore_healthcheck
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/bash
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-u|--url)
url="$2"
shift # past argument
shift # past value
;;
-n|--health-check-name)
json_query="$2"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
# ICINGA Status Codes
STATUS_OK=0
STATUS_WARNING=1
STATUS_CRITICAL=2
STATUS_UNKNOWN=3
json=`curl -sS $url` || exit $STATUS_CRITICAL
if [ "$json_query" = "" ]; then
status=`echo $json | jq -r ".status"`
duration=`echo $json | jq -r ".totalDuration"`
entries=`echo $json | jq -r ".entries"`
message="Overall status fetched, see details below [$duration]"$'\n'"$entries"
else
status=`echo $json | jq -r ".entries.\"$json_query\".status"`
duration=`echo $json | jq -r ".entries.\"$json_query\".duration"`
data=`echo $json | jq -r ".entries.\"$json_query\".data"`
description=`echo $json | jq -r ".entries.\"$json_query\".description"`
message="$description [$duration]"$'\n'"Data: $data"
fi
case "$status" in
Healthy)
echo "OK: $message"
exit $STATUS_OK
;;
Degraded)
echo "WARNING: $message"
exit $STATUS_WARNING
;;
Unhealthy)
echo "CRITICAL: $message"
exit $STATUS_CRITICAL
;;
*)
echo "CRITICAL: Error interpreting service response"
echo $json
exit $STATUS_CRITICAL
;;
esac