LukaszL
Contributor
Contributor

Collect Problem VMs status

Dear all,

I need to create external report (every 5s, 1min) of all problem VMs (Agent Unreachable, Error, Provisioning Error, Already in Use etc).

Something similar to Horizon Dashboard (unfortunately I don't see this kind of dashboard in Horizon HTML5)

pastedImage_0.png
Where Horizon is storing this data ? ADAM,SQL?

Thx in advance!

Regards,
Lukasz

2 Replies
larstr
Champion
Champion

Lukasz,

Horizon 7 has a REST API, but it's currently undocumented, so I guess the easiest solution will be to use powercli:

HVImage6.jpg

I stole the pic above from virtu-al.net article "Getting started with Powercli 6.5 and Horizon View".

Lars

0 Kudos
Mickeybyte2
Hot Shot
Hot Shot

Lukasz,

I've created a PowerCLI script to get this information into our monitoring system of PRTG. Based on the following code and sample output, I hope you can get the necessary information to create your own script. Don't hesitate to ask any questions if somethings not clear.

Regards,

Michiel

The Script: HVProblemVMs.ps1

param (

    [string]$HVServer="your-horizon-connection-server",

    [string]$HVUser,

    [string]$HVPass

)

    Import-Module VMware.VimAutomation.Core

    Import-Module VMware.VimAutomation.HorizonView

    if ($HVUser -eq "" -or $HVPass -eq "") { $con = Connect-HVServer -Server $HVServer  }

    else { $con = Connect-HVServer -Server $HVServer -User $HVUser -Password $HVPass }

    $viewAPI = $Global:DefaultHVServers.ExtensionData

    $query_Service = New-Object "Vmware.Hv.QueryServiceService"

    $query = New-Object "Vmware.Hv.QueryDefinition"

    $query.QueryEntityType = 'MachineSummaryView'

    $HVState = @('PROVISIONING_ERROR',

                    'ERROR',

                    'AGENT_UNREACHABLE',

                    'AGENT_ERR_STARTUP_IN_PROGRESS',

                    'AGENT_ERR_DISABLED',

                    'AGENT_ERR_INVALID_IP',

                    'AGENT_ERR_NEED_REBOOT',

                    'AGENT_ERR_PROTOCOL_FAILURE',

                    'AGENT_ERR_DOMAIN_FAILURE',

                    'AGENT_CONFIG_ERROR',

                    'UNKNOWN',

                    'ALREADY_USED')

    [VMware.Hv.QueryFilter []] $filters = @()

    foreach ($filterstate in $HVState)

    {

        $filters += New-Object VMware.Hv.QueryFilterEquals -Property @{'memberName' = 'base.basicState'; 'value' = $filterstate}

    }

    $orFilter = new-object VMware.Hv.QueryFilterOr -Property @{'filters' = $filters}

    $query.Filter = $orFilter

    $VMs = $query_Service.QueryService_Query($viewAPI,$query)

    write-host "<prtg>"

    $total = $VMs.Results.Length

    write-host "  <result>"

    write-host "    <channel>Total problem vCenter VMs</channel>"

    write-host "    <value>$total</value>"

    write-host "    <unit>count</unit>"

    write-host "  </result>"

    foreach ($item in $filters)

    {

        $errorVMs = $VMs.Results.Base | where BasicState -eq $item.Value

        write-host "  <result>"

        write-host "    <channel>$($item.Value)</channel>"

        write-host "    <value>$($errorVMs.Length)</value>"

        write-host "    <unit>count</unit>"

        write-host "  </result>"

    }

           

    write-host "</prtg>"

    $con = Disconnect-HVServer -server $HVServer -Force -Confirm:$false

It outputs the following XML:

<prtg>

  <result>

    <channel>Total problem vCenter VMs</channel>

    <value>2</value>

    <unit>count</unit>

  </result>

  <result>

    <channel>PROVISIONING_ERROR</channel>

    <value>0</value>

    <unit>count</unit>

  </result>

  <result>

    <channel>ERROR</channel>

    <value>0</value>

    <unit>count</unit>

  </result>

  <result>

    <channel>AGENT_UNREACHABLE</channel>

    <value>2</value>

    <unit>count</unit>

  </result>

  <result>

    <channel>AGENT_ERR_STARTUP_IN_PROGRESS</channel>

    <value>0</value>

    <unit>count</unit>

  </result>

  <result>

    <channel>AGENT_ERR_DISABLED</channel>

    <value>0</value>

    <unit>count</unit>

  </result>

  <result>

    <channel>AGENT_ERR_INVALID_IP</channel>

    <value>0</value>

    <unit>count</unit>

  </result>

  <result>

    <channel>AGENT_ERR_NEED_REBOOT</channel>

    <value>0</value>

    <unit>count</unit>

  </result>

  <result>

    <channel>AGENT_ERR_PROTOCOL_FAILURE</channel>

    <value>0</value>

    <unit>count</unit>

  </result>

  <result>

    <channel>AGENT_ERR_DOMAIN_FAILURE</channel>

    <value>0</value>

    <unit>count</unit>

  </result>

  <result>

    <channel>AGENT_CONFIG_ERROR</channel>

    <value>0</value>

    <unit>count</unit>

  </result>

  <result>

    <channel>UNKNOWN</channel>

    <value>0</value>

    <unit>count</unit>

  </result>

  <result>

    <channel>ALREADY_USED</channel>

    <value>0</value>

    <unit>count</unit>

  </result>

</prtg>

Regards, Michiel.