No instances on API response
- 4 days ago
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; } } }