Skip to content

Commit e702afa

Browse files
committed
List, delete time ranges
1 parent 01ca985 commit e702afa

File tree

5 files changed

+56
-4
lines changed

5 files changed

+56
-4
lines changed

adc.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ function dbmon_create {
185185
}
186186
register dbmon_create Create a new database collector
187187
function timerange_create {
188-
while getopts "s:e:" opt "$@";
188+
local START_TIME=-1
189+
local END_TIME=-1
190+
local DURATION_IN_MINUTES=0
191+
local TYPE=BETWEEN_TIMES
192+
while getopts "s:e:b:" opt "$@";
189193
do
190194
case "${opt}" in
191195
s)
@@ -194,14 +198,32 @@ function timerange_create {
194198
e)
195199
END_TIME=${OPTARG}
196200
;;
201+
b)
202+
DURATION_IN_MINUTES=${OPTARG}
203+
TYPE="BEFORE_NOW"
204+
;;
197205
esac
198206
done;
199207
shiftOptInd
200208
shift $SHIFTS
201209
TIMERANGE_NAME=$@
202-
controller_call -X POST -d "{\"name\":\"$TIMERANGE_NAME\",\"timeRange\":{\"type\":\"BETWEEN_TIMES\",\"durationInMinutes\":0,\"startTime\":$START_TIME,\"endTime\":$END_TIME}}" /controller/restui/user/createCustomRange
210+
controller_call -X POST -d "{\"name\":\"$TIMERANGE_NAME\",\"timeRange\":{\"type\":\"$TYPE\",\"durationInMinutes\":$DURATION_IN_MINUTES,\"startTime\":$START_TIME,\"endTime\":$END_TIME}}" /controller/restui/user/createCustomRange
203211
}
204212
register timerange_create Create a custom time range
213+
function timerange_list {
214+
controller_call -X GET /controller/restui/user/getAllCustomTimeRanges
215+
}
216+
register timerange_list List all custom timeranges available on the controller
217+
function timerange_delete {
218+
local TIMERANGE_ID=$@
219+
if [[ $TIMERANGE_ID =~ ^[0-9]+$ ]]; then
220+
controller_call -X POST -d "$TIMERANGE_ID" /controller/restui/user/deleteCustomRange
221+
else
222+
COMMAND_RESULT=""
223+
error "This is not a number: '$TIMERANGE_ID'"
224+
fi
225+
}
226+
register timerange_delete Delete a specific time range by id
205227
function dashboard_list {
206228
controller_call -X GET /controller/restui/dashboards/getAllDashboardsByType/false
207229
}

commands/timerange/create.sh

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

33
function timerange_create {
4-
while getopts "s:e:" opt "$@";
4+
local START_TIME=-1
5+
local END_TIME=-1
6+
local DURATION_IN_MINUTES=0
7+
local TYPE=BETWEEN_TIMES
8+
while getopts "s:e:b:" opt "$@";
59
do
610
case "${opt}" in
711
s)
@@ -10,12 +14,16 @@ function timerange_create {
1014
e)
1115
END_TIME=${OPTARG}
1216
;;
17+
b)
18+
DURATION_IN_MINUTES=${OPTARG}
19+
TYPE="BEFORE_NOW"
20+
;;
1321
esac
1422
done;
1523
shiftOptInd
1624
shift $SHIFTS
1725
TIMERANGE_NAME=$@
18-
controller_call -X POST -d "{\"name\":\"$TIMERANGE_NAME\",\"timeRange\":{\"type\":\"BETWEEN_TIMES\",\"durationInMinutes\":0,\"startTime\":$START_TIME,\"endTime\":$END_TIME}}" /controller/restui/user/createCustomRange
26+
controller_call -X POST -d "{\"name\":\"$TIMERANGE_NAME\",\"timeRange\":{\"type\":\"$TYPE\",\"durationInMinutes\":$DURATION_IN_MINUTES,\"startTime\":$START_TIME,\"endTime\":$END_TIME}}" /controller/restui/user/createCustomRange
1927
}
2028

2129
register timerange_create Create a custom time range

commands/timerange/delete.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
function timerange_delete {
4+
local TIMERANGE_ID=$@
5+
if [[ $TIMERANGE_ID =~ ^[0-9]+$ ]]; then
6+
controller_call -X POST -d "$TIMERANGE_ID" /controller/restui/user/deleteCustomRange
7+
else
8+
COMMAND_RESULT=""
9+
error "This is not a number: '$TIMERANGE_ID'"
10+
fi
11+
}
12+
13+
register timerange_delete Delete a specific time range by id

commands/timerange/list.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
function timerange_list {
4+
controller_call -X GET /controller/restui/user/getAllCustomTimeRanges
5+
}
6+
7+
register timerange_list List all custom timeranges available on the controller

main.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ source ./commands/controller/call.sh
3737
source ./commands/dbmon/create.sh
3838

3939
source ./commands/timerange/create.sh
40+
source ./commands/timerange/list.sh
41+
source ./commands/timerange/delete.sh
4042

4143
source ./commands/dashboard/list.sh
4244
source ./commands/dashboard/export.sh

0 commit comments

Comments
 (0)