Draft of powershell script to sync information between prtg, netbox, ilo/idrac and vcsa, just to show the main ideas.

If we from the beginning tried to link all systems by serial numbers of physical devices, for example esxi server has consistent serial number attribute in all systems like prtg (for example for this we can use prtg Tags), netbox, ilo/idrac and so on, then we can run queries and auto sync data between the systems without tiresome manually syncs (mandatory to check that entered serial numbers are unique and registered in all systems properly). When we initially normalize all systems by enriching each of them by proper serial numbers, then we can create programmatically (using for example powershell modules) integrity controls, for example comparing/matching data from DNS/DHCP, from IPAM, from Netbox, SystemCenter ConfMgr, Active Directory, VeeamBR and  so on to create email alerts/reminders/notifications and so on (for example to notify absence of the information in one of systems, mismatching information, wrong information and so on)

Below you can find the sample of the script, which reads information from netbox and prtg and writes it into custom attributes of esxi in vcsa ( considered that vcsa is named as  “vcsa.itforce.local”; netbox is named as “netbox.itforce.local”; prtg is named as “prtg.itforce.local”; esxi should be installed mandatory from customized image with support of ilo/idrac vibs) Considered that custom attributes are named as:

  • 0-hostname
  • 00-site
  • 01-rack
  • 02-rack-position
  • 03-serial-number
  • 04-netbox-device
  • 05-ilo-idrac
  • 06-prtg-link

Prerequisites:

  1. the computer “aaa” from which we can run the below script should have all needed network accesses to all systems like PRTG, Netbox, Vcsa and so on
  2. “aaa” should have installed powercli, installed prtgapi and powerbox powershell modules
  3. the below script can be placed into Scheduled Tasks (mandatory to tick “run with highest privileges”)

To pre-create custom attributes for each esxi in your vcsa:

connect-viserver vcsa.itforce.local
New-CustomAttribute -TargetType "vmhost" -Name "0-hostname"
New-CustomAttribute -TargetType "vmhost" -Name "00-site"
New-CustomAttribute -TargetType "vmhost" -Name "01-rack"
and so on
.'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'
connect-viserver vcsa.itforce.local

#replace "xxx", "yyy", "itforce\prtguser" by real secrets; replace all server names for prtg, netbox, vcsa and so on
$prtg_password_plaintext="xxx"
$netbox_api_token_key="yyy"
Import-Module prtgapi
$cred="itforce\prtguser"
$prtg_password = ConvertTo-SecureString -String $prtg_password_plaintext -AsPlainText -Force
$prtg_cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $cred,$prtg_password
connect-prtgserver -credential $prtg_cred -server prtg.itforce.local

import-module powerbox
$Pass = ConvertTo-SecureString -String $netbox_api_token_key -AsPlainText -Force
Connect-nbAPI -Token $Pass -APIurl http://netbox.itforce.local/api

$failed=$null
$vmhostserials= Get-VMHost |Select-Object Name,NetworkInfo,@{N="SerialNumber";E={(Get-VMHostHardware -vmhost $_).SerialNumber}}, @{ N="OutOfBandIP";E={(Get-VMHostWSManInstance -VMHost $_ -ignoreCertFailures -class OMC_IPMIIPProtocolEndpoint).IPv4Address}}


foreach ($item in $vmhostserials)
{
$fromnetbox=$null
$sn=$item.SerialNumber.trim()
$fromnetbox=Get-nbDevice -query @{serial=$sn}

$site=$fromnetbox.site
$rack=$fromnetbox.rack
$position=$fromnetbox.position
$netboxid=$fromnetbox.id
$iloidrac=$item.OutOfBandIP
$fqdn=$item.NetworkInfo
$netboxlink="http://netbox.itforce.local/dcim/devices/"+$netboxid+"/"

$site
$rack
$position
$sn
$netboxid
$iloidrac
$netboxlink

$fromprtg=get-device *$sn*
$prtgid=$fromprtg.id
$prtglink="https://prtg.itforce.local/device.htm?id="+$prtgid

$prtgid
$prtglink

Try {

if ($fqdn -ne ""){
get-vmhost $item.name | Set-Annotation -CustomAttribute "0-hostname" -Value $fqdn -ErrorAction Stop
}

if ($site -ne ""){
get-vmhost $item.name | Set-Annotation -CustomAttribute "00-site" -Value $site -ErrorAction Stop
}
if ($rack -ne ""){
get-vmhost $item.name | Set-Annotation -CustomAttribute "01-rack" -Value $rack -ErrorAction Stop
}
if ($position -ne ""){
get-vmhost $item.name | Set-Annotation -CustomAttribute "02-rack-position" -Value $position -ErrorAction Stop
}

get-vmhost $item.name | Set-Annotation -CustomAttribute "03-serial-number" -Value $sn -ErrorAction Stop

if ($netboxlink -ne ""){
get-vmhost $item.name | Set-Annotation -CustomAttribute "04-netbox-device" -Value $netboxlink -ErrorAction Stop
}

get-vmhost $item.name | Set-Annotation -CustomAttribute "05-ilo-idrac" -Value $iloidrac -ErrorAction Stop

if ($fromprtg.count -ne "0") 
{
get-vmhost $item.name | Set-Annotation -CustomAttribute "06-prtg-link" -Value $prtglink -ErrorAction Stop
}

}

catch 
{

$failed+=$item.vmhost.name
}


}


write-host "-----------------"
write-host "script failed for below esxi:"
write-host $failed

disconnect-viserver vcsa.itforce.local