tduong

Members
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About tduong

  • Rank
    Community Member
  1. Hi All, I'm trying to create a new device with auto balance group with the below code. But I'm getting response error message "Collector (id=0) does not exist" status 1404. Not sure what went wrong... please advise what need to be done if you've come across this before. Thank you in advance $httpVerb = 'POST' $resourcePath = '/device/devices' $data = "{`"name`":`"10.10.10.10`",`"displayName`":`"test1`",`"autoBalancedCollectorGroupId`":2,`"preferredCollectorGroupName`":`"group1`",`"hostGroupIds`":`"316`",`"preferredCollectorId`":0}" <# 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 Post -Header $headers -Body $data
  2. I tried to extract the data using 'device/groups/{id}/devices' hoping LM would return all devices under subgroups but it doesn't. Worked out a 'workaround' for this using device/devices and filter on systemProperties. Not sure if there are any other ways to do this?... Try the below api, replace grouppath with your group path. For space and / you have to use url encode (space = %20, / = %2) $resourcePath = '/device/devices' $queryParams = '?size=500&filter=systemProperties~grouppath'