vCenter Plug Ins

Following on from my previous post I thought about how to show the resulting information from the PowerCLI one liner in vCenter.

This is actually pretty simple.  You need to make a couple of files and then you are done.

First make your web application or page.  What I did was to schedule a run of the PowerCLI script from the last post piped to ConvertToHTML and put the file under the UI folder within the Tomcat installation on my vCenter server which is

C:\Program Files\VMware\Infrastructure\tomcat\webapps\ui

Here is the actual script with some CSS added to so you can adjust how things look, a note if you are cut-n-pasting please make sure you don't add any line breaks as this will break the code.

# Add VMWare Snap In
Add-PSSnapin VMware.VimAutomation.Core

# Connect to vCenter
Connect-VIServer -Server vcenter


# Set up the styles
$a = '<style>';
$a = $a + 'BODY{background-color:#eeeeee;}';
$a = $a + 'TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}';
$a = $a + 'TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#618ab7}';
$a = $a + 'TD{border-width: 1px;padding: 0px;border-style: solid;border-color:grey;background-color:PaleGoldenrod}';
$a = $a + '</style><basefont face=arial size=5>';


# Get Cluster Capacity
Get-Cluster | Select Name, @{N="Total VMs";E={($_ | Get-VM).Count}},@{N="Powered VMs";E={($_ | Get-VM | where {$_.PowerState -eq "PoweredOn"} ).Count}} | Sort Name | ConvertTo-Html -Head $a > "C:\Program Files\VMware\Infrastructure\tomcat\webapps\ui\capacity.html"


I saved this as script.ps1 and created a batch file to run it,

powershell -command "& 'C:\script.ps1' "

And then a scheduled task to run this...*phew*  I know you can run PowerShell directly from the scheduled task but something in me makes me write batch files :)  Who you run the scheduled task as should have enough rights within vCenter to gather this information.

I had to use a scheduled task as although I found a method of running the PowerShell script on demand from JavaScript (remember in my case the hosting webserver is Tomcat!) but I was not impressed by the performance and slightly clunky method.  I guess you could do all this on an IIS box and use ASPX to fire things off - it would be much nicer :)  Unfortunately I didn't have the luxury of an IIS box hanging around doing nothing so I mend and make-do!

Next up is a description of the plugin which you import into vCenter.  This is an XML file which bascially shows the display name, description, the location of the web application to show and under what tab...here's an example

<scriptConfiguration  version="1.0">
<key>Cluster Capacity</key>
<description>LUN Capacity PowerShell Script</description>
<vendor>NAPP</vendor>
<multiVCsupported>false</multiVCsupported>
<extension parent="InventoryView.Cluster">
<title locale="en">Capacity</title>
<url  display="window">https://vcenter:8443/ui/capacity.html</url>
</extension>
</scriptConfiguration>


Fill in your own details.  The extension parent bit is how you tell vCenter where to display your plugin/webpage.  I've chosen to show this as a tab when the user clicks on the cluster.  So along with the "Getting Started", "Summary" and "Hosts" tabs (amongst others) is a tab called "Capacity".  You may have to use the scroll buttons to move the tabs to the left to see your new tab.

Save this file to the vCenter server under the plugin folder.  This meant in my case

C:\Program Files\VMware\Infrastructure\tomcat\webapps\ui\plugin

Now run your scheduled task/powershell script to create the HTML page and fire up vCenter.

From vCenter go to the Plug-ins menu and click Manage Plug-ins...

Right click in any blank space in the Plug-in Manager Dialog and click  New Plug-in...

Click Browse... and locate your xml file in the plugin folder

C:\Program Files\VMware\Infrastructure\tomcat\webapps\ui\plugin

If successfully loaded the xml will be displayed underneath if all looks good click the Register Plug-in button.

Hopefully a dialog will pop up tell you things went well.

Close and re-open vCenter, I'm not sure why I had to do this but this was the only way things worked and refreshed properly for me (may be different for you).  Open the Plug-in Manager again and you should see your plug-in listed.  Right click on it and select Enable.

Close the plug-in Manager and click on a Cluster, check the tabs in the right pane to see your webpage!

Simple.  Although it did take a bit of fiddling to get this method down, so you may need to adjust for your scenario.

This makes the Plug-in avaliable to all users of vCenter from that vCenter server so be aware that all your change requests are in and water tight :) ITIL....ITIL....ITIL :)

Comments

Popular posts from this blog

PXE booting, MDT and 802.1x

Intune installation requires a wire...or does it?

Security Policy 1001