Forum Discussion
7 years ago
Hi George,
I am looking for device SDT which it can read devices from txt file. I tried to modify the above script and getting below error. Could you help me on it.
I am looking the solution to read the device names from txt file and making it in to sdt. Getting below output
Status:1007
Response:
<# account info #>
$accessId = 'XXXXX'
$accessKey = 'XXXXX'
$company = 'XXX'
# stdTYpe (integer)
# 1 - one time, 2 - Weekly SDT, 3 - Monthly SDT, 4 - Daily SDT
# we have to use "one time" style values because LM has no concept of day of month
$stdTYpe = 1
# type (string)
# ServiceGroupSDT, DeviceGroupSDT, CollectorSDT
$type = "DeviceSDT"
# deviceGroupId (string)
#
$deviceDisplayName = 'hostname'
# dataSourceId (integer)
# 0 = ALL
#$dataSourceId = 0
<# request details #>
$httpVerb = 'POST'
$resourcePath = '/sdt/sdts'
# maintenance start
$maintenancestart = "07/12/2018 11:30:00"
#maintenance length (in minutes)
$maintenancelength = 30
$startDate = (Get-Date -Date $maintenancestart).ToUniversalTime()
$startDateepoch = [Math]::Round((New-TimeSpan -start (Get-Date -Date "1/1/1970") -end $startDate).TotalMilliseconds)
$endDate = $startDate.AddMinutes($maintenancelength)
$endDateepoch = [Math]::Round((New-TimeSpan -start (Get-Date -Date "1/1/1970") -end $endDate).TotalMilliseconds)
# device group data
$data = '{"sdtType":'+$stdTYpe+',"type":"'+ $type +'","devicename":'+ $deviceDisplayName +',"startDateTime":'+ $startDateepoch +',"endDateTime":'+ $endDateepoch +'}'
<# Construct URL #>
$url = 'https://' + $company + '.logicmonitor.com/santaba/rest' + $resourcePath
<# Get current time in milliseconds #>
$epoch = [Math]::Round((New-TimeSpan -start (Get-Date -Date "1/1/1970") -end (Get-Date).ToUniversalTime()).TotalMilliseconds)
<# Concatenate Request Details #>
$requestVars = $httpVerb + $epoch + $data + $resourcePath
<# Construct Signature #>
$hmac = New-Object System.Security.Cryptography.HMACSHA256
$hmac.Key = [Text.Encoding]::UTF8.GetBytes($accessKey)
$signatureBytes = $hmac.ComputeHash([Text.Encoding]::UTF8.GetBytes($requestVars))
$signatureHex = [System.BitConverter]::ToString($signatureBytes) -replace '-'
$signature = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($signatureHex.ToLower()))
<# Construct Headers #>
$auth = 'LMv1 ' + $accessId + ':' + $signature + ':' + $epoch
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization",$auth)
$headers.Add("Content-Type",'application/json')
<# Make Request #>
$response = Invoke-RestMethod -Uri $url -Method $httpVerb -Body $data -Header $headers
<# Print status and body of response #>
$status = $response.status
$body = $response.data| ConvertTo-Json -Depth 5
# Write-Host "Query:$response"
Write-Host "Status:$status"
Write-Host "Response:$body"
Related Content
- 5 months ago
- 7 months ago