From dc9c98e9406121b60240bed2193fcc9ba84967eb Mon Sep 17 00:00:00 2001 From: Mark Kelly-Smith Date: Wed, 2 Sep 2020 12:41:18 +0100 Subject: [PATCH] Added auto-detect feature for controller version This enables auto-switch of restui call format --- recipes/get_node_extrainfo.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/recipes/get_node_extrainfo.sh b/recipes/get_node_extrainfo.sh index ab3c652..0ee5e52 100755 --- a/recipes/get_node_extrainfo.sh +++ b/recipes/get_node_extrainfo.sh @@ -3,8 +3,6 @@ ################################################################################ # Gets extra node info from an applications node list # -# NB; review SOURCE_API_NODEINFO setup, for version of controller -# # Useful output lines for debug; # echo "lines: ${#app_list_array[@]} | entries: ${#app_array[@]}" # for key in "${!app_array[@]}"; do echo "key : $key"; echo "value : ${app_array[$key]}"; done @@ -42,12 +40,6 @@ usage () { ################################################################################ # Setup Variables, etc ################################################################################ -# RESTUI API call -# TODO: Find exact version api calls changed -# NB; this api call is valid on > mid-4.5 controller... -SOURCE_API_NODEINFO="/controller/restui/v1/nodes/list/health/ids" -# ...before which it was -#SOURCE_API_NODEINFO="/controller/restui/nodes/list/health/ids" # Set default input params LEVEL="0" #This means -A is mandatory unless -L is changed @@ -129,6 +121,19 @@ runChecks () { if [[ ${LEVEL} == "0" && -z ${APP_ID} ]]; then echo "No -A param passed for -L=0."; usage; exit 1; fi } +# Gets the controllers version, to switch the restui API format +# TODO: Find exact version api calls changed, assumed 4.5.15 at present +getControllerVer () { + VER=$(../act.sh -E ${ENVIRONMENT} controller version) + if [[ -z ${VER} ]]; then echo "Unable to get controllers version."; exit 1; fi + # If controller version is less than 4.5.15, then use old restui API format + if [[ ${VER} =~ ^4.5.([0-9]*) && ${BASH_REMATCH[1]} -lt 15 ]]; then + SOURCE_API_NODEINFO="/controller/restui/nodes/list/health/ids" + else + SOURCE_API_NODEINFO="/controller/restui/v1/nodes/list/health/ids" + fi +} + # Setup our data sources setupSources () { # Filenames for input, if SOURCE=1 @@ -348,6 +353,7 @@ getNodeInfo () { # Lets get ready runChecks +getControllerVer setupSources # Output header line