Not a customer? Click the 'Start a free trial' link to begin a 30-day SaaS trial of our product and to join our community.
Existing Cisco AppDynamics customers should click the 'Sign In' button to authenticate to access the community
on
09-19-2019
03:02 PM
- edited on
04-28-2021
02:56 PM
by
Claudia.Landiva
AppDynamics users can write their own monitoring extension scripts to add custom metrics to the set that AppDynamics already collects and reports to the Controller.
This article features resources (provided by AppDynamics) for Windows and Powershell (5.1) users who want to onboard REST API usage. It contains the necessary steps for adding custom metrics using a shell script.
Found under Extensions and Custom Metrics, refer to Build a Monitoring Extension Using Scripts for the general steps to creating your own monitoring extension.
$controller = "YOUR_CONTROLLER_HOST"
$port = "YOUR_CONTROLLER_PORT"
$protocol = "YOUR_CONTROLLER_SCHEMA"
$account = "ACCOUNT_NAME"
$user = "USER_NAME"
$password = "PASSWORD"
$controllerEndpoint = "YOUR_REST_API_URL"
$restURL = "${protocol}://${controller}:${port}/${controllerEndpoint}"
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${user}@${account}:${password}"))}
$response = Invoke-WebRequest -Uri $restURL -Headers $headers
$response.content
$JSON = @'
{
"key1":"value1",
"key2":"value2",
"key3":[
{"key31":"value31"},
{"key32":"value32"},
{"key33":"value33"}
]
}
'@
$controller = "YOUR_CONTROLLER_HOST"
$port = "YOUR_CONTROLLER_PORT"
$protocol = "YOUR_CONTROLLER_SCHEMA"
$account = "ACCOUNT_NAME"
$user = "USER_NAME"
$password = "PASSWORD"
$controllerEndpoint = "YOUR_REST_API_URL"
$restURL = "${protocol}://${controller}:${port}/${controllerEndpoint}"
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("username@account:password"))}
$response = Invoke-RestMethod -Uri $restURL -Method Post -Headers $headers -Body $JSON -ContentType "application/json"
$response.content
$controller = "YOUR_CONTROLLER_HOST"
$port = "YOUR_CONTROLLER_PORT"
$protocol = "YOUR_CONTROLLER_SCHEMA"
$account = "ACCOUNT_NAME"
$user = "USER_NAME"
$password = "PASSWORD"
$controllerEndpoint = "YOUR_REST_API_IMPORT_URL"
$restURL = "${protocol}://${controller}:${port}/${controllerEndpoint}"
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("username@account:password"))}
$filePath = "YOUR_FILE_TO_BE_IMPORTED";
$fileBin=[System.IO.File]::ReadAllBytes(".\" + $filePath)
$CODEPAGE="UTF-8"
$enc = [System.Text.Encoding]::GetEncoding($CODEPAGE)
$fileEnc = $enc.GetString($fileBin)
$boundary = [System.Guid]::NewGuid().ToString()
$LF = "`r`n"
$bodyLines = (
"--$boundary",
"Content-Disposition: form-data; name=`"file`"; filename=`"Import.xml`"",
"Content-Type: application/octet-stream$LF",
$fileEnc,"--$boundary--$LF") -join $LF
$response = Invoke-RestMethod -Uri $restURL -Method Post -Headers $headers -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines
$response.content
controller |
Controller host name |
GET POST with JSON POST with file upload |
port |
Controller port name |
GET POST with JSON POST with file upload |
protocol |
Controller schema type:
|
GET POST with JSON POST with file upload |
account |
Name of account in controller Single-tenant hosts use "customer1" |
GET POST with JSON POST with file upload |
user |
The username of your user with sufficient permissions to access target API |
GET POST with JSON POST with file upload |
password |
The password of your user with sufficient permissions to access target API |
GET POST with JSON POST with file upload |
controllerEndpoint |
Target Controller's REST API to be accessed Usually, it starts with "controller/" |
GET POST with JSON POST with file upload |
restURL |
Full URL for API to be used for file import, e.g., $restURL = "http://controller:port/controller/ transactiondetection/<app_id>/custom" |
GET POST with JSON POST with file upload |
headers |
Section to be modified to replace dummy credentials (username@account:password) with the user's real credentials |
GET POST with JSON POST with file upload |
methodName |
Rest API Method name
|
GET POST with file upload |
filePath |
Full valid path to the file to be imported on the Windows host e.g., $filePath = "C:/Import.xml"; |
POST with file upload |
To learn about extending AppDynamics with APIs, see:
https://docs.appdynamics.com/display/PRO45/AppDynamics+APIs
For more information about Microsoft PowerShell, see:
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/powershell
The "GET Request API Call" section has an error!
The line that reads:
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${user}@${account}:${password"}))}
Needs to be changed to:
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${user}@${account}:${password}"))}
The last double quote is in the wrong position
Hi, @Keith.Sanders
Thank you! I've corrected the error you pointed out.
On behalf of everyone in the Community, thanks for letting us know!
Claudia Landivar
Community Manager & Editor
Thank you! Your submission has been received!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form