needing some more examples of pulling data from a device or interface of a device. #6
-
My focus is on the many WAN devices in our LM setup. We have a central system but we also have some 90+ Facilities that connect to our DataCenter via WAN connections. My ask is to be able to pull the WAN Interfaces that are also broken up into VLAN sets as the interface shows 0/0/1.400 for the Vlan 400 link that is shared between all other locations on the same vlan 400 link. What I would like to do: I am thinking I may need to provide an input file that has the device and interfaces that I need to pull data for and that the code would read this file to know which devices to work on. Ideally pulling this data weekly for review should be enough to build up the information and study it. But if need be, it could be pulled daily to keep the data as detailed as possible. I'm thinking that this may require a secondary database to save off the detail information from the LM gathering process and for further detail study of this usage. My question is how to pull the data using the API interface to pull information from selected devices and interfaces and then capture this as CSV information for follow on processing to study. How do I construct the API Call to pull the detail data per interface of a device? But also pull it in such a way that I do not overload the API Interface. The Dashboard Detail has our information at 2 minute intervals. But when I go to the 7 day view - it summarizes it as 11 minute intervals. I really need it at the 2 minute interval if possible. Or I need to pull the data daily to keep it at the 2 minute interval. Thanks for your help and guidance on how to pull the data with the Window API Calls? Suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
You should be able to achieve that fairly easily with the PS module. Here is a sample snippet of code that does most of what you are looking for, you would just need to add the logic to only take action on the vlan specific instances and the code to figure out the contract values for the in and out speed but this script will take a device and pull the instance list for network interfaces and then proceed to set the custom properties for controlling in and out speed along with pulling the last 24 hours of metrics and exporting the entire result set for analysis. #Setup variables
$InterfaceInstanceData = $null
$Results = New-Object System.Collections.ArrayList
#Get device info and datasource/instance list
$Device = Get-LMDevice -Name "192.168.1.4"
$DeviceDS = Get-LMDeviceDatasourceList -id $Device.id -Filter "dataSourceName -eq 'SNMP_Network_Interfaces'"
$DeviceInstances = Get-LMDeviceDatasourceInstance -Deviceid $Device.id -datasourceId $DeviceDS.dataSourceId
Write-Host "Processing Device: $($Device.Name) with $($DeviceInstances.Count) instances"
Foreach($Instance in $DeviceInstances){
Write-Host "Processing Instance: $($Instance.Name)"
#Get last 24 hours of instance data
$InterfaceInstanceData = Get-LMDeviceData -DeviceId $Device.id -DatasourceId $DeviceDS.dataSourceId -InstanceId $Instance.Id
#Optionally set interface speed based on contract logic would go here
$UpdatedDeviceInstance = Set-LMDeviceDatasourceInstance -DeviceId $Device.id -DatasourceId $DeviceDS.dataSourceId -InstanceId $Instance.Id -Properties @{out_speed="1000000";in_speed="2000000"}
#Get updated interface properties, make sure they are set correctly
$InSpeedIndex = $UpdatedDeviceInstance.customProperties.name.IndexOf("in_speed")
If($InSpeedIndex -ne -1) {
$InstanceDownSpeed = $UpdatedDeviceInstance.customProperties.value[$InSpeedIndex]
}
$OutSpeedIndex = $UpdatedDeviceInstance.customProperties.name.IndexOf("out_speed")
If($OutSpeedIndex -ne -1) {
$InstanceUpSpeed = $UpdatedDeviceInstance.customProperties.value[$OutSpeedIndex]
}
#Add Results to Array
$Results.Add(
[PSCustomObject]@{
DeviceName = $Device.Name
DatasourceName = $DeviceDS.DataSourceName
InstanceName = $Instance.Name
InstanceDisplayName = $Instance.displayName
InstanceDescription = $Instance.description
InstanceUpSpeed = $InstanceUpSpeed
InstanceDownSpeed = $InstanceDownSpeed
Metrics = $InterfaceInstanceData
}
) | Out-Null
} |
Beta Was this translation helpful? Give feedback.
-
Thank you for your help - - I learn by example and this is a great example to learn from. How do I know it is for the last 24 hours? I see that output in the variable set Metrics = $InterfaceInstanceData Thank you again for a good example. This is great stuff and the building blocks for being able to do more with the data that is being collected. |
Beta Was this translation helpful? Give feedback.
-
Another person helped to decode the custom object in this script. This is looking for the variable Metrics to then expand. Function to flatten PSCustom Object with nested Metricsfunction Flatten-PSCustomObject {
$commonProperties = $obj.PSObject.Properties | Where-Object { $_.Name -ne 'Metrics' }
$flattenedObject[$property.Name] = $property.Value
foreach ($property in $metric.PSObject.Properties) {
} Flatten-PSCustomObject($results) |
Beta Was this translation helpful? Give feedback.
Thank you for your help - - I learn by example and this is a great example to learn from.
This shows how to get the data for one Device - and all the interfaces on that device.
How do I know it is for the last 24 hours?
I see that output in the variable set Metrics = $InterfaceInstanceData
Thank you again for a good example. This is great stuff and the building blocks for being able to do more with the data that is being collected.