Skip to content

Commit ae4101a

Browse files
committed
Add sep list from official api; add auto loading from account id
1 parent 0f2f902 commit ae4101a

File tree

5 files changed

+122
-36
lines changed

5 files changed

+122
-36
lines changed

USAGE.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ The following commands in the global namespace can be called directly.
2929
| version | Print the current version of act.sh | `act.sh version ` |
3030

3131

32+
## account
33+
34+
Query the Account API
35+
36+
| Command | Description | Example |
37+
| ------- | ----------- | ------- |
38+
| my | Get details about the current account This command requires no further arguments. | `act.sh account my ` |
39+
40+
3241
## action
3342

3443
Import or export all actions in the specified application to a JSON file.
@@ -332,7 +341,7 @@ List service endpoints
332341

333342
| Command | Description | Example |
334343
| ------- | ----------- | ------- |
335-
| list | List all SEPs. Provide an application id (-a), as well as an time range string (-t). | `act.sh sep list -a 29 -t last_1_hour.BEFORE_NOW.-1.-1.60` |
344+
| list | List all SEPs. Provide an application id (-a). | `act.sh sep list -a 29` |
336345

337346

338347
## server

act.sh

+36-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
ACT_VERSION="v0.5.0"
3-
ACT_LAST_COMMIT="c1a2ea67f69c379a97e89b91341f4386e40535a3"
3+
ACT_LAST_COMMIT="0f2f90254db898dd245958b4c2f0f19c9dd9e265"
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"
@@ -62,6 +62,11 @@ RRREOF
6262
${4}
6363
RRREOF
6464
}
65+
doc account << EOF
66+
Query the Account API
67+
EOF
68+
account_my() { apiCall '/controller/api/accounts/myaccount' "$@" ; }
69+
rde account_my "Get details about the current account" "This command requires no further arguments." ""
6570
doc action << EOF
6671
Import or export all actions in the specified application to a JSON file.
6772
EOF
@@ -256,8 +261,8 @@ rde scope_list "List all scopes." "Provide an application id (-a) as parameter"
256261
doc sep << EOF
257262
List service endpoints
258263
EOF
259-
sep_list() { apiCall '/controller/restui/serviceEndpoint/list2/{{a:application}}/{{a:application}}/APPLICATION?time-range={{t:time_range}}' "$@" ; }
260-
rde sep_list "List all SEPs." "Provide an application id (-a), as well as an time range string (-t)." "-a 29 -t last_1_hour.BEFORE_NOW.-1.-1.60"
264+
sep_list() { apiCall '/controller/api/accounts/{{i:accountid}}/applications/{{a:application}}/sep' "$@" ; }
265+
rde sep_list "List all SEPs." "Provide an application id (-a)." "-a 29"
261266
doc server << EOF
262267
List servers, their properties and metrics
263268
EOF
@@ -1622,18 +1627,34 @@ apiCall() {
16221627
while [[ $ENDPOINT =~ \{\{([a-zA-Z])(:[a-zA-Z0-9_-]+)?(\??)\}\} ]] ; do
16231628
if [ -z "$1" ] && [[ "${OPTIONAL_OPTIONS}" != *"${BASH_REMATCH[1]}"* ]] ; then
16241629
local MISSING=${BASH_REMATCH:2:1}
1625-
if [ "${MISSING}" == "a" ] && [ -n "${CONFIG_CONTROLLER_DEFAULT_APPLICATION}" ] ; then
1626-
debug "Using default application for -a: ${CONFIG_CONTROLLER_DEFAULT_APPLICATION}"
1627-
ENDPOINT=${ENDPOINT//'{{a}}'/${CONFIG_CONTROLLER_DEFAULT_APPLICATION}}
1628-
else
1629-
ERROR_MESSAGE="Please provide an argument for parameter -${MISSING}"
1630-
for TYPE in "${OPTS_TYPES[@]}" ;
1631-
do
1632-
if [[ "${TYPE}" == ${MISSING}:* ]] ; then
1633-
TYPE=${TYPE//_/ }
1634-
ERROR_MESSAGE="Missing ${TYPE#*:}: ${ERROR_MESSAGE}"
1635-
fi
1636-
done;
1630+
ERROR_MESSAGE="Please provide an argument for parameter -${MISSING}"
1631+
for TYPE in "${OPTS_TYPES[@]}" ;
1632+
do
1633+
if [[ "${TYPE}" == ${MISSING}:* ]] ; then
1634+
TYPE=${TYPE//_/ }
1635+
TYPE=${TYPE#*:}
1636+
if [[ "${TYPE}" == "application" ]] ; then
1637+
debug "Using default application for -a: ${CONFIG_CONTROLLER_DEFAULT_APPLICATION}"
1638+
ENDPOINT=${ENDPOINT//'{{a:application}}'/${CONFIG_CONTROLLER_DEFAULT_APPLICATION}}
1639+
ERROR_MESSAGE=""
1640+
elif [[ "${TYPE}" == "accountid" ]] ; then
1641+
debug "Querying myaccount..."
1642+
JSON=$(httpClient -s --user "${CONFIG_CONTROLLER_CREDENTIALS}" "${CONFIG_CONTROLLER_HOST}/controller/api/accounts/myaccount")
1643+
JSON=${JSON// /}
1644+
JSON=${JSON##*id\":\"}
1645+
ACCOUNT_ID=${JSON%%\",*}
1646+
debug "Account ID: ${ACCOUNT_ID}"
1647+
COMMAND_RESULT=""
1648+
debug ${ENDPOINT}
1649+
ENDPOINT=${ENDPOINT//'{{i:accountid}}'/${ACCOUNT_ID}}
1650+
debug ${ENDPOINT}
1651+
ERROR_MESSAGE=""
1652+
else
1653+
ERROR_MESSAGE="Missing ${TYPE}: ${ERROR_MESSAGE}"
1654+
fi;
1655+
fi
1656+
done;
1657+
if [ -n "${ERROR_MESSAGE}" ] ; then
16371658
error "${ERROR_MESSAGE}"
16381659
return;
16391660
fi

commands.yml

+12-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ action:
2626
method: POST
2727
endpoint: /controller/restui/policy/deleteActions
2828
payload: [{{i:action_id}}]
29+
account:
30+
title: Account API
31+
description: Query the Account API
32+
my:
33+
title: Get details about the current account
34+
description: This command requires no further arguments.
35+
example:
36+
method: GET
37+
endpoint: /controller/api/accounts/myaccount
2938
application:
3039
title: Application Model API
3140
description: The applications API lets you retrieve information about the monitored environment as modeled in AppDynamics.
@@ -467,9 +476,9 @@ sep:
467476
description: List service endpoints
468477
list:
469478
title: List all SEPs.
470-
description: Provide an application id (-a), as well as an time range string (-t).
471-
example: -a 29 -t last_1_hour.BEFORE_NOW.-1.-1.60
472-
endpoint: /controller/restui/serviceEndpoint/list2/{{a:application}}/{{a:application}}/APPLICATION?time-range={{t:time_range}}
479+
description: Provide an application id (-a).
480+
example: -a 29
481+
endpoint: /controller/api/accounts/{{i:accountid}}/applications/{{a:application}}/sep
473482
server:
474483
title: Server & Infrastructure Monitoring API
475484
description: List servers, their properties and metrics

helpers/apiCall.sh

+29-12
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,35 @@ apiCall() {
145145
while [[ $ENDPOINT =~ \{\{([a-zA-Z])(:[a-zA-Z0-9_-]+)?(\??)\}\} ]] ; do
146146
if [ -z "$1" ] && [[ "${OPTIONAL_OPTIONS}" != *"${BASH_REMATCH[1]}"* ]] ; then
147147
local MISSING=${BASH_REMATCH:2:1}
148-
if [ "${MISSING}" == "a" ] && [ -n "${CONFIG_CONTROLLER_DEFAULT_APPLICATION}" ] ; then
149-
debug "Using default application for -a: ${CONFIG_CONTROLLER_DEFAULT_APPLICATION}"
150-
ENDPOINT=${ENDPOINT//'{{a}}'/${CONFIG_CONTROLLER_DEFAULT_APPLICATION}}
151-
else
152-
ERROR_MESSAGE="Please provide an argument for parameter -${MISSING}"
153-
for TYPE in "${OPTS_TYPES[@]}" ;
154-
do
155-
if [[ "${TYPE}" == ${MISSING}:* ]] ; then
156-
TYPE=${TYPE//_/ }
157-
ERROR_MESSAGE="Missing ${TYPE#*:}: ${ERROR_MESSAGE}"
158-
fi
159-
done;
148+
149+
ERROR_MESSAGE="Please provide an argument for parameter -${MISSING}"
150+
for TYPE in "${OPTS_TYPES[@]}" ;
151+
do
152+
if [[ "${TYPE}" == ${MISSING}:* ]] ; then
153+
TYPE=${TYPE//_/ }
154+
TYPE=${TYPE#*:}
155+
if [[ "${TYPE}" == "application" ]] ; then
156+
debug "Using default application for -a: ${CONFIG_CONTROLLER_DEFAULT_APPLICATION}"
157+
ENDPOINT=${ENDPOINT//'{{a:application}}'/${CONFIG_CONTROLLER_DEFAULT_APPLICATION}}
158+
ERROR_MESSAGE=""
159+
elif [[ "${TYPE}" == "accountid" ]] ; then
160+
debug "Querying myaccount..."
161+
JSON=$(httpClient -s --user "${CONFIG_CONTROLLER_CREDENTIALS}" "${CONFIG_CONTROLLER_HOST}/controller/api/accounts/myaccount")
162+
JSON=${JSON// /}
163+
JSON=${JSON##*id\":\"}
164+
ACCOUNT_ID=${JSON%%\",*}
165+
debug "Account ID: ${ACCOUNT_ID}"
166+
COMMAND_RESULT=""
167+
debug ${ENDPOINT}
168+
ENDPOINT=${ENDPOINT//'{{i:accountid}}'/${ACCOUNT_ID}}
169+
debug ${ENDPOINT}
170+
ERROR_MESSAGE=""
171+
else
172+
ERROR_MESSAGE="Missing ${TYPE}: ${ERROR_MESSAGE}"
173+
fi;
174+
fi
175+
done;
176+
if [ -n "${ERROR_MESSAGE}" ] ; then
160177
error "${ERROR_MESSAGE}"
161178
return;
162179
fi

postman-collection.json

+35-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
1-
{"info": {"name": "AppDynamics API","schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"}, "auth": {"type": "basic","basic": [{"key": "password","value": "{{controller_password}}","type": "string"},{"key": "username","value": "{{controller_user}}@{{controller_account}}","type": "string"}]}, "event": [{"listen": "test","script": {"type": "text/javascript","exec": ["pm.globals.set(\"X-CSRF-TOKEN\", postman.getResponseCookie(\"X-CSRF-TOKEN\").value);"]}}],"item": [{"name": "action","item": [{
1+
{"info": {"name": "AppDynamics API","schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"}, "auth": {"type": "basic","basic": [{"key": "password","value": "{{controller_password}}","type": "string"},{"key": "username","value": "{{controller_user}}@{{controller_account}}","type": "string"}]}, "event": [{"listen": "test","script": {"type": "text/javascript","exec": ["pm.globals.set(\"X-CSRF-TOKEN\", postman.getResponseCookie(\"X-CSRF-TOKEN\").value);"]}}],"item": [{"name": "account","item": [{
2+
"name": "Get details about the current account",
3+
"request": {
4+
"method": "GET",
5+
"header": [
6+
{
7+
"key": "Content-Type",
8+
"value": "application/json;charset=UTF-8",
9+
"type": "text"
10+
},
11+
{
12+
"key": "X-CSRF-TOKEN",
13+
"value": "{{X-CSRF-TOKEN}}",
14+
"type": "text"
15+
}
16+
],
17+
"body": {
18+
"mode": "raw",
19+
"raw": ""
20+
},
21+
"url": {
22+
"raw": "{{controller_host}}/controller/api/accounts/myaccount",
23+
"host": [
24+
"{{controller_host}}"
25+
],
26+
"path": ["controller","api","accounts","myaccount"],
27+
"query": []
28+
},
29+
"description": "This command requires no further arguments."
30+
}
31+
}]},{"name": "action","item": [{
232
"name": "",
333
"request": {
434
"method": "POST",
@@ -1909,14 +1939,14 @@
19091939
"raw": ""
19101940
},
19111941
"url": {
1912-
"raw": "{{controller_host}}/controller/restui/serviceEndpoint/list2/{{a:application}}/{{a:application}}/APPLICATION?time-range={{t:time_range}}",
1942+
"raw": "{{controller_host}}/controller/api/accounts/{{i:accountid}}/applications/{{a:application}}/sep",
19131943
"host": [
19141944
"{{controller_host}}"
19151945
],
1916-
"path": ["controller","restui","serviceEndpoint","list2","{{application}}","{{application}}","APPLICATION"],
1917-
"query": [{"key": "time-range","value": "{{time_range}}"}]
1946+
"path": ["controller","api","accounts","{{accountid}}","applications","{{application}}","sep"],
1947+
"query": []
19181948
},
1919-
"description": "Provide an application id (-a), as well as an time range string (-t)."
1949+
"description": "Provide an application id (-a)."
19201950
}
19211951
}]},{"name": "server","item": [{
19221952
"name": "Get a machine.",

0 commit comments

Comments
 (0)