VMware Cloud Community
Ziaad
Contributor
Contributor
Jump to solution

Workaround for Error in deserializing body of reply message for operation 'RetrieveProperties'

I am having trouble finding  the Get-VIEvent  equivalent in the vcenter   and vcenter server API.

Am I missing something?

Or is it not there, YET?

1 Solution

Accepted Solutions
Ziaad
Contributor
Contributor
Jump to solution

Thank you for your guidance, and also some of your previous scripts for capturing the event type.

As noted before, and on other posts and sites, that there are a few types of events that have the deserialization issue.

And those event types are:

    HostSpecificationRequireEvent

    HostSubSpecificationUpdateEvent

And I used the script made by you to capture the Events was:

$eventMgr = Get-View EventManager

$events = foreach($event in $eventMgr.Description.EventInfo){

  New-Object PSOBject -Property @{

    Key = $event.Key

    Category = $event.Category

    EventTypeId = &{

      If('ExtendedEvent','EventEx' -contains $event.Key){

        $event.FullFormat.Split('|')[0]

      }

      else{ $null}}

    Description = $event.Description

  }

}

___________________________________________________________________________

From there I pushed each event into a loop  and captured where the errors happened:

$servins= get-view serviceinstance

$evtmgr= get-view $servins.Content.EventManager

$longlisteventcapture = @()

$erroreventlist = @()

foreach($singleevent in ($events.key | Select -Unique)) {

## Clear Errors to capture only when error happens in loop instance ##

$error.clear()

$NewEventFilterSpec = New-Object VMware.Vim.EventFilterSpec

$NewEventFilterSpec.Type = "$singleevent"

[array]$newlistofevents = $evtmgr.QueryEvents($NewEventFilterSpec)

if ($error -ne $null) {Write-host "$singleevent error"; $erroreventlist += $singleevent}

Else {$longlisteventcapture += $newlistofevents}

}

_____________________________________________________________________________________

Now I have the workaround where  I just avoid the 2 bad event types:

foreach($singleevent in ($events.key | Where {$_ -notlike "*HostSpecificationRequireEvent*" -and $_ -notlike "*HostSubSpecificationUpdateEvent*"} | Select -Unique)) {

$error.clear()

$NewEventFilterSpec = New-Object VMware.Vim.EventFilterSpec

$NewEventFilterSpec.Type = "$singleevent"

[array]$newlistofevents = $evtmgr.QueryEvents($NewEventFilterSpec)

if ($error -ne $null) {Write-host "$singleevent error"; $erroreventlist += $singleevent}

Else {$longlisteventcapture += $newlistofevents}

}

________________________________________________________________________________________

Its much slower and somewhat more resource intensive than Get-VIEvent, but it works for now

Again Thank you for your help

View solution in original post

8 Replies
LucD
Leadership
Leadership
Jump to solution

Have a look at my Get-VIEventPlus function I introduced in Get The VMotion/SvMotion History


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Ziaad
Contributor
Contributor
Jump to solution

Hmm, thank you.

I apologize for this, but I am having a little difficulty making it out to convert it into a REST api call.

The actual reason I am even going there, is due to the Error in deserializing body of reply message for operation 'RetrieveProperties' problem/bug, for which I was having serious trouble finding a resolution in powercli for.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik there is no REST API yet to access the events.

You'll have the same issue when you use the SOAP API from PowerCLI.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Ziaad
Contributor
Contributor
Jump to solution

Thanks, 

Is there a method, work-around or fix for the deserialization problem by any chance? 

I mean I have come across something similar before, and it was a powershell json handling problem where if the json was too large and or too deep sometimes it wouldnt deserialize properly.

   

function ProcessLargeJSON-FromString ($datavariable) {

#use the $json.deserialize($variable,[system.object]) to capture data on object
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
$json = New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer
$json.MaxJsonLength = 104857600 #100mb as bytes, default is 2mb

if ($datavariable.GetType().name -eq 'string') {$datavariable = $json.Deserialize($datavariable,[System.Object])}

}

 

this is what I used to solve the problem back then, if it is related to large json handling maybe this can be used to fix the cmdlet(which truthfully I dont know how to)

function ProcessLargeJSON-FromString ($datavariable) {
 
#use the $json.deserialize($variable,[system.object]) to capture data on object
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
$json = New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer
$json.MaxJsonLength = 104857600 #100mb as bytes, default is 2mb
 
if ($datavariable.GetType().name -eq 'string') {$datavariable = $json.Deserialize($datavariable,[System.Object])}
 
}
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, it doesn't look to be a json handling issue.

The workaround, if you can call it that, is to explicitly specify the event types you want to retrieve in the EventFilterSpec.

With the huge number of events available, this might not be a practical solution though.

See also Error in deserializing body of reply message for operation 'ReadNextEvents'


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Ziaad
Contributor
Contributor
Jump to solution

Thanks.

I guess I am gonna have to figure out what we need as categories as then do them. Hopefully, the list of necessary event types doesn't include the HostSubSpecificationUpdateEvent or other ones that cause the same issue.

I have opened a Support request as well just in case. It seems to be a 6.5 API problem and can be also worked around by downgrading to PowerCLI 6.3 (which uses API 6.0 I presume). I might do that as well as a temporary solution, but the light modularity of PowerCLI 10 and ability to use it on low resource OS server Linux instances for monitoring was a major reason we wanted to use this.

Again, Thank you very much for your time.

If I get an update, if this is still left open, I will post it here.

Reply
0 Kudos
Ziaad
Contributor
Contributor
Jump to solution

Thank you for your guidance, and also some of your previous scripts for capturing the event type.

As noted before, and on other posts and sites, that there are a few types of events that have the deserialization issue.

And those event types are:

    HostSpecificationRequireEvent

    HostSubSpecificationUpdateEvent

And I used the script made by you to capture the Events was:

$eventMgr = Get-View EventManager

$events = foreach($event in $eventMgr.Description.EventInfo){

  New-Object PSOBject -Property @{

    Key = $event.Key

    Category = $event.Category

    EventTypeId = &{

      If('ExtendedEvent','EventEx' -contains $event.Key){

        $event.FullFormat.Split('|')[0]

      }

      else{ $null}}

    Description = $event.Description

  }

}

___________________________________________________________________________

From there I pushed each event into a loop  and captured where the errors happened:

$servins= get-view serviceinstance

$evtmgr= get-view $servins.Content.EventManager

$longlisteventcapture = @()

$erroreventlist = @()

foreach($singleevent in ($events.key | Select -Unique)) {

## Clear Errors to capture only when error happens in loop instance ##

$error.clear()

$NewEventFilterSpec = New-Object VMware.Vim.EventFilterSpec

$NewEventFilterSpec.Type = "$singleevent"

[array]$newlistofevents = $evtmgr.QueryEvents($NewEventFilterSpec)

if ($error -ne $null) {Write-host "$singleevent error"; $erroreventlist += $singleevent}

Else {$longlisteventcapture += $newlistofevents}

}

_____________________________________________________________________________________

Now I have the workaround where  I just avoid the 2 bad event types:

foreach($singleevent in ($events.key | Where {$_ -notlike "*HostSpecificationRequireEvent*" -and $_ -notlike "*HostSubSpecificationUpdateEvent*"} | Select -Unique)) {

$error.clear()

$NewEventFilterSpec = New-Object VMware.Vim.EventFilterSpec

$NewEventFilterSpec.Type = "$singleevent"

[array]$newlistofevents = $evtmgr.QueryEvents($NewEventFilterSpec)

if ($error -ne $null) {Write-host "$singleevent error"; $erroreventlist += $singleevent}

Else {$longlisteventcapture += $newlistofevents}

}

________________________________________________________________________________________

Its much slower and somewhat more resource intensive than Get-VIEvent, but it works for now

Again Thank you for your help

wilcodl
Contributor
Contributor
Jump to solution

Thanx Ziaad, your code works perfectly. I added the functionality to filter for an entity, here's the total code:


$vmhost = Get-VMHost vmhost1

$eventMgr = Get-View EventManager
$events = foreach ($event in $eventMgr.Description.EventInfo){
$EventTypeId = $null
if ('ExtendedEvent','EventEx' -contains $event.Key){
$EventTypeId = $event.FullFormat.Split('|')[0]
}
New-Object PSOBject -Property @{
Key = $event.Key
Category = $event.Category
EventTypeId = $EventTypeId
Description = $event.Description
}
}
$servins = get-view serviceinstance
$evtmgr = get-view $servins.Content.EventManager
$longlisteventcapture = @()
$erroreventlist = @()
$FilteredEvents = $events.key | Where-Object { $_ -notlike "*HostSpecificationRequireEvent*" -and $_ -notlike "*HostSubSpecificationUpdateEvent*" -and $_ -notlike "*HostSubSpecificationDeleteEvent*" } | Select-Object -Unique
foreach ($singleevent in $FilteredEvents) {
$error.clear()
$EventFilterSpecByEntity = New-Object VMware.Vim.EventFilterSpecByEntity
$EventFilterSpecByEntity.Entity = $vmhost.id
$NewEventFilterSpec = New-Object VMware.Vim.EventFilterSpec
$NewEventFilterSpec.Type = $singleevent
$NewEventFilterSpec.Entity = $EventFilterSpecByEntity
[array]$newlistofevents = $evtmgr.QueryEvents($NewEventFilterSpec)
if ($error -ne $null) {
Write-host "$singleevent error"; $erroreventlist += $singleevent
} else {
$longlisteventcapture += $newlistofevents
}
}
$longlisteventcapture

 

$vmhost = Get-VMHost vmhost1
 
 
$eventMgr = Get-View EventManager
 
$events = foreach ($event in $eventMgr.Description.EventInfo){
$EventTypeId = $null
if ('ExtendedEvent','EventEx' -contains $event.Key){
$EventTypeId = $event.FullFormat.Split('|')[0]
}
 
New-Object PSOBject -Property @{
Key = $event.Key
Category = $event.Category
EventTypeId = $EventTypeId
Description = $event.Description
}
}
 
$servins = get-view serviceinstance
$evtmgr = get-view $servins.Content.EventManager
$longlisteventcapture = @()
$erroreventlist = @()
 
$FilteredEvents = $events.key | Where-Object { $_ -notlike "*HostSpecificationRequireEvent*" -and $_ -notlike "*HostSubSpecificationUpdateEvent*" -and $_ -notlike "*HostSubSpecificationDeleteEvent*" } | Select-Object -Unique
 
foreach ($singleevent in $FilteredEvents) {
$error.clear()
 
$EventFilterSpecByEntity = New-Object VMware.Vim.EventFilterSpecByEntity
$EventFilterSpecByEntity.Entity = $vmhost.id
 
$NewEventFilterSpec = New-Object VMware.Vim.EventFilterSpec
$NewEventFilterSpec.Type = $singleevent
$NewEventFilterSpec.Entity = $EventFilterSpecByEntity
 
[array]$newlistofevents = $evtmgr.QueryEvents($NewEventFilterSpec)
 
if ($error -ne $null) {
Write-host "$singleevent error"; $erroreventlist += $singleevent
} else {
$longlisteventcapture += $newlistofevents
}
}
 
$longlisteventcapture
Reply
0 Kudos