Using PowerVRNI to Register Applications

One of my customers wants to use VRNI to better understand their environment.  They've been fairly disciplined about putting VMs into folders based on the application that the VM serves.  Unfortunately, they've been a little too good about putting the VMs in folders, as each application is broken up into several subfolders.  This causes a bit of a problem when we want to use VRNI to analyze an application's traffic, as the query flows where folder like *application* certainly works based on the VM folder... but it only looks at the immediate folder for the VM, rather than the whole path.  Since we had everything broken up into subfolders, that query doesn't do us much good here.

So, I put together a quick script that can scrape a vCenter inventory to register VRNI applications for each folder that it finds.  Those applications are named based on the absolute path of the VM folder, so that you can run queries like flows where application like *application* to find all network flows for a given application.  I originally wanted to have the script register an application for each parent folder with child folders becoming tiers, but the VRNI API has a hard limit of 6 tiers (that limit doesn't seem to exist in the GUI) per Application, and some of the larger applications here had significantly more than 6 subfolders.  So, I ended up creating one application per subfolder, but I made sure that the application was named for the absolute VM folder path.  Here's what I came up with.

This script loads up the vCenter inventory as a PSDrive and gets all of the VMs that way, rather than by the standard get-vm cmdlet.  This method is actually a lot slower, but it has one key advantage: the psparentpath property.  Unlike the VM Object's .folder property, the .psparentpath property shows the absolute path for the VM, making it easy for my flows where application like *application* VRNI query to work.  I ended up prepending the application names with vc_ (to show that they came from a vCenter object), just to make sure that I didn't stomp on anything that was pre-existing.

The script is pretty easy to use.  You just need to have a PowerShell session with the VMware.PowerCLI and PowerVRNI modules loaded and active sessions on both vCenter and vRNI.  Then, just run the script and specify whatever VM folder name you're interested in.  The script will then scrape the vCenter inventory for any VM that contains the name that you typed anywhere in its absolute path, then will generate vRNI applications based on those paths and register the VMs in the appropriate applications.


Comments

Popular posts from this blog

PowerShell Sorting by Multiple Columns

Clone a Standard vSwitch from one ESXi Host to Another

Deleting Orphaned (AKA Zombie) VMDK Files