Forum Discussion

juramir's avatar
juramir
Icon for Neophyte rankNeophyte
16 days ago
Solved

No instances on API response

Hello everyone,

Sorry if this is a repeat topic here, but I'm having some trouble polling data from our new LogicMonitor setup via API.

As I understand it, I'll need device ID, device datasource ID, instance ID, all together to get graph data over a specific time period. I can successfully pull the first two (device id and datasource id), but when I pull the instances resource, I'm not getting any response.

Example resource path:

/device/devices/{device id}/devicedatasources/{datasourceid}/instances

The response I get is:

{
  "total": 0,
  "items": [],
  "searchId": null,
  "isMin": false
}

 

indicating that there's no instances. This is where I seem to get stuck, I don't seem to be able to move on any further. Has anybody run into this, and can give me a direction for next steps? Anything is appreciated!

  • I dont usually get my instances that way, so apologies if I'm about to be confusing. :) But I think you are using this call: "/device/devices/{deviceId}/devicedatasources/{hdsId}/instances". I dont think that hdsId is the global template datasource id. In your post you mention "device datasource ID" in your text but then make a reference to {datasourceid} and they arent the same.

    If you already knew that, apologies. Anyway, what I usually do is slightly different. I do:

    • pull "/device/devices/{deviceId}/devicedatasources" to get the "instantiation" of the global datasource id that exists at the device level.
    • hunt through the responses to get the device-level template Id of the datasource by name.
    • If found, grab the "dataSourceId" property, to get the device-level template Id of the datasource.
    • pull /device/devices/{deviceId}/instances to get back all my instances, but I also filter on the device template datasource id with &filter=dataSourceId:"{the thing I just got}"
    • and from there, I have my actual instances in the responses

    So TL;DR I just wanted to be sure you know that for some of these calls, the "datasource id" isnt necessarily the number you'd see when editing the datasource. Apologies if I just focused in on the wrong thing in your post.

    Maybe I'll just focus on something where I have some target devices in a Map and I'm snagging the actual instances of a specific logicmodule to roll up into something else I'm doing. Its a different way to get to the data, and I have some function calls here that I dont show but hopefully are clear.

    If this muddies the water, I apologize. I'm just hoping it will help, since so many people here have helped me.

    Feel free to ignore me and just open a support ticket. :)

    for (String currentObject : filteredObjects.keySet()) {
        
        def Map<String, String> objectInfo = filteredObjects[currentObject];
        
        def String objectId = objectInfo."id";
        def String hostname = objectInfo."name";
        def String displayName = objectInfo."displayName".trim();
            
        //pull list of datasources that can be found on the resource
        def String deviceDatasourcesEndpoint = "/device/devices/" + objectId + "/devicedatasources";
        def String deviceDatasourcesFilter = "";
        
        deviceDatasources = getAPIObjectsByFilter (deviceDatasourcesEndpoint, deviceDatasourcesFilter, accessId, accessKey, account, httpclient);
        
        //one of these is the correct resource, grab it
        vmwareEsxiCpuDatasource = getDatasourceByName(deviceDatasources,"VMware ESXi CPU");
        
        if (vmwareEsxiCpuDatasource != null) {
    
            //get dataSourceId. This is not the global template ID, but the "instance" of the global one
            dsId = vmwareEsxiCpuDatasource["dataSourceId"];
    
            //call API for the instances belonging to this devices' "VMware ESXi CPU" datasource
            instancesEndpoint = "/device/devices/" + objectId + "/instances";
            instancesFilter = "&filter=dataSourceId%3A%22" + dsId + "%22"
                    
            snagInstances = getAPIObjectsByFilter (instancesEndpoint, instancesFilter, accessId, accessKey, account, httpclient);
            
            //do the actual roll-up total for the resource folder (usually a cluster)
            snagInstances.each {
                
                def thisInstance = it; //Map
                        
                //update the group rollup
                def Integer instanceCoreCount = getMapFromProperties(thisInstance."autoProperties")["auto.cpu.core_count"].toInteger();
                esxiCoreCount += instanceCoreCount;
                
                def Integer instanceThreadCount = getMapFromProperties(thisInstance."autoProperties")["auto.cpu.thread_count"].toInteger();
                esxiThreadCount += instanceThreadCount;
                        
            }
    
        }
    
    }

     

6 Replies

  • I dont usually get my instances that way, so apologies if I'm about to be confusing. :) But I think you are using this call: "/device/devices/{deviceId}/devicedatasources/{hdsId}/instances". I dont think that hdsId is the global template datasource id. In your post you mention "device datasource ID" in your text but then make a reference to {datasourceid} and they arent the same.

    If you already knew that, apologies. Anyway, what I usually do is slightly different. I do:

    • pull "/device/devices/{deviceId}/devicedatasources" to get the "instantiation" of the global datasource id that exists at the device level.
    • hunt through the responses to get the device-level template Id of the datasource by name.
    • If found, grab the "dataSourceId" property, to get the device-level template Id of the datasource.
    • pull /device/devices/{deviceId}/instances to get back all my instances, but I also filter on the device template datasource id with &filter=dataSourceId:"{the thing I just got}"
    • and from there, I have my actual instances in the responses

    So TL;DR I just wanted to be sure you know that for some of these calls, the "datasource id" isnt necessarily the number you'd see when editing the datasource. Apologies if I just focused in on the wrong thing in your post.

    Maybe I'll just focus on something where I have some target devices in a Map and I'm snagging the actual instances of a specific logicmodule to roll up into something else I'm doing. Its a different way to get to the data, and I have some function calls here that I dont show but hopefully are clear.

    If this muddies the water, I apologize. I'm just hoping it will help, since so many people here have helped me.

    Feel free to ignore me and just open a support ticket. :)

    for (String currentObject : filteredObjects.keySet()) {
        
        def Map<String, String> objectInfo = filteredObjects[currentObject];
        
        def String objectId = objectInfo."id";
        def String hostname = objectInfo."name";
        def String displayName = objectInfo."displayName".trim();
            
        //pull list of datasources that can be found on the resource
        def String deviceDatasourcesEndpoint = "/device/devices/" + objectId + "/devicedatasources";
        def String deviceDatasourcesFilter = "";
        
        deviceDatasources = getAPIObjectsByFilter (deviceDatasourcesEndpoint, deviceDatasourcesFilter, accessId, accessKey, account, httpclient);
        
        //one of these is the correct resource, grab it
        vmwareEsxiCpuDatasource = getDatasourceByName(deviceDatasources,"VMware ESXi CPU");
        
        if (vmwareEsxiCpuDatasource != null) {
    
            //get dataSourceId. This is not the global template ID, but the "instance" of the global one
            dsId = vmwareEsxiCpuDatasource["dataSourceId"];
    
            //call API for the instances belonging to this devices' "VMware ESXi CPU" datasource
            instancesEndpoint = "/device/devices/" + objectId + "/instances";
            instancesFilter = "&filter=dataSourceId%3A%22" + dsId + "%22"
                    
            snagInstances = getAPIObjectsByFilter (instancesEndpoint, instancesFilter, accessId, accessKey, account, httpclient);
            
            //do the actual roll-up total for the resource folder (usually a cluster)
            snagInstances.each {
                
                def thisInstance = it; //Map
                        
                //update the group rollup
                def Integer instanceCoreCount = getMapFromProperties(thisInstance."autoProperties")["auto.cpu.core_count"].toInteger();
                esxiCoreCount += instanceCoreCount;
                
                def Integer instanceThreadCount = getMapFromProperties(thisInstance."autoProperties")["auto.cpu.thread_count"].toInteger();
                esxiThreadCount += instanceThreadCount;
                        
            }
    
        }
    
    }

     

    • juramir's avatar
      juramir
      Icon for Neophyte rankNeophyte

      Thanks a bunch for your reply! I checked it out today and it looks like I haven't been running into any issues. I think I got stuck in the "hierarchical" structure that I expected (Device -> Datasource -> instance) and it looks like I completely missed over that endpoint. 

      I've now tested on several devices and ports (instances) and not seeing any issues so far.

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

    Hi juramir​ as long as you have instances associated with the datasource, you should be seeing instance details in the response. Would you be able to share the device type and datasource you are referencing? Also, have you tried reaching out to LM Support for help with this issue?

    • juramir's avatar
      juramir
      Icon for Neophyte rankNeophyte

      Hi jake_nahm​ thanks for checking in. No support case yet, as I wasn't sure this was my issue or not. The devices I'm trying to poll are simply just Cisco routers and switches, which are having their SNMP data collected. 

      sn.device_role = L3 Switch

      sn.device_type = Switch

       

      • juramir's avatar
        juramir
        Icon for Neophyte rankNeophyte

        And just to add more detail, the GUI itself has several instances per datasource, it's just the API response that's not showing anything. I cycled through every instance and got the same response as above.

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

    Thanks juramir​. Definitely worth raising a support ticket for this case. Based on the information provided it seems like you should be getting a response.