What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Can I use PRTG to find out if I have unregistered VM's in VCenter?

Votes:

0

Is it possible to find out if I have Zombie VM's on my Datastores with PRTG?

unregistered-vm vcenter vm-not-in-inventory vmware

Created on Jan 21, 2016 6:01:57 PM by  Greg Campion [Paessler Support]



1 Reply

Votes:

0

This article applies to PRTG Network Monitor 14 or later

Unregistered VM Sensor

With the following script, you can use PRTG to find out what .vmx files are on your datastore that aren't registered in VMWare. Knowing this can allow you to free up space on your datastore or register VM's that have fallen by the wayside.

Notes

  • You have to have the VMWare PowerCLI installed on the probe running this sensor
  • The probe service must be running with a PowerCLI enabled users' Credentials
  • Test this script in Powershell to see how long it takes to run and set up your sensor accordingly. I would recommend not more than once a day.
  • The parameters "-Cluster, -VCenterServer, -Username, -Password" must be set in the settings for this sensor or in the script itself for it to work but you can use some of the placeholders defined in the API under Custom Sensors to fill them out.
  • The parameter -datastores can be set if you only want to monitor a single datastore, if it is not set, the script will automatically query all of the datastores attached to the cluster.
param(
$Cluster,
$VCenterServer,
$datastores,
$Username,
$Password
)

$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$myCred    = New-Object System.Management.Automation.PSCredential ($Username, $secpasswd)

try {
    #Connect to VCenter Server
    connect-viserver $VCenterServer -Credential $myCred | Out-Null

    #Get Datastore names for all datastores on Cluster if no parameter defined
    if($datastores -eq $null)
        {
            $datastorelist = Get-cluster $Cluster | Get-Datastore | select name
            $datastores = $datastorelist | %{$_.name}
        } 
    
    $ESXHost = Get-Cluster $Cluster | Get-VMHost | select -First 1
 
    foreach($Datastore in Get-Datastore $datastores) {
      # Collect .vmx paths of registered VMs on the datastore. Credit to http://www.lucd.info/2011/08/11/vmx-raiders-revisited/
      $registered = @{}
      Get-VM -Datastore $Datastore | %{$_.Extensiondata.LayoutEx.File | where {$_.Name -like "*.vmx"} | %{$registered.Add($_.Name,$true)}}
 
       # Set up Search for .VMX Files in Datastore
      New-PSDrive -Name TgtDS -Location $Datastore -PSProvider VimDatastore -Root '\' | Out-Null
      $unregistered = @(Get-ChildItem -Path TgtDS: -Recurse | `
        where {$_.FolderPath -notmatch “.snapshot” -and $_.Name -like “*.vmx” -and !$registered.ContainsKey($_.DatastoreFullPath)})
      Remove-PSDrive -Name TgtDS
      }
 
       #write all .vmx Files as VMs on the datastore
       foreach($VMXFile in $unregistered) {
       $path = $VMXFile.DatastoreFullPath.split("/")[0]
        $lastmessage += "  $path;"
       }

    $vmxcount = $unregistered.Count
    write-host 
        "    
        <prtg>
        <result>
        <channel>Unregistered vmx files</channel>
        <value>$vmxcount</value>
        </result>
        <text>$lastmessage</text>
        </prtg>
        "

} catch {
    $errorcode =  $Error[0].Exception
    write-host
        "<prtg>
              <error>1</error>
              <text>$errorcode</text>
              </prtg>"
           
} finally {
    Disconnect-VIServer -Confirm:$false
}

Sensor Settings with Placeholders Screenshot

Sensor Settings Screenshot

Enlarge

Created on Jan 25, 2016 5:25:18 PM by  Greg Campion [Paessler Support]

Last change on Jan 25, 2016 5:27:20 PM by  Greg Campion [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.