Download CloudHub Application Log Files Using Anypoint CLI

Mazhar Ansari
3 min readSep 14, 2020

Note: While copy/paste the code snippet from blog please covert quotes and double quotes.

CloudHub stores up to 100 MB of log data per application per worker, or up to 30 days, whichever limit is reached first. This is not applicable for clients who have Titanium subscription. For Titanium Subscription, you will get 200 GB per production core.

Objective of this blog to discuss a generic approach which can help clients to download application log files if they are not using any centralized logging server with Mulesoft.

MuleSoft Options to Overcome such issue?

  • Manually download log files
  • Anypoint CLI
  • Anypoint CloudHub API

In this blog we will discuss option # 2 and try to create scripted solutions for the same.

Anypoint CLI:

  • Anypoint Platform provides a scripting and command-line tool for both Anypoint Platform and Anypoint Platform Private Cloud Edition (Anypoint Platform PCE).
  • The command-line interface (CLI) supports both the interactive shell and standard CLI modes.
  • Anypoint CLI is a NodeJS based application which works on all kinds of operating systems.

Anypoint CLI Installation:

npm install -g anypoint-cli@latest

Shell Script Overview:

Below Algorithm is used.

  • Find all deployed and running application in a particular environment
  • Download Log Files one by one
#!/bin/bashif [ $# -ge 5 ]; then
echo "Your command line contains $# arguments"
else
echo "Usage: $0 UserName Password AnypointOrgName AnypointEnvNameFileDir"
exit 0
fi
#anypoint-cli environment variables
ANYPOINT_USERNAME=$1
ANYPOINT_PASSWORD=$2
ANYPOINT_ORG=$3
#Other Const
anypointEnv=$4
fileDir=$5
results=` anypoint-cli --environment=$anypointEnv runtime-mgr cloudhub-application list -o json | jq '.[].Application' | awk '{print $1}' | sed 's/"//g' `for appName in $results
do
anypoint-cli --environment=$anypointEnv runtime-mgr cloudhub-application download-logs $appName $fileDir
done
  • Line # 1 define which shell to use for execution
  • Line # 3–8 check if correct parameters are passed of not
  • Line # 11–13 set Anypoint related variables
  • Line # 16 set Anypoint CloudHub Environment Name
  • Line # 17 set the file directory
  • Line # 19 get all deployed and running applications in a particular environment
  • Line # 21–24 download the log files one by one
downloadLogFiles.sh

Execution:

  • Create a file named downloadLogFiles.sh and save it on Unix system
  • Change permissions of file to execute it
chmod 777 downloadLogFiles.sh
  • Run the command
./downloadLogFiles.sh <UserName> <Password> <BusinessGroup> <EnvName> <FileDir>
Output
  • It will download all files in given directory
File List

Note: This script can be modified and used in Windows System as well.

--

--

Mazhar Ansari

I am seasoned Integration Architect with around 18+ yrs of exp. I have extensively worked on TIBCO and Mulesoft. Mainly in EAI, ESB, SOA, API and BPM projects.