Skip to content

Commit 4552f78

Browse files
committed
Add wildcard expansion to apiCall
1 parent 43a2301 commit 4552f78

File tree

9 files changed

+223
-37
lines changed

9 files changed

+223
-37
lines changed

USAGE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ Import and export custom dashboards in the AppDynamics controller
164164
| ------- | ----------- | ------- |
165165
| delete | Delete a dashboard. Provide a dashboard id (-i) as parameter | `act.sh dashboard delete -i 2` |
166166
| export | Export a dashboard. Provide a dashboard id (-i) as parameter | `act.sh dashboard export -i 2` |
167+
| import | Import a dashboard. Provide a dashboard file or json (-d) as parameter. | `act.sh dashboard import -d @examples/dashboard.json` |
167168
| list | List all dashboards. This command requires no further arguments. | `act.sh dashboard list ` |
168-
| update | Update a dashboard. Provide a dashboard file or json (-f) as parameter. Please not that the json you need to provide is not compatible with the export format. | `act.sh dashboard update -i 2` |
169-
| import | Import a dashboard from a given file | |
169+
| update | Update a dashboard. Provide a dashboard file or json (-f) as parameter. Please not that the json you need to provide is not compatible with the export format. | `act.sh dashboard update -d @dashboardUpdate.json` |
170170

171171

172172
## dbmon

act.sh

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
ACT_VERSION="v0.4.0"
3-
ACT_LAST_COMMIT="05b09dfd00a013c4ec108156661cd20e8218bde2"
3+
ACT_LAST_COMMIT="43a2301ebe6ce3e819b9ac5a09a6fb0a3687c4a7"
44
USER_CONFIG="$HOME/.appdynamics/act/config.sh"
55
GLOBAL_CONFIG="/etc/appdynamics/act/config.sh"
66
CONFIG_CONTROLLER_COOKIE_LOCATION="/tmp/appdynamics-controller-cookie.txt"
@@ -162,10 +162,12 @@ function dashboard_delete { apiCall -X POST -d '[{{i:dashboard_id}}]' '/controll
162162
rde dashboard_delete "Delete a dashboard." "Provide a dashboard id (-i) as parameter" "-i 2"
163163
function dashboard_export { apiCall '/controller/CustomDashboardImportExportServlet?dashboardId={{i:dashboard_id}}' "$@" ; }
164164
rde dashboard_export "Export a dashboard." "Provide a dashboard id (-i) as parameter" "-i 2"
165+
function dashboard_import { apiCallExpand -X POST -F 'file={{d:dashboard}}' '/controller/CustomDashboardImportExportServlet' "$@" ; }
166+
rde dashboard_import "Import a dashboard." "Provide a dashboard file or json (-d) as parameter." "-d @examples/dashboard.json"
165167
function dashboard_list { apiCall '/controller/restui/dashboards/getAllDashboardsByType/false' "$@" ; }
166168
rde dashboard_list "List all dashboards." "This command requires no further arguments." ""
167169
function dashboard_update { apiCall -X POST -d '{{f:dashboard_definition}}' '/controller/restui/dashboards/updateDashboard' "$@" ; }
168-
rde dashboard_update "Update a dashboard." "Provide a dashboard file or json (-f) as parameter. Please not that the json you need to provide is not compatible with the export format." "-i 2"
170+
rde dashboard_update "Update a dashboard." "Provide a dashboard file or json (-f) as parameter. Please not that the json you need to provide is not compatible with the export format." "-d @dashboardUpdate.json"
169171
doc dbmon << EOF
170172
Use the Database Visibility API to get, create, update, and delete Database Visibility Collectors.
171173
EOF
@@ -612,19 +614,6 @@ Get installed version from controller
612614
EOF
613615
example controller_version << EOF
614616
EOF
615-
function dashboard_import {
616-
FILE="$*"
617-
if [ -r $FILE ] ; then
618-
controller_call -X POST -F file=@$FILE /controller/CustomDashboardImportExportServlet
619-
else
620-
COMMAND_RESULT=""
621-
error "File not found or not readable: $FILE"
622-
fi
623-
}
624-
register dashboard_import Import a dashboard
625-
describe dashboard_import << EOF
626-
Import a dashboard from a given file
627-
EOF
628617
function actiontemplate_delete {
629618
local TYPE="httprequest"
630619
local ID=0
@@ -1442,6 +1431,44 @@ function recursiveSource {
14421431
done
14431432
fi
14441433
}
1434+
# Helper function to expand multiple files that are provided as payload
1435+
function apiCallExpand {
1436+
debug "Calling apiCallExpand"
1437+
local COUNTER=0
1438+
local PREFIX=""
1439+
local SUFFIX=""
1440+
local LIST=""
1441+
declare -i COUNTER
1442+
for ARG in $*; do
1443+
if [ "${ARG:0:1}" = "@" ] && [ "${ARG:1}" != "$(echo ${ARG:1})" ] ; then
1444+
LIST=$(echo ${ARG:1})
1445+
COUNTER=${COUNTER}+1
1446+
elif [ "${COUNTER}" -eq "0" ]; then
1447+
PREFIX="${PREFIX} ${ARG}"
1448+
else
1449+
SUFFIX="${SUFFIX} ${ARG}"
1450+
fi;
1451+
done;
1452+
case "${COUNTER}" in
1453+
"0")
1454+
debug "apiCallExpand: No expansion"
1455+
apiCall "$@"
1456+
;;
1457+
"1")
1458+
debug "apiCallExpand: With expansion"
1459+
local COMBINED_RESULT=""
1460+
for ELEMENT in ${LIST}; do
1461+
COMBINED_RESULT="${COMBINED_RESULT}${EOL}$(apiCall ${PREFIX} @${ELEMENT} ${SUFFIX})"
1462+
echo $COMBINED_RESULT
1463+
done;
1464+
COMMAND_RESULT=${COMBINED_RESULT}
1465+
;;
1466+
*)
1467+
error "You can only provide one file list for expansion."
1468+
COMMAND_RESULT=""
1469+
;;
1470+
esac
1471+
}
14451472
function apiCall {
14461473
local OPTS
14471474
local OPTIONAL_OPTIONS=""
@@ -1563,7 +1590,7 @@ function apiCall {
15631590
CONTROLLER_ARGS+=("-B")
15641591
debug "Using basic http authentication"
15651592
fi;
1566-
if [ -n "$PAYLOAD" ] ; then
1593+
if [ -n "${PAYLOAD}" ] ; then
15671594
if [ "${PAYLOAD:0:1}" = "@" ] ; then
15681595
debug "Loading payload from file ${PAYLOAD:1}"
15691596
if [ -r "${PAYLOAD:1}" ] ; then

commands.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,18 @@ dashboard:
287287
update:
288288
title: Update a dashboard.
289289
description: Provide a dashboard file or json (-f) as parameter. Please not that the json you need to provide is not compatible with the export format.
290-
example: -i 2
290+
example: -d @dashboardUpdate.json
291291
method: POST
292292
endpoint: /controller/restui/dashboards/updateDashboard
293293
payload: {{f:dashboard_definition}}
294+
import:
295+
title: Import a dashboard.
296+
description: Provide a dashboard file or json (-d) as parameter.
297+
example: -d @examples/dashboard.json
298+
method: POST
299+
endpoint: /controller/CustomDashboardImportExportServlet
300+
form: file={{d:dashboard}}
301+
expand: true
294302
event:
295303
title: Events
296304
description: Create and list events in your business applications.

commands/dashboard/import.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/dashboard_empty.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"schemaVersion": null,
3+
"dashboardFormatVersion": "4.0",
4+
"name": "Empty Dashboard",
5+
"description": null,
6+
"properties": null,
7+
"templateEntityType": "APPLICATION_COMPONENT_NODE",
8+
"associatedEntityTemplates": null,
9+
"minutesBeforeAnchorTime": -1,
10+
"startDate": null,
11+
"endDate": null,
12+
"refreshInterval": 120000,
13+
"backgroundColor": 15856629,
14+
"color": 15856629,
15+
"height": 768,
16+
"width": 1024,
17+
"canvasType": "CANVAS_TYPE_GRID",
18+
"layoutType": "",
19+
"widgetTemplates": null,
20+
"warRoom": false,
21+
"template": false
22+
}

examples/dashboard_one_widget.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"schemaVersion": null,
3+
"dashboardFormatVersion": "4.0",
4+
"name": "One Widget Dashboard",
5+
"description": null,
6+
"properties": null,
7+
"templateEntityType": "APPLICATION_COMPONENT_NODE",
8+
"associatedEntityTemplates": null,
9+
"minutesBeforeAnchorTime": -1,
10+
"startDate": null,
11+
"endDate": null,
12+
"refreshInterval": 120000,
13+
"backgroundColor": 15856629,
14+
"color": 15856629,
15+
"height": 768,
16+
"width": 1024,
17+
"canvasType": "CANVAS_TYPE_GRID",
18+
"layoutType": "",
19+
"widgetTemplates": [
20+
{
21+
"widgetType": "TextWidget",
22+
"title": null,
23+
"height": 1,
24+
"width": 4,
25+
"minHeight": 0,
26+
"minWidth": 0,
27+
"x": 0,
28+
"y": 0,
29+
"label": null,
30+
"description": null,
31+
"drillDownUrl": null,
32+
"useMetricBrowserAsDrillDown": false,
33+
"drillDownActionType": null,
34+
"backgroundColor": 16777215,
35+
"backgroundColors": null,
36+
"backgroundColorsStr": "16777215,16777215",
37+
"color": 1646891,
38+
"fontSize": 12,
39+
"useAutomaticFontSize": false,
40+
"borderEnabled": false,
41+
"borderThickness": 0,
42+
"borderColor": 14408667,
43+
"backgroundAlpha": 1,
44+
"showValues": false,
45+
"formatNumber": null,
46+
"numDecimals": 0,
47+
"removeZeros": null,
48+
"compactMode": false,
49+
"showTimeRange": false,
50+
"renderIn3D": false,
51+
"showLegend": null,
52+
"legendPosition": null,
53+
"legendColumnCount": null,
54+
"startTime": null,
55+
"endTime": null,
56+
"minutesBeforeAnchorTime": 15,
57+
"isGlobal": true,
58+
"propertiesMap": null,
59+
"dataSeriesTemplates": null,
60+
"text": "Dashboard label",
61+
"textAlign": "CENTER",
62+
"margin": 4
63+
}
64+
],
65+
"warRoom": false,
66+
"template": false
67+
}

helpers/apiCall.sh

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,43 @@
11
#!/bin/bash
2+
# Helper function to expand multiple files that are provided as payload
3+
function apiCallExpand {
4+
debug "Calling apiCallExpand"
5+
local COUNTER=0
6+
local PREFIX=""
7+
local SUFFIX=""
8+
local LIST=""
9+
declare -i COUNTER
10+
for ARG in $*; do
11+
if [ "${ARG:0:1}" = "@" ] && [ "${ARG:1}" != "$(echo ${ARG:1})" ] ; then
12+
LIST=$(echo ${ARG:1})
13+
COUNTER=${COUNTER}+1
14+
elif [ "${COUNTER}" -eq "0" ]; then
15+
PREFIX="${PREFIX} ${ARG}"
16+
else
17+
SUFFIX="${SUFFIX} ${ARG}"
18+
fi;
19+
done;
20+
21+
case "${COUNTER}" in
22+
"0")
23+
debug "apiCallExpand: No expansion"
24+
apiCall "$@"
25+
;;
26+
"1")
27+
debug "apiCallExpand: With expansion"
28+
local COMBINED_RESULT=""
29+
for ELEMENT in ${LIST}; do
30+
COMBINED_RESULT="${COMBINED_RESULT}${EOL}$(apiCall ${PREFIX} @${ELEMENT} ${SUFFIX})"
31+
echo $COMBINED_RESULT
32+
done;
33+
COMMAND_RESULT=${COMBINED_RESULT}
34+
;;
35+
*)
36+
error "You can only provide one file list for expansion."
37+
COMMAND_RESULT=""
38+
;;
39+
esac
40+
}
241

342
function apiCall {
443
local OPTS
@@ -134,7 +173,7 @@ function apiCall {
134173
debug "Using basic http authentication"
135174
fi;
136175

137-
if [ -n "$PAYLOAD" ] ; then
176+
if [ -n "${PAYLOAD}" ] ; then
138177
if [ "${PAYLOAD:0:1}" = "@" ] ; then
139178
debug "Loading payload from file ${PAYLOAD:1}"
140179
if [ -r "${PAYLOAD:1}" ] ; then

postman-collection.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,36 @@
958958
},
959959
"description": "Provide a dashboard id (-i) as parameter"
960960
}
961+
},{
962+
"name": "Import a dashboard.",
963+
"request": {
964+
"method": "POST",
965+
"header": [
966+
{
967+
"key": "Content-Type",
968+
"value": "application/json;charset=UTF-8",
969+
"type": "text"
970+
},
971+
{
972+
"key": "X-CSRF-TOKEN",
973+
"value": "{{X-CSRF-TOKEN}}",
974+
"type": "text"
975+
}
976+
],
977+
"body": {
978+
"mode": "raw",
979+
"raw": ""
980+
},
981+
"url": {
982+
"raw": "{{controller_host}}/controller/CustomDashboardImportExportServlet",
983+
"host": [
984+
"{{controller_host}}"
985+
],
986+
"path": ["controller","CustomDashboardImportExportServlet"],
987+
"query": []
988+
},
989+
"description": "Provide a dashboard file or json (-d) as parameter."
990+
}
961991
},{
962992
"name": "List all dashboards.",
963993
"request": {

yaml-build.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ ASDF
3030
ENDPOINT="y_${NS}_${CMD}_endpoint"
3131
PAYLOAD="y_${NS}_${CMD}_payload"
3232
FORM="y_${NS}_${CMD}_form"
33+
EXPAND="y_${NS}_${CMD}_expand"
3334

3435
ENDPOINT=${!ENDPOINT}
3536
PAYLOAD=${!PAYLOAD}
3637
FORM=${!FORM}
38+
EXPAND=${!EXPAND}
3739

3840
# echo -e "\t- ${CMD} (${ENDPOINT})"
3941

@@ -114,10 +116,17 @@ ASDF
114116
METHOD=""
115117
fi;
116118

117-
read -r -d '' OUTPUT << ASDF
119+
if [ "${EXPAND}" == "true" ] ; then
120+
read -r -d '' OUTPUT << ASDF
121+
function ${NS}_${CMD} { apiCallExpand${METHOD}${PAYLOAD}${FORM} '${ENDPOINT}' "\$@" ; }
122+
rde ${NS}_${CMD} "${!TITLE}" "${!DESCRIPTION}" "${!EXAMPLE}"\n
123+
ASDF
124+
else
125+
read -r -d '' OUTPUT << ASDF
118126
function ${NS}_${CMD} { apiCall${METHOD}${PAYLOAD}${FORM} '${ENDPOINT}' "\$@" ; }
119127
rde ${NS}_${CMD} "${!TITLE}" "${!DESCRIPTION}" "${!EXAMPLE}"\n
120128
ASDF
129+
fi
121130

122131
echo -en "${OUTPUT}" >> temp.sh
123132
done;

0 commit comments

Comments
 (0)