Forum Discussion

gwengrafana's avatar
6 years ago

Access Raw Data via API

Hey

I'm wanting to access the ping data of a device.  I've not found an example in the v1 API document that shows how to do this. I've tried the below but haven't found what I expect, i.e. a long list of ping + time + result.

 

$resourcePath = '/device/devices/465103/devicedatasources/376/data'

$epochseconds = Get-Date (Get-Date).ToUniversalTime() -UFormat %s

$fields =  '?start=' + $epochseconds

$url = 'https://' + $company + '.logicmonitor.com/santaba/rest' + $resourcePath + $fields

 

Thanks

 

  • @gwengrafana the resource path should be: $resourcePath =  '/device/devices/465103/devicedatasources/8252658/data to get data for all instances of the Ping DataSource. The Ping deviceDataSourceId in this case is the 8252658.

  • I can see from 

    $resourcePath = '/setting/datasources'
    $fields = '?filter=displayName:Ping'

    That the dataSourceId I am interested in is id = 21

                          "id":  21,
                          "description":  "",
                          "group":  "",
                          "appliesTo":  "isDevice()",
                          "technology":  "",
                          "tags":  "ping,network",
                          "name":  "Ping",
                          "displayName":  "Ping",
                          "version":  1515163055,
                          "auditVersion":  0,
                          "hasMultiInstances":  false,
                          "collectInterval":  60,
                          "collectMethod":  "ping",

     

    But when I look at the machine I am interested in, I do not find that id attached, yet in the UI the Ping graph is being filled in.

     

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

    @gwengrafana there is an example on this page that shows how to get raw data via the API: https://www.logicmonitor.com/support/rest-api-developers-guide/v1/data/get-data/

    Getting data for Ping is the same as getting data for any other DataSource, so that example does apply. Your approach looks correct, but make sure you're using the correct Id - you need the deviceDataSource Id, *not* the DataSource Id. /settings/datasources endpoint will only return the Ids of the DataSources in your account, but what you want is the Id of the instantiated Ping DataSource for a given device. If you instead request /device/devices/ID/devicedatasources, you should see Ping in that list with the deviceDataSource id, which can be used in the get data request.

  • Thanks, $resourcePath = '/device/devices/465103/devicedatasources' gives me

                          "id":  8252658,
                          "deviceId":  465103,
                          "dataSourceId":  376,

     

    $resourcePath = '/device/devices/465103/devicedatasources'

    $fields = '?filter=dataSourceId:376'

    Gives me a slimdowned version of the results. But I am failing to understand deviceDataSourceId as 

    $resourcePath =  '/device/devices/465103/devicedatasources/376/instances

    OR

    $resourcePath =  '/device/devices/465103/devicedatasources/8252658/instances

    returns nothing. 

     

     

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

    @gwengrafana the resource path should be: $resourcePath =  '/device/devices/465103/devicedatasources/8252658/data to get data for all instances of the Ping DataSource. The Ping deviceDataSourceId in this case is the 8252658.

  • Ak okay, so data rather than instances. Thank you, this gives with some data back although seems to have no values but I guess that may be a different issue.

     

    {
        "dataSourceName":  "PingMulti",
        "dataPoints":  [
                           "avgrtt",
                           "maxrtt",
                           "minrtt",
                           "PingLossPercent",
                           "recvdpkts",
                           "sentpkts"
                       ],
        "instances":  {

                      }
    }