cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create HTTP Monitor using API via PowerShell script

sriramprabhakar
Newcomer

Hi,

I am trying to automate the creation of an HTTP monitor using PowerShell scripts. However, I always get a 400 when I try to pass the value of the location via variable. Please see below

 

[array]$location = "[GEOLOCATION-2FD31C834DE4D601]"

Write-Host $location
$headers = @{
Authorization= ' Api-Token xxxxxxxxxxx'

}
$body = '{
"frequencyMin": 10,
"anomalyDetection": {
"outageHandling": {
"globalOutage": true,
"localOutage": false,
"localOutagePolicy": {
"affectedLocations": 1,
"consecutiveRuns": 3
}
},
"loadingTimeThresholds": {
"enabled": false

}
},
"type": "HTTP",
"name": "Created_via_Devops_pipeline",
"locations": $location ,
"enabled": true,
"keyPerformanceMetrics": {
"loadActionKpm": "VISUALLY_COMPLETE",
"xhrActionKpm": "VISUALLY_COMPLETE"
},
"script": {
"version": "1.0",
"requests": [{
"description": "CreatedByDevops",
"url": "https://{environmentid}.live.dynatrace.com/api/v1/synthetic/monitors -Method post -Headers $headers -ContentType 'application/json' -body $body

1 REPLY 1

zofiatarant
Dynatracer
Dynatracer

Hi! You're missing quotation marks around the location ID. Please try:

$location='["GEOLOCATION-2FD31C834DE4D601"]'