Skip to content

Commit d39ad43

Browse files
committed
Additional sub-commands ; updated README.MD
1 parent 7c51c0e commit d39ad43

File tree

9 files changed

+153
-13
lines changed

9 files changed

+153
-13
lines changed

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,59 @@ adc.sh config -f
2525
`adc.sh` integrates different commands to interact with your AppDynamics controller. Call `adc.sh help` to get a full list:
2626

2727
```
28-
Usage: ./adc.sh <namespace> <command>
29-
30-
To execute a action, provide a namespace and a command, e.g. "dbmon list" to list all database collectors.
28+
Usage: adc.sh [-H <controller-host>] [-C <controller-credentials>] [-D <output-verbosity>] [-P <plugin-directory>] [-A <application-name>] <namespace> <command>
29+
30+
You can use the following options on a global level:
31+
-H <controller-host> specify the host of the controller you want to connect to
32+
-C <controller-credentials> provide the credentials for the controller. Format: user@tenant:password
33+
-D <output-verbosity> Change the output verbosity. Provide a list of the following values: debug,error,warn,info,output
34+
-D <application-name> Provide a default application
35+
To execute a action, provide a namespace and a command, e.g. "metrics get" to get a specific metric.
3136
Finally the following commands in the global namespace can be called directly:
37+
config Initialize the adc configuration file
3238
help Display the global usage information
33-
config Initialize the adc configuration file
39+
install Run through the process of setting up the appdynamics plattform
3440
3541
application
42+
export Export an application from the controller
3643
list List all applications available on the controller
3744
3845
controller
3946
call Send a custom HTTP call to a controller
4047
login Login to your controller
4148
ping Check the availability of an appdynamics controller
4249
status Get server status from controller
50+
version Get installed version from controller
4351
4452
dashboard
4553
delete Delete a specific dashboard
4654
export Export a specific dashboard
55+
import Import a dashboard
4756
list List all dashboards available on the controller
4857
4958
dbmon
5059
create Create a new database collector
60+
delete Delete a database collector
61+
list List all database collectors
5162
5263
event
5364
create Create a custom event for a given application
5465
55-
metrics
56-
get List all metrics available for one application
57-
list List all metrics available for one application
66+
metric
67+
get Get a specific metric
68+
list List metrics available for one application.
69+
tree Build and return a metrics tree for one application
70+
71+
portal
72+
download Download an appdynamics agent
73+
login Login to portal.appdynamics.com
5874
5975
timerange
6076
create Create a custom time range
6177
delete Delete a specific time range by id
6278
list List all custom timeranges available on the controller
79+
80+
Run adc.sh help <namespace> to get detailed help on subcommands in that namespace.
6381
```
6482

6583
A simple work flow example is listing, exporting and deleting a dashboard:

adc.sh

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function output {
5757
fi
5858
}
5959
function httpClient {
60+
debug "$*"
6061
curl -L --connect-timeout 10 "$@"
6162
}
6263
SHIFTS=0
@@ -243,7 +244,8 @@ EOF
243244
function controller_call {
244245
debug "Calling $CONFIG_CONTROLLER_HOST"
245246
local METHOD="GET"
246-
while getopts "X:d:" opt "$@";
247+
local FORM=""
248+
while getopts "X:d:F:" opt "$@";
247249
do
248250
case "${opt}" in
249251
X)
@@ -252,6 +254,9 @@ function controller_call {
252254
d)
253255
PAYLOAD=${OPTARG}
254256
;;
257+
F)
258+
FORM=${OPTARG}
259+
;;
255260
esac
256261
done
257262
shiftOptInd
@@ -264,9 +269,10 @@ function controller_call {
264269
COMMAND_RESULT=$(httpClient -s -b $CONFIG_CONTROLLER_COOKIE_LOCATION \
265270
-X $METHOD\
266271
-H "X-CSRF-TOKEN: $XCSRFTOKEN" \
267-
-H "Content-Type: application/json;charset=UTF-8" \
272+
"`[ -z "$FORM" ] && echo -H "Content-Type: application/json;charset=UTF-8"`" \
268273
-H "Accept: application/json, text/plain, */*"\
269-
-d "$PAYLOAD" \
274+
"`[ -n "$PAYLOAD" ] && echo -d ${PAYLOAD}`" \
275+
"`[ -n "$FORM" ] && echo -F ${FORM}`" \
270276
$CONFIG_CONTROLLER_HOST$ENDPOINT)
271277
else
272278
COMMAND_RESULT="Controller Login Error! Please check hostname and credentials"
@@ -424,6 +430,19 @@ register application_list List all applications available on the controller
424430
describe application_list << EOF
425431
List all applications available on the controller. This command requires no further arguments.
426432
EOF
433+
function application_export {
434+
local APPLICATION_ID=$*
435+
if [[ $APPLICATION_ID =~ ^[0-9]+$ ]]; then
436+
controller_call /controller/ConfigObjectImportExportServlet?applicationId=97
437+
else
438+
COMMAND_RESULT=""
439+
error "This is not a number: '$APPLICATION_ID'"
440+
fi
441+
}
442+
register application_export Export an application from the controller
443+
describe application_export << EOF
444+
Export a application from the controller. Specifiy the application id as parameter.
445+
EOF
427446
function metric_list {
428447
local APPLICATION=${CONFIG_CONTROLLER_DEFAULT_APPLICATION}
429448
local METRIC_PATH=""
@@ -600,6 +619,26 @@ register dbmon_create Create a new database collector
600619
describe dbmon_create << EOF
601620
Create a new database collector
602621
EOF
622+
function dbmon_list {
623+
controller_call /controller/restui/databases/collectors/
624+
}
625+
register dbmon_list List all database collectors
626+
describe dbmon_list << EOF
627+
List all database collectors
628+
EOF
629+
function dbmon_delete {
630+
local COLLECTOR_ID=$*
631+
if [[ $COLLECTOR_ID =~ ^[0-9]+$ ]]; then
632+
controller_call -X POST -d "[$COLLECTOR_ID]" /controller/restui/databases/collectors/configuration/batchDelete
633+
else
634+
COMMAND_RESULT=""
635+
error "This is not a number: '$COLLECTOR_ID'"
636+
fi
637+
}
638+
register dbmon_delete Delete a database collector
639+
describe dbmon_delete << EOF
640+
Delete a database collector. Provide the collector id as parameter.
641+
EOF
603642
function event_create {
604643
local APPLICATION=${CONFIG_CONTROLLER_DEFAULT_APPLICATION}
605644
local NODE
@@ -713,6 +752,19 @@ register dashboard_export Export a specific dashboard
713752
describe dashboard_export << EOF
714753
Export a specific dashboard
715754
EOF
755+
function dashboard_import {
756+
FILE="$*"
757+
if [ -r $FILE ] ; then
758+
controller_call -X POST -F file=@$FILE /controller/CustomDashboardImportExportServlet
759+
else
760+
COMMAND_RESULT=""
761+
error "File not found or not readable: $FILE"
762+
fi
763+
}
764+
register dashboard_import Import a dashboard
765+
describe dashboard_import << EOF
766+
Import a dashboard from a given file
767+
EOF
716768
function dashboard_delete {
717769
local DASHBOARD_ID=$*
718770
if [[ $DASHBOARD_ID =~ ^[0-9]+$ ]]; then

commands/application/export.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
function application_export {
4+
local APPLICATION_ID=$*
5+
if [[ $APPLICATION_ID =~ ^[0-9]+$ ]]; then
6+
controller_call /controller/ConfigObjectImportExportServlet?applicationId=97
7+
else
8+
COMMAND_RESULT=""
9+
error "This is not a number: '$APPLICATION_ID'"
10+
fi
11+
12+
}
13+
14+
register application_export Export an application from the controller
15+
16+
describe application_export << EOF
17+
Export a application from the controller. Specifiy the application id as parameter.
18+
EOF

commands/controller/call.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
function controller_call {
44
debug "Calling $CONFIG_CONTROLLER_HOST"
55
local METHOD="GET"
6-
while getopts "X:d:" opt "$@";
6+
local FORM=""
7+
while getopts "X:d:F:" opt "$@";
78
do
89
case "${opt}" in
910
X)
@@ -12,6 +13,9 @@ function controller_call {
1213
d)
1314
PAYLOAD=${OPTARG}
1415
;;
16+
F)
17+
FORM=${OPTARG}
18+
;;
1519
esac
1620
done
1721

@@ -27,9 +31,10 @@ function controller_call {
2731
COMMAND_RESULT=$(httpClient -s -b $CONFIG_CONTROLLER_COOKIE_LOCATION \
2832
-X $METHOD\
2933
-H "X-CSRF-TOKEN: $XCSRFTOKEN" \
30-
-H "Content-Type: application/json;charset=UTF-8" \
34+
"`[ -z "$FORM" ] && echo -H "Content-Type: application/json;charset=UTF-8"`" \
3135
-H "Accept: application/json, text/plain, */*"\
32-
-d "$PAYLOAD" \
36+
"`[ -n "$PAYLOAD" ] && echo -d ${PAYLOAD}`" \
37+
"`[ -n "$FORM" ] && echo -F ${FORM}`" \
3338
$CONFIG_CONTROLLER_HOST$ENDPOINT)
3439
else
3540
COMMAND_RESULT="Controller Login Error! Please check hostname and credentials"

commands/dashboard/import.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
function dashboard_import {
4+
FILE="$*"
5+
if [ -r $FILE ] ; then
6+
controller_call -X POST -F file=@$FILE /controller/CustomDashboardImportExportServlet
7+
else
8+
COMMAND_RESULT=""
9+
error "File not found or not readable: $FILE"
10+
fi
11+
}
12+
13+
register dashboard_import Import a dashboard
14+
describe dashboard_import << EOF
15+
Import a dashboard from a given file
16+
EOF

commands/dbmon/delete.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
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
11+
}
12+
13+
register dbmon_delete Delete a database collector
14+
describe dbmon_delete << EOF
15+
Delete a database collector. Provide the collector id as parameter.
16+
EOF

commands/dbmon/list.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
function dbmon_list {
4+
controller_call /controller/restui/databases/collectors/
5+
}
6+
7+
register dbmon_list List all database collectors
8+
describe dbmon_list << EOF
9+
List all database collectors
10+
EOF

helpers/httpClient.sh

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

33
function httpClient {
4+
debug "$*"
45
curl -L --connect-timeout 10 "$@"
56
}

main.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ source ./commands/portal/login.sh
5252
source ./commands/portal/download.sh
5353

5454
source ./commands/application/list.sh
55+
source ./commands/application/export.sh
5556

5657
source ./commands/metric/list.sh
5758
source ./commands/metric/get.sh
5859
source ./commands/metric/tree.sh
5960

6061
source ./commands/dbmon/create.sh
62+
source ./commands/dbmon/list.sh
63+
source ./commands/dbmon/delete.sh
6164

6265
source ./commands/event/create.sh
6366

@@ -67,6 +70,7 @@ source ./commands/timerange/delete.sh
6770

6871
source ./commands/dashboard/list.sh
6972
source ./commands/dashboard/export.sh
73+
source ./commands/dashboard/import.sh
7074
source ./commands/dashboard/delete.sh
7175

7276
if [ -f "${GLOBAL_CONFIG}" ]; then

0 commit comments

Comments
 (0)