From 6be1515e86cce225f5fe3f6d5f5c98c3414274e0 Mon Sep 17 00:00:00 2001 From: alex_jov Date: Wed, 20 Jan 2021 18:39:10 +0100 Subject: [PATCH] Custom dahboard - continue upload on application placeholder missing; Echo - replace path with file name; Refactor debug curl flags; --- modules/dashboards/upload_custom_dashboard.sh | 53 ++++++++----------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/modules/dashboards/upload_custom_dashboard.sh b/modules/dashboards/upload_custom_dashboard.sh index 3491b0a..8d5fe11 100755 --- a/modules/dashboards/upload_custom_dashboard.sh +++ b/modules/dashboards/upload_custom_dashboard.sh @@ -11,64 +11,55 @@ _debug=${5} _custom_dash_dir="./custom_dashboards" #I might move this into dashboard folder.. let see.. _temp_dash_dir="$_custom_dash_dir/temp" + templateAppName="ChangeApplicationName" +_dasboard_API_endpoint="CustomDashboardImportExportServlet" + dt=$(date '+%Y-%m-%d_%H-%M-%S') -#check if custom dashboards exist +# check if custom dashboard files exist if [ "$(ls -A $_custom_dash_dir/*.json)" ]; then - echo "" echo "Found custom JSON file(s) in $_custom_dash_dir" - ls -l $_custom_dash_dir/*.json + #ls -l $_custom_dash_dir/*.json else - echo "" echo "$_custom_dash_dir directory is empty. " - echo "Please add custom dashboard JSON files to the $_custom_dash_dir directory " - echo "Aborting.." + echo "Please add custom dashboard JSON files to the $_custom_dash_dir directory. " + echo "Aborting..." exit 1 fi -#check if App exist - -# allApplications=$(curl -s --user ${_user_credentials} ${_controller_url}/rest/applications?output=JSON $_proxy_details) - -# applicationObject=$(jq --arg appName "$_application_name" '.[] | select(.name == $appName)' <<<$allApplications) - -# if [ "$applicationObject" = "" ]; then -# func_check_http_response 404 "Application '"$_application_name"' not found. Aborting..." -# fi - -#All conditions met.. processing dashboards. - -_dasboard_API_endpoint="CustomDashboardImportExportServlet" - mkdir -p "$_temp_dash_dir" && cp -r "$_custom_dash_dir"/*.json "$_temp_dash_dir" for _dash_file in $_temp_dash_dir/*.json; do - echo "" - echo "Processing ${_dash_file} dashboard template. Using the '${_application_name}' application" + + _file_name="$(basename -- $_dash_file)" + + echo -e "Processing ${_file_name} dashboard template. Using the '${_application_name}' application. \n" if grep -q $templateAppName ${_dash_file}; then sed -i -e "s/${templateAppName}/${_application_name}/g" "${_dash_file}" else - echo "Error occured. Please ensure you replace the applicationName object in the json file with '$templateAppName' " - echo "Refer to the documentation for details. TODO [add link]" - exit 1 + echo -e "WARNING Placeholder value '$templateAppName' not found in json file provided. Application name not replaced. " + echo -e " Refer to the documentation for more details: https://appdynamics.github.io/ConfigMyApp/usecases/8-custom_dashboards.html \n" + #exit 1 fi - sleep 2 # let it cool off - echo "" - echo "Uploading $_dash_file to ${_controller_url}... " + sleep 1 # let it cool off + + echo "Uploading '${_file_name}' custom dashboard..." #$_dash_file to ${_controller_url}... " if [ $_debug = true ]; then - response=$(curl -v -X POST --user ${_user_credentials} ${_controller_url}/${_dasboard_API_endpoint} -F file=@${_dash_file} ${_proxy_details}) + output="-v" else - response=$(curl -s -X POST --user ${_user_credentials} ${_controller_url}/${_dasboard_API_endpoint} -F file=@${_dash_file} ${_proxy_details}) + output="-s" fi + response=$(curl ${output} -X POST --user ${_user_credentials} ${_controller_url}/${_dasboard_API_endpoint} -F file=@${_dash_file} ${_proxy_details}) + expected_response='"success":true' func_check_http_response "\{$response}" $expected_response - sleep 1 + # save used uploaded files mkdir -p "${_custom_dash_dir}/uploaded"