• 0

downloading a collector file using the rest api is downloading corrupted file few times


When we are downloading the collector file using https://www.logicmonitor.com/support/rest-api-developers-guide/collectors/downloading-a-collector-installer/ rest API we're getting corrupted file for few of our products, which is not consistent. We're getting this issue for random products and today we're not able to reproduce the issue for the same products.

I would like to know in which scenarios we'll be able to reproduce the issue or is there an issue with API.  Any quick update or heads up will be a great help!!

Below is the powershell code we're using to download collector file.

function downloadCollector
  [parameter(mandatory = $true)]
  [parameter(mandatory = $true)]
  [parameter(mandatory = $true)]
  [parameter(mandatory = $true)]

  write-host "In the downloadCollector function.."

  $baseLMUrl = 'https://{0}.logicmonitor.com/santaba/rest{1}'
  #$resourcePath = [string]::Format("/setting/collectors/{0}/installers/Win64?useEA=true", $CollectorId)
  $resourcePath = [string]::Format("/setting/collectors/{0}/installers/Win64", $CollectorId)
  $localFile = 'C:\inforbc\tmp\logicmonitoring.exe'

  <# Construct URL #>
  $url = [string]::Format($baseLMUrl, $portal, $resourcePath)
  $url = [string]::Format("{0}?useEA=true?collectorSize=small", $url)

  <# 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 #>
  if ([String]::IsNullOrEmpty($data))
      $requestVars = $verb + $epoch + $resourcePath
      $requestVars = $verb + $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]]"

  #(New-Object System.Net.WebClient).DownloadFile($url, $installFile)
  Invoke-WebRequest -Uri $url -Headers $headers -ContentType 'application/json' -OutFile $localFile



Share this post

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

The issue here could be that some of your Windows systems are defaulting to connect to LogicMonitor endpoints using TLS 1.0, which we no longer support. You can ensure your scripts are using a more recent version of TLS by prepending the following line of code:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12;

Hope this helps.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.