I thought I had posted at one time (but obviously didn't), here's a PowerShell script that parses through the data that's returned so that you can have a good object to work with. Can see what's done here to possibly work in whatever language you want to program in.
there's some work that I haven't finished on this (mainly if it doesn't include an instance ID), but thanks @Sarah Terry for the additional rest path as well, I'll be using that to narrow this function even more!
function lm-getdatarest {
[CmdletBinding()]
Param (
[Parameter(Position=0,Mandatory=$true)]
[string]$DeviceID,
[Parameter(Position=1,Mandatory=$true)]
[string]$DatasourceID,
[Parameter(Position=2,Mandatory=$false)]
[string]$InstanceID
)
<# account info #>
$accessId = 'xxxxx'
$accessKey = 'xxxxx'
$company = 'xxxx'
<# request details #>
$httpVerb = 'GET'
if (!($InstanceID)) {$resourcePath = '/device/devices/' + $DeviceID + '/devicedatasources/' + $DatasourceID + '/data'}
if ($InstanceID) {$resourcePath = '/device/devices/' + $DeviceID + '/devicedatasources/' + $DatasourceID + '/instances/' + $InstanceID + '/data'}
<# 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 + $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 -Header $headers
<# Print status and body of response #>
$body = $response.data
$data = @()
$a = 0
if ($InstanceID) {
foreach ($iteration in $body.time) {
$b= 0
$epoch = [datetime]"1/1/1970"
$date = $epoch.AddMilliseconds($iteration)
foreach ($datapoint in $($body.values[$a])) {
$detailprop = @{'value'=$datapoint;
'datapoint'=$($body.dataPoints[$b]);
'timestamp'=$date}
$objectD = New-Object -TypeName PSObject -Prop $detailprop
$data += $objectD
$b++
}
$a++
}
}
return $data
}#lm-getdatarest
#$output = lm-getdatarest "25991" "961171"
<# Example
datapoint timestamp value
--------- --------- -----
average 6/14/2017 5:17:08 PM 0
maxrtt 6/14/2017 5:17:08 PM 0
minrtt 6/14/2017 5:17:08 PM 0
PingLossPercent 6/14/2017 5:17:08 PM 0
recvdpkts 6/14/2017 5:17:08 PM 10
sentpkts 6/14/2017 5:17:08 PM 10
#>