Rest API and Powershell
So I have had pretty good luck converting the Python examples to Powershell.
The one thing I can not figure out how to do is return volume usage for a specific host.
Anyone got any example powershell script using Rest API to pull volume usage on a host?
Gary_Dewrell
Posted 9 years ago·Last reply 7 years ago
7 comments
Cole McDonald
·7 years agoExcellent, thank you... progress! new error... but in a response code :)/emoticons/smile@2x.png 2x" title=":)" width="20"> 1401 auth failed... I can work with that.
<edit> Working now! I had to refresh all of the variable contents in my ISE session. </edit>
Sarah_Terry
·7 years agoHi @Cole McDonald -
Have you seen our PowerShell examples here: https://www.logicmonitor.com/support/rest-api-developers-guide/v1/rest-api-v1-examples/? You may need to add a line to use TLS 1.2:
Let us know if that doesn't fix it!
Thanks,
Sarah
Cole McDonald
·7 years agoI'm working on transitioning some of our custom reporting over from SCOM to LM as we transition. I'm having a difficult time getting REST to give me anything at all. I have an API Token created and have saved it into my credential store. I'm using the CredentialManager 2.0 module to access them. Here's the rest:
I'm getting this response:
what am I missing here? All of the parts look right going into the invoke:
(Moderator: please feel free to move this reply if necessary - Not sure if you want this in a new thread or not.)
Gary_Dewrell
OP9 years agoSarah you Rock!
Sarah_Terry
·9 years agoHi Gary - DataSources have two ids: one id for the DataSource template, and another id for each Device-DataSource combinations (for each device it's applied to). So in this case, 94 is the id of the DataSource itself, but what you want is the id of the DataSource instantiated for device 1. So in your example, you want the 'id' field (58), which corresponds to the unque device-datasource combination, instead of the dataSourceId field (94). Additionally, the instances themselves have ids, so you'd need to get the instance id to put in the resource path if you wanted data for one specific instance. I recommend omitting the instance id from the resource path if you don't mind getting data for multiple instances. So the resource path should be:
Otherwise, you could make a GET request to /device/devices/1/devicedatasources/58/instances to get instance ids. Does that make sense?
Thanks,
Sarah
Gary_Dewrell
OP9 years agoThank you for your quick response. I feel like I am close. I wrote code to return the device and datasource info. Here is a sample output:
id : 58
deviceId : 1
dataSourceId : 94
dataSourceName : WinVolumeUsage-
dataSourceDescription :
dataSourceDisplayName : Volume Usage
graphs :
overviewGraphs :
groupName : Disks
deviceName : c896-01
deviceDisplayName : volta-c896-01
monitoringInstanceNumber : 2
instanceNumber : 2
instanceAutoGroupEnabled : False
groupsDisabledThisSource :
status : 0
createdOn : 0
updatedOn : 1490145619
assignedOn : 1490145552
nextAutoDiscoveryOn : 1490231952
autoDiscovery : True
isMultiple : True
alertStatus : none
alertStatusPriority : 100000
sdtStatus : SDT-none-none
alertDisableStatus : none-none-none
stopMonitoring : False
alertingDisabledOn :
sdtAt : _hs-customer
dataSourceType : DS
From this I believe the
Status:1007
Response:
What am I missing?
Sarah_Terry
·9 years agoHi Gary,
To get volume usage, you'll want to use the data resource: https://www.logicmonitor.com/support/rest-api-developers-guide/data/get-data/
You'll need the id of the device you want to get volume usage for, and the datasource and instance ids that correspond to volume usage for that device. Alternatively, you can leave out the instance id if you have multiple volumes you want usage for on the same device. In PowerShell, the request should look something like this (with the correct ids, of course):
Thanks,
Sarah