Forum Discussion

Todd_Theoret's avatar
8 years ago

REST API - Services "Properties"

Trying to get "serviceProperties" to populate when pulled via the REST API.

I add a Properties entry on a Web Service Check:  Name - [account_name],  Value - [TheoretDevelopment] but the results always come back empty.  Tried various options.

Does the REST API actually support this field?  Any assistance would be much appreciated.

Thank you!

 

serviceProperties The properties associated with the Service JSON Object "serviceProperties" : [ {"name" : "billing","value" : "website"}, {"name" : "team","value" : "TechOps"}, {"name" : "production","value" : "true"} ]

 

 

 

 

 {
                      "type":  "webservice",
                      "id":  177,
                      "name":  "careers.zzz.org",
                      "description":  "If this site goes down, follow standard critical alert procedures per the client policy",
                      "serviceFolderId":  247,
                      "stopMonitoring":  false,
                      "stopMonitoringByFolder":  false,
                      "disableAlerting":  false,
                      "individualSmAlertEnable":  false,
                      "individualAlertLevel":  "warn",
                      "overallAlertLevel":  "critical",
                      "alertStatus":  "none",
                      "alertStatusPriority":  100000,
                      "sdtStatus":  "none-none-none",
                      "alertDisableStatus":  "none-none-none",
                      "pollingInterval":  1,
                      "transition":  9,
                      "testLocation":  "{\"all\":false,\"smgIds\":[1,2]}",
                      "globalSmAlertCond":  0,
                      "useDefaultLocationSetting":  false,
                      "useDefaultAlertSetting":  false,
                      "userPermission":  "write",
                      "checkpoints":  "  ",
                      "serviceProperties":  "",
                      "serviceStatus":  "alive",
                      "isInternal":  false,
                      "collectors":  "",
                      "script":  "",
                      "method":  "tabledriven",
                      "ignoreSSL":  true,
                      "pageLoadAlertTimeInMS":  30000,
                      "steps":  ""
                  },

 

 

6 Replies

Replies have been turned off for this discussion
  • Sarah_Terry's avatar
    Sarah_Terry
    Icon for Product Manager rankProduct Manager

    Hi Todd - The REST API does indeed support the serviceProperties field.  I'm unable to replicate the issue you're seeing, but it appears the response is also missing the value for the 'checkpoints' object.  Are you using a script to make the request?

  • 3 hours ago, Sarah Terry said:

    Hi Todd - The REST API does indeed support the serviceProperties field.  I'm unable to replicate the issue you're seeing, but it appears the response is also missing the value for the 'checkpoints' object.  Are you using a script to make the request?

    Thanks for the reply Sarah.  Yes, I am utilizing a PowerShell script. Almost identical to the example at: https://www.logicmonitor.com/support/rest-api-developers-guide/overview/using-logicmonitors-rest-api/ except I added: $queryParams = '?size=900'

    <# account info #> $accessId = 'unique' $accessKey = 'unique' $company = 'cwps' <# request details #> $httpVerb = 'GET' $resourcePath = '/service/services'
    $queryParams = '?size=900'

     
    <# Construct URL #>
    $url = 'https://' + $company + '.logicmonitor.com/santaba/rest' + $resourcePath + $queryParams
    
    <# 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 + $queryParams
    
    <# 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 Get -Header $headers 
    
    <# Print status and body of response #>
    $status = $response.status
    $body = $response.data| ConvertTo-Json
    
    Write-Host "Status:$status"
    Write-Host "Response:$body"
  • Sarah_Terry's avatar
    Sarah_Terry
    Icon for Product Manager rankProduct Manager

    Got it - I think found the issue:  When the script converts the response to JSON, it isn't catching those nested objects like checkpoints, serviceProperties, etc.  If you add '-Depth 5' as an option when converting, such that the full line is '$body = $response.data | ConvertTo-Json -Depth 5', you'll see those nested JSON objects.  I'll correct the example scripts - sorry for the confusion!  Let me know if this doesn't fix your issue. 

  • Sarah, unfortunately the -Depth 5 did not pull the properties.  I utilized the exact PowerShell example, with our creds of course.

     

      "checkpoints":  [
                          {
                              "id":  282,
                              "geoInfo":  "Overall",
                              "smgId":  0
                          },
                          {
                              "id":  151899387,
                              "geoInfo":  "US - Los Angeles",
                              "smgId":  1
                          },
                          {
                              "id":  281,
                              "geoInfo":  "US - Washington DC",
                              "smgId":  2
                          }
                      ],
      "serviceProperties":  [

                            ],

  • Sarah_Terry's avatar
    Sarah_Terry
    Icon for Product Manager rankProduct Manager

    Are the properties you're trying to pull set at the service level, or inherited from a group?  The serviceProperties object will only display properties set for the service in question, and won't include any inherited properties (we'll be publishing a properties sub-resource in our next release that includes all service properties, including inherited properties, and labels them by type).

  • I was trying from the Group level as some of our clients (group) have 15+ Services.  But you did solve the mystery. Thank you very much Sarah!

     

                          }
                      ],
      "serviceProperties":  [
                                {
                                    "name":  "account_name",
                                    "value":  "At_Service_Level"
                                }
                            ],