diff --git a/adc.sh b/adc.sh index dbad66f..85ad315 100755 --- a/adc.sh +++ b/adc.sh @@ -185,7 +185,11 @@ function dbmon_create { } register dbmon_create Create a new database collector function timerange_create { - while getopts "s:e:" opt "$@"; + local START_TIME=-1 + local END_TIME=-1 + local DURATION_IN_MINUTES=0 + local TYPE=BETWEEN_TIMES + while getopts "s:e:b:" opt "$@"; do case "${opt}" in s) @@ -194,14 +198,32 @@ function timerange_create { e) END_TIME=${OPTARG} ;; + b) + DURATION_IN_MINUTES=${OPTARG} + TYPE="BEFORE_NOW" + ;; esac done; shiftOptInd shift $SHIFTS TIMERANGE_NAME=$@ - controller_call -X POST -d "{\"name\":\"$TIMERANGE_NAME\",\"timeRange\":{\"type\":\"BETWEEN_TIMES\",\"durationInMinutes\":0,\"startTime\":$START_TIME,\"endTime\":$END_TIME}}" /controller/restui/user/createCustomRange + 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 } register timerange_create Create a custom time range +function timerange_list { + controller_call -X GET /controller/restui/user/getAllCustomTimeRanges +} +register timerange_list List all custom timeranges available on the controller +function timerange_delete { + local TIMERANGE_ID=$@ + if [[ $TIMERANGE_ID =~ ^[0-9]+$ ]]; then + controller_call -X POST -d "$TIMERANGE_ID" /controller/restui/user/deleteCustomRange + else + COMMAND_RESULT="" + error "This is not a number: '$TIMERANGE_ID'" + fi +} +register timerange_delete Delete a specific time range by id function dashboard_list { controller_call -X GET /controller/restui/dashboards/getAllDashboardsByType/false } diff --git a/commands/timerange/create.sh b/commands/timerange/create.sh index de80f8f..78c555f 100644 --- a/commands/timerange/create.sh +++ b/commands/timerange/create.sh @@ -1,7 +1,11 @@ #!/bin/bash function timerange_create { - while getopts "s:e:" opt "$@"; + local START_TIME=-1 + local END_TIME=-1 + local DURATION_IN_MINUTES=0 + local TYPE=BETWEEN_TIMES + while getopts "s:e:b:" opt "$@"; do case "${opt}" in s) @@ -10,12 +14,16 @@ function timerange_create { e) END_TIME=${OPTARG} ;; + b) + DURATION_IN_MINUTES=${OPTARG} + TYPE="BEFORE_NOW" + ;; esac done; shiftOptInd shift $SHIFTS TIMERANGE_NAME=$@ - controller_call -X POST -d "{\"name\":\"$TIMERANGE_NAME\",\"timeRange\":{\"type\":\"BETWEEN_TIMES\",\"durationInMinutes\":0,\"startTime\":$START_TIME,\"endTime\":$END_TIME}}" /controller/restui/user/createCustomRange + 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 } register timerange_create Create a custom time range diff --git a/commands/timerange/delete.sh b/commands/timerange/delete.sh new file mode 100644 index 0000000..2aaf0b1 --- /dev/null +++ b/commands/timerange/delete.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +function timerange_delete { + local TIMERANGE_ID=$@ + if [[ $TIMERANGE_ID =~ ^[0-9]+$ ]]; then + controller_call -X POST -d "$TIMERANGE_ID" /controller/restui/user/deleteCustomRange + else + COMMAND_RESULT="" + error "This is not a number: '$TIMERANGE_ID'" + fi +} + +register timerange_delete Delete a specific time range by id diff --git a/commands/timerange/list.sh b/commands/timerange/list.sh new file mode 100644 index 0000000..d628f9c --- /dev/null +++ b/commands/timerange/list.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +function timerange_list { + controller_call -X GET /controller/restui/user/getAllCustomTimeRanges +} + +register timerange_list List all custom timeranges available on the controller diff --git a/main.sh b/main.sh index e835eb2..2fb0bf9 100755 --- a/main.sh +++ b/main.sh @@ -37,6 +37,8 @@ source ./commands/controller/call.sh source ./commands/dbmon/create.sh source ./commands/timerange/create.sh +source ./commands/timerange/list.sh +source ./commands/timerange/delete.sh source ./commands/dashboard/list.sh source ./commands/dashboard/export.sh