Skip to content

Commit cfe06bb

Browse files
committed
Converted dbmon create to apiCall
1 parent d532f37 commit cfe06bb

File tree

3 files changed

+65
-105
lines changed

3 files changed

+65
-105
lines changed

adc.sh

Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ function apiCall {
120120
OLDIFS=$IFS
121121
IFS="\$"
122122
for MATCH in $PAYLOAD ; do
123-
if [ "${MATCH::1}" = "{" ] ; then
123+
if [ "${MATCH::1}" = "{" ] && [ "${MATCH:2:1}" = "}" ] ; then
124124
MATCH=${MATCH:1}
125125
OPT=${MATCH%%\}*}:
126126
OPTS="${OPTS}${OPT}"
127127
fi
128128
done;
129129
for MATCH in $ENDPOINT ; do
130-
if [ "${MATCH::1}" = "{" ] ; then
130+
if [ "${MATCH::1}" = "{" ] && [ "${MATCH:2:1}" = "}" ] ; then
131131
MATCH=${MATCH:1}
132132
OPT=${MATCH%%\}*}:
133133
OPTS="${OPTS}${OPT}"
@@ -143,6 +143,14 @@ function apiCall {
143143
shiftOptInd
144144
shift $SHIFTS
145145
fi
146+
while [[ $PAYLOAD =~ \${[^}]*} ]] ; do
147+
if [ -z "$1" ] ; then
148+
error "Please provide an argument for paramater -${BASH_REMATCH:2:1}"
149+
return;
150+
fi
151+
PAYLOAD=${PAYLOAD//${BASH_REMATCH[0]}/$1}
152+
shift
153+
done
146154
while [[ $ENDPOINT =~ \${[^}]*} ]] ; do
147155
if [ -z "$1" ] ; then
148156
error "Please provide an argument for paramater -${BASH_REMATCH:2:1}"
@@ -153,9 +161,9 @@ function apiCall {
153161
done
154162
debug "Call Controller: -X $METHOD -d $PAYLOAD $ENDPOINT"
155163
if [ -n "$PAYLOAD" ] ; then
156-
controller_call -X $METHOD -d $PAYLOAD $ENDPOINT
164+
echo -X $METHOD -d $PAYLOAD $ENDPOINT
157165
else
158-
controller_call -X $METHOD $ENDPOINT
166+
echo -X $METHOD $ENDPOINT
159167
fi
160168
}
161169
# __call GET "/controller/rest/applications/\${a}/business-transactions" -a ECommerce
@@ -644,48 +652,12 @@ describe metric_tree << EOF
644652
Create a metric tree for the given application (-a). Note that this will create a lot of requests towards your controller.
645653
EOF
646654
function dbmon_create {
647-
local DB_USER=""
648-
local DB_HOSTNAME=""
649-
local DB_AGENT=""
650-
local DB_TYPE=""
651-
local DB_COLLECTOR_NAME=""
652-
local DB_NAME=""
653-
local DB_PORT=""
654-
local DB_PASSWORD=""
655-
while getopts "u:h:a:t:n:p:s:" opt "$@";
656-
do
657-
case "${opt}" in
658-
u)
659-
DB_USER=${OPTARG}
660-
;;
661-
h)
662-
DB_HOSTNAME=${OPTARG}
663-
;;
664-
a)
665-
DB_AGENT=${OPTARG}
666-
;;
667-
t)
668-
DB_TYPE=${OPTARG}
669-
;;
670-
n)
671-
DB_NAME=${OPTARG}
672-
;;
673-
p)
674-
DB_PORT=${OPTARG}
675-
;;
676-
s)
677-
DB_PASSWORD=${OPTARG}
678-
;;
679-
esac
680-
done;
681-
shiftOptInd
682-
shift $SHIFTS
683-
DB_COLLECTOR_NAME="$*"
684-
controller_call -X POST -d "{ \
685-
\"username\": \"$DB_USER\",\
686-
\"hostname\": \"$DB_HOSTNAME\",\
687-
\"agentName\": \"$DB_AGENT\",\
688-
\"type\": \"$DB_TYPE\",\
655+
apiCall -X POST -d "{ \
656+
\"name\": \"\${i}\",\
657+
\"username\": \"\${u}\",\
658+
\"hostname\": \"\${h}\",\
659+
\"agentName\": \"\${a}\",\
660+
\"type\": \"\${t}\",\
689661
\"orapkiSslEnabled\": false,\
690662
\"orasslTruststoreLoc\": null,\
691663
\"orasslTruststoreType\": null,\
@@ -694,17 +666,24 @@ function dbmon_create {
694666
\"orasslKeystoreLoc\": null,\
695667
\"orasslKeystoreType\": null,\
696668
\"orasslKeystorePassword\": null,\
697-
\"name\": \"$DB_COLLECTOR_NAME\",\
698-
\"databaseName\": \"$DB_NAME\",\
699-
\"port\": \"$DB_PORT\",\
700-
\"password\": \"$DB_PASSWORD\",\
669+
\"databaseName\": \"\${n}\",\
670+
\"port\": \"\${p}\",\
671+
\"password\": \"\${s}\",\
701672
\"excludedSchemas\": [],\
702673
\"enabled\": true\
703-
}" /controller/restui/databases/collectors/createConfiguration
674+
}" /controller/restui/databases/collectors/createConfiguration "$@"
704675
}
705676
register dbmon_create Create a new database collector
706677
describe dbmon_create << EOF
707-
Create a new database collector
678+
Create a new database collector. You need to provide the following parameters:
679+
-i name
680+
-u user name
681+
-h host name
682+
-a agent name
683+
-t type
684+
-d database name
685+
-p port
686+
-s password
708687
EOF
709688
function dbmon_list {
710689
controller_call /controller/restui/databases/collectors/

commands/dbmon/create.sh

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,12 @@
11
#!/bin/bash
22

33
function dbmon_create {
4-
local DB_USER=""
5-
local DB_HOSTNAME=""
6-
local DB_AGENT=""
7-
local DB_TYPE=""
8-
local DB_COLLECTOR_NAME=""
9-
local DB_NAME=""
10-
local DB_PORT=""
11-
local DB_PASSWORD=""
12-
13-
while getopts "u:h:a:t:n:p:s:" opt "$@";
14-
do
15-
case "${opt}" in
16-
u)
17-
DB_USER=${OPTARG}
18-
;;
19-
h)
20-
DB_HOSTNAME=${OPTARG}
21-
;;
22-
a)
23-
DB_AGENT=${OPTARG}
24-
;;
25-
t)
26-
DB_TYPE=${OPTARG}
27-
;;
28-
n)
29-
DB_NAME=${OPTARG}
30-
;;
31-
p)
32-
DB_PORT=${OPTARG}
33-
;;
34-
s)
35-
DB_PASSWORD=${OPTARG}
36-
;;
37-
esac
38-
done;
39-
shiftOptInd
40-
shift $SHIFTS
41-
DB_COLLECTOR_NAME="$*"
42-
controller_call -X POST -d "{ \
43-
\"username\": \"$DB_USER\",\
44-
\"hostname\": \"$DB_HOSTNAME\",\
45-
\"agentName\": \"$DB_AGENT\",\
46-
\"type\": \"$DB_TYPE\",\
4+
apiCall -X POST -d "{ \
5+
\"name\": \"\${i}\",\
6+
\"username\": \"\${u}\",\
7+
\"hostname\": \"\${h}\",\
8+
\"agentName\": \"\${a}\",\
9+
\"type\": \"\${t}\",\
4710
\"orapkiSslEnabled\": false,\
4811
\"orasslTruststoreLoc\": null,\
4912
\"orasslTruststoreType\": null,\
@@ -52,16 +15,24 @@ function dbmon_create {
5215
\"orasslKeystoreLoc\": null,\
5316
\"orasslKeystoreType\": null,\
5417
\"orasslKeystorePassword\": null,\
55-
\"name\": \"$DB_COLLECTOR_NAME\",\
56-
\"databaseName\": \"$DB_NAME\",\
57-
\"port\": \"$DB_PORT\",\
58-
\"password\": \"$DB_PASSWORD\",\
18+
\"databaseName\": \"\${n}\",\
19+
\"port\": \"\${p}\",\
20+
\"password\": \"\${s}\",\
5921
\"excludedSchemas\": [],\
6022
\"enabled\": true\
61-
}" /controller/restui/databases/collectors/createConfiguration
23+
}" /controller/restui/databases/collectors/createConfiguration "$@"
6224
}
6325

6426
register dbmon_create Create a new database collector
6527
describe dbmon_create << EOF
66-
Create a new database collector
28+
Create a new database collector. You need to provide the following parameters:
29+
30+
-i name
31+
-u user name
32+
-h host name
33+
-a agent name
34+
-t type
35+
-d database name
36+
-p port
37+
-s password
6738
EOF

helpers/apiCall.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ function apiCall {
2525
OLDIFS=$IFS
2626
IFS="\$"
2727
for MATCH in $PAYLOAD ; do
28-
if [ "${MATCH::1}" = "{" ] ; then
28+
if [ "${MATCH::1}" = "{" ] && [ "${MATCH:2:1}" = "}" ] ; then
2929
MATCH=${MATCH:1}
3030
OPT=${MATCH%%\}*}:
3131
OPTS="${OPTS}${OPT}"
3232
fi
3333
done;
34+
3435
for MATCH in $ENDPOINT ; do
35-
if [ "${MATCH::1}" = "{" ] ; then
36+
if [ "${MATCH::1}" = "{" ] && [ "${MATCH:2:1}" = "}" ] ; then
3637
MATCH=${MATCH:1}
3738
OPT=${MATCH%%\}*}:
3839
OPTS="${OPTS}${OPT}"
@@ -50,6 +51,15 @@ function apiCall {
5051
shift $SHIFTS
5152
fi
5253

54+
while [[ $PAYLOAD =~ \${[^}]*} ]] ; do
55+
if [ -z "$1" ] ; then
56+
error "Please provide an argument for paramater -${BASH_REMATCH:2:1}"
57+
return;
58+
fi
59+
PAYLOAD=${PAYLOAD//${BASH_REMATCH[0]}/$1}
60+
shift
61+
done
62+
5363
while [[ $ENDPOINT =~ \${[^}]*} ]] ; do
5464
if [ -z "$1" ] ; then
5565
error "Please provide an argument for paramater -${BASH_REMATCH:2:1}"
@@ -61,9 +71,9 @@ function apiCall {
6171

6272
debug "Call Controller: -X $METHOD -d $PAYLOAD $ENDPOINT"
6373
if [ -n "$PAYLOAD" ] ; then
64-
controller_call -X $METHOD -d $PAYLOAD $ENDPOINT
74+
echo -X $METHOD -d $PAYLOAD $ENDPOINT
6575
else
66-
controller_call -X $METHOD $ENDPOINT
76+
echo -X $METHOD $ENDPOINT
6777
fi
6878
}
6979

0 commit comments

Comments
 (0)