Scripts

Welcome to the Nutanix NEXT community. To get started please read our short welcome post. Thanks!

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically generate your Visio Diagram

Highlighted
Trailblazer

Dynamically generate your Visio Diagram

Hi there,

 

Here is my contribution to the Nutanix Community, a simple and easy to use powershell script to diagram your NTNX infrastructure.

All you need to have is Office Visio 2013 on your workstation (haven't tested it with 2010). I hope it will help IT consultant avoiding some boring tasks during the customer report Smiley Very Happy

 

This script report all nodes composing your cluster, the containers and the VMs hosted on each of your hosts into a new Visio Sheet.

 

It recognize the Block model type of your hardware, the upperlying hypervisor type and the OS in your VM.

You can see all the possible shape combination in this pictures :

NTNX_Shape.png

 

My script is composed of 2 files:

  • NTNX_Shape.vssx, a Visio 2013 Gabarit which contains the shapes. This files need to be placed in the same folder that the PS Script.
  • NTNXvision.ps1, the Powershell script that you need to launch to orchestrate all this stuff Smiley Happy

Here, you can see the result of the Visio diagram from my in-place NTNX infrastructure (anonymized obviously):

NTNXoutputHPV.png

 

You can customize the diagram by simply changing some value in the script, if you would like to apply some Office Theme or anything.

 

<#
.SYNOPSIS
	Retrieves Nutanix cluster information to automatically generate a Visio diagram of the infrastructure.
.DESCRIPTION

.PARAMETER NTNXCluster 
	A cluster name or IP to connect to the Nutanix Cluster

.EXAMPLE
	Connect to the cluster "myntnxclu.lab.local"
	./NTNXvision.ps1 myntnxclu.lab.local
.EXAMPLE 
	Launch the script
	./NTNXvision.ps1
.NOTES
	You don't have to specify any cluster name or username as the script will ask for.

#>


Param ($NTNXCluster=$FALSE)

if ( (Get-PSSnapin -Name NutanixCmdletsPSSnapin -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin NutanixCmdletsPSSnapin
}

# The name of the Visio Gabarit used to draw the diagram with the right stencil
# It must be located with this script, at the same directory level !
$shpFile = "NTNX_Shape.vssx"

# In case of a missing argument, ask for the NTNXcluster name/ip to connect
if ($NTNXCluster -eq $FALSE) { $NTNXCluster = Read-Host "Please enter the IP or name of the Nutanix Cluster " }


# A generic function to add an object into a visio shape
function add-visioobject ($mastObj, $item)
{
 		Write-Host "Adding $item"
		# Drop the selected stencil on the active page, with the coordinates x, y
  		$shpObj = $pagObj.Drop($mastObj, $x, $y)
		# Enter text for the object
		$shpObj.Text = $item
		#Return the visioobject to be used
		return $shpObj
 }

# Create an instance of Visio and create a document based on the Basic Diagram template.
$AppVisio = New-Object -ComObject Visio.Application
$docsObj = $AppVisio.Documents
#$DocObj = $docsObj.Add("Basic Diagram.vst")
$DocObj = $docsObj.Add("")

# Set the active page of the document to page 1
$pagsObj = $AppVisio.ActiveDocument.Pages
$pagObj = $pagsObj.Item(1)

# Connect to the NTNX Cluster
$NTNXCluster = Connect-NTNXCluster $NTNXCluster -AcceptInvalidSSLCerts 

# Load a set of stencils and select one to drop
$stnPath = (Get-Location).path
$stnObj = $AppVisio.Documents.Add($stnPath+"\"+$shpFile)
$HostNXObj = $stnObj.Masters.Item("NX")
$Host7Obj = $stnObj.Masters.Item("XC730")
$Host6Obj = $stnObj.Masters.Item("XC630")
$VMWObj = $stnObj.Masters.Item("VM Windows")
$VMLObj = $stnObj.Masters.Item("VM Linux")
$VMObj =  $stnObj.Masters.Item("VM")

# Load the default container shape
$stencil = $AppVisio.Documents.OpenEx($AppVisio.GetBuiltInStencilFile(2,1),64)
$container = $stencil.Masters.ItemFromID(2)

# Test if the Cluster exist
If ((Get-NTNXCluster) -ne $Null){
	# Get all the NTNX object required
	$Cluster = (Get-NTNXCluster)
	$NTNXHosts = (Get-NTNXHost)
	$NTNXVMs = (Get-NTNXVM | where {$_.vmName -notmatch "-CVM"})
	$NTNXSPs = (Get-NTNXStoragePool)
	$NTNXContainers = (Get-NTNXContainer)
	
	# Set Visio to its initial position
	$x = 0
	$y = 0
	
	# Create the container for the Cluster
	$boxCluster = $pagObj.Drop($container, $x ,$y)
	$boxCluster.Text = $Cluster.name

	# Add each of the host of the cluster into the container
	ForEach ($NTNXHost in $NTNXHosts)
	{
		if ($NTNXHost.blockModelName.contains("730") -eq $True)
		{
			$Object1 = add-visioobject $Host7Obj $NTNXHost.name
		}elseif ($NTNXHost.blockModelName.contains("630") -eq $True)
		{
			$Object1 = add-visioobject $Host6Obj $NTNXHost.name
		}else
		{
			$Object1 = add-visioobject $HostNXObj $NTNXHost.name
		}
		$boxCluster.containerProperties.AddMember($Object1,1)
		$hpv = $pagObj.DrawRectangle($x-0.7, $y+0.2, $x+0.7, $y+0.6)
		$hpv.CellsU("LinePattern").FormulaU = "0"
		if ($NTNXHost.hypervisorType.contains("kHyperv") -eq $True)
		{
			$hpv.Text = "Hyper-V"
			$hpv.CellsU("FillForegnd").FormulaU = "=RGB(75, 172, 198)"
		}elseif ($NTNXHost.hypervisorType.contains("kVMware") -eq $True)
		{
			$hpv.Text = "VMware"
			$hpv.CellsU("FillForegnd").FormulaU = "=RGB(255,192,0)"
		}elseif ($NTNXHost.hypervisorType.contains("KVM ") -eq $True)
		{
			$hpv.Text = "KVM"
			$hpv.CellsU("FillForegnd").FormulaU = "=RGB(157, 187, 97)"
		}else
		{
			$hpv.Text = "Acropolis"
			$hpv.CellsU("FillForegnd").FormulaU = "=RGB(192, 80, 70)"
		}
		$x = 0
		$y += 2.50
	}
	$boxCluster.resize(2,60,33)
	$y = 0
	$x = 1.6

	# Add each of the NTNXContainer of the cluster into the sheet (a rectangle)
	ForEach ($NTNXContainer in $NTNXContainers)
	{
		# Don't use a VisioContainer here because it breaks the layout
		$Cont = $pagObj.DrawRectangle($x, $y-1, $x+2, $y+(2.5*$NTNXHosts.count)-1.3)
		$Cont.CellsU("LinePattern").FormulaU = "16"
		$Cont.Text = $NTNXContainer.name +"
Max Capacity : " + [math]::truncate($NTNXContainer.maxCapacity / 1GB) + " GB
Usable Capacity : " + [math]::truncate(($NTNXContainer.maxCapacity/$NTNXContainer.replicationFactor) / 1GB) + " GB"
		$x += 2
	}
	
	# Add each of the VM of the cluster into a container by host
	ForEach ($NTNXHost in $NTNXHosts)
	{
		$x = 0.6 + (2*$NTNXContainer.count)
		$box = $pagObj.Drop($container, $x+$x ,$y)
		$box.Text = $NTNXHost.name
		ForEach ($NTNXVM in $NTNXVMs)
		{	
			# Test if the VM is hosted on the host
			if ($NTNXVM.hostName -eq $NTNXHost.name)
			{
				$x += 1.50
				# Check the OS type of the VM to assign a different logo
				$os = $NTNXVM.guestOperatingSystem
				If ($os.contains("Windows") -eq $True)
				{
					$Object2 = add-visioobject $VMWObj $NTNXVM.vmName
				}
				Elseif($os.contains("Linux") -eq $True)
				{
					$Object2 = add-visioobject $VMLObj $NTNXVM.vmName
				}
				Else
				{
					$Object2 = add-visioobject $VMObj $NTNXVM.vmName
				}
				$Object2.resize(1,50,33)
				# Add the VM into the right container
				$box.containerProperties.AddMember($Object2,1)
				$Object1 = $Object2
			}
		}
		$y += 2.50
	}
}

# Resize to fit page
$pagObj.ResizeToFitContents()

 

Short User Guide:

 

1) Visio 2013 needs to be installed

2) Download NTNX_Shape.vssx.

3) Copy the script and save as NTNXvision.ps1 in same folder as step 2. (if using Notepad make sure all file type is selected while saving file )

4) Download and install Nutanix Powershell cmdlets.

5) Double click Nutanix Powershell cmdlets  (NutanixCmdlets from desktop) to start PowerShell with NutanixCmdlets Module.

6) Change to directory as step 2.

7) Run .\NTNXvision.ps1

8) Enter your Nutanix Cluster hostname or IP Address.

9) Enter Prism username and password (admin/(your prism password))

10 ) Visio 2013 is automatically launched with your Nutanix Cluster Details.

(Thanks @farhanparkar for the guide Smiley Wink )

 

17 REPLIES
Community Manager

Re: Dynamically generate your Visio Diagram

Nice one, good luck!

Explorer

Re: Dynamically generate your Visio Diagram

looks great, keen to try it out, but where do you get the visio file NTNX_Shape.vssx ? the stencils link off nutanix.com doesn't contain the Dell nodes

Trailblazer

Re: Dynamically generate your Visio Diagram

Oops, my bad, I forgot to upload it...

Here is the link to retrieve the NTNX_Shape.vssx -> https://mega.nz/#!X9EV3CZY!6rISP_twYFHrBrmoatubfvR-hrSM44EuCmOb5KjY6J4

Voyager

Re: Dynamically generate your Visio Diagram

Link on Mega is not working. Is it only me?

Trailblazer

Re: Dynamically generate your Visio Diagram

I checked and the mega link is working fine for me.

 

Anyway, I've uploaded it on these others platforms:

Hope it'll work for you.

Voyager

Re: Dynamically generate your Visio Diagram

Perfect! Thanks a lot !!! Will try this asap!

Vanguard

Re: Dynamically generate your Visio Diagram

Hi tduval,

Nice script, appreciated for effort. I had tried the script and works perfect, only the password is displayed as plain text while entering. Nutanix has to update cmdlets to make password entry secure.

 

Short User Guide:

 

1) Visio 2013 is installed

2) Download NTNX_Shape.vssx.

3) Copy the script and save as NTNXvision.ps1 in same folder as step 2. (if using Notepad make sure all file type is selected while saving file )

4) Download and install Nutanix Powershell cmdlets.

5) Double click Nutanix Powershell cmdlets  (NutanixCmdlets from desktop) to start PowerShell with NutanixCmdlets Module.

6) Chnage to directory as step 2.

7) Run .\NTNXvision.ps1

8) Enter your Nutanix Cluster hostname or IP Address.

9) Enter Prism username and password (admin/(your prism password))

10 ) Visio 2013 is automatically launched with your Nutanix Cluster Details save the Visio file for your reference.

 

 

Credit goes to tduval.

 

 

Regards

vF.P

Trailblazer

Re: Dynamically generate your Visio Diagram

Incedible work, i love this script ;-)

 

One issue: The nodes are always drawn as Acropolis Hypervisors instead of ESXi 

 

THX Thomas

@Oppelman
Trailblazer

Re: Dynamically generate your Visio Diagram

Tanks @farhanparkar for your feedback and for the user guide, I've intergrated it to the original post.

 

@ThomasD, Sorry for that but you'll have to run this cmdlets on your NTNX cluster :

Get-NTNXHost | select name, hypervisorType

It will display the value I used into my if statements to determine the hypervisor type. As I have only Hyper-V node at work, I cannot know the other exact value for this fields.

By the way, if you have ESXi, KVM or even Acropolis nodes in your cluster, you should send me these values to update the script Smiley Happy