Skip to content

Commit

Permalink
Merge pull request #44 from Appdynamics/features/custom-dash-bug
Browse files Browse the repository at this point in the history
Custom dashboards - bugfix
  • Loading branch information
AlexJov committed Feb 4, 2021
2 parents f2d0efe + 6be1515 commit c659bea
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions modules/dashboards/upload_custom_dashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit c659bea

Please sign in to comment.