Forum Discussion

Vinusha's avatar
7 years ago

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
{
  param(
  [parameter(mandatory = $true)]
  [string]$CollectorId,
  [parameter(mandatory = $true)]
  [string]$portal,
  [parameter(mandatory = $true)]
  [string]$AccessId,
  [parameter(mandatory = $true)]
  [string]$AccessKey)

  write-host "In the downloadCollector function.."

  $verb='GET'
  $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
  }
  else
  {
      $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]]"
  $headers.Add("Authorization",$auth)
  #$headers.Add("Content-Type",'application/json')

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

}

 

  • 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.