aboutsummaryrefslogtreecommitdiff
path: root/quickstat.m4
blob: dfdd1df778158362ac2d869c30eaa61ed2456ca4 (plain)
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
#!/bin/bash

APPROOT="ROOTDIR"

. $APPROOT/lib/monitors.inc.sh

genall() {
	MONLIST	
}

availres=(RESLIST)
availact=(GET)
read request
action=$(printf "$request" | awk '{ print $1 }')
resource=$(printf "$request" | awk '{ print $2 }')

if [ -z "$(which iostat)" ]; then
        read -r -d '' RESPBODY <<HERE
{ "error":"command iostat unavailable" }
HERE
        echo "HTTP/1.1 500 Internal Server Error"
        echo "Content-Length: ${#RESPBODY}"
        echo "Date: $(date -Ru)"
        echo ""
        echo "$RESPBODY"
elif [ -z "$(awk -v thisact="$action" 'BEGIN { RS=" " } { if (thisact == $1) { print thisact } }' <<< "${availact[@]}")" ]; then
        read -r -d '' RESPBODY <<HERE
{ "error":"invalid HTTP method ($action)" }
HERE
        echo "HTTP/1.1 500 Internal Server Error"
        echo "Content-Length: ${#RESPBODY}"
        echo "Date: $(date -Ru)"
        echo ""
        echo "$RESPBODY"
elif [ -z "$(awk -v thisres="$resource" 'BEGIN { RS=" " } { if (thisres == $1) { print thisres } }' <<< "${availres[@]}")" ]; then
        read -r -d '' RESPBODY <<HERE
{ "error":"invalid path ($resource)" }
HERE
        echo "HTTP/1.1 404 Not Found"
        echo "Content-Length: ${#RESPBODY}"
        echo "Date: $(date -Ru)"
        echo ""
        echo "$RESPBODY"
else
        shortrec="$(sed 's/^\/stats[\/]*//g' <<< "$resource")"
        [[ -z "$shortrec" ]] && shortrec="all"

        read -r -d '' JSONDATA <<HERE
{
$(gen$shortrec)
}
HERE
        echo "HTTP/1.1 200 OK"
        echo "Content-Length: ${#JSONDATA}"
        echo "Date: $(date -Ru)"
        echo ""
        echo "$JSONDATA"
fi