Skip to content

Commit d532f37

Browse files
committed
Implemented apiCall wrapper ; fixed a bug with dbmon creation
1 parent b5b40ab commit d532f37

File tree

8 files changed

+181
-30
lines changed

8 files changed

+181
-30
lines changed

adc.sh

Lines changed: 80 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,69 @@ function recursiveSource {
9898
done
9999
fi
100100
}
101+
function apiCall {
102+
local OPTS
103+
while getopts "X:d:" opt "$@";
104+
do
105+
case "${opt}" in
106+
X)
107+
METHOD=${OPTARG}
108+
;;
109+
d)
110+
PAYLOAD=${OPTARG}
111+
;;
112+
esac
113+
done
114+
shiftOptInd
115+
shift $SHIFTS
116+
ENDPOINT=$1
117+
debug "Unparsed endpoint is $ENDPOINT"
118+
debug "Unparsed payload is $PAYLOAD"
119+
shift
120+
OLDIFS=$IFS
121+
IFS="\$"
122+
for MATCH in $PAYLOAD ; do
123+
if [ "${MATCH::1}" = "{" ] ; then
124+
MATCH=${MATCH:1}
125+
OPT=${MATCH%%\}*}:
126+
OPTS="${OPTS}${OPT}"
127+
fi
128+
done;
129+
for MATCH in $ENDPOINT ; do
130+
if [ "${MATCH::1}" = "{" ] ; then
131+
MATCH=${MATCH:1}
132+
OPT=${MATCH%%\}*}:
133+
OPTS="${OPTS}${OPT}"
134+
fi
135+
done;
136+
IFS=$OLDIFS
137+
if [ -n "$OPTS" ] ; then
138+
while getopts ${OPTS} opt;
139+
do
140+
PAYLOAD=${PAYLOAD//\$\{$opt\}/$OPTARG}
141+
ENDPOINT=${ENDPOINT//\$\{$opt\}/$OPTARG}
142+
done
143+
shiftOptInd
144+
shift $SHIFTS
145+
fi
146+
while [[ $ENDPOINT =~ \${[^}]*} ]] ; do
147+
if [ -z "$1" ] ; then
148+
error "Please provide an argument for paramater -${BASH_REMATCH:2:1}"
149+
return;
150+
fi
151+
ENDPOINT=${ENDPOINT//${BASH_REMATCH[0]}/$1}
152+
shift
153+
done
154+
debug "Call Controller: -X $METHOD -d $PAYLOAD $ENDPOINT"
155+
if [ -n "$PAYLOAD" ] ; then
156+
controller_call -X $METHOD -d $PAYLOAD $ENDPOINT
157+
else
158+
controller_call -X $METHOD $ENDPOINT
159+
fi
160+
}
161+
# __call GET "/controller/rest/applications/\${a}/business-transactions" -a ECommerce
162+
# echo "########"
163+
# __call GET "/controller/rest/applications/\${a}/nodes/\${n}" -n Web2 -a ECommerce
101164
function _config {
102165
local FORCE=0
103166
local GLOBAL=0
@@ -272,7 +335,7 @@ function controller_call {
272335
COMMAND_RESULT=$(httpClient -s -b $CONFIG_CONTROLLER_COOKIE_LOCATION \
273336
-X $METHOD\
274337
-H "X-CSRF-TOKEN: $XCSRFTOKEN" \
275-
"`[ -z "$FORM" ] && echo -H "Content-Type: application/json;charset=UTF-8"`" \
338+
"$([ -z "$FORM" ] && echo "-HContent-Type: application/json;charset=UTF-8")" \
276339
-H "Accept: application/json, text/plain, */*"\
277340
"`[ -n "$PAYLOAD" ] && echo -d ${PAYLOAD}`" \
278341
"`[ -n "$FORM" ] && echo -F ${FORM}`" \
@@ -447,18 +510,26 @@ describe application_export << EOF
447510
Export a application from the controller. Specifiy the application id as parameter.
448511
EOF
449512
function bt_list {
450-
local APPLICATION_ID=$*
451-
if [[ $APPLICATION_ID =~ ^[0-9]+$ ]]; then
452-
controller_call /controller/rest/applications/${APPLICATION_ID}/business-transactions
453-
else
454-
COMMAND_RESULT=""
455-
error "This is not a number: '$APPLICATION_ID'"
456-
fi
513+
apiCall -X GET "/controller/rest/applications/\${a}/business-transactions" "$@"
457514
}
458515
register bt_list List all business transactions for a given application
459516
describe bt_list << EOF
460517
List all business transactions for a given application. Provide the application id as parameter.
461518
EOF
519+
function tier_list {
520+
apiCall -X GET "/controller/rest/applications/\${a}/tiers" "$@"
521+
}
522+
register tier_list List all tiers for a given application
523+
describe tier_list << EOF
524+
List all tiers for a given application. Provide the application id as parameter.
525+
EOF
526+
function tier_get {
527+
apiCall -X GET "/controller/rest/applications/\${a}/tiers/\${t}" "$@"
528+
}
529+
register tier_get Retrieve Tier Information by Tier Name
530+
describe tier_get << EOF
531+
Retrieve Tier Information by Tier Name. Provide the application and the tier as parameters
532+
EOF
462533
function metric_list {
463534
local APPLICATION=${CONFIG_CONTROLLER_DEFAULT_APPLICATION}
464535
local METRIC_PATH=""
@@ -643,13 +714,7 @@ describe dbmon_list << EOF
643714
List all database collectors
644715
EOF
645716
function dbmon_delete {
646-
local COLLECTOR_ID=$*
647-
if [[ $COLLECTOR_ID =~ ^[0-9]+$ ]]; then
648-
controller_call -X POST -d "[$COLLECTOR_ID]" /controller/restui/databases/collectors/configuration/batchDelete
649-
else
650-
COMMAND_RESULT=""
651-
error "This is not a number: '$COLLECTOR_ID'"
652-
fi
717+
apiCall -X POST -d "[\${c}]" /controller/restui/databases/collectors/configuration/batchDelete "$@"
653718
}
654719
register dbmon_delete Delete a database collector
655720
describe dbmon_delete << EOF

commands/bt/list.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#!/bin/bash
22

33
function bt_list {
4-
local APPLICATION_ID=$*
5-
if [[ $APPLICATION_ID =~ ^[0-9]+$ ]]; then
6-
controller_call /controller/rest/applications/${APPLICATION_ID}/business-transactions
7-
else
8-
COMMAND_RESULT=""
9-
error "This is not a number: '$APPLICATION_ID'"
10-
fi
4+
apiCall -X GET "/controller/rest/applications/\${a}/business-transactions" "$@"
115
}
126

137
register bt_list List all business transactions for a given application

commands/controller/call.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function controller_call {
3131
COMMAND_RESULT=$(httpClient -s -b $CONFIG_CONTROLLER_COOKIE_LOCATION \
3232
-X $METHOD\
3333
-H "X-CSRF-TOKEN: $XCSRFTOKEN" \
34-
"`[ -z "$FORM" ] && echo -H "Content-Type: application/json;charset=UTF-8"`" \
34+
"$([ -z "$FORM" ] && echo "-HContent-Type: application/json;charset=UTF-8")" \
3535
-H "Accept: application/json, text/plain, */*"\
3636
"`[ -n "$PAYLOAD" ] && echo -d ${PAYLOAD}`" \
3737
"`[ -n "$FORM" ] && echo -F ${FORM}`" \

commands/dbmon/delete.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#!/bin/bash
22

33
function dbmon_delete {
4-
local COLLECTOR_ID=$*
5-
if [[ $COLLECTOR_ID =~ ^[0-9]+$ ]]; then
6-
controller_call -X POST -d "[$COLLECTOR_ID]" /controller/restui/databases/collectors/configuration/batchDelete
7-
else
8-
COMMAND_RESULT=""
9-
error "This is not a number: '$COLLECTOR_ID'"
10-
fi
4+
apiCall -X POST -d "[\${c}]" /controller/restui/databases/collectors/configuration/batchDelete "$@"
115
}
126

137
register dbmon_delete Delete a database collector

commands/tier/get.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
function tier_get {
4+
apiCall -X GET "/controller/rest/applications/\${a}/tiers/\${t}" "$@"
5+
}
6+
7+
register tier_get Retrieve Tier Information by Tier Name
8+
9+
describe tier_get << EOF
10+
Retrieve Tier Information by Tier Name. Provide the application and the tier as parameters
11+
EOF

commands/tier/list.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
function tier_list {
4+
apiCall -X GET "/controller/rest/applications/\${a}/tiers" "$@"
5+
}
6+
7+
register tier_list List all tiers for a given application
8+
9+
describe tier_list << EOF
10+
List all tiers for a given application. Provide the application id as parameter.
11+
EOF

helpers/apiCall.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
function apiCall {
4+
local OPTS
5+
6+
while getopts "X:d:" opt "$@";
7+
do
8+
case "${opt}" in
9+
X)
10+
METHOD=${OPTARG}
11+
;;
12+
d)
13+
PAYLOAD=${OPTARG}
14+
;;
15+
esac
16+
done
17+
shiftOptInd
18+
shift $SHIFTS
19+
20+
ENDPOINT=$1
21+
debug "Unparsed endpoint is $ENDPOINT"
22+
debug "Unparsed payload is $PAYLOAD"
23+
shift
24+
25+
OLDIFS=$IFS
26+
IFS="\$"
27+
for MATCH in $PAYLOAD ; do
28+
if [ "${MATCH::1}" = "{" ] ; then
29+
MATCH=${MATCH:1}
30+
OPT=${MATCH%%\}*}:
31+
OPTS="${OPTS}${OPT}"
32+
fi
33+
done;
34+
for MATCH in $ENDPOINT ; do
35+
if [ "${MATCH::1}" = "{" ] ; then
36+
MATCH=${MATCH:1}
37+
OPT=${MATCH%%\}*}:
38+
OPTS="${OPTS}${OPT}"
39+
fi
40+
done;
41+
IFS=$OLDIFS
42+
43+
if [ -n "$OPTS" ] ; then
44+
while getopts ${OPTS} opt;
45+
do
46+
PAYLOAD=${PAYLOAD//\$\{$opt\}/$OPTARG}
47+
ENDPOINT=${ENDPOINT//\$\{$opt\}/$OPTARG}
48+
done
49+
shiftOptInd
50+
shift $SHIFTS
51+
fi
52+
53+
while [[ $ENDPOINT =~ \${[^}]*} ]] ; do
54+
if [ -z "$1" ] ; then
55+
error "Please provide an argument for paramater -${BASH_REMATCH:2:1}"
56+
return;
57+
fi
58+
ENDPOINT=${ENDPOINT//${BASH_REMATCH[0]}/$1}
59+
shift
60+
done
61+
62+
debug "Call Controller: -X $METHOD -d $PAYLOAD $ENDPOINT"
63+
if [ -n "$PAYLOAD" ] ; then
64+
controller_call -X $METHOD -d $PAYLOAD $ENDPOINT
65+
else
66+
controller_call -X $METHOD $ENDPOINT
67+
fi
68+
}
69+
70+
# __call GET "/controller/rest/applications/\${a}/business-transactions" -a ECommerce
71+
# echo "########"
72+
# __call GET "/controller/rest/applications/\${a}/nodes/\${n}" -n Web2 -a ECommerce

main.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ source ./helpers/httpClient.sh
4141
source ./helpers/shiftOptInd.sh
4242
source ./helpers/urlencode.sh
4343
source ./helpers/recursiveSource.sh
44+
source ./helpers/apiCall.sh
4445

4546
source ./commands/config.sh
4647
source ./commands/help.sh
@@ -59,6 +60,9 @@ source ./commands/application/export.sh
5960

6061
source ./commands/bt/list.sh
6162

63+
source ./commands/tier/list.sh
64+
source ./commands/tier/get.sh
65+
6266
source ./commands/metric/list.sh
6367
source ./commands/metric/get.sh
6468
source ./commands/metric/tree.sh

0 commit comments

Comments
 (0)